Esempio n. 1
0
class AddForm(QtGui.QWidget):
    def __init__(self, event_handler):
        super(AddForm, self).__init__(None)
        self.ui = Ui_addForm()
        self.ui.setupUi(self)
        self._event_handler = event_handler
        self._is_name_modified = False

        QtCore.QObject.connect(self.ui.ok_button, QtCore.SIGNAL("clicked()"), self._on_ok_button_clicked)
        QtCore.QObject.connect(self.ui.browse_button, QtCore.SIGNAL("clicked()"), self._on_browse_button_clicked)
        QtCore.QObject.connect(self.ui.name_edit, QtCore.SIGNAL("textChanged(QString)"), self._on_name_edit_textchanged)

    def show(self, name=''):
        self._is_name_modified = False if len(name)==0 else True
        self.ui.path_edit.clear()
        self.ui.name_edit.setText(name.decode('utf-8'))
        super(AddForm, self).show()

    def _on_ok_button_clicked(self):
        self._event_handler.on_add(unicode(self.ui.name_edit.text()).encode('utf-8'), unicode(self.ui.path_edit.text()).encode('utf-8'))
        self.close()

    def _on_browse_button_clicked(self):
        file_dialog = QtGui.QFileDialog()
        filepath = unicode(file_dialog.getOpenFileName())
        if len(filepath) != 0:
            filename = os.path.basename(filepath)
            self.ui.path_edit.setText(filepath)
            if not self._is_name_modified:
                self.ui.name_edit.setText(filename)

    def _on_name_edit_textchanged(self):
        self._is_name_modified = True
Esempio n. 2
0
    def __init__(self, event_handler):
        super(AddForm, self).__init__(None)
        self.ui = Ui_addForm()
        self.ui.setupUi(self)
        self._event_handler = event_handler
        self._is_name_modified = False

        QtCore.QObject.connect(self.ui.ok_button, QtCore.SIGNAL("clicked()"), self._on_ok_button_clicked)
        QtCore.QObject.connect(self.ui.browse_button, QtCore.SIGNAL("clicked()"), self._on_browse_button_clicked)
        QtCore.QObject.connect(self.ui.name_edit, QtCore.SIGNAL("textChanged(QString)"), self._on_name_edit_textchanged)