def get_icon(name, default=None, resample=False): """Return image inside a QIcon object. default: default image name or icon resample: if True, manually resample icon pixmaps for usual sizes (16, 24, 32, 48, 96, 128, 256). This is recommended for QMainWindow icons created from SVG images on non-Windows platforms due to a Qt bug (see Issue 1314). """ icon_path = get_image_path(name, default=None) if icon_path is not None: icon = QIcon(icon_path) elif isinstance(default, QIcon): icon = default elif default is None: try: icon = get_std_icon(name[:-4]) except AttributeError: icon = QIcon(get_image_path(name, default)) else: icon = QIcon(get_image_path(name, default)) if resample: icon0 = QIcon() for size in (16, 24, 32, 48, 96, 128, 256, 512): icon0.addPixmap(icon.pixmap(size, size)) return icon0 else: return icon
def mk_enableicon(): enableicon = QIcon() enableicon.addPixmap(QPixmap(path("icons/enable.png")), state=enableicon.Off) enableicon.addPixmap(QPixmap(path("icons/disable.png")), state=enableicon.On) return enableicon
def get_icon(name, default=None, resample=False): """Return image inside a QIcon object. default: default image name or icon resample: if True, manually resample icon pixmaps for usual sizes (16, 24, 32, 48, 96, 128, 256). This is recommended for QMainWindow icons created from SVG images on non-Windows platforms due to a Qt bug (see Issue 1314). """ icon_path = get_image_path(name, default=None) if icon_path is not None: icon = QIcon(icon_path) elif isinstance(default, QIcon): icon = default elif default is None: try: icon = get_std_icon(name[:-4]) except AttributeError: icon = QIcon(get_image_path(name, default)) else: icon = QIcon(get_image_path(name, default)) if resample: icon0 = QIcon() for size in (16, 24, 32, 48, 96, 128, 256, 512): icon0.addPixmap(icon.pixmap(size, size)) return icon0 else: return icon
def get_icon(name, default=None, resample=True): """Return image inside a QIcon object default: default image name or icon resample: if True, manually resample icon pixmaps for usual sizes (16, 24, 32, 48, 96, 128, 256). This is recommended for QMainWindow icons created from SVG images on non-Windows platforms due to a Qt bug (see http://code.google.com/p/spyderlib/issues/detail?id=1314).""" icon = icon_cache.get((name, default, resample)) if icon: return icon if default is None: icon = QIcon(get_image_path(name)) elif isinstance(default, QIcon): icon_path = get_image_path(name) icon = default if icon_path is None else QIcon(icon_path) else: icon = QIcon(get_image_path(name)) if resample: icon0 = QIcon() for size in (16, 24, 32, 48, 96, 128, 256, 512): icon0.addPixmap(icon.pixmap(size, size)) icon_cache[(name, default, resample)] = icon0 ret = icon0 else: ret = icon icon_cache[(name, default, resample)] = ret return ret
def set_options(self, generators, icons): self.build_name_edit.clear() self.generators_list.clear() self.icon_combobox.clear() for generator in generators: item = QListWidgetItem(generator, self.generators_list) item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Checked) self.generators_list.addItem(item) for icon in icons: name = icon.get("name") pix = QPixmap() pix.loadFromData(base64.b64decode(icon.get("ico"))) ico = QIcon() ico.addPixmap(pix) self.icon_combobox.addItem(ico, name) self.spinner.stop()
def make_icon_pair(style, parent, standard_pixmap, transparent_role=QIcon.Disabled, *, transparency=0.25): ''' Using a standard pixmap (e.g., close button), create two pixmaps and set parent icon ''' icon = QIcon() normal_pixmap = style.standardPixmap(standard_pixmap, None, parent) icon.addPixmap(create_transparent_pixmap(normal_pixmap, transparency), transparent_role) icon.addPixmap(normal_pixmap, QIcon.Normal) parent.setIcon(icon) return icon
def get_icon(self, name, resample=False): """Return image inside a QIcon object. default: default image name or icon resample: if True, manually resample icon pixmaps for usual sizes (16, 24, 32, 48, 96, 128, 256). This is recommended for QMainWindow icons created from SVG images on non-Windows platforms due to a Qt bug. See spyder-ide/spyder#1314. """ icon_path = get_image_path(name) icon = QIcon(icon_path) if resample: icon0 = QIcon() for size in (16, 24, 32, 48, 96, 128, 256, 512): icon0.addPixmap(icon.pixmap(size, size)) return icon0 else: return icon
def __init__(self): """Main Window UI를 설정한다.""" super().__init__() self.setWindowTitle(f"Typing Number - {VER}") icon = QIcon() icon.addPixmap(QPixmap(r'ok_64x64.ico'), QIcon.Normal, QIcon.Off) self.setWindowIcon(icon) self.setMinimumSize(800, 100) # Typing Info self.typing = ManageTyping() # Setup StatusBar self.statusBar().showMessage("") self.statusBar().addPermanentWidget(VLine()) self.label_typing_avg = QLabel("평균타수 : 0.0타/초", self) self.statusBar().addPermanentWidget(self.label_typing_avg) self.statusBar().addPermanentWidget(VLine()) self.label_total_time = QLabel("총 연습시간", self) self.statusBar().addPermanentWidget(self.label_total_time) # Setup LineEdit self.line_for_number = QLineEdit(self) self.line_for_typing = QLineEdit(self) self.line_for_error = QLineEdit(self) self.setup_lineedit() vbox = QVBoxLayout() vbox.addWidget(self.line_for_number) vbox.addWidget(self.line_for_typing) vbox.addWidget(self.line_for_error) central_widget = QWidget(self) central_widget.setLayout(vbox) self.setCentralWidget(central_widget) self.new_game()
def __init__(self): """Init Main Window.""" super().__init__() # Title and set icon self.setWindowTitle(f"LightsOut by ok97465 - {VER}") icon = QIcon() icon.addPixmap(QPixmap(r'ok_64x64.ico'), QIcon.Normal, QIcon.Off) self.setWindowIcon(icon) # Setup toolbar self.toolbar = QToolBar() self.new_btn = None self.clear_btn = None self.n_lights_1axis_spinbox = None self.show_solution_chkbox = None self.setup_toolbar() # Setup Button self.btn_grid_table = QTableWidget(self) # Setup Status Bar self.n_clicked = 0 self.clicked_label = QLabel("0", self) self.n_solution_1_label = QLabel("0", self) self.setup_status_bar() # Setup info of lights out self.manage_puzzle = ManageLightsOutPuzzle() self.new_game() # Setup Main Layout self.setCentralWidget(self.btn_grid_table) self.resize_main_window() QTimer.singleShot(100, self.resize_main_window)
def get_icon(self, name, resample=False): """Return image inside a QIcon object. Parameters ---------- name: str Image name or icon resample: bool If True, manually resample icon pixmaps for usual sizes (16, 24, 32, 48, 96, 128, 256). This is recommended for QMainWindow icons created from SVG images on non-Windows platforms due to a Qt bug. See spyder-ide/spyder#1314. """ icon_path = get_image_path(name) if resample: # This only applies to the Spyder 2 icons icon = QIcon(icon_path) icon0 = QIcon() for size in (16, 24, 32, 48, 96, 128, 256, 512): icon0.addPixmap(icon.pixmap(size, size)) return icon0 else: icon = QIcon() # Normal state normal_state = QPixmap(icon_path) icon.addPixmap(normal_state, QIcon.Normal) # This is the color GammaRay reports for icons in disabled # buttons, both for the dark and light themes disabled_color = QColor(150, 150, 150) # Paint icon with the previous color to get the disabled state. # Taken from https://stackoverflow.com/a/65618075/438386 disabled_state = QPixmap(icon_path) qp = QPainter(disabled_state) qp.setCompositionMode(QPainter.CompositionMode_SourceIn) qp.fillRect(disabled_state.rect(), disabled_color) qp.end() icon.addPixmap(disabled_state, QIcon.Disabled) return icon
button.setSizePolicy(sp) button.clicked.connect(index.data()) self._parent.setIndexWidget(index, button) class DisableDelegate(QItemDelegate): def __init__(self, parent): super(DisableDelegate, self).__init__(parent) self._parent = parent def paint(self, painter, option, index): if not self._parent.indexWidget(index): button = QToolButton(self.parent()) button.setText("i") button.setAutoRaise(True) button.setIcon(enableicon) button.setCheckable(True) sp = QSizePolicy() sp.setWidthForHeight(True) button.setSizePolicy(sp) button.clicked.connect(index.data()) self._parent.setIndexWidget(index, button) enableicon = QIcon() enableicon.addPixmap(QPixmap(path("icons/enable.png")), state=enableicon.Off) enableicon.addPixmap(QPixmap(path("icons/disable.png")), state=enableicon.On)
def resourceStateIcon(on, off): """Load two images as an icon with on and off states""" icon = QIcon() icon.addPixmap(resourceImage(on), state=QIcon.On) icon.addPixmap(resourceImage(off), state=QIcon.Off) return icon
def __init__(self): super().__init__() self.setWindowTitle("OkPlayer") icon = QIcon() icon.addPixmap(QPixmap("ok_64x64.ico"), QIcon.Normal, QIcon.Off) self.setWindowIcon(icon) self.recent_file_acts = [] self.init_menu() self.now = datetime.now() # Setting self.setting = {} self.load_setting() # Status bar self.learning_time_ms = 0 self.learning_time_ms_total = self.setting.get( "learning_time_ms_total", 0) self.status_bar = self.statusBar() self.label_learning_time = QLabel(self) self.label_learning_time.setAlignment(Qt.AlignRight) self.status_bar.addPermanentWidget(self.label_learning_time) self.label_learning_time.setText( f"Learning time: 00:00" f" / total {ms2min_sec(self.learning_time_ms_total)}") # Timer for learning time self.timer_learning_time = QTimer(self) self.timer_learning_time.timeout.connect(self.update_learning_time) self.timer_learning_time.setInterval(1000) # Player self.player = QMediaPlayer(self) self.player.mediaStatusChanged.connect(self.qmp_status_changed) self.player.positionChanged.connect(self.qmp_position_changed) self.player.setNotifyInterval(50) self.player.setVolume(50) self.player_buf = QBuffer() self.path_media = "" self.music_data = None self.duration_ms = 0 self.duration_str = "" # A/B Loop self.pos_loop_a = None self.pos_loop_b = None # Layout self.label_music = QLabel("No music", self) self.ico_play = qta.icon("fa.play") self.ico_pause = qta.icon("fa.pause") layout = QVBoxLayout() layout_volume = QHBoxLayout() layout_btn_progress = QVBoxLayout() layout_music_btns = QHBoxLayout() self.btn_rewind = QPushButton(qta.icon("fa.backward"), "", self) self.btn_rewind.clicked.connect(self.rewind) self.btn_play = QPushButton(self.ico_play, "", self) self.btn_play.clicked.connect(self.play) self.btn_fastforward = QPushButton(qta.icon("fa.forward"), "", self) self.btn_fastforward.clicked.connect(self.fastforward) self.btn_rewind.setFocusPolicy(Qt.NoFocus) self.btn_play.setFocusPolicy(Qt.NoFocus) self.btn_fastforward.setFocusPolicy(Qt.NoFocus) layout_music_btns.addWidget(self.btn_rewind) layout_music_btns.addWidget(self.btn_play) layout_music_btns.addWidget(self.btn_fastforward) layout_progress = QHBoxLayout() self.progressbar = MusicProgressBar(self) self.progressbar.sig_pb_pos.connect(self.set_media_position) self.elapsed_time = QLineEdit(f"00:00 / 00:00", self) self.elapsed_time.setReadOnly(True) self.elapsed_time.setAlignment(Qt.AlignHCenter) layout_progress.addWidget(self.progressbar) layout_progress.addWidget(self.elapsed_time) layout_btn_progress.addWidget(self.label_music) layout_btn_progress.addLayout(layout_music_btns) layout_btn_progress.addLayout(layout_progress) # Volume self.qdial_volume = QDial(self) self.qdial_volume.setMinimumWidth(110) self.qdial_volume.setWrapping(False) self.qdial_volume.setNotchesVisible(True) self.qdial_volume.setMinimum(0) self.qdial_volume.setMaximum(100) self.qdial_volume.setValue(self.player.volume()) self.qdial_volume.valueChanged.connect(self.qdial_changed) layout_volume.addLayout(layout_btn_progress) layout_volume.addWidget(self.qdial_volume) # Lyrics self.display_lyrics = LyricsDisplay(self) layout.addLayout(layout_volume) layout.addWidget(self.display_lyrics) central_widget = QWidget() central_widget.setLayout(layout) self.setCentralWidget(central_widget) # Auto Play self.update_recent_file_action() path = self.setting.get("LastPlayedPath", "") if osp.isfile(path): self.load_music_file(path) self.setFocus()
def setupUi(self, MainWindow, title): MainWindow.setWindowTitle(title) MainWindow.setObjectName("MainWindow") MainWindow.resize(500, 500) MainWindow.setMinimumSize(QSize(300, 350)) self.centralWidget = QWidget(MainWindow) self.centralWidget.setObjectName("centralWidget") self.gridLayout = QGridLayout(self.centralWidget) self.gridLayout.setContentsMargins(11, 11, 11, 11) self.gridLayout.setSpacing(6) self.gridLayout.setObjectName("gridLayout") self.horizontalLayout_5 = QHBoxLayout() self.horizontalLayout_5.setContentsMargins(11, 11, 11, 11) self.horizontalLayout_5.setSpacing(6) self.horizontalLayout_5.setObjectName("horizontalLayout_5") self.lines_selected_label = QLabel(self.centralWidget) self.lines_selected_label.setObjectName("lines_selected_label") self.horizontalLayout_5.addWidget(self.lines_selected_label) self.label = QLabel(self.centralWidget) self.label.setObjectName("label") self.horizontalLayout_5.addWidget(self.label) self.draw_button = QPushButton(self.centralWidget) self.draw_button.setObjectName("draw_button") self.horizontalLayout_5.addWidget(self.draw_button) self.erase_button = QPushButton(self.centralWidget) self.erase_button.setObjectName("erase_button") self.horizontalLayout_5.addWidget(self.erase_button) self.dismiss_button = QPushButton(self.centralWidget) self.dismiss_button.setObjectName("dismiss_button") self.horizontalLayout_5.addWidget(self.dismiss_button) self.gridLayout.addLayout(self.horizontalLayout_5, 4, 0, 1, 1) self.verticalLayout_11 = QVBoxLayout() self.verticalLayout_11.setContentsMargins(11, 11, 11, 11) self.verticalLayout_11.setSpacing(6) self.verticalLayout_11.setObjectName("verticalLayout_11") self.tabWidget = QTabWidget(self.centralWidget) self.tabWidget.setObjectName("tabWidget") self.verticalLayout_11.addWidget(self.tabWidget) self.gridLayout.addLayout(self.verticalLayout_11, 0, 0, 1, 1) self.horizontalLayout_7 = QHBoxLayout() self.horizontalLayout_7.setContentsMargins(11, 11, 11, 11) self.horizontalLayout_7.setSpacing(6) self.horizontalLayout_7.setObjectName("horizontalLayout_7") self.add_set_button = QPushButton(self.centralWidget) self.add_set_button.setObjectName("add_set_button") self.horizontalLayout_7.addWidget(self.add_set_button) spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_7.addItem(spacerItem) self.gridLayout.addLayout(self.horizontalLayout_7, 2, 0, 2, 1) MainWindow.setCentralWidget(self.centralWidget) self.menuBar = QMenuBar(MainWindow) self.menuBar.setGeometry(QRect(0, 0, 767, 22)) self.menuBar.setObjectName("menuBar") self.menuFile = QMenu(self.menuBar) self.menuFile.setObjectName("menuFile") MainWindow.setMenuBar(self.menuBar) self.mainToolBar = QToolBar(MainWindow) self.mainToolBar.setMovable(False) self.mainToolBar.setFloatable(False) self.mainToolBar.setObjectName("mainToolBar") MainWindow.addToolBar(Qt.TopToolBarArea, self.mainToolBar) self.statusBar = QStatusBar(MainWindow) self.statusBar.setObjectName("statusBar") MainWindow.setStatusBar(self.statusBar) self.actionOpen = QAction(MainWindow) icon = QIcon() icon.addPixmap(QPixmap(":/img/Open Folder-48.png"), QIcon.Normal, QIcon.Off) self.actionOpen.setIcon(icon) self.actionOpen.setObjectName("actionOpen") self.actionExit = QAction(MainWindow) self.actionExit.setObjectName("actionExit") self.actionRemove = QAction(MainWindow) self.actionRemove.setObjectName("actionRemove") self.actionChange_Color = QAction(MainWindow) self.actionChange_Color.setObjectName("actionChange_Color") self.menuFile.addAction(self.actionOpen) self.menuFile.addSeparator() self.menuFile.addAction(self.actionExit) self.menuBar.addAction(self.menuFile.menuAction()) self.mainToolBar.addAction(self.actionOpen) self.mainToolBar.addSeparator() self.retranslateUi(MainWindow) QMetaObject.connectSlotsByName(MainWindow)
def create_icon(icon_path: str = ":/pyqt/source/images/New.png"): icon = QIcon() icon.addPixmap(QPixmap(icon_path), QIcon.Normal, QIcon.Off) return icon