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 run(self): """ Run the application. Returns: -------- Whether the application started successfully (i.e., without a veto). """ # Make sure the GUI has been created (so that, if required, the splash # screen is shown). gui = self.gui started = self.start() if started: app = get_app_qt4(['']) # Create windows from the default or saved application layout. self._create_windows() kernel = self.get_service(IPYTHON_KERNEL_PROTOCOL) kernel.init_ipkernel('qt4') app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()")) app.aboutToQuit.connect(kernel.cleanup_consoles) gui.set_trait_later(self, 'application_initialized', self) kernel.ipkernel.start() return started
def __init__(self, parent, html, scale_dx, scale_dy): """ Initializes the object. """ # Local import to avoid a WebKit dependency when one isn't needed. from pyface.qt import QtWebKit QtGui.QDialog.__init__(self, parent) layout = QtGui.QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) # Create the html control html_control = QtWebKit.QWebView() html_control.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) html_control.setHtml(html) layout.addWidget(html_control) # Create the OK button bbox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok, QtCore.Qt.Horizontal) QtCore.QObject.connect(bbox, QtCore.SIGNAL('accepted()'), self, QtCore.SLOT('accept()')) layout.addWidget(bbox) # Position and show the dialog position_window(self, parent=parent) self.show()
def _create_buttons(self, parent): """ Create the buttons at the bottom of the dialog box. We're overriding (and stealing code from) pyface.qt._create_buttons in order to add "Add tube.... " and "Add plate..." buttons. """ buttons = QtGui.QWidget() layout = QtGui.QHBoxLayout() btn_tube = QtGui.QPushButton("Add tubes...") layout.addWidget(btn_tube) QtCore.QObject.connect(btn_tube, QtCore.SIGNAL('clicked()'), self.handler._on_add_tubes) # btn_plate = QtGui.QPushButton("Add plate...") # layout.addWidget(btn_plate) # QtCore.QObject.connect(btn_plate, QtCore.SIGNAL('clicked()'), # self.handler._on_add_plate) btn_add_cond = QtGui.QPushButton("Add condition...") layout.addWidget(btn_add_cond) QtCore.QObject.connect(btn_add_cond, QtCore.SIGNAL('clicked()'), self.handler._on_add_condition) layout.addStretch() # 'OK' button. btn_ok = QtGui.QPushButton("OK") btn_ok.setDefault(True) layout.addWidget(btn_ok) QtCore.QObject.connect(btn_ok, QtCore.SIGNAL('clicked()'), self.control, QtCore.SLOT('accept()')) # 'Cancel' button. btn_cancel = QtGui.QPushButton("Cancel") layout.addWidget(btn_cancel) QtCore.QObject.connect(btn_cancel, QtCore.SIGNAL('clicked()'), self.control, QtCore.SLOT('reject()')) # add the button container to the widget buttons.setLayout(layout) return buttons
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 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 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, root, parent): """ Initialise the instance. """ QtGui.QTabBar.__init__(self, parent) # XXX this requires Qt > 4.5 if sys.platform == 'darwin': self.setDocumentMode(True) self._root = root self._drag_state = None # LineEdit to change tab bar title te = _IndependentLineEdit("", self) te.hide() te.connect(te, QtCore.SIGNAL('editingFinished()'), te, QtCore.SLOT('hide()')) self.connect(te, QtCore.SIGNAL('returnPressed()'), self._setCurrentTabText) self._title_edit = te
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 _create_buttons(self, parent): """ Create the buttons at the bottom of the dialog box. We're overriding (and stealing code from) pyface.qt._create_buttons in order to add "Add tube.... " and "Add plate..." buttons. """ buttons = QtGui.QWidget() #layout = QtGui.QHBoxLayout() layout = QtGui.QGridLayout() btn_add_tube = QtGui.QPushButton("Add tubes...") layout.addWidget(btn_add_tube, 0, 0) QtCore.QObject.connect(btn_add_tube, QtCore.SIGNAL('clicked()'), self.handler._on_add_tubes) btn_remove_tubes = QtGui.QPushButton("Remove tubes") layout.addWidget(btn_remove_tubes, 1, 0) QtCore.QObject.connect(btn_remove_tubes, QtCore.SIGNAL('clicked()'), self.handler._on_remove_tubes) btn_remove_tubes.setEnabled(len(self.model.tubes) > 0) self.handler.btn_remove_tubes = btn_remove_tubes # start disabled if there aren't any tubes in the model btn_add_cond = QtGui.QPushButton("Add condition...") layout.addWidget(btn_add_cond, 0, 1) QtCore.QObject.connect(btn_add_cond, QtCore.SIGNAL('clicked()'), self.handler._on_add_condition) btn_add_cond.setEnabled(len(self.model.tubes) > 0) self.handler.btn_add_cond = btn_add_cond btn_remove_cond = QtGui.QPushButton("Remove condition") layout.addWidget(btn_remove_cond, 1, 1) QtCore.QObject.connect(btn_remove_cond, QtCore.SIGNAL('clicked()'), self.handler._on_remove_condition) btn_remove_cond.setEnabled(len(self.model.tubes) > 0) self.handler.btn_remove_cond = btn_remove_cond layout.addItem(QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Maximum), 0, 2) layout.addItem(QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Maximum), 1, 2) #layout.addStretch() # 'OK' button. btn_ok = QtGui.QPushButton("OK") btn_ok.setDefault(True) layout.addWidget(btn_ok, 0, 3) QtCore.QObject.connect(btn_ok, QtCore.SIGNAL('clicked()'), self.control, QtCore.SLOT('accept()')) # 'Cancel' button. btn_cancel = QtGui.QPushButton("Cancel") layout.addWidget(btn_cancel, 0, 4) QtCore.QObject.connect(btn_cancel, QtCore.SIGNAL('clicked()'), self.control, QtCore.SLOT('reject()')) # add the button container to the widget buttons.setLayout(layout) return buttons