def build_widget(self): layout = QtGui.QVBoxLayout() layout.setMargin(4) layout.setSpacing(2) self.searchBox = QSearchBox(True, False, self) layout.addWidget(self.searchBox) options_layout = QtGui.QHBoxLayout() options_layout.setSpacing(5) options_layout.setAlignment(QtCore.Qt.AlignLeft) options_layout.addWidget(QtGui.QLabel("Search:")) searchAll = QtGui.QRadioButton("Open Vistrails") searchCurrent = QtGui.QRadioButton("Current Vistrail") searchWorkflow = QtGui.QRadioButton("Current Workflow") useRegex = QtGui.QCheckBox("Regular expression") self.level_group = QtGui.QButtonGroup() self.level_group.addButton(searchAll) self.level_group.addButton(searchCurrent) self.level_group.addButton(searchWorkflow) self.level_map = \ Bidict([(QueryController.LEVEL_ALL, searchAll), (QueryController.LEVEL_VISTRAIL, searchCurrent), (QueryController.LEVEL_WORKFLOW, searchWorkflow)]) options_layout.addWidget(searchAll) options_layout.addWidget(searchCurrent) options_layout.addWidget(searchWorkflow) options_layout.addWidget(useRegex) searchCurrent.setChecked(True) self.editButton = QtGui.QPushButton("Edit") self.editButton.setEnabled(False) self.backButton = QtGui.QPushButton("Back to Search") self.backButton.setEnabled(False) options_layout.addStretch(1) options_layout.addWidget(self.editButton, 0, QtCore.Qt.AlignRight) options_layout.addWidget(self.backButton, 0, QtCore.Qt.AlignRight) layout.addLayout(options_layout) self.setLayout(layout) self.connect(self.searchBox, QtCore.SIGNAL('resetSearch()'), self.resetSearch) self.connect(self.searchBox, QtCore.SIGNAL('executeSearch(QString)'), self.executeSearch) self.connect(self.searchBox, QtCore.SIGNAL('refineMode(bool)'), self.refineMode) self.connect(self.backButton, QtCore.SIGNAL('clicked()'), self.backToSearch) self.connect(self.editButton, QtCore.SIGNAL('clicked()'), self.doEdit) self.connect(self.level_group, QtCore.SIGNAL('buttonClicked(QAbstractButton*)'), self.levelChanged) self.connect(useRegex, QtCore.SIGNAL('stateChanged(int)'), self.useRegexChanged)
def build_gui(self, path_type): layout = QtGui.QVBoxLayout() self.search_ref = QSearchBox(False, False) self.connect(self.search_ref, QtCore.SIGNAL('executeSearch(QString)'), self.search_string) self.connect(self.search_ref, QtCore.SIGNAL('resetSearch()'), self.reset_search) layout.addWidget(self.search_ref) self.ref_widget = PersistentRefView(path_type, self) layout.addWidget(self.ref_widget) layout.setMargin(0) self.setLayout(layout)
class QQueryBox(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.build_widget() self.controller = None def set_controller(self, controller=None): self.controller = controller def build_widget(self): layout = QtGui.QVBoxLayout() layout.setMargin(4) layout.setSpacing(2) self.searchBox = QSearchBox(True, False, self) layout.addWidget(self.searchBox) options_layout = QtGui.QHBoxLayout() options_layout.setSpacing(5) options_layout.setAlignment(QtCore.Qt.AlignLeft) options_layout.addWidget(QtGui.QLabel("Search:")) searchAll = QtGui.QRadioButton("Open Vistrails") searchCurrent = QtGui.QRadioButton("Current Vistrail") searchWorkflow = QtGui.QRadioButton("Current Workflow") useRegex = QtGui.QCheckBox("Regular expression") self.level_group = QtGui.QButtonGroup() self.level_group.addButton(searchAll) self.level_group.addButton(searchCurrent) self.level_group.addButton(searchWorkflow) self.level_map = \ Bidict([(QueryController.LEVEL_ALL, searchAll), (QueryController.LEVEL_VISTRAIL, searchCurrent), (QueryController.LEVEL_WORKFLOW, searchWorkflow)]) options_layout.addWidget(searchAll) options_layout.addWidget(searchCurrent) options_layout.addWidget(searchWorkflow) options_layout.addWidget(useRegex) searchCurrent.setChecked(True) self.editButton = QtGui.QPushButton("Edit") self.editButton.setEnabled(False) self.backButton = QtGui.QPushButton("Back to Search") self.backButton.setEnabled(False) options_layout.addStretch(1) options_layout.addWidget(self.editButton, 0, QtCore.Qt.AlignRight) options_layout.addWidget(self.backButton, 0, QtCore.Qt.AlignRight) layout.addLayout(options_layout) self.setLayout(layout) self.connect(self.searchBox, QtCore.SIGNAL('resetSearch()'), self.resetSearch) self.connect(self.searchBox, QtCore.SIGNAL('executeSearch(QString)'), self.executeSearch) self.connect(self.searchBox, QtCore.SIGNAL('refineMode(bool)'), self.refineMode) self.connect(self.backButton, QtCore.SIGNAL('clicked()'), self.backToSearch) self.connect(self.editButton, QtCore.SIGNAL('clicked()'), self.doEdit) self.connect(self.level_group, QtCore.SIGNAL('buttonClicked(QAbstractButton*)'), self.levelChanged) self.connect(useRegex, QtCore.SIGNAL('stateChanged(int)'), self.useRegexChanged) def resetSearch(self, emit_signal=True): """ resetSearch() -> None """ if self.controller and emit_signal: self.controller.reset_search() self.emit(QtCore.SIGNAL('textQueryChange(bool)'), False) else: self.searchBox.clearSearch() def backToSearch(self): if self.controller: self.controller.back_to_search() def doEdit(self): if self.controller: self.controller.goto_edit() def levelChanged(self, button): self.controller.set_level(self.level_map.inverse[button]) def useRegexChanged(self, status): self.controller.set_use_regex(status != QtCore.Qt.Unchecked) def setLevel(self, level): self.level_map[level].setChecked(True) def executeSearch(self, text): """ executeSearch(text: QString) -> None """ s = str(text) if self.controller: try: self.controller.run_search(s) except re.error as e: debug.critical('Error in regular expression: %s' % str(e)) # try: # search = CombinedSearch(s, # search = SearchCompiler(s).searchStmt # except SearchParseError, e: # debug.warning("Search Parse Error", e) # search = None # self.controller.set_search(search, s) # self.emit(QtCore.SIGNAL('textQueryChange(bool)'), s!='') def refineMode(self, on): """ refineMode(on: bool) -> None """ if self.controller: self.controller.set_refine(on) def getCurrentText(self): return self.searchBox.getCurrentText() def setManualResetEnabled(self, boolVal): self.searchBox.setManualResetEnabled(boolVal)
class QQueryBox(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.build_widget() self.controller = None def set_controller(self, controller=None): self.controller = controller def build_widget(self): layout = QtGui.QVBoxLayout() layout.setMargin(4) layout.setSpacing(2) self.searchBox = QSearchBox(True, False, self) layout.addWidget(self.searchBox) radio_layout = QtGui.QHBoxLayout() radio_layout.setSpacing(5) radio_layout.setAlignment(QtCore.Qt.AlignLeft) radio_layout.addWidget(QtGui.QLabel("Search:")) searchAll = QtGui.QRadioButton("Open Vistrails") searchCurrent = QtGui.QRadioButton("Current Vistrail") searchWorkflow = QtGui.QRadioButton("Current Workflow") self.level_group = QtGui.QButtonGroup() self.level_group.addButton(searchAll) self.level_group.addButton(searchCurrent) self.level_group.addButton(searchWorkflow) self.level_map = \ Bidict([(QueryController.LEVEL_ALL, searchAll), (QueryController.LEVEL_VISTRAIL, searchCurrent), (QueryController.LEVEL_WORKFLOW, searchWorkflow)]) radio_layout.addWidget(searchAll) radio_layout.addWidget(searchCurrent) radio_layout.addWidget(searchWorkflow) searchCurrent.setChecked(True) self.editButton = QtGui.QPushButton("Edit") self.editButton.setEnabled(False) self.backButton = QtGui.QPushButton("Back to Search") self.backButton.setEnabled(False) radio_layout.addStretch(1) radio_layout.addWidget(self.editButton, 0, QtCore.Qt.AlignRight) radio_layout.addWidget(self.backButton, 0, QtCore.Qt.AlignRight) layout.addLayout(radio_layout) self.setLayout(layout) self.connect(self.searchBox, QtCore.SIGNAL('resetSearch()'), self.resetSearch) self.connect(self.searchBox, QtCore.SIGNAL('executeSearch(QString)'), self.executeSearch) self.connect(self.searchBox, QtCore.SIGNAL('refineMode(bool)'), self.refineMode) self.connect(self.backButton, QtCore.SIGNAL('clicked()'), self.backToSearch) self.connect(self.editButton, QtCore.SIGNAL('clicked()'), self.doEdit) self.connect(self.level_group, QtCore.SIGNAL('buttonClicked(QAbstractButton*)'), self.levelChanged) def resetSearch(self, emit_signal=True): """ resetSearch() -> None """ if self.controller and emit_signal: self.controller.reset_search() self.emit(QtCore.SIGNAL('textQueryChange(bool)'), False) else: self.searchBox.clearSearch() def backToSearch(self): if self.controller: self.controller.back_to_search() def doEdit(self): if self.controller: self.controller.goto_edit() def levelChanged(self, button): self.controller.set_level(self.level_map.inverse[button]) def setLevel(self, level): self.level_map[level].setChecked(True) def executeSearch(self, text): """ executeSearch(text: QString) -> None """ s = str(text) if self.controller: self.controller.run_search(s) # try: # search = CombinedSearch(s, # search = SearchCompiler(s).searchStmt # except SearchParseError, e: # debug.warning("Search Parse Error", str(e)) # search = None # self.controller.set_search(search, s) # self.emit(QtCore.SIGNAL('textQueryChange(bool)'), s!='') def refineMode(self, on): """ refineMode(on: bool) -> None """ if self.controller: self.controller.set_refine(on) def getCurrentText(self): return self.searchBox.getCurrentText() def setManualResetEnabled(self, boolVal): self.searchBox.setManualResetEnabled(boolVal)
def __init__(self, param, parent=None): QtGui.QDialog.__init__(self, parent) # two tabs, one for starting from managed, one for local file # options are set accordingly # uuid assigned when options are set, either new or existing # don't compute uuid for local file that hasn't been run # need PersistentReference parameter # allow user to pass contents in to PersistentRef self.setWindowTitle("Configure Persistent Reference...") self.settings = { 'ref_id': None, 'ref_version': None, 'local_path': None, 'versioning': False, 'local_read_priority': True, 'write_back': True } self.current_file = "" db_file = "/vistrails/managed/files.db" layout = QtGui.QVBoxLayout() managed_group = QtGui.QGroupBox("Persistent Data") managed_layout = QtGui.QVBoxLayout() search = QSearchBox(False, False) def keyPressEvent(obj, e): print "got to key press event", e.key() if e.key() in (QtCore.Qt.Key_Return, QtCore.Qt.Key_Enter): if obj.currentText(): obj.emit(QtCore.SIGNAL('executeSearch(QString)'), obj.searchEdit.currentText()) else: obj.emit(QtCore.SIGNAL('resetSearch()')) QtGui.QComboBox.keyPressEvent(obj, e) print 'keyPressEvent:', search.searchEdit.keyPressEvent search.searchEdit.keyPressEvent = keyPressEvent print 'keyPressEvent:', search.searchEdit.keyPressEvent self.connect(search, QtCore.SIGNAL('executeSearch(QString)'), self.search_string) self.connect(search, QtCore.SIGNAL('resetSearch()'), self.reset_search) managed_layout.addWidget(search) self.table = PersistentRefView(db_file, self) managed_layout.addWidget(self.table) managed_group.setLayout(managed_layout) layout.addWidget(managed_group) local_group = QtGui.QGroupBox("Local Data") local_layout = QtGui.QHBoxLayout() self.filename_edit = QtGui.QLineEdit() local_layout.addWidget(self.filename_edit) filename_button = QtGui.QToolButton() filename_button.setIcon( QtGui.QIcon(filename_button.style().standardPixmap( QtGui.QStyle.SP_DirOpenIcon))) filename_button.setIconSize(QtCore.QSize(12, 12)) filename_button.connect(filename_button, QtCore.SIGNAL('clicked()'), self.choose_file) local_layout.addWidget(filename_button) local_group.setLayout(local_layout) layout.addWidget(local_group) pref_layout = QtGui.QHBoxLayout() version_group = QtGui.QGroupBox("Versioning") version_layout = QtGui.QVBoxLayout() version_off = QtGui.QRadioButton("Create New ID") version_layout.addWidget(version_off) version_on = QtGui.QRadioButton("Create New Version") version_layout.addWidget(version_on) version_group.setLayout(version_layout) pref_layout.addWidget(version_group) r_priority_group = QtGui.QGroupBox("Read Priority") r_priority_layout = QtGui.QVBoxLayout() r_priority_off = QtGui.QRadioButton("Local") r_priority_layout.addWidget(r_priority_off) r_priority_on = QtGui.QRadioButton("Persistent Store") r_priority_layout.addWidget(r_priority_on) r_priority_group.setLayout(r_priority_layout) pref_layout.addWidget(r_priority_group) w_priority_group = QtGui.QGroupBox("Write Priority") w_priority_layout = QtGui.QVBoxLayout() w_priority_off = QtGui.QRadioButton("Local") w_priority_layout.addWidget(w_priority_off) w_priority_on = QtGui.QRadioButton("Persistent Store") w_priority_layout.addWidget(w_priority_on) w_priority_group.setLayout(w_priority_layout) pref_layout.addWidget(w_priority_group) layout.addLayout(pref_layout) button_layout = QtGui.QHBoxLayout() button_layout.setDirection(QtGui.QBoxLayout.RightToLeft) button_layout.setAlignment(QtCore.Qt.AlignRight) ok_button = QtGui.QPushButton("OK") ok_button.setFixedWidth(100) self.connect(ok_button, QtCore.SIGNAL('clicked()'), self.close) button_layout.addWidget(ok_button) cancel_button = QtGui.QPushButton("Cancel") cancel_button.setFixedWidth(100) self.connect(cancel_button, QtCore.SIGNAL('clicked()'), self.cancel) button_layout.addWidget(cancel_button) layout.addLayout(button_layout) self.setLayout(layout)