def execute(self): app = QApplication([]) tab1 = 20 tab2 = 110 yStart = 10 yInc = 20 w = QWidget() w.setGeometry(100, 100, 320, 240) w.setWindowTitle('World Clock') self._utc_label = self._create_label(w, 'UTC:', yStart, tab1, tab2) self._eastern_label = self._create_label(w, 'US/Eastern:', yStart + yInc * 2, tab1, tab2) self._central_label = self._create_label(w, 'US/Central:', yStart + yInc * 3, tab1, tab2) self._mountain_label = self._create_label(w, 'US/Mountain:', yStart + yInc * 4, tab1, tab2) self._pacific_label = self._create_label(w, 'US/Pacific:', yStart + yInc * 5, tab1, tab2) self._berlin_label = self._create_label(w, 'Berlin:', yStart + yInc * 7, tab1, tab2) self._london_label = self._create_label(w, 'London:', yStart + yInc * 8, tab1, tab2) self._paris_label = self._create_label(w, 'Paris:', yStart + yInc * 9, tab1, tab2) w.show() self._timer.start(1000) exit(app.exec())
def App(): app = QApplication(sys.argv) win = QWidget() win.setWindowTitle("PyQt6 QLabel Example") win.left = 100 win.top = 100 l1 = QLabel("Hello World") l2 = QLabel("Welcome to Python GUI Programming") # # Because you can't instantiate a QLable directly with a QPixmap. # l3 = QLabel() l3.setPixmap(QPixmap("python-small.png")) l1.setAlignment(Qt.Alignment.AlignCenter) l2.setAlignment(Qt.Alignment.AlignCenter) l3.setAlignment(Qt.Alignment.AlignCenter) vbox = QVBoxLayout() vbox.addWidget(l1) vbox.addStretch() vbox.addWidget(l2) vbox.addStretch() vbox.addWidget(l3) vbox.addStretch() win.setLayout(vbox) win.show() sys.exit(app.exec())
def __init__(self, args): Log.append('app_init', 'Info', 'version: %s' % Const.version) set_default(default_zone=Zone(home_dir=pyinstaller.get_runtime_dir())) self.qt = QApplication(args) self.qt.setApplicationName(Const.app_name) self.qt.setWindowIcon( QIcon('%s/app/res/icon.png' % pyinstaller.get_runtime_dir())) self.hook_exception() self.config = Config() self.config.load() self.lang = None # type: English self.load_language(Config.language) self.events = { 'process_events': self.qt.processEvents, 'export_log': self.export_log, 'check_update': self.check_update, 'load_language': self.load_language, 'get_language': lambda: self.lang, 'set_language': self.set_language, 'get_config': lambda: self.config, }
def main(): app = QApplication(sys.argv) ventana = Captura_Datos() ventana.show() sys.exit(app.exec())
def gmxmmpbsa_ana(): try: from PyQt6.QtWidgets import QApplication pyqt = True except: try: from PyQt5.QtWidgets import QApplication pyqt = True except: pyqt = False finally: if not pyqt: GMXMMPBSA_ERROR( 'Could not import PyQt5/PyQt6. gmx_MMPBSA_ana will be disabled until PyQt5/PyQt6 is ' 'installed') from GMXMMPBSA.analyzer.gui import GMX_MMPBSA_ANA from GMXMMPBSA.analyzer.utils import get_files app = QApplication(sys.argv) app.setApplicationName('gmx_MMPBSA Analyzer (gmx_MMPBSA_ana)') try: parser = anaparser.parse_args(sys.argv[1:]) except CommandlineError as e: GMXMMPBSA_ERROR('%s: %s' % (type(e).__name__, e)) sys.exit(1) ifiles = get_files(parser) w = GMX_MMPBSA_ANA() w.gettting_data(ifiles) w.show() sys.exit(app.exec())
def main(): app = QApplication(sys.argv) ventana = VentanaPrincipal() ventana.show() sys.exit(app.exec())
def copy_to_clipboard(self, *args): QApplication.clipboard().setText( '%s, version %s\n%s: %s\n\n%s' % (appname, str_version, self.windowTitle(), self.msg.text(), self.det_msg.toPlainText())) if hasattr(self, 'ctc_button'): self.ctc_button.setText(_('Copied'))
def __init__(self, master_password=None, urls=(), new_instance=False, shutdown=False, restart_state=None, no_session=False, run_local_server=True): if not isosx: # OS X turns this on automatically for v in ('QT_AUTO_SCREEN_SCALE_FACTOR', 'QT_SCALE_FACTOR', 'QT_SCREEN_SCALE_FACTORS', 'QT_DEVICE_PIXEL_RATIO'): if os.environ.get(v): break else: QApplication.setAttribute( Qt.ApplicationAttribute.AA_EnableHighDpiScaling, True) QApplication.__init__(self, [appname, '-name', appname]) if in_dark_mode: self.setPalette(dark_palette()) self.setOrganizationName('kovidgoyal') self.setApplicationName(appname) self.setApplicationVersion(str_version) self.no_session = no_session self.handle_unix_signals() if not QSslSocket.supportsSsl(): raise SystemExit('Qt has been compiled without SSL support!') from .config import font_families ff = font_families().get('sans-serif') or 'default' if ff == 'default': ff = font_families().get('default') or 'default' f = self.font() if ff != 'default': f.setFamily(ff) self.setFont(f) self.password_loaded.connect(self.on_password_load, type=Qt.ConnectionType.QueuedConnection) if master_password is not None: password_db.start_load(master_password, self.password_loaded.emit) elif restart_state and 'key' in restart_state: password_db.start_load(restart_state.pop('key'), self.password_loaded.emit, pw_is_key=True) self.lastWindowClosed.connect(self.shutdown) if run_local_server: self.run_local_server(urls, new_instance, shutdown) sys.excepthook = self.on_unhandled_error self.windows = [] f = self.font() if (f.family(), f.pointSize()) == ( 'Sans Serif', 9): # Hard coded Qt settings, no user preference detected f.setPointSize(10) if 'Ubuntu' in QFontDatabase().families(): f.setFamily('Ubuntu') self.setFont(f) self.downloads = Downloads(self) self.disk_cache = create_favicon_cache() self.key_filter = KeyFilter(self) self.installEventFilter(self.key_filter)
def send_key_sequence(self, event_string): ''' Fake key sequence.''' event_list = event_string.split("-") if len(event_list) > 1: for widget in [self.buffer_widget.focusProxy()]: last_char = event_list[-1] last_key = last_char if len(last_char) == 1: last_key = last_char.lower() modifiers = Qt.KeyboardModifier.NoModifier for modifier in event_list[0:-1]: if modifier == "C": modifiers |= Qt.KeyboardModifier.ControlModifier elif modifier == "M": modifiers |= Qt.KeyboardModifier.AltModifier elif modifier == "S": modifiers |= Qt.KeyboardModifier.KeyboardModifier.ShiftModifier elif modifier == "s": modifiers |= Qt.KeyboardModifier.MetaModifier if last_key in qt_text_dict: last_key = qt_text_dict[last_key] QApplication.postEvent(widget, QKeyEvent(QEvent.Type.KeyPress, qt_key_dict[last_key], modifiers, last_key))
def main(): app = QApplication(sys.argv) ventana = Ventana_Calculadora() ventana.show() sys.exit(app.exec())
def send_key(self, event_string): ''' Fake key event.''' # Init. text = event_string modifier = Qt.KeyboardModifier.NoModifier # Get key text. if event_string in qt_text_dict: text = qt_text_dict[event_string] if event_string == "<backtab>": modifier = Qt.KeyboardModifier.ShiftModifier elif len(event_string) == 1 and event_string.isupper(): modifier = Qt.KeyboardModifier.ShiftModifier # print("Press: ", event_string, modifier, text) # NOTE: don't ignore text argument, otherwise QWebEngineView not respond key event. try: key_press = QKeyEvent(QEvent.Type.KeyPress, qt_key_dict[event_string], modifier, text) except: key_press = QKeyEvent(QEvent.Type.KeyPress, Qt.Key.Key_unknown, modifier, text) for widget in self.get_key_event_widgets(): QApplication.postEvent(widget, key_press) self.send_key_filter(event_string)
def scroll_line(key, window, focus_widget, key_filter, *args, **kwargs): if focus_widget is not None: with key_filter.disable_filtering: QApplication.sendEvent( focus_widget, QKeyEvent(QEvent.Type.KeyPress, key, Qt.KeyboardModifier(0))) return True
def contextMenuEvent(self, event): context_menu = QMenu(self) exit_action = context_menu.addAction("Quit") action = context_menu.exec_(self.mapToGlobal(event.pos())) if action == exit_action: QApplication.instance().quit()
def focus_widget(self, event=None): '''Focus buffer widget.''' if event is None: event = QFocusEvent(QEvent.Type.FocusIn, Qt.FocusReason.MouseFocusReason) QApplication.postEvent(self.buffer_widget.focusProxy(), event) # Activate emacs window when call focus widget, avoid first char is not eval_in_emacs('eaf-activate-emacs-window', [])
def __init__(self): app = QApplication(sys.argv) super().__init__() self.setWindowTitle('PyQt6 Tab Example') self.setGeometry(100, 100, 640, 300) self.setCentralWidget(MyTabWidget(self)) self.show() sys.exit(app.exec())
def store_passwd(ok, during_shutdown): if ok == 'never': exclude = gprefs.get('never-store-password-for', {}) exclude[key] = True password_exclusions.set(key, True) elif ok and not during_shutdown: QApplication.instance().store_password( url, username, password)
def scroll_page(up, window, focus_widget, key_filter, *args, **kwargs): if focus_widget is not None: with key_filter.disable_filtering: key = Qt.Key.Key_PageUp if up else Qt.Key.Key_PageDown QApplication.sendEvent( focus_widget, QKeyEvent(QEvent.Type.KeyPress, key, Qt.KeyboardModifier(0))) return True
def scroll_to_boundary(top, window, focus_widget, key_filter, *args, **kwargs): if focus_widget is not None: with key_filter.disable_filtering: key = Qt.Key.Key_Home if top else Qt.Key.Key_End QApplication.sendEvent( focus_widget, QKeyEvent(QEvent.Type.KeyPress, key, Qt.KeyboardModifier(0))) return True
def __init__(self): app = QApplication(sys.argv) super().__init__() self.setWindowTitle('PyQt6 Minimal Window') self.setGeometry(100, 100, 640, 480) self.statusBar().showMessage('Message in statusbar.') self.show() sys.exit(app.exec())
def copy_url(window, *args, **kwargs): if window.current_tab is not None: qurl = window.current_tab.url() if not qurl.isEmpty(): QApplication.clipboard().setText(qurl.toString()) window.show_status_message( _('Copied: ') + qurl.toString(), 2, 'success') window.statusBar() return True
def develop(): from PyQt6.QtWidgets import QApplication, QLabel app = QApplication([]) r = RotatingIcon(icon_size=64) l = QLabel() l.setPixmap(r.first_frame) r.updated.connect(l.setPixmap) r.start() l.show() app.exec()
def main(): Tag_editor = QApplication(sys.argv) view = View() model = Model() controller = Controller(view, model) view.show() sys.exit(Tag_editor.exec())
def contextMenuEvent(self, event): cmenu = QMenu(self) newAct = cmenu.addAction("New") openAct = cmenu.addAction("Open") quitAct = cmenu.addAction("Quit") action = cmenu.exec(self.mapToGlobal(event.pos())) if action == quitAct: QApplication.instance().quit()
def mousePressEvent(self, mouseEvent: QMouseEvent): if (not self.pressed and not self.scrolling and mouseEvent.modifiers() == QtCore.Qt.KeyboardModifier.NoModifier): if mouseEvent.buttons() == QtCore.Qt.MouseButton.LeftButton: self.pressed = True self.scrolling = False self.handIsClosed = False QApplication.setOverrideCursor( QtCore.Qt.CursorShape.OpenHandCursor) self.scrollMousePress = self.scrollPosition() self.positionMousePress = mouseEvent.pos()
def __init__(self): logger.debug('Ui class initializing') self.eog = False self.app = QApplication([]) super().__init__() self.field = [] self.layout = QGridLayout() self.gui_init()
def main(): """RP Contacts main function.""" # Create the application app = QApplication(sys.argv) # Connect to the database before creating any window if not createConnection("contacts.sqlite"): sys.exit(1) # Create the main window if the connection succeeded win = Window() win.show() # Run the event loop sys.exit(app.exec())
def __init__(self): app = QApplication(sys.argv) super().__init__() self.setWindowTitle('PyQt6 Horizontal Layout') self.setGeometry(100, 100, 400, 100) self.CreateHorizontalLayout() windowLayout = QVBoxLayout() windowLayout.addWidget(self.horizontalGroupBox) self.setLayout(windowLayout) self.show() sys.exit(app.exec())
def main(): app = QApplication(sys.argv) w = QWidget() w.resize(250, 200) w.move(300, 300) w.setWindowTitle('Simple') w.show() sys.exit(app.exec())
def main(): """Main function.""" # Create an instance of `QApplication` pycalc = QApplication(sys.argv) # Show the calculator's GUI view = PyCalcUi() view.show() # Create instances of the model and the controller model = evaluateExpression PyCalcCtrl(model=model, view=view) # Execute calculator's main loop sys.exit(pycalc.exec())
def quit_application(self): # Stops animation (updating changing elements of the Figure) self.anim._stop() # Stops the two threads updating the GUI labels and updating the state of Cart instance self.run_set_labels_thread = False self.terminate_experiment_or_replay_thread = True self.pause_experiment_or_replay_thread = False # Closes the GUI window self.close() # The standard command # It seems however not to be working by its own # I don't know how it works QApplication.quit()