def delete_confirmation(parent, _id: str, action: Callable): msg = QMessageBox() msg.setText("Are you sure, you want to remove ?") msg.setStyleSheet(''' background-color: #1d251c; color: #bdc0bd; ''') msg.setParent(parent) msg.setWindowModality(Qt.WindowModality.WindowModal) style = ''' margin-top: 20px; border: none; ''' yes_btn = QPushButton(" Yes") yes_btn.setIcon(QIcon(full_path("assets/images/icons/trash-can.ico"))) yes_btn.setStyleSheet(style) no_btn = QPushButton(" Cancel") no_btn.setStyleSheet(style) no_btn.setIcon(QIcon(full_path("assets/images/icons/cancel.ico"))) yes_btn.setDefault(True) msg.addButton(no_btn, msg.ButtonRole.NoRole) msg.addButton(yes_btn, msg.ButtonRole.YesRole) msg.buttonClicked.connect(lambda x: action(_id) if x.text().lower().strip() == "yes" else do_nothing()) msg.exec()
def __init__(self): super(Window, self).__init__() self.groupBox = QGroupBox( "What is your favorite programming Language ?") self.groupBox.setFont(QFont("Sanserif", 13)) self.checkBox1 = QCheckBox("Python") self.checkBox1.setIcon(QIcon("")) self.checkBox1.setWhatsThis("This is a checkbox of Python") self.checkBox2 = QCheckBox("C++") self.checkBox2.setIcon(QIcon("")) self.checkBox1.setWhatsThis("This is a checkbox of C++") self.checkBox3 = QCheckBox("Java") self.checkBox3.setIcon(QIcon("")) self.checkBox1.setWhatsThis("This is a checkbox of Java") self.label = QLabel("You Have Selected FootBall") self.title = " " self.left = 100 self.top = 200 self.width = 400 self.height = 300 self.InitWindow()
def make_file_menu(self, main_menu): file_menu = main_menu.addMenu('&File') new_action = QAction(QIcon(), 'New', self) new_action.setStatusTip('New clear edit area') new_action.triggered.connect(self.newFile) file_menu.addAction(new_action) open_action = QAction(QIcon(), 'Open', self) open_action.setStatusTip('Open file') open_action.triggered.connect(self.openFile) file_menu.addAction(open_action) save_action = QAction(QIcon(), 'Save', self) file_menu.addAction(save_action) save_as_action = QAction(QIcon(), 'Save as', self) file_menu.addAction(save_as_action) file_menu.addSeparator() exit_action = QAction(QIcon("application-exit.png"), 'Exit', self) exit_action.setShortcut('Ctrl+Q') exit_action.setStatusTip('Exit application') exit_action.triggered.connect(self.close) file_menu.addAction(exit_action)
def set_file_icon(name): suffix = name.split(".")[-1] ico_path = SRC_DIR + f"{suffix}.gif" if os.path.isfile(ico_path): return QIcon(ico_path) else: return QIcon(SRC_DIR + "file.ico")
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 add_or_button(button: QToolButton): if button.text().lower() == "and": button.setText("or") button.setIcon(QIcon(full_path("assets/images/icons/or.ico"))) elif button.text().lower() == "or": button.setText("and") button.setIcon(QIcon(full_path("assets/images/icons/and.ico")))
def show_selected(self): self.model.removeRows(0, self.model.rowCount()) for item in self.selected: if os.path.isfile(item): self.model.appendRow( QStandardItem(QIcon(SRC_DIR + "file.ico"), item)) else: self.model.appendRow( QStandardItem(QIcon(SRC_DIR + "folder.gif"), item)) self.set_size()
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 __init__(self, nugget_list_widget): super(NuggetListItemWidget, self).__init__(nugget_list_widget) self.nugget_list_widget = nugget_list_widget self.nugget = None self.setFixedHeight(40) self.setStyleSheet("background-color: white") self.layout = QHBoxLayout(self) self.layout.setContentsMargins(20, 0, 20, 0) self.layout.setSpacing(10) self.info_label = QLabel() self.info_label.setFont(CODE_FONT_BOLD) self.layout.addWidget(self.info_label) self.left_split_label = QLabel("|") self.left_split_label.setFont(CODE_FONT_BOLD) self.layout.addWidget(self.left_split_label) self.text_edit = QTextEdit() self.text_edit.setReadOnly(True) self.text_edit.setFrameStyle(0) self.text_edit.setFont(CODE_FONT) self.text_edit.setLineWrapMode(QTextEdit.LineWrapMode.FixedPixelWidth) self.text_edit.setLineWrapColumnOrWidth(10000) self.text_edit.setHorizontalScrollBarPolicy( Qt.ScrollBarPolicy.ScrollBarAlwaysOff) self.text_edit.setVerticalScrollBarPolicy( Qt.ScrollBarPolicy.ScrollBarAlwaysOff) self.text_edit.setFixedHeight(30) self.text_edit.setText("") self.layout.addWidget(self.text_edit) self.right_split_label = QLabel("|") self.right_split_label.setFont(CODE_FONT_BOLD) self.layout.addWidget(self.right_split_label) self.match_button = QPushButton() self.match_button.setIcon(QIcon("aset_ui/resources/correct.svg")) self.match_button.setFlat(True) self.match_button.clicked.connect(self._match_button_clicked) self.layout.addWidget(self.match_button) self.fix_button = QPushButton() self.fix_button.setIcon(QIcon("aset_ui/resources/incorrect.svg")) self.fix_button.setFlat(True) self.fix_button.clicked.connect(self._fix_button_clicked) self.layout.addWidget(self.fix_button)
def initUI(self): self.setWindowTitle("确认删除") self.setWindowIcon(QIcon(SRC_DIR + "delete.ico")) self.layout = QVBoxLayout() self.list_view = QListView() self.list_view.setViewMode(QListView.ViewMode.ListMode) # 列表 self.slm = QStandardItem() self.model = QStandardItemModel() max_len = 10 count = 0 for info in self.infos: if info.is_file: # 文件 self.model.appendRow( QStandardItem(set_file_icon(info.name), info.name)) else: self.model.appendRow( QStandardItem(QIcon(SRC_DIR + "folder.gif"), info.name)) self.out.append({ 'fid': info.id, 'is_file': info.is_file, 'name': info.name }) # id,文件标示, 文件名 count += 1 if max_len < len(info.name): # 使用最大文件名长度 max_len = len(info.name) self.list_view.setModel(self.model) self.lb_name = QLabel("尝试删除以下{}个文件(夹):".format(count)) self.buttonBox = QDialogButtonBox() self.buttonBox.setOrientation(Qt.Orientation.Horizontal) self.buttonBox.setStandardButtons( QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel) self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setText("确定") self.buttonBox.button( QDialogButtonBox.StandardButton.Cancel).setText("取消") self.layout.addWidget(self.lb_name) self.layout.addWidget(self.list_view) self.layout.addWidget(self.buttonBox) self.setLayout(self.layout) self.buttonBox.accepted.connect(self.btn_ok) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.setMinimumWidth(400) self.resize(int(max_len * 8), int(count * 34 + 60))
def initUI(self): self.setWindowIcon(QIcon(SRC_DIR + "desc.ico")) self.lb_name = QLabel() self.lb_name.setText("文件夹名:") self.lb_name.setAlignment(Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignTrailing | Qt.AlignmentFlag.AlignVCenter) self.tx_name = QLineEdit() self.lb_desc = QLabel() self.tx_desc = QTextEdit() self.lb_desc.setText("描 述:") self.lb_desc.setAlignment(Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignTrailing | Qt.AlignmentFlag.AlignVCenter) self.buttonBox = QDialogButtonBox() self.buttonBox.setOrientation(Qt.Orientation.Horizontal) self.buttonBox.setStandardButtons( QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel) self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setText("确定") self.buttonBox.button( QDialogButtonBox.StandardButton.Cancel).setText("取消") self.grid = QGridLayout() self.grid.setSpacing(10) self.grid.addWidget(self.lb_name, 1, 0) self.grid.addWidget(self.tx_name, 1, 1) self.grid.addWidget(self.lb_desc, 2, 0) self.grid.addWidget(self.tx_desc, 2, 1, 5, 1) self.grid.addWidget(self.buttonBox, 7, 1, 1, 1) self.setLayout(self.grid) self.buttonBox.accepted.connect(self.btn_ok) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject)
def __init__(self, email, password, computer_id): QDialog.__init__(self) Ui_RestoreDialog.__init__(self) self.setupUi(self) self.email = email self.password = password self.computer_id = computer_id self.logger = get_logger() self.setWindowIcon(QIcon(LOGO_PATH)) self.snapshot_tree_widget = QLazyTreeWidget() self.snapshot_tree_layout.addWidget(self.snapshot_tree_widget) self.snapshots_combo_box.currentTextChanged.connect( self.load_current_snapshot) self.restore_button.pressed.connect(self.restore) self.set_elements_enabled(False) self.setWindowTitle("Loading Backups. Please Wait...") self.snapshots_combo_box.clear() self.snapshots_thread = SnapshotsThread(email, password, computer_id) self.snapshots_thread.loaded.connect(self.snapshots_loaded) self.snapshots_thread.start() self.reset_loading_backup_dialog() self.restoring_dialog = LoadingDialog( self, "Restoring. Please Wait...", ) self.logger.info("Restore dialog displayed.")
def __init_ui(self): self.log.debug("Initializing UI") self.setWindowTitle("Revenant") # TODO: Update this with some sort of connection string when connected self.status_bar.showMessage("Not Connected") self.__add_output_window() self.__add_input_field() exit_action = QAction(QIcon("exit.png"), "&Exit", self) exit_action.setShortcut("Ctrl-Q") exit_action.setStatusTip("Exit") exit_action.triggered.connect(QApplication.instance().quit) view_status_bar = QAction("Status Bar", self, checkable=True) view_status_bar.setStatusTip("Show the status bar") view_status_bar.setChecked(True) view_status_bar.triggered.connect(self.toggle_menu) menubar = self.menuBar() file_menu = menubar.addMenu("&File") file_menu.addAction(exit_action) view_menu = menubar.addMenu("View") view_menu.addAction(view_status_bar) self.show()
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 other(self): self.activated.connect(self.iconClied) # 把鼠标点击图标的信号和槽连接 self.messageClicked.connect(self.mClied) # 把鼠标点击弹出消息的信号和槽连接 self.setIcon(QIcon("ico.ico")) self.icon = self.icon()
def __init__(self, email, password): QDialog.__init__(self) Ui_WelcomeDialog.__init__(self) self.setupUi(self) self.email = email self.password = password self.logger = get_logger() self.setWindowIcon(QIcon(LOGO_PATH)) self.account_label.setText(f"Account: {email}") self.logo_label.setPixmap(get_pixmap(LOGO_PATH, 20, 20)) self.initialize_thread = InitializeThread(email, password) self.initialize_thread.initialized.connect(self.accept) self.start_backing_up_button.pressed.connect(self.initialize) self.terms_of_service_label.linkActivated.connect( lambda: webbrowser.open(TERMS_URL)) self.restore_files_label.linkActivated.connect(self.restore_files) if not self.has_computers(): self.restore_files_label.setVisible(False) self.logger.info("Welcome dialog displayed.")
def __init__(self, main_window): QDialog.__init__(self) Ui_SettingsDialog.__init__(self) self.setupUi(self) self.logger = get_logger() self.main_window = main_window self.setWindowIcon(QIcon(LOGO_PATH)) self.populate_settings() self.inclusions_add_button.pressed.connect(self.inclusions_add) self.inclusions_remove_button.pressed.connect(self.inclusions_remove) self.exclusions_add_button.pressed.connect(self.exclusions_add) self.exclusions_remove_button.pressed.connect(self.exclusions_remove) self.restore_different_computer_label.linkActivated.connect( self.restore_different_computer ) self.inherit_backup_history_label.linkActivated.connect( self.inherit_backup_history ) self.change_password_label.linkActivated.connect(self.change_password) self.save_button.pressed.connect(self.accept) if not self.has_other_computers(): self.restore_different_computer_label.setVisible(False) self.inherit_backup_history_label.setVisible(False) if is_windows(): self.backup_connected_file_systems_label.setVisible(False) self.backup_connected_file_systems_combo_box.setVisible(False) self.logger.info("Settings dialog displayed.")
def __init__(self, first_time=False): QMainWindow.__init__(self) Ui_MainWindow.__init__(self) self.setupUi(self) self.logger = get_logger() self.setWindowIcon(QIcon(LOGO_PATH)) self.logo_label.setPixmap(get_pixmap(LOGO_PATH, 20, 20)) self.computer_label.setPixmap(get_pixmap(COMPUTER_PATH, 20, 20)) self.arrow_label.setPixmap(get_pixmap(ARROW_PATH, 20, 20)) self.cloud_label.setPixmap(get_pixmap(CLOUD_PATH, 20, 20)) self.settings_button.pressed.connect(self.open_settings) self.backup_now_button.pressed.connect(self.toggle_backup) self.restore_button.pressed.connect(self.open_restore_files) self.privacy_label.linkActivated.connect( lambda: webbrowser.open(PRIVACY_URL)) self.support_label.linkActivated.connect( lambda: webbrowser.open(SUPPORT_URL)) self.launch_status_thread() self.launch_backup_thread() if first_time: dialog = BackupStartedDialog() dialog.exec()
def __init__(self, *args, **kwargs): super(SwaVanMainWindow, self).__init__(*args, **kwargs) self.setWindowIcon(QIcon(full_path("assets/images/logo/swavan_one_ui.png"))) self.setContentsMargins(0, 0, 0, 0) _window = SwaVanDashboard() self.setCentralWidget(_window) self.setWindowTitle("SwaVan")
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 eventFilter(self, source, event): if event.type( ) == QEvent.Type.ContextMenu and source is self.mock_env_list: menu = QMenu() _copy = menu.addAction( QIcon(full_path("assets/images/icons/export.ico")), "Export") _remove = menu.addAction( QIcon(full_path("assets/images/icons/trash-can.ico")), "Remove") if source.itemAt(event.pos()): action = menu.exec(event.globalPos()) _item = source.itemAt(event.pos()) _id = _item.whatsThis() if action == _remove: delete_confirmation(self, _id, self.delete) return True return super().eventFilter(source, event)
def __init__(self, document_base_viewer): super(AttributeWidget, self).__init__(document_base_viewer) self.document_base_viewer = document_base_viewer self.attribute = None self.setFixedHeight(40) self.setStyleSheet("background-color: white") self.layout = QHBoxLayout(self) self.layout.setContentsMargins(20, 0, 20, 0) self.layout.setSpacing(40) self.attribute_name = QLabel() self.attribute_name.setFont(CODE_FONT_BOLD) self.layout.addWidget(self.attribute_name, alignment=Qt.AlignmentFlag.AlignLeft) self.num_matched = QLabel("matches: -") self.num_matched.setFont(CODE_FONT) self.layout.addWidget(self.num_matched, alignment=Qt.AlignmentFlag.AlignLeft) self.buttons_widget = QWidget() self.buttons_layout = QHBoxLayout(self.buttons_widget) self.buttons_layout.setContentsMargins(0, 0, 0, 0) self.buttons_layout.setSpacing(10) self.layout.addWidget(self.buttons_widget, alignment=Qt.AlignmentFlag.AlignRight) self.forget_matches_button = QPushButton() self.forget_matches_button.setIcon(QIcon("aset_ui/resources/redo.svg")) self.forget_matches_button.setToolTip( "Forget matches for this attribute.") self.forget_matches_button.setFlat(True) self.forget_matches_button.clicked.connect( self._forget_matches_button_clicked) self.buttons_layout.addWidget(self.forget_matches_button) self.remove_button = QPushButton() self.remove_button.setIcon(QIcon("aset_ui/resources/trash.svg")) self.remove_button.setToolTip("Remove this attribute.") self.remove_button.setFlat(True) self.remove_button.clicked.connect(self._remove_button_clicked) self.buttons_layout.addWidget(self.remove_button)
def __init__(self): super(Window, self).__init__() self.groupBox = QGroupBox("What is your favorite sport ?") self.radiobtn3 = QRadioButton("BasketBall") self.radiobtn3.setIcon(QIcon("")) self.radiobtn2 = QRadioButton("Swimming") self.radiobtn2.setIcon(QIcon("")) self.radiobtn1 = QRadioButton("FootBall") self.radiobtn1.setIcon(QIcon("")) self.label = QLabel("You Have Selected FootBall") self.title = " " self.left = 100 self.top = 200 self.width = 400 self.height = 300 self.InitWindow()
def __init__(self, table_view): """ A simple class that inherits QWidget and acts as a container for items added to QTableView cells """ super().__init__() self.table_view = table_view self.setAutoFillBackground(True) view_button = QPushButton(QIcon("icons/view.png"), None) view_button.clicked.connect(self.displayItemValues) delete_button = QPushButton(QIcon("icons/trash.png"), None) delete_button.clicked.connect(self.deleteTableRows) # Create the layout for the buttons cell_layout = QHBoxLayout() cell_layout.setContentsMargins(0, 0, 0, 0) cell_layout.setSpacing(0) cell_layout.addWidget(view_button) cell_layout.addWidget(delete_button) self.setLayout(cell_layout)
def update_env_list(self): mocks = MockEnvironmentService.load() self.mock_env_list.clear() for _mock_env in mocks: item = QListWidgetItem() item.setWhatsThis(_mock_env.id) item.setIcon( QIcon(full_path("assets/images/icons/environment.ico"))) item.setText(f"{_mock_env.name}:{_mock_env.port}") self.mock_env_list.addItem(item)
def __init__(self, app): self.icon = QIcon( resourcePath(os.path.join("vi", "ui", "res", "logo_small.png")) ) QSystemTrayIcon.__init__(self, self.icon, app) self.setToolTip("Your Spyglass Information Service! :)") self.lastNotifications = {} self.setContextMenu(TrayContextMenu(self)) self.showAlarm = True self.showRequest = True self.alarmDistance = 0
def __init__(self): super().__init__() self.setWindowTitle('LazyDictionary') self.setWindowIcon(QIcon('book.png')) self.setFixedHeight(100) self.setFixedWidth(300) self.label = QLabel('word count: 0', self) self.label.setFont(QFont('san serif', 15)) self.label.move(90, 0) self.button() self.oneClick = True
def icon_url_changed(self, url): dc = QApplication.instance().disk_cache.data(url) if dc is not None: with closing(dc): raw = dc.readAll() p = QPixmap() p.loadFromData(raw) if not p.isNull(): ic = QIcon() ic.addPixmap(p) self.set_data(DECORATION_ROLE, ic)
def draw_item(self, painter, style, option): option.features |= option.HasDecoration option.icon = self.icon text_rect = style.subElementRect(style.SE_ItemViewItemText, option, None) if not option.icon.isNull(): icon_rect = style.subElementRect(style.SE_ItemViewItemDecoration, option, None) option.icon.paint(painter, icon_rect, alignment=Qt.AlignmentFlag.AlignBottom | Qt.AlignmentFlag.AlignHCenter) option.icon = QIcon() x, y = text_rect.x(), text_rect.y() y += (text_rect.height() - self.text.size().height()) // 2 painter.drawStaticText(QPoint(x, y), self.text)
def run_gui(): # Creat an instance of PyQt6 application # Every PyQt6 application has to contain this line app = QApplication(sys.argv) # Set the default icon to use for all the windows of our application app.setWindowIcon( QIcon('GUI/gui_icon.ico')) # GUI Icon, feel free to change # Create an instance of the GUI window. window = MainWindow() window.show() # Next line hands the control over to Python GUI app.exec()