def apply_theme(self, theme): self.theme = theme pal = self.palette() pal.setColor(pal.Base, theme_color(theme, 'Normal', 'bg')) pal.setColor(pal.AlternateBase, theme_color(theme, 'CursorLine', 'bg')) pal.setColor(pal.Text, theme_color(theme, 'Normal', 'fg')) pal.setColor(pal.Highlight, theme_color(theme, 'Visual', 'bg')) pal.setColor(pal.HighlightedText, theme_color(theme, 'Visual', 'fg')) self.setPalette(pal) self.tooltip_palette = pal = QPalette() pal.setColor(pal.ToolTipBase, theme_color(theme, 'Tooltip', 'bg')) pal.setColor(pal.ToolTipText, theme_color(theme, 'Tooltip', 'fg')) self.line_number_palette = pal = QPalette() pal.setColor(pal.Base, theme_color(theme, 'LineNr', 'bg')) pal.setColor(pal.Text, theme_color(theme, 'LineNr', 'fg')) pal.setColor(pal.BrightText, theme_color(theme, 'LineNrC', 'fg')) self.match_paren_format = theme_format(theme, 'MatchParen') font = self.font() ff = tprefs['editor_font_family'] if ff is None: ff = default_font_family() font.setFamily(ff) font.setPointSize(tprefs['editor_font_size']) self.tooltip_font = QFont(font) self.tooltip_font.setPointSize(font.pointSize() - 1) self.setFont(font) self.highlighter.apply_theme(theme) w = self.fontMetrics() self.number_width = max(map(lambda x: w.width(str(x)), xrange(10))) self.size_hint = QSize( self.expected_geometry[0] * w.averageCharWidth(), self.expected_geometry[1] * w.height()) self.highlight_color = theme_color(theme, 'HighlightRegion', 'bg') self.highlight_cursor_line() self.completion_popup.clear_caches(), self.completion_popup.update()
def __init__(self, prompt='>>> ', continuation='... ', parent=None): QTextEdit.__init__(self, parent) self.shutting_down = False self.compiler = CommandCompiler() self.buf = self.old_buf = [] self.history = History([''], dynamic.get('console_history', [])) self.prompt_frame = None self.allow_output = False self.prompt_frame_format = QTextFrameFormat() self.prompt_frame_format.setBorder(1) self.prompt_frame_format.setBorderStyle(QTextFrameFormat.BorderStyle_Solid) self.prompt_len = len(prompt) self.doc.setMaximumBlockCount(int(prefs['scrollback'])) self.lexer = PythonLexer(ensurenl=False) self.tb_lexer = PythonTracebackLexer() self.context_menu = cm = QMenu(self) # {{{ cm.theme = ThemeMenu(cm) # }}} self.formatter = Formatter(prompt, continuation, style=prefs['theme']) p = QPalette() p.setColor(p.Base, QColor(self.formatter.background_color)) p.setColor(p.Text, QColor(self.formatter.color)) self.setPalette(p) self.key_dispatcher = { # {{{ Qt.Key_Enter : self.enter_pressed, Qt.Key_Return : self.enter_pressed, Qt.Key_Up : self.up_pressed, Qt.Key_Down : self.down_pressed, Qt.Key_Home : self.home_pressed, Qt.Key_End : self.end_pressed, Qt.Key_Left : self.left_pressed, Qt.Key_Right : self.right_pressed, Qt.Key_Backspace : self.backspace_pressed, Qt.Key_Delete : self.delete_pressed, } # }}} motd = textwrap.dedent('''\ # Python {0} # {1} {2} '''.format(sys.version.splitlines()[0], __appname__, __version__)) sys.excepthook = self.unhandled_exception self.controllers = [] QTimer.singleShot(0, self.launch_controller) with EditBlock(self.cursor): self.render_block(motd)
def __InitView(self): # 初始化界面 palette = QPalette() # 新建调色板 palette.setColor(QPalette.Window, Qt.blue) # 将调色板中的窗体背景色设置为蓝色 self.setPalette(palette) # 在本窗体载入此调色板 self.setWindowFlags(Qt.FramelessWindowHint) # 设置窗体为无边框模式 self.setWindowOpacity(0.5) # 设置窗体的透明度为0.5 self.resize(200, 60) # 设置界面尺寸,宽150px,高60px self.setNumDigits(8) # 允许显示8个字符 原因,自己数右边几个字符 【HH:MM:SS】 self.showTime() # 初始化时间的显示
def disable_lineedit(lineedit_obj, change_to_disabled): """Change the background of a textfield""" if change_to_disabled: new_color = "#ccc" else: # Not disabled should be white new_color = "#fff" palette = QPalette() lineedit_obj.setReadOnly(change_to_disabled) palette.setColor(lineedit_obj.backgroundRole(), QColor(new_color)) lineedit_obj.setPalette(palette) lineedit_obj.setPalette(palette)
def __init__(self, parent=None): super(Main, self).__init__(parent) self.desktop = QApplication.desktop() self.screenRect = self.desktop.screenGeometry() self.h = self.screenRect.height() self.w = self.screenRect.width() self.xr = self.w / 930 self.yr = self.h / 640 self.zr = min(self.xr, self.yr) self.resize(self.w, self.h) palette = QPalette() palette.setBrush( QPalette.Background, QBrush(QPixmap("./resource/image/back.jpg").scaled(self.size()))) self.setPalette(palette)
def __init__(self, app): super(MainWindow, self).__init__() self.app = app print('window created') self.setWindowIcon(QIcon('img/icon.png')) self.setWindowTitle('Kasino') self.setPalette(QPalette(Qt.darkGreen)) self.setup_music() self.statusbar = QStatusBar(self) self.statusbar.setStyleSheet('background: white') self.setStatusBar(self.statusbar) self.statusbar.showMessage('Welcome to the Cassino game!') self.menubar = QMenuBar(self) self.optionsMenu = self.menubar.addMenu('Options') self.music_toggle = QAction() self.music_toggle.setText('Music') self.music_toggle.setShortcut('Ctrl+m') self.music_toggle.setCheckable(True) self.music_toggle.setChecked(True) self.optionsMenu.addAction(self.music_toggle) self.music_toggle.triggered.connect(self.toggle_music) self.speedGroup = QActionGroup(self) self.speedGroup.triggered.connect(self.set_speed) self.slow_speed = QAction('Slow', self.speedGroup) self.slow_speed.setCheckable(True) self.normal_speed = QAction('Normal', self.speedGroup) self.normal_speed.setCheckable(True) self.fast_speed = QAction('Fast', self.speedGroup) self.fast_speed.setCheckable(True) self.vfast_speed = QAction('Very Fast', self.speedGroup) self.vfast_speed.setCheckable(True) self.normal_speed.setChecked(True) self.speed_menu = self.optionsMenu.addMenu('Speed') self.speed_menu.addActions(self.speedGroup.actions()) self.menubar.setMouseTracking(False) self.setMenuBar(self.menubar) self.play_widget = PlayWidget(self) self.main_menu = MainMenu(self) self.start_menu = StartMenu(self) self.widgets = QStackedWidget(self) self.widgets.addWidget(self.play_widget) self.widgets.addWidget(self.main_menu) self.widgets.addWidget(self.start_menu) self.widgets.setCurrentWidget(self.main_menu) self.setCentralWidget(self.widgets) self.setGeometry(25, 50, 1028, 720) self.main_menu.startbutton.clicked.connect(self.init_game) self.main_menu.loadbutton.clicked.connect(self.load_game) self.main_menu.quitbutton.clicked.connect(self.quit) self.play_widget.quit_button.clicked.connect(self.quit_to_menu) self.play_widget.save_button.clicked.connect(self.save_game) self.start_menu.startbutton.clicked.connect(self.start_game)
def __init__(self, right=False, parent=None, show_open_in_editor=False): PlainTextEdit.__init__(self, parent) self.setFrameStyle(0) self.show_open_in_editor = show_open_in_editor self.side_margin = 0 self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.show_context_menu) self.setFocusPolicy(Qt.NoFocus) self.right = right self.setReadOnly(True) self.setLineWrapMode(self.WidgetWidth) font = self.font() ff = tprefs['editor_font_family'] if ff is None: ff = default_font_family() font.setFamily(ff) font.setPointSize(tprefs['editor_font_size']) self.setFont(font) self.calculate_metrics() self.setTabStopWidth(tprefs['editor_tab_stop_width'] * self.space_width) font = self.heading_font = QFont(self.font()) font.setPointSize(int(tprefs['editor_font_size'] * 1.5)) font.setBold(True) theme = get_theme(tprefs['editor_theme']) pal = self.palette() pal.setColor(pal.Base, theme_color(theme, 'Normal', 'bg')) pal.setColor(pal.AlternateBase, theme_color(theme, 'CursorLine', 'bg')) pal.setColor(pal.Text, theme_color(theme, 'Normal', 'fg')) pal.setColor(pal.Highlight, theme_color(theme, 'Visual', 'bg')) pal.setColor(pal.HighlightedText, theme_color(theme, 'Visual', 'fg')) self.setPalette(pal) self.viewport().setCursor(Qt.ArrowCursor) self.line_number_area = LineNumbers(self) self.blockCountChanged[int].connect(self.update_line_number_area_width) self.updateRequest.connect(self.update_line_number_area) self.line_number_palette = pal = QPalette() pal.setColor(pal.Base, theme_color(theme, 'LineNr', 'bg')) pal.setColor(pal.Text, theme_color(theme, 'LineNr', 'fg')) pal.setColor(pal.BrightText, theme_color(theme, 'LineNrC', 'fg')) self.line_number_map = LineNumberMap() self.search_header_pos = 0 self.changes, self.headers, self.images = [], [], OrderedDict() self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff), self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.diff_backgrounds = { 'replace' : theme_color(theme, 'DiffReplace', 'bg'), 'insert' : theme_color(theme, 'DiffInsert', 'bg'), 'delete' : theme_color(theme, 'DiffDelete', 'bg'), 'replacereplace': theme_color(theme, 'DiffReplaceReplace', 'bg'), 'boundary': QBrush(theme_color(theme, 'Normal', 'fg'), Qt.Dense7Pattern), } self.diff_foregrounds = { 'replace' : theme_color(theme, 'DiffReplace', 'fg'), 'insert' : theme_color(theme, 'DiffInsert', 'fg'), 'delete' : theme_color(theme, 'DiffDelete', 'fg'), 'boundary': QColor(0, 0, 0, 0), } for x in ('replacereplace', 'insert', 'delete'): f = QTextCharFormat() f.setBackground(self.diff_backgrounds[x]) setattr(self, '%s_format' % x, f)
def init_ui(self): self.resize(1300, 880) self.setFixedSize(self.width(), self.height()) self.setWindowTitle('图片识别') self.input = QLabel('待载入图片', self) self.input.setGeometry(10, 20, 600, 400) self.input.setStyleSheet( "QLabel{background:gray;}""QLabel{color:rgb(0,0,0,120);font-size:15px;font-weight:bold;font-family:宋体;}" ) self.input.setAlignment(QtCore.Qt.AlignCenter) self.detection_result = QLabel('检测结果', self) self.detection_result.setGeometry(10, 450, 600, 400) self.detection_result.setStyleSheet("QLabel{background:white;}" "QLabel{color:rgb(0,0,0,120);font-size:15px;font-weight:bold;font-family:宋体;}" ) self.detection_result.setAlignment(QtCore.Qt.AlignCenter) # 结果显示框 self.recognition_result = QLabel('识别结果', self) self.recognition_result.setGeometry(650, 10, 600, 400) self.recognition_result.setWordWrap(True) self.recognition_result.setAlignment(Qt.AlignCenter) QPalette().setColor(QPalette.WindowText, Qt.black) self.recognition_result.setAutoFillBackground(True) QPalette().setColor(QPalette.Window, Qt.white) self.recognition_result.setPalette(QPalette()) self.btn_select = QPushButton('选择图片', self) self.btn_select.setGeometry(900, 550, 100, 30) self.btn_select.clicked.connect(self.select_image) self.btn_dis = QPushButton('处理图片', self) self.btn_dis.setGeometry(900, 600, 100, 30) self.btn_dis.clicked.connect(self.on_btn_handle_Clicked) self.btn = QPushButton('返回', self) self.btn.setGeometry(900, 650, 100, 30) self.btn.clicked.connect(self.slot_btn_function) self.btn_exit = QPushButton('退出', self) self.btn_exit.setGeometry(900, 700, 100, 30) self.btn_exit.clicked.connect(self.quit)
def _initialize_collections(self): ''' Populate the data model with current collection assignments Hook click, doubleClick events ''' self._log_location() # Set the bg color of the description text fields to the dialog bg color if False: bgcolor = self.palette().color(QPalette.Background) palette = QPalette() palette.setColor(QPalette.Base, bgcolor) self.calibre_lw.setPalette(palette) self.marvin_lw.setPalette(palette) if self.calibre_collections is not None: for ca in self.calibre_collections: item = ListWidgetItem(ca) item.setData(Qt.UserRole, ca) if RENAMING_ENABLED: item.setFlags(item.flags() | Qt.ItemIsEditable) self.calibre_lw.addItem(item) for ma in self.marvin_collections: item = ListWidgetItem(ma) item.setData(Qt.UserRole, ma) if RENAMING_ENABLED: item.setFlags(item.flags() | Qt.ItemIsEditable) self.marvin_lw.addItem(item) # Capture click events to clear selections in opposite list self.calibre_lw.clicked.connect(self._clear_marvin_selection) self.marvin_lw.clicked.connect(self._clear_calibre_selection) # Hook double-click events if RENAMING_ENABLED: self.calibre_lw.doubleClicked.connect(self.rename_calibre_tag) self.marvin_lw.doubleClicked.connect(self.rename_marvin_tag) # Enable sorting if self.calibre_collections is not None: self.calibre_lw.setSortingEnabled(True) self.marvin_lw.setSortingEnabled(True)
def _populate_description(self): # Set the bg color of the description text fields to the dialog bg color bgcolor = self.palette().color(QPalette.Background) palette = QPalette() palette.setColor(QPalette.Base, bgcolor) self.calibre_description.setPalette(palette) self.marvin_description.setPalette(palette) if 'comments' in self.mismatches: self.calibre_description_label.setText(self.YELLOW_BG.format("<b>Description</b>")) if self.mismatches['comments']['calibre']: self.calibre_description.setText(self.mismatches['comments']['calibre']) self.marvin_description_label.setText(self.YELLOW_BG.format("<b>Description</b>")) if self.mismatches['comments']['Marvin']: self.marvin_description.setText(self.mismatches['comments']['Marvin']) else: if self.installed_book.comments: self.calibre_description.setText(self.installed_book.comments) self.marvin_description.setText(self.installed_book.comments)
def setupUi(self, MainWindow): p = QPalette() p.setColor(QPalette.Window, QColor(192, 253, 123)) MainWindow.setObjectName("1") MainWindow.resize(288, 202) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget) self.verticalLayout.setObjectName("verticalLayout") self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget) self.pushButton_2.setObjectName("pushButton_2") self.verticalLayout.addWidget(self.pushButton_2) self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget) self.pushButton_3.setObjectName("pushButton_3") self.verticalLayout.addWidget(self.pushButton_3) self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget) self.pushButton_4.setObjectName("pushButton_4") self.verticalLayout.addWidget(self.pushButton_4) self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget) self.pushButton_5.setObjectName("pushButton_5") self.verticalLayout.addWidget(self.pushButton_5) self.pushButton_6 = QtWidgets.QLabel(self.centralwidget) self.pushButton_6.setObjectName("pushButton_6") self.verticalLayout.addWidget(self.pushButton_6) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 288, 23)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.pushButton_6.setOpenExternalLinks(True) self.pushButton_6.setText( "<a href=https://sort.hust.cc >-----------------参考书推荐-----------------</a>" ) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow)
def insert_chekbox_to_table(self, row, column, status): cell_widget = QWidget() chk_bx = QCheckBox() chk_bx.setObjectName('{}-{}'.format(row, column)) lay_out = QHBoxLayout(cell_widget) lay_out.addWidget(chk_bx) lay_out.setAlignment(Qt.AlignCenter) lay_out.setContentsMargins(0, 0, 0, 0) cell_widget.setLayout(lay_out) pl = QPalette() if status: if column == 1: pl.setColor(QPalette.Background, Qt.green) else: pl.setColor(QPalette.Background, Qt.red) chk_bx.setCheckState(Qt.Checked) cell_widget.setAutoFillBackground(True) cell_widget.setPalette(pl) else: chk_bx.setCheckState(Qt.Unchecked) chk_bx.clicked.connect(self.onStateChanged) self.work_table.setFocusPolicy(Qt.NoFocus) self.work_table.setCellWidget(row, column, cell_widget)
def set_color(self): r, g, b = gprefs['cover_grid_color'] pal = QPalette() col = QColor(r, g, b) pal.setColor(pal.Base, col) tex = gprefs['cover_grid_texture'] if tex: from calibre.gui2.preferences.texture_chooser import texture_path path = texture_path(tex) if path: pm = QPixmap(path) if not pm.isNull(): val = pm.scaled(1, 1).toImage().pixel(0, 0) r, g, b = qRed(val), qGreen(val), qBlue(val) pal.setBrush(pal.Base, QBrush(pm)) dark = (r + g + b) / 3.0 < 128 pal.setColor(pal.Text, QColor(Qt.white if dark else Qt.black)) self.setPalette(pal) self.delegate.highlight_color = pal.color(pal.Text)
def __init__(self, parent, index): super(PlayerInfoField, self).__init__(parent) self.index = index self.layout = QHBoxLayout() self.auto_button = Button(self, 'Auto') self.auto_button.setFixedWidth(60) self.auto_button.clicked.connect(self.generate_name) self.layout.addWidget(self.auto_button) self.name_field = QLineEdit() self.name_field.setPalette(QPalette(Qt.white)) self.name_field.setPlaceholderText('Name') self.name_field.setClearButtonEnabled(True) self.name_field.setFixedWidth(250) self.layout.addWidget(self.name_field) self.AItoggle = QCheckBox() self.AItoggle.setText('Computer') self.AItoggle.setFixedWidth(100) self.layout.addWidget(self.AItoggle) self.AItoggle.stateChanged.connect(self.AIToggled) self.AIdifficulty = QComboBox() self.AIdifficulty.setPalette(QPalette(Qt.white)) self.AIdifficulty.setFixedWidth(100) self.AIdifficulty.addItems(['Braindead', 'Easy', 'Normal', 'Hard', 'HAL-9000']) self.AIdifficulty.setCurrentIndex(2) self.AIdifficulty.setDisabled(True) self.layout.addWidget(self.AIdifficulty) self.spacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.layout.addItem(self.spacer) self.layout.setContentsMargins(0, 0, 0, 0) self.setLayout(self.layout)
def _populate_description(self): # Set the bg color of the description text fields to the dialog bg color bgcolor = self.palette().color(QPalette.Background) palette = QPalette() palette.setColor(QPalette.Base, bgcolor) self.calibre_description.setPalette(palette) self.marvin_description.setPalette(palette) if 'comments' in self.mismatches: self.calibre_description_label.setText( self.YELLOW_BG.format("<b>Description</b>")) if self.mismatches['comments']['calibre']: self.calibre_description.setText( self.mismatches['comments']['calibre']) self.marvin_description_label.setText( self.YELLOW_BG.format("<b>Description</b>")) if self.mismatches['comments']['Marvin']: self.marvin_description.setText( self.mismatches['comments']['Marvin']) else: if self.installed_book.comments: self.calibre_description.setText(self.installed_book.comments) self.marvin_description.setText(self.installed_book.comments)
def set_color(self): r, g, b = gprefs['cover_grid_color'] pal = QPalette() col = QColor(r, g, b) pal.setColor(pal.Base, col) tex = gprefs['cover_grid_texture'] if tex: from calibre.gui2.preferences.texture_chooser import texture_path path = texture_path(tex) if path: pm = QPixmap(path) if not pm.isNull(): val = pm.scaled(1, 1).toImage().pixel(0, 0) r, g, b = qRed(val), qGreen(val), qBlue(val) pal.setBrush(pal.Base, QBrush(pm)) dark = (r + g + b)/3.0 < 128 pal.setColor(pal.Text, QColor(Qt.white if dark else Qt.black)) self.setPalette(pal) self.delegate.highlight_color = pal.color(pal.Text)
def __init__(self, prompt='>>> ', continuation='... ', parent=None): QTextEdit.__init__(self, parent) self.shutting_down = False self.compiler = CommandCompiler() self.buf = self.old_buf = [] self.history = History([''], dynamic.get('console_history', [])) self.prompt_frame = None self.allow_output = False self.prompt_frame_format = QTextFrameFormat() self.prompt_frame_format.setBorder(1) self.prompt_frame_format.setBorderStyle( QTextFrameFormat.BorderStyle_Solid) self.prompt_len = len(prompt) self.doc.setMaximumBlockCount(int(prefs['scrollback'])) self.lexer = PythonLexer(ensurenl=False) self.tb_lexer = PythonTracebackLexer() self.context_menu = cm = QMenu(self) # {{{ cm.theme = ThemeMenu(cm) # }}} self.formatter = Formatter(prompt, continuation, style=prefs['theme']) p = QPalette() p.setColor(p.Base, QColor(self.formatter.background_color)) p.setColor(p.Text, QColor(self.formatter.color)) self.setPalette(p) self.key_dispatcher = { # {{{ Qt.Key_Enter : self.enter_pressed, Qt.Key_Return : self.enter_pressed, Qt.Key_Up : self.up_pressed, Qt.Key_Down : self.down_pressed, Qt.Key_Home : self.home_pressed, Qt.Key_End : self.end_pressed, Qt.Key_Left : self.left_pressed, Qt.Key_Right : self.right_pressed, Qt.Key_Backspace : self.backspace_pressed, Qt.Key_Delete : self.delete_pressed, } # }}} motd = textwrap.dedent('''\ # Python {0} # {1} {2} '''.format(sys.version.splitlines()[0], __appname__, __version__)) sys.excepthook = self.unhandled_exception self.controllers = [] QTimer.singleShot(0, self.launch_controller) with EditBlock(self.cursor): self.render_block(motd)
def initItems(self): font = QFont() font.setPixelSize(16) self.prepareModel(os.getcwd()) self.setToolTip(os.getcwd()) # prepare drag and drop self.setDragEnabled(False) sizePolicy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.setSizePolicy(sizePolicy) self.setAutoExpandDelay(2) self.setAlternatingRowColors(False) self.setAnimated(False) self.setIndentation(20) self.setSortingEnabled(False) self.setRootIsDecorated(False) self.setPalette(QPalette(Qt.black)) self.verticalScrollBar().setStyleSheet("""border: 20px solid black; background-color: darkgreen; alternate-background-color: #FFFFFF;""") self.horizontalScrollBar().setStyleSheet("""border: 20px solid black; background-color: darkgreen; alternate-background-color: #FFFFFF;""") self.setFont(font) # signals self.doubleClicked.connect(self.onDoubleClicked) self.clicked.connect(self.onClicked) self.pressed.connect(self.onClicked) #self.entered.connect(self.onEntered) self.columnMoved() # that hides the size, file type and last modified colomns self.setHeaderHidden(True) self.hideColumn(1) self.hideColumn(2) self.hideColumn(3) self.resize(400, 400)
def initialize(self, parent, book_id, cid, installed_book, enable_metadata_updates, marvin_db_path): ''' __init__ is called on SizePersistedDialog() shared attributes of interest: .authors .author_sort .cover_hash .pubdate .publisher .rating .series .series_index .title .title_sort .comments .tags .uuid ''' self.setupUi(self) self.book_id = book_id self.cid = cid self.connected_device = parent.opts.gui.device_manager.device self.installed_book = installed_book self.marvin_db_path = marvin_db_path self.opts = parent.opts self.parent = parent self.stored_command = None self.verbose = parent.verbose self.BORDER_LR = 4 self.BORDER_TB = 8 self.GREY_FG = '<font style="color:#A0A0A0">{0}</font>' self.YELLOW_BG = '<font style="background:#FDFF99">{0}</font>' self._log_location(installed_book.title) # Subscribe to Marvin driver change events self.connected_device.marvin_device_signals.reader_app_status_changed.connect( self.marvin_status_changed) #self._log("mismatches:\n%s" % repr(installed_book.metadata_mismatches)) self.mismatches = installed_book.metadata_mismatches self._populate_title() self._populate_title_sort() self._populate_series() self._populate_authors() self._populate_author_sort() self._populate_uuid() self._populate_covers() self._populate_subjects() self._populate_publisher() self._populate_pubdate() self._populate_rating() self._populate_description() # ~~~~~~~~ Export to Marvin button ~~~~~~~~ self.export_to_marvin_button.setIcon(QIcon(os.path.join(self.parent.opts.resources_path, 'icons', 'from_calibre.png'))) self.export_to_marvin_button.clicked.connect(partial(self.store_command, 'export_metadata')) self.export_to_marvin_button.setEnabled(enable_metadata_updates) # ~~~~~~~~ Import from Marvin button ~~~~~~~~ self.import_from_marvin_button.setIcon(QIcon(os.path.join(self.parent.opts.resources_path, 'icons', 'from_marvin.png'))) self.import_from_marvin_button.clicked.connect(partial(self.store_command, 'import_metadata')) self.import_from_marvin_button.setEnabled(enable_metadata_updates) # If no calibre book, or no mismatches, adjust the display accordingly if not self.cid: #self._log("self.cid: %s" % repr(self.cid)) #self._log("self.mismatches: %s" % repr(self.mismatches)) self.calibre_gb.setVisible(False) self.import_from_marvin_button.setVisible(False) self.setWindowTitle(u'Marvin metadata') elif not self.mismatches: # Show both panels, but hide the transfer buttons self.export_to_marvin_button.setVisible(False) self.import_from_marvin_button.setVisible(False) else: self.setWindowTitle(u'Metadata Summary') if False: # Set the Marvin QGroupBox to Marvin red marvin_red = QColor() marvin_red.setRgb(189, 17, 20, alpha=255) palette = QPalette() palette.setColor(QPalette.Background, marvin_red) self.marvin_gb.setPalette(palette) # ~~~~~~~~ Add a Close or Cancel button ~~~~~~~~ self.close_button = QPushButton(QIcon(I('window-close.png')), 'Close') if self.mismatches: self.close_button.setText('Cancel') self.bb.addButton(self.close_button, QDialogButtonBox.RejectRole) self.bb.clicked.connect(self.dispatch_button_click) # Restore position self.resize_dialog()
def initialize(self, parent, book_id, cid, installed_book, enable_metadata_updates, marvin_db_path): ''' __init__ is called on SizePersistedDialog() shared attributes of interest: .authors .author_sort .cover_hash .pubdate .publisher .rating .series .series_index .title .title_sort .comments .tags .uuid ''' self.setupUi(self) self.book_id = book_id self.cid = cid self.connected_device = parent.opts.gui.device_manager.device self.installed_book = installed_book self.marvin_db_path = marvin_db_path self.opts = parent.opts self.parent = parent self.stored_command = None self.verbose = parent.verbose self.BORDER_LR = 4 self.BORDER_TB = 8 self.GREY_FG = '<font style="color:#A0A0A0">{0}</font>' self.YELLOW_BG = '<font style="background:#FDFF99">{0}</font>' self._log_location(installed_book.title) # Subscribe to Marvin driver change events self.connected_device.marvin_device_signals.reader_app_status_changed.connect( self.marvin_status_changed) #self._log("mismatches:\n%s" % repr(installed_book.metadata_mismatches)) self.mismatches = installed_book.metadata_mismatches self._populate_title() self._populate_title_sort() self._populate_series() self._populate_authors() self._populate_author_sort() self._populate_uuid() self._populate_covers() self._populate_subjects() self._populate_publisher() self._populate_pubdate() self._populate_rating() self._populate_description() # ~~~~~~~~ Export to Marvin button ~~~~~~~~ self.export_to_marvin_button.setIcon( QIcon( os.path.join(self.parent.opts.resources_path, 'icons', 'from_calibre.png'))) self.export_to_marvin_button.clicked.connect( partial(self.store_command, 'export_metadata')) self.export_to_marvin_button.setEnabled(enable_metadata_updates) # ~~~~~~~~ Import from Marvin button ~~~~~~~~ self.import_from_marvin_button.setIcon( QIcon( os.path.join(self.parent.opts.resources_path, 'icons', 'from_marvin.png'))) self.import_from_marvin_button.clicked.connect( partial(self.store_command, 'import_metadata')) self.import_from_marvin_button.setEnabled(enable_metadata_updates) # If no calibre book, or no mismatches, adjust the display accordingly if not self.cid: #self._log("self.cid: %s" % repr(self.cid)) #self._log("self.mismatches: %s" % repr(self.mismatches)) self.calibre_gb.setVisible(False) self.import_from_marvin_button.setVisible(False) self.setWindowTitle(u'Marvin metadata') elif not self.mismatches: # Show both panels, but hide the transfer buttons self.export_to_marvin_button.setVisible(False) self.import_from_marvin_button.setVisible(False) else: self.setWindowTitle(u'Metadata Summary') if False: # Set the Marvin QGroupBox to Marvin red marvin_red = QColor() marvin_red.setRgb(189, 17, 20, alpha=255) palette = QPalette() palette.setColor(QPalette.Background, marvin_red) self.marvin_gb.setPalette(palette) # ~~~~~~~~ Add a Close or Cancel button ~~~~~~~~ self.close_button = QPushButton(QIcon(I('window-close.png')), 'Close') if self.mismatches: self.close_button.setText('Cancel') self.bb.addButton(self.close_button, QDialogButtonBox.RejectRole) self.bb.clicked.connect(self.dispatch_button_click) # Restore position self.resize_dialog()
for dirpath, dirnames, filenames in os.walk(start1): for filename in filenames: if filename == "US_Accidents_Dec19.csv": filename = os.path.join(dirpath, filename) os.chdir(dirpath) print("Path Created") #########-------------------------------------- CREATE APPLICATION -------------------------------------- ######### print( "--------------------------APPLICATION--------------------------\nRunning Application..." ) #create application instance. Should only be one running at a time app = QApplication(sys.argv) app.setStyle("Fusion") palette = QPalette() palette.setColor(QPalette.Window, QColor(53, 53, 53)) palette.setColor(QPalette.WindowText, QColor(255, 255, 255)) palette.setColor(QPalette.Base, QColor(25, 25, 25)) palette.setColor(QPalette.AlternateBase, QColor(53, 53, 53)) palette.setColor(QPalette.ToolTipBase, QColor(255, 255, 255)) palette.setColor(QPalette.ToolTipText, QColor(255, 255, 255)) palette.setColor(QPalette.Text, QColor(255, 255, 255)) palette.setColor(QPalette.Button, QColor(53, 53, 53)) palette.setColor(QPalette.ButtonText, QColor(255, 255, 255)) palette.setColor(QPalette.BrightText, QColor(255, 0, 0)) palette.setColor(QPalette.Link, QColor(42, 130, 218)) palette.setColor(QPalette.Highlight, QColor(42, 130, 218)) palette.setColor(QPalette.HighlightedText, QColor(0, 0, 0)) app.setPalette(palette)
def hsiPlot(X): """Hyperspectral data viewer Displays the hyperspectral data. This is one of two methods to do this. Parameters ---------- X : object, Process instance The object X containing the hyperspectral array. """ app = QApplication(sys.argv) # Setting the dark-themed Fusion style for the GUI app.setStyle(QStyleFactory.create('Fusion')) dark_palette = QPalette() dark_palette.setColor(QPalette.Window, QColor(23, 23, 23)) dark_palette.setColor(QPalette.WindowText, QColor(200, 200, 200)) dark_palette.setColor(QPalette.Base, QColor(18, 18, 18)) dark_palette.setColor(QPalette.AlternateBase, QColor(53, 53, 53)) dark_palette.setColor(QPalette.ToolTipBase, Qt.white) dark_palette.setColor(QPalette.ToolTipText, Qt.white) dark_palette.setColor(QPalette.Text, QColor(200, 200, 200)) dark_palette.setColor(QPalette.Button, QColor(33, 33, 33)) dark_palette.setColor(QPalette.ButtonText, QColor(200, 200, 200)) dark_palette.setColor(QPalette.BrightText, Qt.red) dark_palette.setColor(QPalette.Link, QColor(42, 130, 218)) dark_palette.setColor(QPalette.Highlight, QColor(42, 130, 218)) dark_palette.setColor(QPalette.HighlightedText, Qt.white) dark_palette.setColor(QPalette.Active, QPalette.Button, QColor(33, 33, 33)) dark_palette.setColor(QPalette.Disabled, QPalette.Button, QColor(20, 20, 20)) dark_palette.setColor(QPalette.Disabled, QPalette.ButtonText, QColor(120, 120, 120)) app.setPalette(dark_palette) form = HSIDialog(X) form.show() app.exec_()
class DBSample(QMainWindow): def __init__(self): super().__init__() uic.loadUi('UI1.ui', self) self.setWindowTitle('Sql Reader') self.connection = sqlite3.connect("Res\\logs.db") self.pushButton.clicked.connect(self.select_data) self.horizontalSlider.valueChanged[int].connect(self.changeValue) self.comboBox.addItems(["White", "Dark", "Yarik's Orientation"]) self.comboBox.activated[str].connect(self.themes) self.themes('White') self.textEdit.setPlainText("SELECT * FROM Action") self.error = 0 def select_data(self): query = self.textEdit.toPlainText() if 'order by' not in str(query).lower(): query += ' order by "data time" desc' try: self.error = 0 res = self.connection.cursor().execute(query).fetchall() except: self.error = 1 self.label_3.setText('Sql request Error') self.tableWidget.setColumnCount(3) self.tableWidget.setHorizontalHeaderLabels( ['Action', 'Message', 'Data Time']) self.tableWidget.setColumnWidth(0, 150) self.tableWidget.setColumnWidth(1, 473) if self.error != 1: self.tableWidget.setColumnWidth(2, 110) else: self.tableWidget.setColumnWidth(2, 149) self.tableWidget.setRowCount(0) try: self.error = 0 for i, row in enumerate(res): self.tableWidget.setRowCount(self.tableWidget.rowCount() + 1) for j, elem in enumerate(row): self.tableWidget.setItem(i, j, QTableWidgetItem(str(elem))) self.error = 0 except: self.error = 1 self.label_3.setText('Sql request Error') def themes(self, text): if text == "Yarik's Orientation": self.label.setStyleSheet("color: rgb(0, 0, 0);") self.label_2.setStyleSheet("color: rgb(0, 0, 0);") self.label_3.setStyleSheet("color: rgb(0, 0, 0);") self.label_5.setStyleSheet("color: rgb(0, 0, 0);") self.pushButton.setStyleSheet( "background-image: url('Res/Timber.jpg');border-radius: 10px;") self.textEdit.setStyleSheet("background-image: url(Res/input.jpg)") self.Image = QImage("Res\\Azure Pop.jpg") self.Image = self.Image.scaled(QSize(800, 600)) self.palette = QPalette() self.palette.setBrush(10, QBrush(self.Image)) self.setPalette(self.palette) self.tableWidget.setStyleSheet( 'background-image: url(Res/table.jpg)') stylesheet = """ QTableWidget {background-image: url(Res/table.jpg)} QTableWidget QHeaderView::section:horizontal:first {background-image: url(Res/table0.jpg); border: none; border-style: none;} QTableWidget QHeaderView::section:horizontal:middle {background-image: url(Res/table1.jpg); border: none; border-style: none;} QTableWidget QHeaderView::section:horizontal:last {background-image: url(Res/table2.jpg); border: none; border-style: none;} QTableWidget QHeaderView::section:vertical {background-image: url(Res/table.jpg); border: none; border-style: none;} QTableWidget QTableCornerButton::section {background-image: url(Res/table.jpg); border: 0px} """ self.tableWidget.setStyleSheet(stylesheet) elif text == "Dark": self.label.setStyleSheet("color: rgb(235, 235, 235);") self.label_2.setStyleSheet("color: rgb(235, 235, 235);") self.label_3.setStyleSheet("color: rgb(235, 235, 235);") self.label_5.setStyleSheet("color: rgb(235, 235, 235);") self.pushButton.setStyleSheet( "background-color: white;border-radius: 10px;") self.textEdit.setStyleSheet( "color: rgb(235, 235, 235); background-color: rgb(50, 50, 50)") self.palette = QPalette() self.palette.setBrush(10, QBrush(QColor(27, 27, 27))) self.setPalette(self.palette) stylesheet = """ QTableWidget {color: rgb(235, 235, 235); background-color: rgb(50, 50, 50)} QTableWidget QHeaderView::section {background-color: rgb(50, 50, 50); border: none; border-style: none;} QTableWidget QHeaderView {color: rgb(235, 235, 235);background-color: rgb(50, 50, 50); border: none; border-style: none;} QTableWidget QTableCornerButton::section {background-color: rgb(50, 50, 50); border: 0px} """ self.tableWidget.setStyleSheet(stylesheet) elif text == "White": self.label.setStyleSheet("color: rgb(0, 0, 0);") self.label_2.setStyleSheet("color: rgb(0, 0, 0);") self.label_3.setStyleSheet("color: rgb(0, 0, 0);") self.label_5.setStyleSheet("color: rgb(0, 0, 0);") self.pushButton.setStyleSheet( "background-color: rgb(255, 255, 255);border-radius: 10px;") self.textEdit.setStyleSheet("background-color: rgb(255, 255, 255)") self.palette = QPalette() self.palette.setBrush(10, QBrush(QColor(240, 240, 240))) self.setPalette(self.palette) stylesheet = """ QTableWidget {background-color: rgb(255, 255, 255)} QTableWidget QHeaderView::section {background-color: rgb(255, 255, 255); border: none; border-style: none;} QTableWidget QHeaderView {background-color: rgb(255, 255, 255); border: none; border-style: none;} QTableWidget QTableCornerButton::section {background-color: rgb(255, 255, 255); border: 0px} """ self.tableWidget.setStyleSheet(stylesheet) def changeValue(self, value): self.setWindowOpacity(value / 100) def closeEvent(self, event): self.connection.close()
def themes(self, text): if text == "Yarik's Orientation": self.label.setStyleSheet("color: rgb(0, 0, 0);") self.label_2.setStyleSheet("color: rgb(0, 0, 0);") self.label_3.setStyleSheet("color: rgb(0, 0, 0);") self.label_5.setStyleSheet("color: rgb(0, 0, 0);") self.pushButton.setStyleSheet( "background-image: url('Res/Timber.jpg');border-radius: 10px;") self.textEdit.setStyleSheet("background-image: url(Res/input.jpg)") self.Image = QImage("Res\\Azure Pop.jpg") self.Image = self.Image.scaled(QSize(800, 600)) self.palette = QPalette() self.palette.setBrush(10, QBrush(self.Image)) self.setPalette(self.palette) self.tableWidget.setStyleSheet( 'background-image: url(Res/table.jpg)') stylesheet = """ QTableWidget {background-image: url(Res/table.jpg)} QTableWidget QHeaderView::section:horizontal:first {background-image: url(Res/table0.jpg); border: none; border-style: none;} QTableWidget QHeaderView::section:horizontal:middle {background-image: url(Res/table1.jpg); border: none; border-style: none;} QTableWidget QHeaderView::section:horizontal:last {background-image: url(Res/table2.jpg); border: none; border-style: none;} QTableWidget QHeaderView::section:vertical {background-image: url(Res/table.jpg); border: none; border-style: none;} QTableWidget QTableCornerButton::section {background-image: url(Res/table.jpg); border: 0px} """ self.tableWidget.setStyleSheet(stylesheet) elif text == "Dark": self.label.setStyleSheet("color: rgb(235, 235, 235);") self.label_2.setStyleSheet("color: rgb(235, 235, 235);") self.label_3.setStyleSheet("color: rgb(235, 235, 235);") self.label_5.setStyleSheet("color: rgb(235, 235, 235);") self.pushButton.setStyleSheet( "background-color: white;border-radius: 10px;") self.textEdit.setStyleSheet( "color: rgb(235, 235, 235); background-color: rgb(50, 50, 50)") self.palette = QPalette() self.palette.setBrush(10, QBrush(QColor(27, 27, 27))) self.setPalette(self.palette) stylesheet = """ QTableWidget {color: rgb(235, 235, 235); background-color: rgb(50, 50, 50)} QTableWidget QHeaderView::section {background-color: rgb(50, 50, 50); border: none; border-style: none;} QTableWidget QHeaderView {color: rgb(235, 235, 235);background-color: rgb(50, 50, 50); border: none; border-style: none;} QTableWidget QTableCornerButton::section {background-color: rgb(50, 50, 50); border: 0px} """ self.tableWidget.setStyleSheet(stylesheet) elif text == "White": self.label.setStyleSheet("color: rgb(0, 0, 0);") self.label_2.setStyleSheet("color: rgb(0, 0, 0);") self.label_3.setStyleSheet("color: rgb(0, 0, 0);") self.label_5.setStyleSheet("color: rgb(0, 0, 0);") self.pushButton.setStyleSheet( "background-color: rgb(255, 255, 255);border-radius: 10px;") self.textEdit.setStyleSheet("background-color: rgb(255, 255, 255)") self.palette = QPalette() self.palette.setBrush(10, QBrush(QColor(240, 240, 240))) self.setPalette(self.palette) stylesheet = """ QTableWidget {background-color: rgb(255, 255, 255)} QTableWidget QHeaderView::section {background-color: rgb(255, 255, 255); border: none; border-style: none;} QTableWidget QHeaderView {background-color: rgb(255, 255, 255); border: none; border-style: none;} QTableWidget QTableCornerButton::section {background-color: rgb(255, 255, 255); border: 0px} """ self.tableWidget.setStyleSheet(stylesheet)
def set_style(app): app.setStyle("Fusion") palette = QPalette() palette.setColor(QPalette.Window, QColor(255, 255, 255)) palette.setColor(QPalette.WindowText, Qt.black) palette.setColor(QPalette.Base, QColor(220, 220, 220)) palette.setColor(QPalette.AlternateBase, QColor(255, 255, 255)) palette.setColor(QPalette.ToolTipBase, Qt.black) palette.setColor(QPalette.ToolTipText, Qt.black) palette.setColor(QPalette.Text, Qt.black) palette.setColor(QPalette.Button, QColor(255, 255, 255)) palette.setColor(QPalette.ButtonText, Qt.black) palette.setColor(QPalette.BrightText, Qt.red) palette.setColor(QPalette.Link, QColor(42, 130, 218)) palette.setColor(QPalette.Highlight, QColor(220, 220, 220)) #QColor(42, 130, 218) palette.setColor(QPalette.HighlightedText, Qt.white) app.setPalette(palette) f = app.font() f.setFamily('sans-serif') f.setPointSize(12) app.setFont(f) directory = os.path.dirname(os.path.realpath(__file__)) with open(directory + '/style.qss', 'r') as file: app.setStyleSheet(file.read())
def main(): app = QApplication(sys.argv) # Setting the dark-themed Fusion style for the GUI app.setStyle(QStyleFactory.create('Fusion')) dark_palette = QPalette() dark_palette.setColor(QPalette.Window, QColor(23, 23, 23)) dark_palette.setColor(QPalette.WindowText, QColor(200, 200, 200)) dark_palette.setColor(QPalette.Base, QColor(18, 18, 18)) dark_palette.setColor(QPalette.AlternateBase, QColor(53, 53, 53)) dark_palette.setColor(QPalette.ToolTipBase, Qt.white) dark_palette.setColor(QPalette.ToolTipText, Qt.white) dark_palette.setColor(QPalette.Text, QColor(200, 200, 200)) dark_palette.setColor(QPalette.Button, QColor(33, 33, 33)) dark_palette.setColor(QPalette.ButtonText, QColor(200, 200, 200)) dark_palette.setColor(QPalette.BrightText, Qt.red) dark_palette.setColor(QPalette.Link, QColor(42, 130, 218)) dark_palette.setColor(QPalette.Highlight, QColor(42, 130, 218)) dark_palette.setColor(QPalette.HighlightedText, Qt.white) dark_palette.setColor(QPalette.Active, QPalette.Button, QColor(33, 33, 33)) dark_palette.setColor(QPalette.Disabled, QPalette.Button, QColor(20, 20, 20)) dark_palette.setColor(QPalette.Disabled, QPalette.ButtonText, QColor(120, 120, 120)) app.setPalette(dark_palette) form = ScanCARS() form.show() sys.exit(app.exec_())
def onStateChanged(self): ch_sender = self.sender() row, column = str(ch_sender.objectName()).split('-') pl = QPalette() if ch_sender.checkState() == Qt.Checked: if column == '1': pl.setColor(QPalette.Background, Qt.green) w_item = self.work_table.cellWidget(int(row), int(column)) w_item.setAutoFillBackground(True) w_item.setPalette(pl) pl.setColor(QPalette.Background, Qt.white) w_another_ch = self.work_table.cellWidget(int(row), 2) child_ch = w_another_ch.findChild(QCheckBox) child_ch.setCheckState(Qt.Unchecked) w_another_ch.setAutoFillBackground(True) w_another_ch.setPalette(pl) else: pl.setColor(QPalette.Background, Qt.red) w_item = self.work_table.cellWidget(int(row), int(column)) w_item.setAutoFillBackground(True) w_item.setPalette(pl) pl.setColor(QPalette.Background, Qt.white) w_another_ch = self.work_table.cellWidget(int(row), 1) child_ch = w_another_ch.findChild(QCheckBox) child_ch.setCheckState(Qt.Unchecked) w_another_ch.setAutoFillBackground(True) w_another_ch.setPalette(pl) else: pl.setColor(QPalette.Background, Qt.white) w_item = self.work_table.cellWidget(int(row), int(column)) w_item.setAutoFillBackground(True) w_item.setPalette(pl) pass
def __init__(self, parent): super(PlayWidget, self).__init__(parent) self.setAutoFillBackground(True) self.hlayout = QHBoxLayout(self) self.table_view = CardView(self) sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.table_view.sizePolicy().hasHeightForWidth()) self.table_view.setSizePolicy(sizePolicy) self.table_view.setMinimumHeight(200) self.table_view.setBackgroundBrush(Qt.darkGreen) self.table_view.setGeometry(0, 0, 1028, 200) self.hand_view = HandCardView(self) sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.hand_view.sizePolicy().hasHeightForWidth()) self.hand_view.setSizePolicy(sizePolicy) self.hand_view.setMinimumHeight(200) self.hand_view.setBackgroundBrush(Qt.darkGreen) self.hand_view.setGeometry(0, 0, 1028, 200) self.show_button = Button(self, 'Show Hand') self.show_button.setText("Show hand") self.show_button.clicked.connect(self.hand_view.show_cards) self.show_button.hide() self.move_button = Button(self, 'Make Move') self.move_button.setMinimumSize(300, 100) self.move_button.clicked.connect(self.attempt_move) self.move_button.hide() self.start_button = Button(self, 'Start Round') self.start_button.setMinimumHeight(100) self.start_button.clicked.connect(self.start_round) self.next_button = Button(self, 'Continue') self.next_button.setMinimumHeight(100) self.next_button.clicked.connect(self.goto_next_round) self.next_button.hide() self.quit_button = Button(self, 'Quit to menu') self.save_button = Button(self, 'Save') self.show_button.setMaximumWidth(150) self.move_button.setMaximumWidth(150) self.quit_button.setMaximumWidth(150) self.btnlayout = QHBoxLayout() self.btnlayout.addWidget(self.start_button) self.btn2layout = QHBoxLayout() self.btn2layout.addWidget(self.save_button) self.btn2layout.addWidget(self.quit_button) self.playlayout = QVBoxLayout() self.playlayout.addWidget(self.table_view) self.playlayout.addLayout(self.btnlayout) self.playlayout.addWidget(self.hand_view) self.playlayout.addLayout(self.btn2layout) self.hlayout.addLayout(self.playlayout) self.sidelayout = QVBoxLayout() self.log = QPlainTextEdit() self.log.setReadOnly(True) self.log.setPalette(QPalette(Qt.white)) self.log.setMaximumWidth(300) self.log.setMaximumHeight(200) self.sidelayout.addWidget(self.log) self.playerinfolayout = QVBoxLayout() self.sidelayout.addLayout(self.playerinfolayout) self.sidelayout.addItem( QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)) self.hlayout.addLayout(self.sidelayout) self.setup_sound() self.move_count = 0 self.speed = 3 self.game = None
def __init__(self, parent): super(StartMenu, self).__init__(parent) self.tophbox = QHBoxLayout() self.hbox = QHBoxLayout() self.vbox = QVBoxLayout() self.label = QLabel() self.label.setPixmap(QPixmap('img/new-game.png')) self.label.setScaledContents(True) self.label.setFixedSize(600, 200) self.tophbox.addWidget(self.label) self.startbutton = Button(self, 'Start') self.startbutton.setEnabled(False) self.startbutton.setFixedHeight(100) self.tophbox.addWidget(self.startbutton) self.playeramt_label = QLabel('Number of players:') self.playeramt_label.setFixedWidth(125) self.playeramount = QComboBox() self.playeramount.setStyleSheet('color: rgb(0, 0, 0)') self.playeramount.setFixedWidth(50) self.playeramount.addItems([str(i) for i in range(2, 13)]) self.playeramount.setCurrentIndex(2) self.playeramount.setMaxVisibleItems(11) self.playeramount.currentTextChanged.connect(self.form_player_entries) self.score_label = QLabel('Score limit:') self.score_label.setFixedWidth(65) self.score_limit = QLineEdit() self.score_limit.setMaximumWidth(40) self.score_limit.setPalette(QPalette(Qt.white)) self.score_limit.setText('16') self.mode_label = QLabel('Game Mode:') self.mode_label.setFixedWidth(85) self.mode_select = QComboBox() self.mode_select.addItems(['Deal-1', 'Deal-4']) self.mode_select.setPalette(QPalette(Qt.white)) self.mode_select.setFixedWidth(100) self.mode_select.currentTextChanged.connect(self.update_playeramount) self.autofill_button = Button(self, 'Auto Fill') self.autofill_button.clicked.connect(self.auto_fill) self.clear_button = Button(self, 'Clear All') self.clear_button.clicked.connect(self.clear_all) self.player_entries = QVBoxLayout() self.spacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) self.hbox.addWidget(self.playeramt_label) self.hbox.addWidget(self.playeramount) self.hbox.addWidget(self.score_label) self.hbox.addWidget(self.score_limit) self.hbox.addWidget(self.mode_label) self.hbox.addWidget(self.mode_select) self.hbox.addWidget(self.autofill_button) self.hbox.addWidget(self.clear_button) self.vbox.addLayout(self.tophbox) self.vbox.addLayout(self.hbox) self.vbox.addLayout(self.player_entries) self.vbox.addItem(self.spacer) self.setLayout(self.vbox) self.form_player_entries()
def dark_palette(): p = QPalette() dark_color = QColor(45,45,45) disabled_color = QColor(127,127,127) text_color = QColor('#eee') p.setColor(p.Window, dark_color) p.setColor(p.WindowText, text_color) p.setColor(p.Base, QColor(18,18,18)) p.setColor(p.AlternateBase, dark_color) p.setColor(p.ToolTipBase, dark_color) p.setColor(p.ToolTipText, text_color) p.setColor(p.Text, text_color) p.setColor(p.Disabled, p.Text, disabled_color) p.setColor(p.Button, dark_color) p.setColor(p.ButtonText, text_color) p.setColor(p.Disabled, p.ButtonText, disabled_color) p.setColor(p.BrightText, Qt.red) p.setColor(p.Link, dark_link_color) p.setColor(p.Highlight, dark_link_color) p.setColor(p.HighlightedText, Qt.black) p.setColor(p.Disabled, p.HighlightedText, disabled_color) return p
def init_ui(self): self.setWindowIcon(QtGui.QIcon('./icon.jpg')) self.resize(720, 500) self.setFixedSize(self.width(), self.height()) self.setWindowTitle('图片识别') self.label_name4 = QLabel('识别结果', self) self.label_name4.setGeometry(500, 20, 100, 35) self.label_name5 = QLabel('待载入图片', self) self.label_name5.setGeometry(10, 20, 480, 220) self.label_name5.setStyleSheet("QLabel{background:gray;}" "QLabel{color:rgb(0,0,0,120);font-size:15px;font-weight:bold;font-family:宋体;}" ) self.label_name5.setAlignment(QtCore.Qt.AlignCenter) self.label_name6 = QLabel('过程演示图', self) self.label_name6.setGeometry(10, 260, 480, 220) self.label_name6.setStyleSheet("QLabel{background:white;}" "QLabel{color:rgb(0,0,0,120);font-size:15px;font-weight:bold;font-family:宋体;}" ) self.label_name6.setAlignment(QtCore.Qt.AlignCenter) # 结果显示框 self.label_result = QLabel('结果显示结果显示结果显示结果<font color="red">显示结果</font>显示结果显示结果显示结果显示', self) self.label_result.setGeometry(500, 60, 200, 170) self.label_result.setWordWrap(True) # self.label_result.setAlignment(QtCore.Qt.AlignTop) self.label_result.setAlignment(Qt.AlignCenter) # 改颜色字体啥的 # pe = QPalette() QPalette().setColor(QPalette.WindowText, Qt.black) # 设置字体颜色 self.label_result.setAutoFillBackground(True) # 设置背景充满,为设置背景颜色的必要条件 QPalette().setColor(QPalette.Window, Qt.white) # 设置背景颜色 # pe.setColor(QPalette.Background,Qt.blue)<span style="font-family: Arial, Helvetica, sans-serif;">#设置背景颜色,和上面一行的效果一样 self.label_result.setPalette(QPalette()) # self.label_result.setFont(QFont("Roman times", 10, QFont.Bold)) # self.edit = QTextEdit(self) # self.edit.setGeometry(500, 60, 200, 170) self.btn_select = QPushButton('选择图片', self) self.btn_select.setGeometry(550, 270, 100, 30) self.btn_select.clicked.connect(self.select_image) self.btn_dis = QPushButton('检测图片', self) self.btn_dis.setGeometry(550, 310, 100, 30) self.btn_dis.clicked.connect(self.on_btn_Detect_Clicked) self.btn_dis = QPushButton('识别图片', self) self.btn_dis.setGeometry(550, 350, 100, 30) self.btn_dis.clicked.connect(self.on_btn_Recognize_Clicked) self.btn = QPushButton('返回', self) self.btn.setGeometry(550, 390, 100, 30) self.btn.clicked.connect(self.slot_btn_function) self.btn_exit = QPushButton('退出', self) self.btn_exit.setGeometry(550, 430, 100, 30) self.btn_exit.clicked.connect(self.Quit)
def dark_palette(): p = QPalette() disabled_color = QColor(127,127,127) p.setColor(QPalette.ColorRole.Window, dark_color) p.setColor(QPalette.ColorRole.WindowText, dark_text_color) p.setColor(QPalette.ColorRole.Base, QColor(18,18,18)) p.setColor(QPalette.ColorRole.AlternateBase, dark_color) p.setColor(QPalette.ColorRole.ToolTipBase, dark_color) p.setColor(QPalette.ColorRole.ToolTipText, dark_text_color) p.setColor(QPalette.ColorRole.Text, dark_text_color) p.setColor(QPalette.ColorGroup.Disabled, QPalette.ColorRole.Text, disabled_color) p.setColor(QPalette.ColorRole.Button, dark_color) p.setColor(QPalette.ColorRole.ButtonText, dark_text_color) p.setColor(QPalette.ColorGroup.Disabled, QPalette.ColorRole.ButtonText, disabled_color) p.setColor(QPalette.ColorRole.BrightText, Qt.GlobalColor.red) p.setColor(QPalette.ColorRole.Link, dark_link_color) p.setColor(QPalette.ColorRole.Highlight, dark_link_color) p.setColor(QPalette.ColorRole.HighlightedText, Qt.GlobalColor.black) p.setColor(QPalette.ColorGroup.Disabled, QPalette.ColorRole.HighlightedText, disabled_color) return p
def init_ui(self): width = 800 height = 580 self.setFixedSize(width, height) # 设置棋盘背景 oBackGroundImage = QImage("reversi_images/board.png") sBackGroundImage = oBackGroundImage.scaled(QSize( width, height)) # resize Image to widgets size palette = QPalette() palette.setBrush(QPalette.Window, QBrush(sBackGroundImage)) self.setPalette(palette) # 初始化棋盘元素 self.label_count_down = QLabel('', self) self.label_count_down.setStyleSheet( f"color: orange; font-size: 30px; font-weight: bold; font-family: Microsoft YaHei" ) self.label_count_down.setGeometry(350, 0, 500, 60) self.label_turn = QLabel('蓝方回合', self) self.label_turn.setStyleSheet( f"color: blue; font-size: 24px; font-weight: bold; font-family: Microsoft YaHei" ) self.label_turn.setGeometry(320, 60, 500, 40) self.label_blue_name = QLabel('蓝方-AI托管', self) self.label_blue_name.setStyleSheet( f"color: gray; font-size: 18px; font-weight: bold; font-family: Microsoft YaHei" ) self.label_blue_name.setGeometry(150, 40, 180, 20) self.label_blue_score = QLabel('2', self) self.label_blue_score.setStyleSheet( f"color: yellow; font-size: 24px; font-weight: bold; font-family: Microsoft YaHei" ) self.label_blue_score.setGeometry(180, 60, 120, 30) self.label_red_name = QLabel('大师南瓜球', self) self.label_red_name.setStyleSheet( f"color: gray; font-size: 18px; font-weight: bold; font-family: Microsoft YaHei" ) self.label_red_name.setGeometry(520, 40, 180, 20) self.label_red_score = QLabel('2', self) self.label_red_score.setStyleSheet( f"color: yellow; font-size: 24px; font-weight: bold; font-family: Microsoft YaHei" ) self.label_red_score.setGeometry(570, 60, 120, 30) self.btn_manunal_bye = QPushButton('手动轮空', self) self.btn_manunal_bye.setStyleSheet( f"color: #cf8160; font-size: 18px; font-weight: bold; font-family: Microsoft YaHei; background-color: #89090a" ) self.btn_manunal_bye.setGeometry(685, 460, 80, 30) self.btn_manunal_bye.clicked.connect(self.manunal_bye) self.btn_restart = QPushButton('重新开始', self) self.btn_restart.setStyleSheet( f"color: #cf8160; font-size: 18px; font-weight: bold; font-family: Microsoft YaHei; background-color: #89090a" ) self.btn_restart.setGeometry(685, 505, 80, 30) self.btn_restart.clicked.connect(self.restart) # 180 120 # 445 -> 480 (row 1 -> 8 top ) mid_top_x, mid_top_y = 400, 120 self.btn_list_board = [] self.qicon_blue = QIcon(QPixmap("reversi_images/blue.png")) self.qicon_red = QIcon(QPixmap("reversi_images/red.png")) self.qicon_empty = QIcon() self.qicon_next_step = QIcon(QPixmap("reversi_images/next_step.png")) self.qicon_invalid = QIcon(QPixmap("reversi_images/invalid.png")) self.qicon_current_blue = QIcon( QPixmap("reversi_images/current_blue.png")) self.qicon_current_red = QIcon( QPixmap("reversi_images/current_red.png")) for row_index in range_from_one(board_size): label_row = [] row_width = 445 + int((480 - 445) / 7 * (row_index - 1)) for col_index in range_from_one(board_size): cell = self.board[row_index][col_index] x, y = mid_top_x - row_width // 2 + row_width // 8 * ( col_index - 1), mid_top_y + 47 * (row_index - 1) btn = QPushButton(self) btn.setIconSize(QSize(60, 50)) btn.setGeometry(x, y, row_width // 8, 50) btn.setStyleSheet( "QPushButton { background-color: transparent; border: 0px }" ) def cb(ri, ci): def _cb(): logger.debug(f"clicked row={ri}, col={ci}") # 初始化无效格子 if self.invalid_cell_count < invalid_cell_count: if self.board[ri][ci] != cell_empty: logger.info("该格子不为空,不能设置为无效格子") return self.board[ri][ci] = cell_invalid self.invalid_cell_count = self.invalid_cell_count + 1 logger.info(f"设置第{self.invalid_cell_count}个无效位置") self.paint() if self.invalid_cell_count == invalid_cell_count: # 记录点击次数,到达五个按钮时进入正式游戏模式(尝试ai点击)并隐藏提示按钮 self.ai_try_put_cell() return if self.current_step_cell( ) in self.ai_cells and not self.ai_moving: logger.info("当前回合由机器人托管,将无视该点击") return self.ai_moving = False # 判断是否可行 if self.is_game_over(): self.game_over() return if not self.has_any_valid_cell(): logger.info("本轮无任何可行落子,将轮空") self.next_turn() self.loop_index += 1 if not self.has_any_valid_cell(): logger.info("双方均不可再落子,游戏结束") self.game_over() return # 记录下当前方 current_step_cell = self.current_step_cell() # 落子 is_valid = self.put_cell(ri, ci) is not None if is_valid: self.loop_index += 1 # 计算落子后当前方局面分 current_score = self.evaluate(current_step_cell) if current_score >= 0: cr = "bold_red" else: cr = "bold_green" logger.info( color(cr) + f"落子后当前{self.cell_name_without_color(current_step_cell)}局面分为{current_score}" ) # 重绘界面 self.paint() # 若轮到机器人 self.ai_try_put_cell() return _cb btn.clicked.connect(cb(row_index, col_index)) label_row.append(btn) self.btn_list_board.append(label_row) self.paint() self.show()
def __init__(self, parent, text): super(Button, self).__init__(parent) self.setText(text) self.setPalette(QPalette(Qt.white))
def update (self,warrior): self.warrior = warrior groupe_name = warrior.groupe().name if warrior.masterGroupe() != None : groupe_name = warrior.masterGroupe().name+"/"+groupe_name kingdom_name = warrior.kingdom().name empire_name = warrior.empire().name faction_name = warrior.faction().name path = os.path.join(Config().instance.path_to_pic(),faction_name,empire_name,kingdom_name,'Picture',groupe_name,warrior.name) picture = QPixmap(path+"/portrait.jpg").scaledToWidth(self.picture.width()) self.warrior_name.setText(warrior.name.replace("_"," ")) self.warrior_name.setObjectName("Warrior_name") couleur = warrior.groupe().attribs['color'] if warrior.masterGroupe() != None : couleur = warrior.masterGroupe().attribs['color'] self.picture.setPixmap(picture) self.progressBar_life.setStyleSheet(" QProgressBar{ background-color: red;}") #self.ui.progressBar_life.setAlignment(QtCore.Qt.AlignCenter) #self.progressBar_energy.setStyleSheet(" QProgressBar::chunk { background-color: #05B8CC;width: 20px;}") #self.ui.progressBar_MP.setAlignment(QtCore.Qt.AlignCenter) try: hp_percent = float(self.warrior.attribs['HP'] / self.warrior.attribs['HP_max'])* 100 mp_percent = float(self.warrior.attribs['MP'] / self.warrior.attribs['MP_max'])* 100 except (ZeroDivisionError,KeyError) as e : hp_percent =0 mp_percent =0 self.progressBar_life.setValue(int(hp_percent)) self.progressBar_energy.setValue(int(mp_percent)) self.profil_completion.setPixmap(QPixmap(":/icons/128x128/state_"+str(warrior.attribs['complete']+1)).scaledToHeight(32)) self.profil_completion.setStyleSheet("#"+self.profil_completion.objectName()+"{background-color:transparent;}") pal = QPalette(self.rank_text.palette()) image = QImage(os.path.join(Config().instance.path_to_icons(),"rank")+"/star_"+warrior.groupe().attribs["color"]+".png") value = image.pixel(image.width()/2.0,image.height()/2.0) pal.setColor(QPalette.WindowText, QColor(value)) self.rank_text.setPalette(pal) self.rank_text.setText(str(warrior.attribs["rank"])) #Boutton Faction path = os.path.join(Config().instance.path_to_icons(),"faction","32x32",faction_name) self.iconFaction.setIcon(QIcon(path)) self.iconFaction.setToolTip(warrior.faction().name) #Boutton Empire path = os.path.join(Config().instance.path_to_icons(),"empire","32x32",empire_name) self.iconEmpire.setIcon(QIcon(path)) self.iconEmpire.setToolTip(warrior.empire().name) self.iconEmpire.clicked.connect(self.onEmpireClicked) #Boutton Kingdom path = os.path.join(Config().instance.path_to_icons(),"kingdom","32x32",kingdom_name) self.iconKingdom.setIcon(QIcon(path)) self.iconKingdom.setToolTip(self.warrior.kingdom().name) self.iconKingdom.clicked.connect(self.onKingdomClicked) #Boutton Groupe self.iconGroupe.setText(groupe_name.replace("_"," ")) groupe_color = self.warrior.groupe().attribs['color'] if self.warrior.masterGroupe() != None : groupe_color = self.warrior.masterGroupe().attribs['color'] self.iconGroupe.setStyleSheet("#"+self.iconGroupe.objectName()+"{background-image:url(:/textures/"+groupe_color+");}") self.iconGroupe.clicked.connect(self.onGroupClicked) path = os.path.join(Config().instance.path_to_icons(),"actions",warrior.attribs['status']) # Icone d etat self.iconState.setPixmap(QPixmap(path).scaledToHeight(64))