def test_42(self): # QKeyEvent and related issues ef = EventFilter() widget = pya.QLineEdit() widget.setText("ABC") pya.QApplication.processEvents() widget.installEventFilter(ef) ke = pya.QKeyEvent(pya.QEvent.KeyPress, pya.Qt.Key_O.to_i(), pya.Qt.ShiftModifier, "O") pya.QCoreApplication.postEvent(widget, ke) ke = pya.QKeyEvent(pya.QEvent.KeyPress, pya.Qt.Key_Left.to_i(), pya.Qt.NoModifier) pya.QCoreApplication.postEvent(widget, ke) ke = pya.QKeyEvent(pya.QEvent.KeyPress, pya.Qt.Key_P.to_i(), pya.Qt.NoModifier, "p") pya.QCoreApplication.postEvent(widget, ke) pya.QApplication.processEvents() s1 = "QKeyEvent: ShortcutOverride (51)\nQKeyEvent: KeyPress (6)\nQKeyEvent: ShortcutOverride (51)\nQKeyEvent: KeyPress (6)\nQKeyEvent: ShortcutOverride (51)\nQKeyEvent: KeyPress (6)" s2 = "QKeyEvent: KeyPress (6)\nQKeyEvent: KeyPress (6)\nQKeyEvent: KeyPress (6)" s3 = "QKeyEvent_Native: ShortcutOverride (51)\nQKeyEvent: KeyPress (6)\nQKeyEvent_Native: ShortcutOverride (51)\nQKeyEvent: KeyPress (6)\nQKeyEvent_Native: ShortcutOverride (51)\nQKeyEvent: KeyPress (6)" self.assertIn("\n".join(ef.log()), (s1, s2, s3)) ef = None self.assertEqual(widget.text, "ABCpO") widget = None
def __init__(self, parent=None): super(ImageToLayout, self).__init__() self.setWindowTitle("Image to Layout") self.window_width = 800 self.window_height = 600 self.resize(self.window_width, self.window_height) self.layout = pya.QGridLayout(self) self.input_text = pya.QLineEdit(self) self.input_text.setAcceptDrops(True) self.input_text.setFont(pya.QFont('Times', 15)) self.input_text.setText("select image:") self.file_dialog = pya.QFileDialog(self) self.file_dialog.setFont(pya.QFont('Times', 10)) self.select_file_button = pya.QPushButton("select image", self) self.select_file_button.setFont(pya.QFont('Times', 15, pya.QFont.Bold)) self.select_file_button.clicked(self.select_file_button_clicked) self.convert_button = pya.QPushButton("convert to OASIS file", self) self.convert_button.setFont(pya.QFont('Times', 15, pya.QFont.Bold)) self.convert_button.clicked(self.covert_buttion_clicked) self.raw_image_label = pya.QLabel() self.raw_image_info_label = pya.QLabel("image size:") self.raw_image_info_label.setVisible(False) self.threshold_text = pya.QLineEdit(self) self.threshold_text.setAcceptDrops(True) self.threshold_text.setFont(pya.QFont('Times', 15)) self.threshold_text.setText("set threshold: 0 - 255") self.dbu_text = pya.QLineEdit(self) self.dbu_text.setAcceptDrops(True) self.dbu_text.setFont(pya.QFont('Times', 15)) self.dbu_text.setText("set DBU: ") self.inverse_checkbox = pya.QCheckBox("inverse", self) self.inverse_checkbox.setFont(pya.QFont('Times', 15)) self.progress_bar = pya.QProgressBar(self) self.layout.addWidget(self.input_text, 0, 0) self.layout.addWidget(self.select_file_button, 0, 1) self.layout.addWidget(self.raw_image_label, 1, 0, 3, 1) self.layout.addWidget(self.threshold_text, 1, 1) self.layout.addWidget(self.inverse_checkbox, 2, 1) self.layout.addWidget(self.dbu_text, 3, 1) self.layout.addWidget(self.raw_image_info_label, 4, 0) self.layout.addWidget(self.progress_bar, 5, 0) self.layout.addWidget(self.convert_button, 5, 1) self.setLayout(self.layout)
def settings(self, parent=None): if parent is None: parent = self settingw = pya.QWidget(self) vbox = pya.QVBoxLayout(settingw) settingw.setLayout(vbox) self.settingspath = kgit.settings_path self.settings = {} scrollarea = pya.QScrollArea(self) optionswidget = pya.QWidget(self) scrollarea.setWidget(optionswidget) scrollarea.setWidgetResizable(True) optionvbox = pya.QVBoxLayout(optionswidget) categorydict = vars(kgit.settings) hbSplitter = pya.QHBoxLayout() vboxbuttons = pya.QVBoxLayout() vbox.addLayout(hbSplitter) hbSplitter.addWidget(scrollarea) hbSplitter.addLayout(vboxbuttons) resetButton = pya.QPushButton('Restore Defaults', self) resetButton.clicked(self.restoreDefaults) vboxbuttons.addWidget(resetButton) vboxbuttons.addStretch() # Repository Settings cat = 'Repository' groupbox = pya.QGroupBox(cat, self) optionvbox.addWidget(groupbox) vb = pya.QVBoxLayout(groupbox) self.settings['repository'] = {} repdic = self.settings['repository'] repdic['url'] = [ kgit.settings.repository.url(), kgit.settings.repository.url ] l = pya.QHBoxLayout() le = pya.QLineEdit(repdic['url'][0], self) def assignurl(text): repdic['url'][0] = text le.textChanged = assignurl la = pya.QLabel(kgit.settings.repository.url.description, self) l.addWidget(le) l.addWidget(la) vb.addLayout(l) l = pya.QHBoxLayout() repdic['autoupdate'] = [ kgit.settings.repository.autoupdate(), kgit.settings.repository.autoupdate ] b = pya.QCheckBox(kgit.settings.repository.autoupdate.description, groupbox) if repdic['autoupdate'][0]: b.setChecked(True) else: b.setChecked(False) def updateclicked(checked): repdic['autoupdate'][0] = checked b.toggled = updateclicked l.addWidget(b) vb.addLayout(l) # Log settings cat = "Logs" groupbox = pya.QGroupBox(cat, self) optionvbox.addWidget(groupbox) vb = pya.QVBoxLayout(groupbox) self.settings['logging'] = {} logdic = self.settings['logging'] logdic['filelvl'] = [ kgit.settings.logging.logfilelevel.value.index, kgit.settings.logging.logfilelevel ] logdic['streamlvl'] = [ kgit.settings.logging.logstreamlevel.value.index, kgit.settings.logging.logstreamlevel ] ## File Logging v = pya.QComboBox(self) l = pya.QHBoxLayout() for i in kgit.settings.logging.levels(): v.addItem(i) v.currentIndex = logdic['filelvl'][0] vb.addLayout(l) l.addWidget(v) d = pya.QLabel(kgit.settings.logging.logfilelevel.description, self) def logfileindexchanged(index): logdic['filelvl'][0] = index v.currentIndexChanged = logfileindexchanged l.addWidget(d) l.addStretch() ## Stream Logging v = pya.QComboBox(self) l = pya.QHBoxLayout() for i in kgit.settings.logging.levels(): v.addItem(i) v.currentIndex = logdic['streamlvl'][0] vb.addLayout(l) l.addWidget(v) d = pya.QLabel(kgit.settings.logging.logfilelevel.description, self) def logfileindexchanged(index): logdic['streamlvl'][0] = index v.logfileindexchanged = logfileindexchanged l.addWidget(d) l.addStretch() vbox.addStretch() save = pya.QPushButton("Save", self) save.clicked = self.save abort = pya.QPushButton("Cancel", self) abort.clicked = self.abort hbox = pya.QHBoxLayout() vbox.addLayout(hbox) hbox.addWidget(abort) hbox.addStretch() hbox.addWidget(save) optionvbox.addStretch() return settingw
def settings(self, parent=None): if parent is None: parent = self settingw = pya.QWidget(self) vbox = pya.QVBoxLayout(settingw) settingw.setLayout(vbox) self.settingspath = kgit.settings_path self.settings = {} scrollarea = pya.QScrollArea(self) optionswidget = pya.QWidget(self) scrollarea.setWidget(optionswidget) scrollarea.setWidgetResizable(True) optionvbox = pya.QVBoxLayout(optionswidget) categorydict = vars(kgit.settings) hbSplitter = pya.QHBoxLayout() vboxbuttons = pya.QVBoxLayout() vbox.addLayout(hbSplitter) hbSplitter.addWidget(scrollarea) hbSplitter.addLayout(vboxbuttons) resetButton = pya.QPushButton('Restore Defaults', self) resetButton.clicked(self.restoreDefaults) vboxbuttons.addWidget(resetButton) vboxbuttons.addStretch() # General Settings cat = 'Repository' groupbox = pya.QGroupBox(cat, self) optionvbox.addWidget(groupbox) vb = pya.QVBoxLayout(groupbox) self.settings['repository'] = {} repdic = self.settings['repository'] repdic['url'] = (kgit.settings.repository.url(), kgit.settings.repository.url) l = pya.QHBoxLayout() le = pya.QLineEdit(repdic['url'][0], self) la = pya.QLabel(kgit.settings.repository.url.description, self) l.addWidget(le) l.addWidget(la) vb.addLayout(l) # Log settings cat = "Logs" groupbox = pya.QGroupBox(cat, self) optionvbox.addWidget(groupbox) vb = pya.QVBoxLayout(groupbox) self.settings['logging'] = {} logdic = self.settings['logging'] logdic['filelvl'] = (kgit.settings.logging.logfilelevel.value.index, kgit.settings.logging.logfilelevel) logdic['streamlvl'] = ( kgit.settings.logging.logstreamlevel.value.index, kgit.settings.logging.logstreamlevel) ## File Logging v = pya.QComboBox(self) l = pya.QHBoxLayout() for i in kgit.settings.logging.levels(): v.addItem(i) v.currentIndex = logdic['filelvl'][0] vb.addLayout(l) l.addWidget(v) d = pya.QLabel(kgit.settings.logging.logfilelevel.description, self) l.addWidget(d) l.addStretch() ## Stream Logging v = pya.QComboBox(self) l = pya.QHBoxLayout() for i in kgit.settings.logging.levels(): v.addItem(i) v.currentIndex = logdic['streamlvl'][0] vb.addLayout(l) l.addWidget(v) d = pya.QLabel(kgit.settings.logging.logfilelevel.description, self) l.addWidget(d) l.addStretch() vbox.addStretch() save = pya.QPushButton("Save", self) save.clicked = self.save abort = pya.QPushButton("Cancel", self) abort.clicked = self.abort hbox = pya.QHBoxLayout() vbox.addLayout(hbox) hbox.addWidget(abort) hbox.addStretch() hbox.addWidget(save) optionvbox.addStretch() return settingw