def make_tools_menu(self, main_menu): tools_menu = main_menu.addMenu('&Tools') bwColorAction=QAction(QIcon(), 'Background Color', self) bwColorAction.setStatusTip('Select background color') bwColorAction.triggered.connect(self.color_picker) tools_menu.addAction(bwColorAction)
def createActions(self): """Create the application's menu actions.""" # Create actions for File menu self.open_act = QAction("Open...", self, triggered=self.openDirectory) self.open_act.setShortcut(QKeySequence.StandardKey.Open) self.quit_act = QAction("Quit Viewer", self, triggered=self.close) self.quit_act.setShortcut(QKeySequence.StandardKey.Quit) # Ctrl+Q # Create actions for View menu # Handle the visibility of the dock widget self.show_dock_act = self.files_dock.toggleViewAction() self.show_dock_act.setText("Show Media Folder") # Create actions for the toolbar (These actions could also be # added to the GUI's menu bar or to a context menu) self.play_act = QAction(QIcon("icons/play.png"), "Play", self, triggered=self.startMovie) self.pause_act = QAction(QIcon("icons/pause.png"), "Pause", self, triggered=self.pauseMovie) self.stop_act = QAction(QIcon("icons/stop.png"), "Stop/Reset", self, triggered=self.stopMovie) self.disableMovieButtons()
def initGui(self): self.setWindowTitle('My Application!!!') self.setFixedSize(600, 400) #self.showFullScreen() # Label self.lbl_saludo = QLabel('Bienvenido...', self) self.lbl_saludo.move(50, 50) # Menu self.menu_principal = self.menuBar() self.menu_archivo = self.menu_principal.addMenu('Archivo') self.menu_operaciones = self.menu_principal.addMenu('Operaciones') self.menu_ayuda = self.menu_principal.addMenu('Ayuda') # Archivo self.menu_item_salir = QAction('Salir', self) self.menu_item_salir.setShortcut('⌘D') self.menu_item_salir.triggered.connect(self.close) self.menu_archivo.addAction(self.menu_item_salir) # Operaciones self.menu_item_operaciones = QAction('Operaciones', self) self.menu_operaciones.addAction(self.menu_item_operaciones) # Ayuda self.menu_acerca_de = QAction('Acerca de MY Application.', self) self.menu_ayuda.addAction(self.menu_acerca_de) self.menu_ayuda.triggered.connect(self.mostrar_acerca_de)
def init_languages_menu(self): for k in LANGUAGES: a_lang = QAction(self) a_lang.setText(LANGUAGES[k].l_this) a_lang.triggered.connect((lambda x: (lambda _: self.set_language(x)))(k)) self.m_languages.addAction(a_lang)
def initGui(self): self.setWindowTitle('Mi Aplicación.') self.setFixedSize(600, 600) # Pestañas self.mbr_principal = self.menuBar() self.menu_archivo = self.mbr_principal.addMenu('Archivo') self.menu_operaciones = self.mbr_principal.addMenu('Operaciones') self.menu_ayuda = self.mbr_principal.addMenu('Ayuda') # Archivo self.mni_salir = QAction('Salir', self) self.mni_salir.setShortcut('⌘D') self.mni_salir.setStatusTip('Salir de la Aplicación') self.mni_salir.triggered.connect(self.close) self.menu_archivo.addAction(self.mni_salir) # Operaciones self.mni_copiar = QAction('Copiar 📑', self) self.mni_copiar.setShortcut('⌘C') self.menu_operaciones.addAction(self.mni_copiar) self.mni_cortar = QAction('Cortar ✂️', self) self.mni_cortar.setShortcut('⌘X') self.menu_operaciones.addAction(self.mni_cortar) self.mni_pegar = QAction('Pegar 📥', self) self.mni_pegar.setShortcut('⌘V') self.menu_operaciones.addAction(self.mni_pegar) # Ayuda self.mni_acerca_de = QAction('A cerca de') self.menu_ayuda.addAction(self.mni_acerca_de) self.mni_acerca_de.triggered.connect(self.mostrar_acerca_de)
def initUI(self): exitAct = QAction(QIcon('exit24.png'), 'Exit', self) exitAct.setShortcut('Ctrl+Q') exitAct.triggered.connect(QApplication.instance().quit) self.toolbar = self.addToolBar('Exit') self.toolbar.addAction(exitAct) self.setGeometry(300, 300, 350, 250) self.setWindowTitle('Toolbar') self.show()
class TrayContextMenu(QtWidgets.QMenu): instances = set() def __init__(self, trayIcon): """trayIcon = the object with the methods to call""" QtWidgets.QMenu.__init__(self) TrayContextMenu.instances.add(self) self.trayIcon = trayIcon self._buildMenu() def hasJumpGate(sys_name=None) -> bool: return False def updateMenu(self, sys_name=None, rgn_name=None): pass def _buildMenu(self): self.framelessCheck = QAction("Frameless Window", self, checkable=True) self.framelessCheck.triggered.connect(self.trayIcon.changeFrameless) self.addAction(self.framelessCheck) self.addSeparator() self.requestCheck = QAction( "Show status request notifications", self, checkable=True ) self.requestCheck.setChecked(True) self.addAction(self.requestCheck) self.requestCheck.triggered.connect(self.trayIcon.switchRequest) self.alarmCheck = QAction("Show alarm notifications", self, checkable=True) self.alarmCheck.setChecked(True) self.alarmCheck.triggered.connect(self.trayIcon.switchAlarm) self.addAction(self.alarmCheck) distanceMenu = self.addMenu("Alarm Distance") self.distanceGroup = QActionGroup(self) for i in range(0, 6): action = QAction("{0} Jumps".format(i), None, checkable=True) if i == 0: action.setChecked(True) action.alarmDistance = i action.triggered.connect(self.changeAlarmDistance) self.distanceGroup.addAction(action) distanceMenu.addAction(action) self.addMenu(distanceMenu) self.addSeparator() self.quitAction = QAction("Quit", self) self.quitAction.triggered.connect(self.trayIcon.quit) self.addAction(self.quitAction) def changeAlarmDistance(self): for action in self.distanceGroup.actions(): if action.isChecked(): self.trayIcon.alarmDistance = action.alarmDistance self.trayIcon.changeAlarmDistance()
class VentanaPrincipal(QMainWindow): def __init__(self): QMainWindow.__init__(self) self.initGui() def initGui(self): self.setWindowTitle('Mi Aplicación.') self.setFixedSize(600, 600) # Pestañas self.mbr_principal = self.menuBar() self.menu_archivo = self.mbr_principal.addMenu('Archivo') self.menu_operaciones = self.mbr_principal.addMenu('Operaciones') self.menu_ayuda = self.mbr_principal.addMenu('Ayuda') # Archivo self.mni_salir = QAction('Salir', self) self.mni_salir.setShortcut('⌘D') self.mni_salir.setStatusTip('Salir de la Aplicación') self.mni_salir.triggered.connect(self.close) self.menu_archivo.addAction(self.mni_salir) # Operaciones self.mni_copiar = QAction('Copiar 📑', self) self.mni_copiar.setShortcut('⌘C') self.menu_operaciones.addAction(self.mni_copiar) self.mni_cortar = QAction('Cortar ✂️', self) self.mni_cortar.setShortcut('⌘X') self.menu_operaciones.addAction(self.mni_cortar) self.mni_pegar = QAction('Pegar 📥', self) self.mni_pegar.setShortcut('⌘V') self.menu_operaciones.addAction(self.mni_pegar) # Ayuda self.mni_acerca_de = QAction('A cerca de') self.menu_ayuda.addAction(self.mni_acerca_de) self.mni_acerca_de.triggered.connect(self.mostrar_acerca_de) def mostrar_acerca_de(self): mensaje = QMessageBox() mensaje.setWindowTitle('Acerca de') mensaje.setIcon(QMessageBox.Icon.Information) mensaje.setText( 'A cerca de Mi Aplicación.\n\nAplicacion PyQt6.\nDesarrollador: Mauricio Posada.\nVersion 1.0.0\n2021.' ) mensaje.exec()
def initActions(self): self.selectStep = QAction("Select step", self) self.selectSect = QAction("Select section", self) self.selectAllSects = QAction("Select all", self) sep = QAction(self) sep.setSeparator(True) self.dupeStep = QAction("Duplicate step", self) self.dupeSect = QAction("Duplicate section", self) self.addActions([ self.selectStep, self.selectSect, self.selectAllSects, self.dupeStep, self.dupeSect ]) pass
def initUI(self): menubar = self.menuBar() fileMenu = menubar.addMenu('File') impMenu = QMenu('Import', self) impAct = QAction('Import mail', self) impMenu.addAction(impAct) newAct = QAction('New', self) fileMenu.addAction(newAct) fileMenu.addMenu(impMenu) self.setGeometry(300, 300, 350, 250) self.setWindowTitle('Submenu') self.show()
def showMenu(self): "设计托盘的菜单,这里我实现了一个二级菜单" self.menu = QMenu() self.menu1 = QMenu() self.showAction1 = QAction("显示消息1", self, triggered=self.showM) self.showAction2 = QAction("显示消息2", self, triggered=self.showM) self.quitAction = QAction("退出", self, triggered=self.quit) self.menu1.addAction(self.showAction1) self.menu1.addAction(self.showAction2) self.menu.addMenu(self.menu1) self.menu.addAction(self.showAction1) self.menu.addAction(self.showAction2) self.menu.addAction(self.quitAction) self.menu1.setTitle("二级菜单") self.setContextMenu(self.menu)
def __init__(self): super().__init__() self.menu = QMenu() self.usage = QAction() self.usage.setText("Initialised") self.menu.addAction(self.usage) self.version = QAction("Notifier ({})".format(__version__)) self.version.setDisabled(True) self.menu.addAction(self.version) self.menu.addSeparator() self.menu.addAction("Quit", lambda: exit(0)) self.setContextMenu(self.menu) self.setIcon(QIcon("icons/0.svg")) self.show() self.task = TaskCpu() self.task.start() self.task.on_cpu_changed.connect( lambda value: self.set_icon(value)) # noqa
class Captura_Datos(QMainWindow): def __init__(self): QMainWindow.__init__(self) self.initGui() def initGui(self): self.setWindowTitle('My Application!!!') self.setFixedSize(600, 400) #self.showFullScreen() # Label self.lbl_saludo = QLabel('Bienvenido...', self) self.lbl_saludo.move(50, 50) # Menu self.menu_principal = self.menuBar() self.menu_archivo = self.menu_principal.addMenu('Archivo') self.menu_operaciones = self.menu_principal.addMenu('Operaciones') self.menu_ayuda = self.menu_principal.addMenu('Ayuda') # Archivo self.menu_item_salir = QAction('Salir', self) self.menu_item_salir.setShortcut('⌘D') self.menu_item_salir.triggered.connect(self.close) self.menu_archivo.addAction(self.menu_item_salir) # Operaciones self.menu_item_operaciones = QAction('Operaciones', self) self.menu_operaciones.addAction(self.menu_item_operaciones) # Ayuda self.menu_acerca_de = QAction('Acerca de MY Application.', self) self.menu_ayuda.addAction(self.menu_acerca_de) self.menu_ayuda.triggered.connect(self.mostrar_acerca_de) def mostrar_acerca_de(self): mensaje = QMessageBox() mensaje.setIcon(QMessageBox.Icon.Information) mensaje.setText( 'A cerca de My Application.\n\nPyQt6 App.\nDesarrollador: Mauricio Posada.\nVersión: 1.0.0\n2021.' ) mensaje.exec()
def MakeHelpMenu(self, mainMenu): helpMenu = mainMenu.addMenu('&Help') aboutAction = QAction(QIcon(), 'About', self) aboutAction.setStatusTip('About this application') aboutAction.triggered.connect(self.About) helpMenu.addAction(aboutAction) aboutQtAction = QAction(QIcon(), 'About Qt', self) aboutQtAction.setStatusTip('About Qt and Qt Licensing') aboutQtAction.triggered.connect(self.AboutQt) helpMenu.addAction(aboutQtAction)
def initUI(self): self.setWindowTitle(self.title) self.setMinimumHeight(self.height) self.setMinimumWidth(self.width) bar = self.menuBar() about = bar.addMenu("About") config = bar.addMenu("Configuration") info = QAction("App Information", self) about.triggered[QAction].connect(self.aboutThis) about.addAction(info) configAction = QAction("System configuration", self) config.triggered[QAction].connect(self.configWindow) config.addAction(configAction) self.setGeometry(self.left, self.top, self.width, self.height) self.setCentralWidget(self.table_widget) widget = QWidget() container = QHBoxLayout() icon = self.style().standardIcon( QStyle.StandardPixmap.SP_MessageBoxInformation) self.iconLabel.setPixmap(icon.pixmap(QSize(16, 16))) self.restartProcessButton.clicked.connect(self.restartProcess) container.setSpacing(5) container.addWidget(self.iconLabel) container.addWidget(self.informationLabel) if self.classifyExercises is None: self.informationLabel.setText( 'Myo Connect is not running!Please start process.') container.addWidget(self.restartProcessButton) widget.setLayout(container) self.statusBar.addWidget(widget) self.setStatusBar(self.statusBar) self.show()
def __getMenuBar(self) -> QMenuBar: bar = self.menuBar() file = bar.addMenu("File") file.addAction("New") save = QAction("Save", self) save.setShortcut(QKeySequence.StandardKey.Save) file.addAction(save) edit = bar.addMenu("Edit") edit.addAction("copy") edit.addAction("paste") quit = QAction("Quit", self) file.addAction(quit) file.triggered.connect( # type: ignore # no proper type hints for this method yet lambda x: print( x), # type: ignore # no inline type info for lambdas just yet ) return bar
def add_action(self, name: str, func: Callable, menu: str = None, shortcut: str = None, tooltip: str = None, label_text: str = None, parent: QWidget = None, **kw) -> QAction: """Convenience func to create QAction and add to menu bar Parameters ---------- name : str Action name Returns ------- QAction """ name_action = name.replace(' ', '_').lower() name_key = f'act_{name_action}' name = f.nice_title(name.replace( '_', ' ')) if label_text is None else label_text if parent is None: parent = self act = QAction(name, parent, triggered=func, **kw) if not shortcut is None: act.setShortcut(QKeySequence(shortcut)) act.setToolTip(tooltip) # act.setShortcutContext(Qt.ShortcutContext.WidgetShortcut) act.setShortcutVisibleInContextMenu(True) setattr(parent, name_key, act) if not menu is None: menu = self.get_menu(menu) menu.addAction(act) else: parent.addAction(act) return act
def __init__(self, parent=None): super().__init__(parent) self.setupUi(self) self.TRAY = QSystemTrayIcon(self) self.TRAY.setIcon(QApplication.style().standardIcon( QStyle.StandardPixmap.SP_MessageBoxInformation)) self.TRAY.setToolTip('FGO-py') self.MENU_TRAY = QMenu(self) self.MENU_TRAY_QUIT = QAction('退出', self.MENU_TRAY) self.MENU_TRAY.addAction(self.MENU_TRAY_QUIT) self.MENU_TRAY_FORCEQUIT = QAction('强制退出', self.MENU_TRAY) self.MENU_TRAY.addAction(self.MENU_TRAY_FORCEQUIT) self.TRAY.setContextMenu(self.MENU_TRAY) self.TRAY.show() self.reloadTeamup() self.config = Config({ 'stopOnDefeated': (self.MENU_SETTINGS_DEFEATED, fgoKernel.schedule.stopOnDefeated), 'stopOnKizunaReisou': (self.MENU_SETTINGS_KIZUNAREISOU, fgoKernel.schedule.stopOnKizunaReisou), 'closeToTray': (self.MENU_CONTROL_TRAY, None), 'stayOnTop': (self.MENU_CONTROL_STAYONTOP, lambda x: self.setWindowFlag( Qt.WindowType.WindowStaysOnTopHint, x)), 'notifyEnable': (self.MENU_CONTROL_NOTIFY, None) }) self.notifier = ServerChann(**self.config['notifyParam']) self.worker = Thread() self.signalFuncBegin.connect(self.funcBegin) self.signalFuncEnd.connect(self.funcEnd) self.TRAY.activated.connect(lambda reason: self.show( ) if reason == QSystemTrayIcon.ActivationReason.Trigger else None) self.MENU_TRAY_QUIT.triggered.connect(lambda: QApplication.quit() if self.askQuit() else None) self.MENU_TRAY_FORCEQUIT.triggered.connect(QApplication.quit) self.getDevice()
def __init__(self): app = QApplication(sys.argv) super().__init__() self.setWindowTitle('PyQt6 Menu Example') self.setGeometry(100, 100, 640, 480) self.statusBar().showMessage('Message in statusbar.') # We want references to the individual menus so that # menu entries can be added to the top level menu entries. # mainMenu = self.menuBar() fileMenu = mainMenu.addMenu('&File') editMenu = mainMenu.addMenu('&Edit') viewMenu = mainMenu.addMenu('&View') searchMenu = mainMenu.addMenu('&Search') toolsMenu = mainMenu.addMenu('&Tools') self.MakeHelpMenu(mainMenu) # I have a bug here: The icon (QIcon) will not display. # I broke up the instatiation to debug this, but nothing # works. I'm using Raspbian Buster's 24x24 exit PNG file. # exitButton = QAction(QIcon('exit.png'), 'E&xit', self) exitButton.setStatusTip('Exit application') exitButton.triggered.connect(self.close) fileMenu.addAction(exitButton) # Make a toolbar. I'm using the same PNG for an icon # I tried to use on the Exit menu selection. It is # displayed here, but not there. *sigh* # exitAction = QAction(QIcon('exit.png'), 'Exit', self) exitAction.setShortcut('Alt+X') exitAction.triggered.connect(self.close) self.toolbar = self.addToolBar('Exit') self.toolbar.addAction(exitAction) self.show() sys.exit(app.exec())
def initUI(self): exitAct = QAction(QIcon('exit.png'), '&Exit', self) exitAct.setShortcut('Ctrl+Q') exitAct.setStatusTip('Exit application') exitAct.triggered.connect(QApplication.instance().quit) self.statusBar() menubar = self.menuBar() fileMenu = menubar.addMenu('&File') fileMenu.addAction(exitAct) self.setGeometry(300, 300, 350, 250) self.setWindowTitle('Simple menu') self.show()
def __init__(self, parent=None, window=None): """Construct MenuBar instance and create submenus. Args: parent (widget, optional) Objects parent widget. Defaults to None. window (widget, optional) Program's main window. Defaults to None. """ super().__init__(parent=parent) self.setObjectName("MainMenuBar") self.setVisible(True) self.setNativeMenuBar(False) self.window = window self.window.setMenuBar(self) self.filemenu = QMenu("File", parent=self) self.settings = QMenu("Preferences", parent=self) self.help = QMenu("Help", parent=self) self.addMenu(self.filemenu) self.addMenu(self.settings) self.addMenu(self.help) self.exitaction = QAction("&Exit") self.settingsaction = QAction("&Settings") self.newGameAction = QAction("&New Game") self.minimize = QAction("&Minimize") self.maximize = QAction("&Maximize") self.aboutQt = QAction("&About Qt") self.aboutSelf = QAction("&About") self.help.addAction(self.aboutQt) self.help.addAction(self.aboutSelf) self.filemenu.addAction(self.minimize) self.filemenu.addAction(self.maximize) self.filemenu.addAction(self.exitaction) self.settings.addAction(self.settingsaction) self.filemenu.addAction(self.newGameAction) self.aboutQt.triggered.connect(self.aboutQtMenu) self.minimize.triggered.connect(self.minimizeWindow) self.maximize.triggered.connect(self.maxamizeWindow) self.exitaction.triggered.connect(self.exit_app) self.settingsaction.triggered.connect(self.open_settings) self.newGameAction.triggered.connect(self.newGame) self.aboutSelf.triggered.connect(self.about)
def initUI(self): self.statusbar = self.statusBar() self.statusbar.showMessage('Ready') menubar = self.menuBar() viewMenu = menubar.addMenu('View') viewStatAct = QAction('View statusbar', self, checkable=True) viewStatAct.setStatusTip('View statusbar') viewStatAct.setChecked(True) viewStatAct.triggered.connect(self.toggleMenu) viewMenu.addAction(viewStatAct) self.setGeometry(300, 300, 350, 250) self.setWindowTitle('Check menu') self.show()
def initUI(self): self.textEdit = QTextEdit() self.setCentralWidget(self.textEdit) self.statusBar() openFile = QAction(QIcon('open.png'), 'Open', self) openFile.setShortcut('Ctrl+O') openFile.setStatusTip('Open new File') openFile.triggered.connect(self.showDialog) menubar = self.menuBar() fileMenu = menubar.addMenu('&File') fileMenu.addAction(openFile) self.setGeometry(300, 300, 550, 450) self.setWindowTitle('File dialog') self.show()
class WindowCpu(QSystemTrayIcon): def __init__(self): super().__init__() self.menu = QMenu() self.usage = QAction() self.usage.setText("Initialised") self.menu.addAction(self.usage) self.version = QAction("Notifier ({})".format(__version__)) self.version.setDisabled(True) self.menu.addAction(self.version) self.menu.addSeparator() self.menu.addAction("Quit", lambda: exit(0)) self.setContextMenu(self.menu) self.setIcon(QIcon("icons/0.svg")) self.show() self.task = TaskCpu() self.task.start() self.task.on_cpu_changed.connect( lambda value: self.set_icon(value)) # noqa def set_icon(self, value): """ initial == 0 white [0-25) == 1 blue [25-50) == 2 green [50-75) == 3 yellow [75-100) == 4 orange [100-) == 5 red :param value: :return: """ if 0 <= value < 25: icon = 1 elif 25 <= value < 50: icon = 2 elif 50 <= value < 75: icon = 3 elif 75 <= value < 100: icon = 4 else: icon = 5 self.usage.setText("Usage % {}".format(value)) self.setIcon(QIcon("icons/{}.svg".format(icon)))
def initUI(self): textEdit = QTextEdit() self.setCentralWidget(textEdit) exitAct = QAction(QIcon('exit24.png'), 'Exit', self) exitAct.setShortcut('Ctrl+Q') exitAct.setStatusTip('Exit application') exitAct.triggered.connect(self.close) self.statusBar() menubar = self.menuBar() fileMenu = menubar.addMenu('&File') fileMenu.addAction(exitAct) toolbar = self.addToolBar('Exit') toolbar.addAction(exitAct) self.setGeometry(300, 300, 350, 250) self.setWindowTitle('Main window') self.show()
def createActions(self): """Create the application's menu actions.""" # Create actions for File menu self.settings_act = QAction("Settings...", self, triggered=self.showSettingsDialog)
def createActions(self): """Create the application's menu actions.""" # Create actions for File menu self.import_act = QAction("Import Images...", self, triggered=self.importImages) self.import_act.setShortcut("Ctrl+I") self.preferences_act = QAction("Preferences...", self, triggered=self.showPreferencesDialog) self.quit_act = QAction("Quit Task Manager", self, triggered=self.close) self.quit_act.setShortcut(QKeySequence.StandardKey.Quit) # Ctrl+Q # Create actions for Edit menu self.select_all_act = QAction("Select All", self, triggered=self.image_view_lw.selectAll) self.select_all_act.setShortcut(QKeySequence.StandardKey.SelectAll) # Ctrl+A self.delete_act = QAction("Delete Images", self, triggered=self.deleteImages) self.delete_act.setShortcut(QKeySequence.StandardKey.Delete) # Del self.delete_act.setEnabled(False) # Create actions for View menu # Handle the visibility of the dock widget self.show_dock_act = self.image_preview_dock.toggleViewAction() self.show_dock_act.setText("Show Image View") self.sort_ascend_act = QAction("Sort Ascending", self, triggered=lambda: self.sortListItems(Qt.SortOrder.AscendingOrder)) self.sort_ascend_act.setEnabled(False) self.sort_descend_act = QAction("Sort Descending", self, triggered=lambda: self.sortListItems(Qt.SortOrder.DescendingOrder)) self.sort_descend_act.setEnabled(False) self.fullscreen_act = QAction("Show Fullscreen", self, triggered=self.displayFullScreen, checkable=True) # Create actions for Help menu self.about_act = QAction("About Image Manager", self, triggered=self.showAboutDialog)
class MainWindow(QMainWindow): def __init__(self): """MainWindow Constructor for Image Manager""" super().__init__() # Constructor for QMainWindow self.initializeUI() def initializeUI(self): """Set up the GUI's main window.""" self.setWindowTitle("Image Manager") self.setObjectName("ImageManager") # Set up the main window, menu, and dock widgets self.setUpMainWindow() self.displayImagePreviewDock() self.createActions() self.createMenus() self.show() # Display the main window def setUpMainWindow(self): """Set up the application's main window containing the QListWidget.""" self.image_view_lw = ImageViewerListWidget(self) self.setCentralWidget(self.image_view_lw) def createActions(self): """Create the application's menu actions.""" # Create actions for File menu self.import_act = QAction("Import Images...", self, triggered=self.importImages) self.import_act.setShortcut("Ctrl+I") self.preferences_act = QAction("Preferences...", self, triggered=self.showPreferencesDialog) self.quit_act = QAction("Quit Task Manager", self, triggered=self.close) self.quit_act.setShortcut(QKeySequence.StandardKey.Quit) # Ctrl+Q # Create actions for Edit menu self.select_all_act = QAction("Select All", self, triggered=self.image_view_lw.selectAll) self.select_all_act.setShortcut(QKeySequence.StandardKey.SelectAll) # Ctrl+A self.delete_act = QAction("Delete Images", self, triggered=self.deleteImages) self.delete_act.setShortcut(QKeySequence.StandardKey.Delete) # Del self.delete_act.setEnabled(False) # Create actions for View menu # Handle the visibility of the dock widget self.show_dock_act = self.image_preview_dock.toggleViewAction() self.show_dock_act.setText("Show Image View") self.sort_ascend_act = QAction("Sort Ascending", self, triggered=lambda: self.sortListItems(Qt.SortOrder.AscendingOrder)) self.sort_ascend_act.setEnabled(False) self.sort_descend_act = QAction("Sort Descending", self, triggered=lambda: self.sortListItems(Qt.SortOrder.DescendingOrder)) self.sort_descend_act.setEnabled(False) self.fullscreen_act = QAction("Show Fullscreen", self, triggered=self.displayFullScreen, checkable=True) # Create actions for Help menu self.about_act = QAction("About Image Manager", self, triggered=self.showAboutDialog) def createMenus(self): """Create the application's menu.""" self.file_menu = self.menuBar().addMenu("&File") self.file_menu.addAction(self.import_act) self.file_menu.addSeparator() self.file_menu.addAction(self.preferences_act) self.file_menu.addSeparator() self.file_menu.addAction(self.quit_act) self.edit_menu = self.menuBar().addMenu("&Edit") self.edit_menu.addAction(self.select_all_act) self.edit_menu.addSeparator() self.edit_menu.addAction(self.delete_act) self.view_menu = self.menuBar().addMenu("&View") self.view_menu.addAction(self.show_dock_act) self.view_menu.addSeparator() self.view_menu.addAction(self.sort_ascend_act) self.view_menu.addAction(self.sort_descend_act) self.view_menu.addSeparator() self.view_menu.addAction(self.fullscreen_act) self.help_menu = self.menuBar().addMenu("&Help") self.help_menu.addAction(self.about_act) def displayImagePreviewDock(self): """Dock widget that displays a selected image in a scrollable area and uses its file name as the dock's title.""" self.image_preview_dock = QDockWidget() self.image_preview_dock.setObjectName("PreviewDock") self.image_preview_dock.setWindowTitle("Show Image View") self.image_preview_dock.setAllowedAreas(Qt.DockWidgetArea.RightDockWidgetArea) self.display_image_label = QLabel() self.display_image_label.setAlignment(Qt.AlignmentFlag.AlignCenter) self.view_scroll_area = QScrollArea() self.view_scroll_area.setMinimumWidth(300) self.view_scroll_area.setWidgetResizable(True) self.image_preview_dock.setWidget(self.view_scroll_area) # Set initial location of dock widget self.addDockWidget(Qt.DockWidgetArea.RightDockWidgetArea, self.image_preview_dock) def displayFullScreen(self, state): """Check the state of checkable fullscreen_act. If True, show the main window as fullscreen.""" if state: self.showFullScreen() else: self.showNormal() def importImages(self): """Placeholder method.""" pass def deleteImages(self): """Placeholder method.""" pass def showPreferencesDialog(self): """Placeholder method.""" pass def showAboutDialog(self): """Placeholder method.""" pass
class Captura_Datos(QMainWindow): def __init__(self): QMainWindow.__init__(self) self.initGui() def initGui(self): self.setWindowTitle('Aplicación Captura de Datos') self.setFixedSize(400, 400) #self.showFullScreen() # Botones self.btn_nombre = QPushButton('Nombre Completo', self) self.btn_nombre.setFixedWidth(200) self.btn_nombre.move(100, 30) self.btn_nombre.clicked.connect(self.capturar_nombre) self.btn_edad = QPushButton('Edad', self) self.btn_edad.setFixedWidth(200) self.btn_edad.move(100, 60) self.btn_nombre.clicked.connect(self.capturar_edad) self.btn_ahorros = QPushButton('Ahorros', self) self.btn_ahorros.setFixedWidth(200) self.btn_ahorros.move(100, 90) self.btn_nombre.clicked.connect(self.capturar_ahorros) self.btn_color = QPushButton('Color', self) self.btn_color.setFixedWidth(200) self.btn_color.move(100, 120) self.btn_nombre.clicked.connect(self.capturar_color) # Resultado self.lbl_resultado = QLabel('Información personal:', self) self.lbl_resultado.move(100, 180) self.lbl_resultado.setFixedWidth(200) # Etiquetas de datos self.lbl_nombre = QLabel('Nombre Completo:', self) self.lbl_nombre.move(50, 240) self.lbl_nombre.setFixedWidth(200) self.lbl_nombre = QLabel('Edad:', self) self.lbl_nombre.move(50, 270) self.lbl_nombre.setFixedWidth(200) self.lbl_nombre = QLabel('Ahorros:', self) self.lbl_nombre.move(50, 300) self.lbl_nombre.setFixedWidth(200) self.lbl_nombre = QLabel('Color:', self) self.lbl_nombre.move(50, 330) self.lbl_nombre.setFixedWidth(200) # Etiquetas de resultados self.lbl_nombre_result = QLabel(self) self.lbl_nombre_result.move(200, 240) self.lbl_nombre_result.setFixedWidth(200) self.lbl_edad_result = QLabel(self) self.lbl_edad_result.move(200, 270) self.lbl_edad_result.setFixedWidth(200) self.lbl_ahorros_result = QLabel(self) self.lbl_ahorros_result.move(200, 300) self.lbl_ahorros_result.setFixedWidth(200) self.lbl_color_result = QLabel(self) self.lbl_color_result.move(200, 330) self.lbl_color_result.setFixedWidth(200) # Menu self.menu_principal = self.menuBar() self.menu_archivo = self.menu_principal.addMenu('Archivo') self.menu_operaciones = self.menu_principal.addMenu('Operaciones') self.menu_ayuda = self.menu_principal.addMenu('Ayuda') # Archivo self.menu_item_salir = QAction('Salir', self) self.menu_item_salir.setShortcut('⌘D') self.menu_item_salir.triggered.connect(self.close) self.menu_archivo.addAction(self.menu_item_salir) # Operaciones self.menu_item_operaciones = QAction('Operaciones', self) self.menu_operaciones.addAction(self.menu_item_operaciones) # Ayuda self.menu_acerca_de = QAction('Acerca de Aplicación Captura de Datos.', self) self.menu_ayuda.addAction(self.menu_acerca_de) self.menu_ayuda.triggered.connect(self.mostrar_acerca_de) def mostrar_acerca_de(self): mensaje = QMessageBox() mensaje.setIcon(QMessageBox.Icon.Information) mensaje.setText( 'A cerca de Aplicación captura de datos.\n\nAplicacion PyQt6.\nDesarrollador: Mauricio Posada.\nVersión: 1.0.0\n2021.' ) mensaje.exec() def capturar_nombre(self): nombre, ok = QInputDialog.getText(self, 'Captura de datos.', 'Escribe tu nombre completo:') if ok: nombre = nombre.strip() if len(nombre): self.lbl_nombre_result.setText(nombre) def capturar_edad(self): edad, ok = QInputDialog.getInt(self, 'Captura de datos.', 'Escribe tu edad:', 10, 1, 80) if ok: self.lbl_edad_result.setText(str(edad)) def capturar_ahorros(self): ahorros, ok = QInputDialog.getDouble( self, 'Captura de datos.', 'Escribe tu cantidad de ahorros:', 0, 1000, 1000000) # Minimo, incremento, Maximo if ok: self.lbl_ahorros_result.setText(str(ahorros)) def capturar_color(self): colores = [ 'Amarillo', 'Azul', 'Blanco', 'Rojo', 'Verde', 'Negro', 'Morado' ] color, ok = QInputDialog.getItem( self, 'Captura de datos.', 'Selecciona un color.', colores, 0, False ) # 0 inicia desde el color[0], False no permite editar la lista de colores if ok: self.lbl_color_result.setText(color)
def initGui(self): self.setWindowTitle('Aplicación Captura de Datos') self.setFixedSize(400, 400) #self.showFullScreen() # Botones self.btn_nombre = QPushButton('Nombre Completo', self) self.btn_nombre.setFixedWidth(200) self.btn_nombre.move(100, 30) self.btn_nombre.clicked.connect(self.capturar_nombre) self.btn_edad = QPushButton('Edad', self) self.btn_edad.setFixedWidth(200) self.btn_edad.move(100, 60) self.btn_nombre.clicked.connect(self.capturar_edad) self.btn_ahorros = QPushButton('Ahorros', self) self.btn_ahorros.setFixedWidth(200) self.btn_ahorros.move(100, 90) self.btn_nombre.clicked.connect(self.capturar_ahorros) self.btn_color = QPushButton('Color', self) self.btn_color.setFixedWidth(200) self.btn_color.move(100, 120) self.btn_nombre.clicked.connect(self.capturar_color) # Resultado self.lbl_resultado = QLabel('Información personal:', self) self.lbl_resultado.move(100, 180) self.lbl_resultado.setFixedWidth(200) # Etiquetas de datos self.lbl_nombre = QLabel('Nombre Completo:', self) self.lbl_nombre.move(50, 240) self.lbl_nombre.setFixedWidth(200) self.lbl_nombre = QLabel('Edad:', self) self.lbl_nombre.move(50, 270) self.lbl_nombre.setFixedWidth(200) self.lbl_nombre = QLabel('Ahorros:', self) self.lbl_nombre.move(50, 300) self.lbl_nombre.setFixedWidth(200) self.lbl_nombre = QLabel('Color:', self) self.lbl_nombre.move(50, 330) self.lbl_nombre.setFixedWidth(200) # Etiquetas de resultados self.lbl_nombre_result = QLabel(self) self.lbl_nombre_result.move(200, 240) self.lbl_nombre_result.setFixedWidth(200) self.lbl_edad_result = QLabel(self) self.lbl_edad_result.move(200, 270) self.lbl_edad_result.setFixedWidth(200) self.lbl_ahorros_result = QLabel(self) self.lbl_ahorros_result.move(200, 300) self.lbl_ahorros_result.setFixedWidth(200) self.lbl_color_result = QLabel(self) self.lbl_color_result.move(200, 330) self.lbl_color_result.setFixedWidth(200) # Menu self.menu_principal = self.menuBar() self.menu_archivo = self.menu_principal.addMenu('Archivo') self.menu_operaciones = self.menu_principal.addMenu('Operaciones') self.menu_ayuda = self.menu_principal.addMenu('Ayuda') # Archivo self.menu_item_salir = QAction('Salir', self) self.menu_item_salir.setShortcut('⌘D') self.menu_item_salir.triggered.connect(self.close) self.menu_archivo.addAction(self.menu_item_salir) # Operaciones self.menu_item_operaciones = QAction('Operaciones', self) self.menu_operaciones.addAction(self.menu_item_operaciones) # Ayuda self.menu_acerca_de = QAction('Acerca de Aplicación Captura de Datos.', self) self.menu_ayuda.addAction(self.menu_acerca_de) self.menu_ayuda.triggered.connect(self.mostrar_acerca_de)