def create_dialog(self, parent, style): """Create the dialog control.""" self.control = control = _StickyDialog(self.ui, parent) view = self.ui.view control.setModal(style == BaseDialog.MODAL) control.setWindowTitle(view.title or DefaultTitle) QtCore.QObject.connect(control, QtCore.SIGNAL('finished(int)'), self._on_finished)
def close(self): # Don't fire signals for editors that have destroyed their controls. QtCore.QObject.disconnect(self._qt4_editor_area, QtCore.SIGNAL('hasFocus'), self._qt4_editor_focus) self._qt4_editor_area.clear() # Delete all dock widgets. for v in self.window.views: if self.contains_view(v): self._qt4_delete_view_dock_widget(v)
def _create_listbox(self, col, handler1, handler2, title): """Creates a list box. """ # Add the column title in emphasized text: title_widget = QtGui.QLabel(title) font = QtGui.QFont(title_widget.font()) font.setBold(True) font.setPointSize(font.pointSize() + 1) title_widget.setFont(font) self.root_layout.addWidget(title_widget, 0, col, QtCore.Qt.AlignLeft) # Create the list box and add it to the column: list = QtGui.QListWidget() list.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) self.root_layout.addWidget(list, 1, col) list.connect(list, QtCore.SIGNAL('itemClicked(QListWidgetItem *)'), handler1) list.connect(list, QtCore.SIGNAL('itemDoubleClicked(QListWidgetItem *)'), handler2) return list
def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ self.control = QtGui.QWidget() layout = QtGui.QHBoxLayout(self.control) layout.setContentsMargins(0, 0, 0, 0) self._file_name = control = QtGui.QLineEdit() layout.addWidget(control) if self.factory.auto_set: signal = QtCore.SIGNAL('textEdited(QString)') else: # Assume enter_set is set, or else the value will never get updated. signal = QtCore.SIGNAL('editingFinished()') QtCore.QObject.connect(control, signal, self.update_object) button = IconButton(QtGui.QStyle.SP_DirIcon, self.show_file_dialog) layout.addWidget(button) self.set_tooltip(control)
def create_initial_layout(self, parent): self._qt4_editor_area = editor_area = SplitTabWidget(parent) QtCore.QObject.connect(editor_area, QtCore.SIGNAL('hasFocus'), self._qt4_editor_focus) # We are interested in focus changes but we get them from the editor # area rather than qApp to allow the editor area to restrict them when # needed. QtCore.QObject.connect( editor_area, QtCore.SIGNAL('focusChanged(QWidget *,QWidget *)'), self._qt4_view_focus_changed) QtCore.QObject.connect(self._qt4_editor_area, QtCore.SIGNAL('tabTextChanged(QWidget *, QString)'), self._qt4_editor_title_changed) editor_area.new_window_request.connect(self._qt4_new_window_request) editor_area.tab_close_request.connect(self._qt4_tab_close_request) editor_area.tab_window_changed.connect(self._qt4_tab_window_changed) return editor_area
def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ super(ListEditor, self).init(parent) self.control = QtGui.QListWidget() QtCore.QObject.connect(self.control, QtCore.SIGNAL('currentTextChanged(QString)'), self.update_object) self.rebuild_editor() self.set_tooltip()
def _create_buttons(self, dialog, layout): """ Creates the buttons. """ if not (self.can_cancel or self.can_ok): return # Create the button. buttons = QtGui.QDialogButtonBox() if self.can_cancel: buttons.addButton(self.cancel_button_label, QtGui.QDialogButtonBox.RejectRole) if self.can_ok: buttons.addButton(QtGui.QDialogButtonBox.Ok) # TODO: hookup the buttons to our methods, this may involve subclassing from QDialog if self.can_cancel: buttons.connect(buttons, QtCore.SIGNAL('rejected()'), dialog, QtCore.SLOT('reject()')) if self.can_ok: buttons.connect(buttons, QtCore.SIGNAL('accepted()'), dialog, QtCore.SLOT('accept()')) layout.addWidget(buttons)
def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ self._uis = [] # Create a tab widget to hold each separate object's view: self.control = QtGui.QTabWidget() signal = QtCore.SIGNAL('currentChanged(int)') QtCore.QObject.connect(self.control, signal, self._tab_activated) # Create the button to close tabs, if necessary: if self.factory.deletable: button = QtGui.QToolButton() button.setAutoRaise(True) button.setToolTip('Remove current tab ') button.setIcon(ImageResource('closetab').create_icon()) self.control.setCornerWidget(button, QtCore.Qt.TopRightCorner) signal = QtCore.SIGNAL('clicked()') QtCore.QObject.connect(button, signal, self.close_current) self.close_button = button if self.factory.show_notebook_menu: # Create the necessary attributes to manage hiding and revealing of # tabs via a context menu self._context_menu = QtGui.QMenu() self.control.customContextMenuRequested.connect( self._context_menu_requested) self.control.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) # Set up the additional 'list items changed' event handler needed for # a list based trait: self.context_object.on_trait_change(self.update_editor_item, self.extended_name + '_items?', dispatch='ui') # Set of selection synchronization: self.sync_value(self.factory.selected, 'selected')
def setData(self, mi, value, role): """ Reimplmented to allow for modification for the object trait. """ if role != QtCore.Qt.EditRole: return False editor = self._editor obj, name = editor.object, editor.name row, column = mi.row(), mi.column() editor.adapter.set_text(obj, name, row, column, value) signal = QtCore.SIGNAL('dataChanged(QModelIndex,QModelIndex)') self.emit(signal, mi, mi) return True
def __init__(self, millisecs, callable, *args, **kw_args): """ Initialize instance to invoke the given `callable` with given arguments and keyword args after every `millisecs` (milliseconds). """ QtCore.QTimer.__init__(self) self.callable = callable self.args = args self.kw_args = kw_args self.connect(self, QtCore.SIGNAL('timeout()'), self.Notify) self._is_active = True self.start(millisecs)
def _create_buttons(self, parent): buttons = QtGui.QDialogButtonBox() # 'OK' button. if self.ok_label: btn = buttons.addButton(self.ok_label, QtGui.QDialogButtonBox.AcceptRole) else: btn = buttons.addButton(QtGui.QDialogButtonBox.Ok) btn.setDefault(True) QtCore.QObject.connect(btn, QtCore.SIGNAL('clicked()'), self.control, QtCore.SLOT('accept()')) # 'Cancel' button. if self.cancel_label: btn = buttons.addButton(self.cancel_label, QtGui.QDialogButtonBox.RejectRole) else: btn = buttons.addButton(QtGui.QDialogButtonBox.Cancel) QtCore.QObject.connect(btn, QtCore.SIGNAL('clicked()'), self.control, QtCore.SLOT('reject()')) # 'Help' button. # FIXME v3: In the original code the only possible hook into the help # was to reimplement self._on_help(). However this was a private # method. Obviously nobody uses the Help button. For the moment we # display it but can't actually use it. if len(self.help_id) > 0: if self.help_label: buttons.addButton(self.help_label, QtGui.QDialogButtonBox.HelpRole) else: buttons.addButton(QtGui.QDialogButtonBox.Help) return buttons
def _create_control(self, parent): dlg = QtGui.QDialog(parent) # Setting return code and firing close events is handled for 'modal' in # MDialog's open method. For 'nonmodal', we do it here. if self.style == 'nonmodal': QtCore.QObject.connect(dlg, QtCore.SIGNAL('finished(int)'), self._finished_fired) if self.size != (-1, -1): dlg.resize(*self.size) dlg.setWindowTitle(self.title) return dlg
def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ super(RadioEditor, self).init(parent) self.control = QtGui.QWidget() layout = QtGui.QGridLayout(self.control) layout.setContentsMargins(0, 0, 0, 0) self._mapper = QtCore.QSignalMapper() QtCore.QObject.connect(self._mapper, QtCore.SIGNAL('mapped(int)'), self.update_object) self.rebuild_editor()
def _focus_changed(self, old, new): """ Handle a change in focus that affects the current tab. """ # It is possible for the C++ layer of this object to be deleted between # the time when the focus change signal is emitted and time when the # slots are dispatched by the Qt event loop. This may be a bug in PyQt4. if qt_api == 'pyqt': import sip if sip.isdeleted(self): return if self._repeat_focus_changes: self.emit(QtCore.SIGNAL('focusChanged(QWidget *,QWidget *)'), old, new) if new is None: return elif isinstance(new, _DragableTabBar): ntw = new.parent() ntidx = ntw.currentIndex() else: ntw, ntidx = self._tab_widget_of(new) if ntw is not None: self._set_current_tab(ntw, ntidx) # See if the widget that has lost the focus is ours. otw, _ = self._tab_widget_of(old) if otw is not None or ntw is not None: if ntw is None: nw = None else: nw = ntw.widget(ntidx) self.emit(QtCore.SIGNAL('hasFocus'), nw)
def connectSlots(self): ''' connect buttons and functions ''' # quit app QtCore.QObject.connect(self.ui.quitButton, QtCore.SIGNAL('clicked()'), app.quit) # tab 1: general settings QtCore.QObject.connect(self.ui.spatialFnameButton, QtCore.SIGNAL('clicked()'), self.getSpatialFilename) QtCore.QObject.connect(self.ui.adjFnameButton, QtCore.SIGNAL('clicked()'), self.getAdjFilename) QtCore.QObject.connect(self.ui.skullFnameButton, QtCore.SIGNAL('clicked()'), self.getSkullFilename) QtCore.QObject.connect(self.ui.propsFnameButton, QtCore.SIGNAL('clicked()'), self.getPropsFilename) QtCore.QObject.connect(self.ui.brainLoad, QtCore.SIGNAL('clicked()'), self.loadBrain) QtCore.QObject.connect(self.ui.skullLoad, QtCore.SIGNAL('clicked()'), self.loadSkull) QtCore.QObject.connect(self.ui.skullPlot, QtCore.SIGNAL('clicked()'), self.plotSkull) QtCore.QObject.connect( self.ui.plotTree, QtCore.SIGNAL('itemClicked(QTreeWidgetItem*,int)'), self.setPlotValues) self.ui.opacitySlider.valueChanged.connect(self.setOpacity) self.ui.opacityBox.valueChanged.connect(self.setOpacityBox) self.ui.visibleCheckBox.clicked.connect(self.setVisibility) self.ui.redSlider.valueChanged.connect(self.setColourRed) self.ui.redValueBox.valueChanged.connect(self.setColourRedDial) self.ui.greenSlider.valueChanged.connect(self.setColourGreen) self.ui.greenValueBox.valueChanged.connect(self.setColourGreenDial) self.ui.blueSlider.valueChanged.connect(self.setColourBlue) self.ui.blueValueBox.valueChanged.connect(self.setColourBlueDial) self.ui.hlApplyButton.clicked.connect(self.makeHighlight) self.ui.propsLoad.clicked.connect(self.addProperties)
def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ self.control = QtWebKit.QWebView() self.control.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) if self.factory.open_externally: page = self.control.page() page.setLinkDelegationPolicy(QtWebKit.QWebPage.DelegateAllLinks) signal = QtCore.SIGNAL('linkClicked(QUrl)') QtCore.QObject.connect(page, signal, self._link_clicked) self.base_url = self.factory.base_url self.sync_value(self.factory.base_url_name, 'base_url', 'from')
def rebuild_editor(self): """ Rebuilds the contents of the editor whenever the original factory object's **values** trait changes. """ # Clear any existing content: self.clear_layout() # Get the current trait value: cur_name = self.str_value # Create a sizer to manage the radio buttons: names = self.names mapping = self.mapping n = len(names) cols = self.factory.cols rows = (n + cols - 1) / cols if self.row_major: incr = [1] * cols else: incr = [n / cols] * cols rem = n % cols for i in range(cols): incr[i] += (rem > i) incr[-1] = -(reduce(lambda x, y: x + y, incr[:-1], 0) - 1) # Add the set of all possible choices: layout = self.control.layout() index = 0 for i in range(rows): for j in range(cols): if n > 0: name = names[index] rb = self.create_button(name) rb.value = mapping[name] rb.setChecked(name == cur_name) QtCore.QObject.connect(rb, QtCore.SIGNAL('clicked()'), self._mapper, QtCore.SLOT('map()')) self._mapper.setMapping(rb, index) self.set_tooltip(rb) layout.addWidget(rb, i, j) index += incr[j] n -= 1
def init(self, parent): super(_FilterTabularEditor, self).init(parent) self.control.text.textChanged.connect(self.on_text_change) self.control.button.clicked.connect(self.on_action) self.proxyModel = proxyModel = QSortFilterProxyModel() proxyModel.setSourceModel(self.model) self.control.setModel(proxyModel) if self.factory.multi_select: slot = self._on_rows_selection else: slot = self._on_row_selection signal = 'selectionChanged(QItemSelection,QItemSelection)' QtCore.QObject.connect(self.control.selectionModel(), QtCore.SIGNAL(signal), slot)
def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ # FIXME: We ignore orientation, width_padding and height_padding. factory = self.factory btype = self._STYLE_MAP.get(factory.style, QtGui.QPushButton) self.control = btype() self.control.setText(self.string_value(factory.label)) if factory.image is not None: self.control.setIcon(factory.image.create_icon()) QtCore.QObject.connect(self.control, QtCore.SIGNAL('clicked()'), self.update_object) self.set_tooltip()
def rebuild_editor ( self ): """ Rebuilds the editor after its definition is modified. """ # Clear any existing content: self.clear_layout() cur_value = parse_value( self.value ) # Create a sizer to manage the radio buttons: labels = self.names values = self.values n = len( labels ) cols = self.factory.cols rows = (n + cols - 1) / cols incr = [ n / cols ] * cols rem = n % cols for i in range( cols ): incr[i] += (rem > i) incr[-1] = -(reduce( lambda x, y: x + y, incr[:-1], 0 ) - 1) # Add the set of all possible choices: layout = self.control.layout() index = 0 for i in range( rows ): for j in range( cols ): if n > 0: cb = QtGui.QCheckBox(labels[index]) cb.value = values[index] if cb.value in cur_value: cb.setCheckState(QtCore.Qt.Checked) else: cb.setCheckState(QtCore.Qt.Unchecked) QtCore.QObject.connect(cb, QtCore.SIGNAL('clicked()'), self._mapper, QtCore.SLOT('map()')) self._mapper.setMapping(cb, labels[index]) layout.addWidget(cb, i, j) index += incr[j] n -= 1
def __init__(self, sec_info_label, manager): # Needed when user pick the cylinder from visio and # we need to get the section self.cyl2sec = {} # Needed to update the value of a cyl bound to a section self.sec2cyl = {} self.seg2id = {} self.sec2coords = {} self.connections = [] self.n3dpoints_per_sec = {} self.selected_cyl = None # Used for storing the cyl when picked self.sec_info_label = sec_info_label # Info for the selected sec self.manager = manager container = QtGui.QWidget() container.setWindowTitle("Neuronvisio 3D") self.mayavi = MayaviQWidget(container) layout = QtGui.QVBoxLayout(container) layout.addWidget(self.mayavi) # Tell visual to use this as the viewer. #visual.set_viewer(self.mayavi.visualization.scene) # binding to hide event. container.connect(container, QtCore.SIGNAL('closeEvent()'), self.closeEvent) container.show() self.container = container # Connecting the picker. figure = self.mayavi.visualization.scene.mlab.gcf() self.outline = None self.picker = figure.on_mouse_pick(self.picker_callback, type='cell') # ScalarBar and time_point self.colorbar = None self.timelabel = None
def __init__(self, interval, callable, args, kw_args): QtCore.QTimer.__init__(self) global active_timers for timer in self.active_timers: if ((timer.callable == callable) and (timer.args == args) and (timer.kw_args == kw_args)): timer.start(interval) return self.active_timers.append(self) self.callable = callable self.args = args self.kw_args = kw_args self.connect(self, QtCore.SIGNAL('timeout()'), self.Notify) self.setSingleShot(True) self.start(interval)
def init(self, parent): self.control = QtGui.QTabBar() QtCore.QObject.connect(self.control, QtCore.SIGNAL('currentChanged(int)'), self._tab_activated) self.control.setDocumentMode(True) # Set up the additional 'list items changed' event handler needed for # a list based trait. Note that we want to fire the update_editor_item # only when the items in the list change and not when intermediate # traits change. Therefore, replace "." by ":" in the extended_name # when setting up the listener. extended_name = self.extended_name.replace('.', ':') self.context_object.on_trait_change(self.update_editor_item, extended_name + '_items?', dispatch='ui') # Set of selection synchronization: self.sync_value(self.factory.selected, 'selected')
def qt4_editor_factory(parent, editor, use_dir=False, *args): from pyface.qt import QtCore, QtGui from traitsui.qt4.helper import IconButton editor.control = panel = QtGui.QWidget() layout = QtGui.QHBoxLayout(panel) layout.setContentsMargins(0, 0, 0, 0) editor.use_dir = use_dir editor.text_control = text_control = QtGui.QLineEdit() layout.addWidget(text_control) signal = QtCore.SIGNAL('editingFinished()') QtCore.QObject.connect(text_control, signal, lambda: update_file_obj(editor)) button = IconButton(QtGui.QStyle.SP_DirIcon, lambda: button_click(editor)) layout.addWidget(button) return panel
def _create_contents(self, parent): label = QtGui.QLabel() if parent.parent() is not None: title = parent.parent().windowTitle() else: title = "" # Set the title. self.title = "About %s" % title # Load the image to be displayed in the about box. image = self.image.create_image() path = self.image.absolute_path # The additional strings. additions = '<br />'.join(self.additions) # Get the version numbers. py_version = sys.version[0:sys.version.find("(")] qt_version = QtCore.__version__ # Set the page contents. label.setText(_DIALOG_TEXT % (path, additions, py_version, qt_version)) # Create the button. buttons = QtGui.QDialogButtonBox() if self.ok_label: buttons.addButton(self.ok_label, QtGui.QDialogButtonBox.AcceptRole) else: buttons.addButton(QtGui.QDialogButtonBox.Ok) buttons.connect(buttons, QtCore.SIGNAL('accepted()'), parent, QtCore.SLOT('accept()')) lay = QtGui.QVBoxLayout() lay.addWidget(label) lay.addWidget(buttons) parent.setLayout(lay)
def eventFilter(self, obj, event): """ Reimplemented to trap key presses. """ if ( self.__editor.control and obj == self.__editor.control and event.type() == QtCore.QEvent.FocusOut ): # Hack for Traits UI compatibility. self.__editor.control.emit(QtCore.SIGNAL("lostFocus")) elif ( self.__editor.control and obj == self.__editor.control.code and event.type() == QtCore.QEvent.KeyPress ): # Pyface doesn't seem to be Unicode aware. Only keep the key code # if it corresponds to a single Latin1 character. kstr = event.text() try: kcode = ord(str(kstr)) except: kcode = 0 mods = event.modifiers() self.key_pressed = KeyPressedEvent( alt_down=( (mods & QtCore.Qt.AltModifier) == QtCore.Qt.AltModifier ), control_down=( (mods & QtCore.Qt.ControlModifier) == QtCore.Qt.ControlModifier ), shift_down=( (mods & QtCore.Qt.ShiftModifier) == QtCore.Qt.ShiftModifier ), key_code=kcode, event=event, ) return super(PythonEditorEventFilter, self).eventFilter(obj, event)
def loadBrain(self): ''' load a brain using given filenames ''' self.ui.adjPlot.setEnabled(False) # get adjacency filename adj = str(self.ui.adjFilename.text()) # get threshold thType, thVal = self.getThresholdType() # get spatial info file coords = str(self.ui.spatialFilename.text()) # make name for brain brName, brainUsedBool = self.findBrainName() self.currentBrainName = brName # create and add to list of brains if brainUsedBool: # case where brain name exists already br = self.brains[brName] else: # make a new brain br = mb.brainObj() # add properties br.importAdjFile(adj) br.importSpatialInfo(coords) br.applyThreshold(thresholdType = thType, value = thVal) self.brains[brName] = br # add to brains selected for highlighting if not(brainUsedBool): self.ui.brainSelect.addItem(brName) # enable plot button # try: # QtCore.QObject.disconnect(self.ui.adjPlot, QtCore.SIGNAL('clicked()'), self.rePlotBrain) # except: # pass QtCore.QObject.connect(self.ui.adjPlot, QtCore.SIGNAL('clicked()'), self.plotBrain) self.ui.adjPlot.setEnabled(True)
def add_button(self, action, bbox, role, method=None, enabled=True, name=None, default=False): """ Creates a button. """ ui = self.ui if ((action.defined_when != '') and (not ui.eval_when(action.defined_when))): return None if name is None: name = action.name id = action.id button = bbox.addButton(name, role) button.setAutoDefault(False) button.setDefault(default) button.setEnabled(enabled) if (method is None) or (action.enabled_when != '') or (id != ''): editor = ButtonEditor(ui=ui, action=action, control=button) if id != '': ui.info.bind(id, editor) if action.visible_when != '': ui.add_visible(action.visible_when, editor) if action.enabled_when != '': ui.add_enabled(action.enabled_when, editor) if method is None: method = editor.perform if method is not None: button.connect(button, QtCore.SIGNAL('clicked()'), method) if action.tooltip != '': button.setToolTip(action.tooltip) return button
def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ self.icon = QtGui.QIcon(self.factory.filename) if self.factory.toggle_filename: self.toggled_icon = QtGui.QIcon(self.factory.toggle_filename) if self.factory.toggle_label != '': self.toggle_label = self.factory.toggle_label else: self.toggle_label = self.factory.label if self.factory.toggle_tooltip != '': self.toggle_tooltip = self.factory.toggle_tooltip else: self.toggle_tooltip = self.factory.tooltip control = self.control = QtGui.QToolButton() control.setAutoRaise(True) control.setIcon(self.icon) control.setText(self.factory.label) control.setIconSize( QtCore.QSize(self.factory.width, self.factory.height)) if self.factory.label: control.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon) else: control.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly) if self.factory.toggle: control.setCheckable(True) control.toggled.connect(self._toggle_button) QtCore.QObject.connect(control, QtCore.SIGNAL('clicked()'), self.update_object) if self.factory.tooltip: control.setToolTip(self.factory.tooltip) else: self.set_tooltip()
def init(self, parent): self.icon_on = QtGui.QIcon(self.factory.image_on.absolute_path) self.icon_off = QtGui.QIcon(self.factory.image_off.absolute_path) control = self.control = QtGui.QPushButton() # control.setAutoRaise(True) control.setIcon(self.icon_on) # control.setIconSize(QtCore.QSize(self.factory.width, self.factory.height)) self.tooltip_on = self.factory.tooltip_on self.tooltip_off = self.factory.tooltip_off control.setToolTip(self.tooltip_on) control.setCheckable(True) control.toggled.connect(self._toggle_button) # if self.factory.label: # control.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon) # else: # control.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly) QtCore.QObject.connect(control, QtCore.SIGNAL('clicked()'), self.update_object)