Source code for camelot.view.controls.editors.localfileeditor
# ============================================================================
#
# Copyright (C) 2007-2011 Conceptive Engineering bvba. All rights reserved.
# www.conceptive.be / project-camelot@conceptive.be
#
# This file is part of the Camelot Library.
#
# This file may be used under the terms of the GNU General Public
# License version 2.0 as published by the Free Software Foundation
# and appearing in the file license.txt included in the packaging of
# this file. Please review this information to ensure GNU
# General Public Licensing requirements will be met.
#
# If you are unsure which license is appropriate for your use, please
# visit www.python-camelot.com or contact project-camelot@conceptive.be
#
# This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
# WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# For use of this library in commercial applications, please contact
# project-camelot@conceptive.be
#
# ============================================================================
import os.path
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import Qt
from customeditor import CustomEditor, set_background_color_palette
from camelot.view.art import Icon
from camelot.core.utils import ugettext as _
from camelot.view.controls.decorated_line_edit import DecoratedLineEdit
[docs]class LocalFileEditor(CustomEditor):
"""Widget for browsing local files and directories"""
browse_icon = Icon( 'tango/16x16/places/folder-saved-search.png' )
def __init__(self,
parent = None,
field_name = 'local_file',
directory = False,
save_as = False,
file_filter = 'All files (*)',
**kwargs):
CustomEditor.__init__(self, parent)
self.setObjectName( field_name )
self._directory = directory
self._save_as = save_as
self._file_filter = file_filter
self.setup_widget()
@QtCore.pyqtSlot()
[docs] def filename_editing_finished(self):
self.editingFinished.emit()
@QtCore.pyqtSlot()
[docs] def set_value(self, value):
value = CustomEditor.set_value(self, value)
if value:
self.filename.setText( value )
else:
self.filename.setText( '' )
return value
[docs] def get_value(self):
return CustomEditor.get_value(self) or unicode( self.filename.text() )
[docs] def set_field_attributes( self,
editable = True,
background_color = None,
tooltip = None,
**kwargs):
self.setEnabled( editable )
if self.filename:
set_background_color_palette( self.filename, background_color )
self.filename.setToolTip(unicode(tooltip or ''))