def createLayerToolbar(self): """ TOWRITE """ toolbarLayer = self.toolbarLayer actionHash = self.actionHash layerSelector = self.layerSelector qDebug("MainWindow createLayerToolbar()") toolbarLayer.setObjectName("toolbarLayer") toolbarLayer.addAction(actionHash["ACTION_makelayercurrent"]) toolbarLayer.addAction(actionHash["ACTION_layers"]) icontheme = self.getSettingsGeneralIconTheme() # QString layerSelector.setFocusProxy(self.prompt) # NOTE: Qt4.7 wont load icons without an extension... # TODO: Create layer pixmaps by concatenating several icons layerSelector.addItem(QIcon("icons/" + icontheme + "/" + "linetypebylayer" + ".png"), "0") layerSelector.addItem(QIcon("icons/" + icontheme + "/" + "linetypebylayer" + ".png"), "1") layerSelector.addItem(QIcon("icons/" + icontheme + "/" + "linetypebylayer" + ".png"), "2") layerSelector.addItem(QIcon("icons/" + icontheme + "/" + "linetypebylayer" + ".png"), "3") layerSelector.addItem(QIcon("icons/" + icontheme + "/" + "linetypebylayer" + ".png"), "4") layerSelector.addItem(QIcon("icons/" + icontheme + "/" + "linetypebylayer" + ".png"), "5") layerSelector.addItem(QIcon("icons/" + icontheme + "/" + "linetypebylayer" + ".png"), "6") layerSelector.addItem(QIcon("icons/" + icontheme + "/" + "linetypebylayer" + ".png"), "7") layerSelector.addItem(QIcon("icons/" + icontheme + "/" + "linetypebylayer" + ".png"), "8") layerSelector.addItem(QIcon("icons/" + icontheme + "/" + "linetypebylayer" + ".png"), "9") toolbarLayer.addWidget(layerSelector) self.connect(layerSelector, SIGNAL("currentIndexChanged(int)"), self, SLOT("layerSelectorIndexChanged(int)")) toolbarLayer.addAction(actionHash["ACTION_layerprevious"]) self.connect(toolbarLayer, SIGNAL("topLevelChanged(bool)"), self, SLOT("floatingChangedToolBar(bool)"))
def selectAllEstimation(self, doSelect): self.emit(SIGNAL("layoutAboutToBeChanged()")) for key in self.paramToEstimateMap.keys(): self.paramToEstimateMap[key] = doSelect self.emit(SIGNAL("layoutChanged()"))
def _connect_widgets(self): # connect object selection Qt.QtCore.QObject.connect( self._tree_widget.view.selectionModel(), SIGNAL("currentChanged(QModelIndex, QModelIndex)"), self._tree_current_changed ) Qt.QtCore.QObject.connect( self._tree_widget.view.selectionModel(), SIGNAL("selectionChanged(QItemSelection, QItemSelection)"), self._tree_selection_changed ) return # TODO! # connect property selection Qt.QtCore.QObject.connect( self._property_widget.property_view.selectionModel(), SIGNAL("currentChanged(QModelIndex, QModelIndex)"), self._property_current_changed ) Qt.QtCore.QObject.connect( self._property_widget.property_view.selectionModel(), SIGNAL("selectionChanged(QItemSelection, QItemSelection)"), self._property_selection_changed )
def invertSelectionEstimation(self): self.emit(SIGNAL("layoutAboutToBeChanged()")) for key, value in self.paramToEstimateMap.items(): self.paramToEstimateMap[key] = not value self.emit(SIGNAL("layoutChanged()"))
def __init__(self, parent=None): super(Form, self).__init__(parent) self.Replace = '' self.Search = '' self.resize(450, 100) #self.browser = QtGui.QTextBrowser() self.search_label = QtGui.QLabel("Type the text to be replaced here") self.search = QtGui.QLineEdit() self.search.setPlaceholderText("Type the text to be replaced here") #self.search.selectAll() self.replace_label = QtGui.QLabel("Type the replacement text here") self.replace = QtGui.QLineEdit() self.replace.setPlaceholderText("Type the replacement text here") self.buttonBox = QtGui.QDialogButtonBox() self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel | QtGui.QDialogButtonBox.Ok) layout = QtGui.QVBoxLayout() layout.addWidget(self.search_label) layout.addWidget(self.search) layout.addWidget(self.replace_label) layout.addWidget(self.replace) layout.addWidget(self.buttonBox) self.setLayout(layout) self.search.setFocus() self.connect(self.search, SIGNAL('editingFinished()'), self.Next) self.connect(self.replace, SIGNAL('editingFinished()'), self.Final) self.connect(self.buttonBox, SIGNAL('accepted()'), self.OK) self.connect(self.buttonBox, SIGNAL('rejected()'), self.Cancel) self.setWindowTitle('Update git Path in IPython Notebooks')
def setupContextMenu(self, vobj, menu): """Set up the object's context menu in GUI (callback).""" action1 = QAction(QT_TRANSLATE_NOOP("Render", "Set GUI to this camera"), menu) QObject.connect(action1, SIGNAL("triggered()"), self.set_gui_from_camera) menu.addAction(action1) action2 = QAction(QT_TRANSLATE_NOOP("Render", "Set this camera to GUI"), menu) QObject.connect(action2, SIGNAL("triggered()"), self.set_camera_from_gui) menu.addAction(action2) action3 = QAction(QT_TRANSLATE_NOOP("Render", "Point at..."), menu) QObject.connect(action3, SIGNAL("triggered()"), self.point_at) menu.addAction(action3)
def testButtonClicked(self): """Connection of a python slot to QPushButton.clicked()""" button = QPushButton('Mylabel') QObject.connect(button, SIGNAL('clicked()'), self.cb) self.args = tuple() button.emit(SIGNAL('clicked(bool)'), False) self.assert_(self.called)
def __init__(self): """Constructor""" super(MultiButtonDemo, self).__init__() layout = QVBoxLayout() self.label = QLabel("You haven't pressed a button!") # use a normal signal / slot mechanic button1 = QPushButton("One") self.connect(button1, SIGNAL("clicked()"), self.one) # now let's use partial functions button2 = QPushButton("Two") self.connect(button2, SIGNAL("clicked()"), partial(self.onButton, "Two")) button3 = QPushButton("Three") self.btn3Callback = partial(self.onButton, "Three") button3.clicked.connect(self.btn3Callback) # now let's try using a lambda function button4 = QPushButton("Four") button4.clicked.connect(lambda name="Four": self.onButton(name)) layout.addWidget(self.label) layout.addWidget(button1) layout.addWidget(button2) layout.addWidget(button3) layout.addWidget(button4) self.setLayout(layout) self.setWindowTitle("PySide Demo")
def testSimplePythonSignalNoArgs(self): #Connecting a lambda to a simple python signal without arguments obj = Dummy() QObject.connect(obj, SIGNAL('foo()'), lambda: setattr(obj, 'called', True)) obj.emit(SIGNAL('foo()')) self.assert_(obj.called)
def __init__(self, parent=None): super(Form, self).__init__(parent) #self.setWindowIcon(self.style().standardIcon(QStyle.SP_DirIcon)) #QtGui.QIcon(QtGui.QMessageBox.Critical)) self.txt = QLabel() self.txt.setText("This will remove ALL Suffix from selection objects. .\nDo you want to continue?\n\n\'suffix\'") self.le = QLineEdit() self.le.setObjectName("suffix_filter") self.le.setText(".step") self.pb = QPushButton() self.pb.setObjectName("OK") self.pb.setText("OK") self.pbC = QPushButton() self.pbC.setObjectName("Cancel") self.pbC.setText("Cancel") layout = QFormLayout() layout.addWidget(self.txt) layout.addWidget(self.le) layout.addWidget(self.pb) layout.addWidget(self.pbC) self.setLayout(layout) self.connect(self.pb, SIGNAL("clicked()"),self.OK_click) self.connect(self.pbC, SIGNAL("clicked()"),self.Cancel_click) self.setWindowTitle("Warning ...")
def testQThreadReceiversExtern(self): #QThread.receivers() - Inherited protected method obj = QThread() self.assertEqual(obj.receivers(SIGNAL('destroyed()')), 0) QObject.connect(obj, SIGNAL("destroyed()"), self.cb) self.assertEqual(obj.receivers(SIGNAL("destroyed()")), 1)
def invertSelectionSensitivity(self): self.emit(SIGNAL("layoutAboutToBeChanged()")) for key, value in self.paramsToSensitivityMap.items(): self.paramsToSensitivityMap[key] = not value self.emit(SIGNAL("layoutChanged()"))
def __init__(self, app, parent=None): self.conf = config.Config() desk = QtGui.QApplication.desktop( ) #remove hanging on Windows shutdown QtGui.QWidget.__init__(self, parent) self.Label = QtGui.QLabel("Waiting for Something", self) self.trayIcon = QtGui.QSystemTrayIcon(QtGui.QIcon("green.png"), app) self.menu = QtGui.QMenu() self.lastAction = self.menu.addAction("Show Last") self.resetAction = self.menu.addAction("Reset") self.aboutAction = self.menu.addAction("About") self.exitAction = self.menu.addAction("Exit") self.trayIcon.setContextMenu(self.menu) self.DataCollector = TerminalX(self) self.connect(self.DataCollector, QtCore.SIGNAL("Activated ( QString ) "), self.Activated) self.DataCollector.start() self.trayIcon.show() self.exitAction.connect(self.exitAction, SIGNAL("triggered()"), self.closeEvent) self.resetAction.connect(self.resetAction, SIGNAL("triggered()"), self.UnsetAlert) self.aboutAction.connect(self.aboutAction, SIGNAL("triggered()"), self.ShowAbout) self.lastAction.connect(self.lastAction, SIGNAL("triggered()"), self.ShowLast) self.connect(self.DataCollector, QtCore.SIGNAL("UpdateData() "), self.UpdateData) self.StopThreadFlag = [False] startThreads(self, self.StopThreadFlag)
def testIt(self): global called called = False o = QObject() o.connect(o, SIGNAL("ASignal"), functools.partial(someSlot, "partial ..")) o.emit(SIGNAL("ASignal")) self.assertTrue(called)
def selectAllSensitivity(self, doSelect): self.emit(SIGNAL("layoutAboutToBeChanged()")) for key in self.paramsToSensitivityMap.keys(): self.paramsToSensitivityMap[key] = doSelect self.emit(SIGNAL("layoutChanged()"))
def atestSpinBoxValueChangedFewArgs(self): """Emission of signals with fewer arguments than needed""" # XXX: PyQt4 crashes on the assertRaises QObject.connect(self.spin, SIGNAL('valueChanged(int)'), self.cb) self.args = (554, ) self.assertRaises(TypeError, self.spin.emit, SIGNAL('valueChanged(int)'))
def selectAllSensitivity(self, doSelect): self.emit(SIGNAL("layoutAboutToBeChanged()")) for speciesEntity in self.speciesList: speciesEntity.setComputeSensitivity(doSelect) self.emit(SIGNAL("layoutChanged()"))
def testValueChanged(self): """Emission of a python signal to QSpinBox setValue(int)""" QObject.connect(self.obj, SIGNAL('dummy(int)'), self.spin, SLOT('setValue(int)')) self.assertEqual(self.spin.value(), 0) self.obj.emit(SIGNAL('dummy(int)'), 4) self.assertEqual(self.spin.value(), 4)
def _connect_widgets(self): self.check_box.stateChanged.connect(self.tree.setSortingEnabled) if self.USE_FILTER: self.filter_box.textChanged.connect(self._filter_edit_changed) if self.USE_INSPECTOR: # connect inspector widget to tree selection # The usual way doens't seem to work... # self.tree.selectionModel().currentChanged.connect( # self.inspector_widget.setProxySelection # ) if self.USE_FILTER: if False: self.tree.selectionModel().currentChanged.connect( self.inspector_widget.setProxySelection) else: Qt.QtCore.QObject.connect( self.tree.selectionModel(), SIGNAL("currentChanged(QModelIndex, QModelIndex)"), self.inspector_widget.setProxySelection) else: if False: self.tree.selectionModel().currentChanged.connect( self.inspector_widget.setSelection) else: Qt.QtCore.QObject.connect( self.tree.selectionModel(), SIGNAL("currentChanged(QModelIndex, QModelIndex)"), self.inspector_widget.setSelection)
def __init__(self): """Constructor""" super(main, self).__init__() layout = QVBoxLayout() self.label = QLabel("You haven't pressed a button!") # use a normal signal / slot mechanic button1 = QPushButton("One") self.connect(button1, SIGNAL("clicked()"), self.one) # now let's use partial functions button2 = QPushButton("Two") self.connect(button2, SIGNAL("clicked()"), partial(self.onButton, "Two")) button3 = QPushButton("Three") self.btn3Callback = partial(self.onButton, "Three") button3.clicked.connect(self.btn3Callback) # now let's try using a lambda function button4 = QPushButton("Four") button4.clicked.connect(lambda name="Four": self.onButton(name)) # Imiagen posicion del PIC en el ZIF #label=QLabel(self) #label.setPixmap(layout.QPixmap("PIN18.png")) #label.move(470, 0) #Icono en la ventana #icono=self.setWindowIcon(QIcon('PikBurn3.png')) #QApplication.setWindowIcon('PikBurn3.png') #self.setWindowIcon(QIcon('PikBurn3.png')) # boton conectar #self.bconect= QtGui.QPushButton("Conectar",self) #self.bconect.clicked.connect(self.port) #self.bconect.move(10, 10) #layout.addWidget(icono) layout.addWidget(self.label) layout.addWidget(button1) layout.addWidget(button2) layout.addWidget(button3) layout.addWidget(button4) self.setLayout(layout)
def __init__(self): super(Main, self).__init__() self._world = World(random.randint, self) self._world.setN(10) # Dodawanie organizmów self._world.add_organism(Human((10, 10))) org_types = [ Antelope, Fox, Sheep, Turtle, Wolf, Belladonna, Dandelion, Grass, Guarana ] for org_type in org_types: self._init_org(5, org_type, random.randint) self._world.add_pending() # GUI # To okno self._menu_bar_h = 20 x, y, w, h = 300, 50, 870, 600 + self._menu_bar_h self.setGeometry(x, y, w, h) self.setFixedSize(w, h) self.setWindowTitle("Tomasz Stasiak 155197") hbox = QtGui.QHBoxLayout(self) menu_bar = QtGui.QMenuBar(self) menu_bar.setGeometry(0, 0, w, self._menu_bar_h) # Akcje w menu self._game_start = menu_bar.addAction("Start gry") self._next_round = menu_bar.addAction("Następna runda") self._next_round.setVisible(False) save_game = menu_bar.addAction("Zapisz stan") load_game = menu_bar.addAction("Wczytaj stan") # Bindowanie kontrolek do akcji # Start gry QObject.connect(self._game_start, SIGNAL("triggered()"), self, SLOT("start_game()")) QObject.connect(self._next_round, SIGNAL("triggered()"), lambda: self._world.nextRound()) QObject.connect(save_game, SIGNAL("triggered()"), self, SLOT("save_game()")) QObject.connect(load_game, SIGNAL("triggered()"), self, SLOT("load_game()")) # Insze kontrolki # Plansza gry self._game_board = GameBoard(self, 0, self._menu_bar_h) # Panel informaacyjny info_widget = QtGui.QWidget() self._info_panel = QtGui.QVBoxLayout(info_widget) self._info_panel.setAlignment(Qt.AlignTop) info_widget.setLayout(self._info_panel) # Dodanie ww. paneli hbox.addWidget(self._game_board) hbox.addWidget(info_widget) self.setLayout(hbox)
def __init__(self, parent=None): """ Default class constructor. :param `parent`: Pointer to a parent widget instance. :type `parent`: `QWidget`_ """ super(CmdPromptInput, self).__init__(parent) qDebug("CmdPromptInput Constructor") self.setObjectName("Command Prompt Input") self.defaultPrefix = self.tr("Command: ") self.prefix = self.defaultPrefix self.curText = self.prefix self.lastCmd = "help" self.curCmd = "help" self.cmdActive = False self.rapidFireEnabled = False self.isBlinking = False self.setText(self.prefix) self.setFrame(False) self.setMaxLength(266) self.setMaximumSize(5000, 25) self.setDragEnabled(False) self.connect(self, SIGNAL("cursorPositionChanged(int, int)"), self, SLOT("checkCursorPosition(int, int)")) self.connect(self, SIGNAL("textEdited(QString)"), self, SLOT("checkEditedText(QString)")) self.connect(self, SIGNAL("textChanged(QString)"), self, SLOT("checkChangedText(QString)")) self.connect(self, SIGNAL("selectionChanged()"), self, SLOT("checkSelection()")) self.aliasHash = {} # new QHash<QString, QString> self.installEventFilter(self) self.setFocus(Qt.OtherFocusReason) self.applyFormatting() # self.setCompleter(EmbroiderCommanderAutoCompleter(self)) #### self.completer = QCompleter(['LINE', 'HEART', 'DOLPHIN', 'CIRCLE', 'STAR', 'six', 'seven', 'eight', 'nine', 'ten'], self) #### self.completer.setCompletionMode(QCompleter.PopupCompletion) #### self.completer.setCaseSensitivity(Qt.CaseInsensitive) #### self.setCompleter(self.completer) self.curText = str() # QString curText; self.defaultPrefix = str() # QString defaultPrefix; self.prefix = str() # QString prefix; self.lastCmd = str() # QString lastCmd; self.curCmd = str() # QString curCmd; self.cmdActive = str() # bool cmdActive; self.rapidFireEnabled = bool() # bool rapidFireEnabled; self.isBlinking = bool() # bool isBlinking;
def set_list(self, datalist, header=None): self.emit(SIGNAL("layoutToBeChanged()")) self.list = datalist if header is None: self.get_header() else: self.header = header self.emit(SIGNAL("layoutChanged()"))
def testQObjectReceiversExtern(self): #QObject.receivers() - Protected method external access obj = Dummy() self.assertEqual(obj.receivers(SIGNAL("destroyed()")), 0) QObject.connect(obj, SIGNAL("destroyed()"), self.cb) self.assertEqual(obj.receivers(SIGNAL("destroyed()")), 1)
def sort(self, col, order): """sort table by given column number col""" self.emit(SIGNAL("layoutAboutToBeChanged()")) self.mylist = sorted(self.mylist, key=operator.itemgetter(col)) if order == QtCore.Qt.DescendingOrder: self.mylist.reverse() self.emit(SIGNAL("layoutChanged()"))
def testSimplePythonSignal(self): #Connecting a lambda to a simple python signal witharguments obj = Dummy() arg = 42 QObject.connect(obj, SIGNAL('foo(int)'), lambda x: setattr(obj, 'arg', 42)) obj.emit(SIGNAL('foo(int)'), arg) self.assertEqual(obj.arg, arg)
def build_widget(self, parent=None): QDialogButtonBox = QtGui.QDialogButtonBox widget = super(SimpleDialog, self).build_widget(parent) self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, widget) self._layout.addWidget(self.button_box, self._layout.rowCount() + 1, 0, 1, self.NUM_LAYOUT_COLS) widget.connect(self.button_box, SIGNAL("accepted()"), widget.accept) widget.connect(self.button_box, SIGNAL("rejected()"), widget.reject) return widget
def invertSelectionSensitivity(self): self.emit(SIGNAL("layoutAboutToBeChanged()")) for speciesEntity in self.speciesList: speciesEntity.setComputeSensitivity( not speciesEntity.getComputeSensitivity()) self.emit(SIGNAL("layoutChanged()"))
def connect_widgets(self): # self.completer.activated.connect(self.print_test, QtCore.QModelIndex) Qt.QtCore.QObject.connect(self._completer, SIGNAL("activated(QModelIndex)"), self.completer_activated) Qt.QtCore.QObject.connect(self._completer, SIGNAL("highlighted(QString)"), self.test)
def __init__(self, parent= None): super(Widget, self).__init__(parent, QtCore.Qt.WindowStaysOnTopHint) #QtGui.QMainWindow.__init__(self, None, QtCore.Qt.WindowStaysOnTopHint) #icon = style.standardIcon( # QtGui.QStyle.SP_MessageBoxCritical, None, widget) #self.setWindowIcon(self.style().standardIcon(QtGui.QStyle.SP_MessageBoxCritical)) #self.setIcon(self.style().standardIcon(QtGui.QStyle.SP_MessageBoxCritical)) #self.setIcon(self.style().standardIcon(QStyle.SP_DirIcon)) #QtGui.QIcon(QtGui.QMessageBox.Critical)) #icon = QtGui.QIcon() #icon.addPixmap(QtGui.QPixmap("icons/157-stats-bars.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) #Widget.setWindowIcon(icon) self.txt = QLabel() self.txt.setText("This will remove ALL Suffix from selection objects. \nDo you want to continue?\n\n\'suffix\'") self.le = QLineEdit() self.le.setObjectName("suffix_filter") self.le.setText(".step") self.pb = QPushButton() self.pb.setObjectName("OK") self.pb.setText("OK") self.pbC = QPushButton() self.pbC.setObjectName("Cancel") self.pbC.setText("Cancel") layout = QVBoxLayout() layout.addWidget(self.txt) layout.addWidget(self.le) layout.addWidget(self.pb) layout.addWidget(self.pbC) self.setWindowTitle("Warning ...") #self.setWindowIcon(self.style().standardIcon(QtGui.QStyle.SP_MessageBoxCritical)) # btn_folder = QPushButton("Folder") # btn_folder.setIcon(self.style().standardIcon(QStyle.SP_DirIcon)) # # btn_one = QPushButton("Play") # btn_one.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay)) # # btn_two = QPushButton("Stop") # btn_two.setIcon(self.style().standardIcon(QStyle.SP_MediaStop)) # # btn_three = QPushButton("Pause") # btn_three.setIcon(self.style().standardIcon(QStyle.SP_MediaPause)) #layout = QHBoxLayout() #layout.addWidget(btn_folder) #layout.addWidget(btn_one) #layout.addWidget(btn_two) #layout.addWidget(btn_three) self.setLayout(layout) #self.setLayout(layout) self.connect(self.pb, SIGNAL("clicked()"),self.OK_click) self.connect(self.pbC, SIGNAL("clicked()"),self.Cancel_click)