def __init__(self): super().__init__() self.undiscovered_color: str = "#000000" self.discovered_color: str = "#d9d9d9" self.win_timer_color: str = "#e30e0e" self.lose_timer_color: str = "#0cc431" self.curr_time = QTime(00,00,00) self.timer = QTimer() self.timer.timeout.connect(self.time) self.timer_already_started = False self.solved: bool = False self.player_ended: bool = False self.theme: str = "dark" self.list_of_mines: list = [] self.difficulty_slider_default_value: int = 2 self.number_of_mines: int = mines_number(NUMBER_OF_LABELS, self.difficulty_slider_default_value) self.create_GUI()
def createMailModel(parent): model = QStandardItemModel(0, 3, parent) model.setHeaderData(0, Qt.Horizontal, "Subject") model.setHeaderData(1, Qt.Horizontal, "Sender") model.setHeaderData(2, Qt.Horizontal, "Date") addMail(model, "Happy New Year!", "Grace K. <*****@*****.**>", QDateTime(QDate(2006, 12, 31), QTime(17, 3))) addMail(model, "Radically new concept", "Grace K. <*****@*****.**>", QDateTime(QDate(2006, 12, 22), QTime(9, 44))) addMail(model, "Accounts", "*****@*****.**", QDateTime(QDate(2006, 12, 31), QTime(12, 50))) addMail(model, "Expenses", "Joe Bloggs <*****@*****.**>", QDateTime(QDate(2006, 12, 25), QTime(11, 39))) addMail(model, "Re: Expenses", "Andy <*****@*****.**>", QDateTime(QDate(2007, 1, 2), QTime(16, 5))) addMail(model, "Re: Accounts", "Joe Bloggs <*****@*****.**>", QDateTime(QDate(2007, 1, 3), QTime(14, 18))) addMail(model, "Re: Accounts", "Andy <*****@*****.**>", QDateTime(QDate(2007, 1, 3), QTime(14, 26))) addMail(model, "Sports", "Linda Smith <*****@*****.**>", QDateTime(QDate(2007, 1, 5), QTime(11, 33))) addMail(model, "AW: Sports", "Rolf Newschweinstein <*****@*****.**>", QDateTime(QDate(2007, 1, 5), QTime(12, 0))) addMail(model, "RE: Sports", "Petra Schmidt <*****@*****.**>", QDateTime(QDate(2007, 1, 5), QTime(12, 1))) return model
def reset(self) -> None: self.timer = QTimer() self.curr_time = QTime(00,00,00) self.timer.timeout.connect(self.time) self.solved = False self.timer_already_started = False self.player_ended = False self.difficulty_slider.setDisabled(False) self.difficulty_slider_default_value = self.difficulty_slider.value() self.create_GUI()
def from_string(self, text, original_value): if isinstance(original_value, QColor): match = self.color_exp.match(text) return QColor(min(int(match.captured(1)), 255), min(int(match.captured(2)), 255), min(int(match.captured(3)), 255), min(int(match.captured(4)), 255)) if isinstance(original_value, QDate): value = QDate.fromString(text, Qt.ISODate) return value if value.isValid() else None if isinstance(original_value, QDateTime): value = QDateTime.fromString(text, Qt.ISODate) return value if value.isValid() else None if isinstance(original_value, QTime): value = QTime.fromString(text, Qt.ISODate) return value if value.isValid() else None if isinstance(original_value, QPoint): match = self.point_exp.match(text) return QPoint(int(match.captured(1)), int(match.captured(2))) if isinstance(original_value, QRect): match = self.rect_exp.match(text) return QRect(int(match.captured(1)), int(match.captured(2)), int(match.captured(3)), int(match.captured(4))) if isinstance(original_value, QSize): match = self.size_exp.match(text) return QSize(int(match.captured(1)), int(match.captured(2))) if isinstance(original_value, list): return text.split(',') return type(original_value)(text)
def setupUi(self, HoldingsWidget): if not HoldingsWidget.objectName(): HoldingsWidget.setObjectName(u"HoldingsWidget") HoldingsWidget.resize(1066, 589) self.verticalLayout = QVBoxLayout(HoldingsWidget) self.verticalLayout.setSpacing(0) self.verticalLayout.setObjectName(u"verticalLayout") self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.HoldingsParamsFrame = QFrame(HoldingsWidget) self.HoldingsParamsFrame.setObjectName(u"HoldingsParamsFrame") self.HoldingsParamsFrame.setFrameShape(QFrame.Panel) self.HoldingsParamsFrame.setFrameShadow(QFrame.Sunken) self.horizontalLayout_8 = QHBoxLayout(self.HoldingsParamsFrame) self.horizontalLayout_8.setSpacing(6) self.horizontalLayout_8.setObjectName(u"horizontalLayout_8") self.horizontalLayout_8.setContentsMargins(2, 2, 2, 2) self.HoldingsDate = QDateEdit(self.HoldingsParamsFrame) self.HoldingsDate.setObjectName(u"HoldingsDate") self.HoldingsDate.setDateTime( QDateTime(QDate(2020, 11, 24), QTime(21, 0, 0))) self.HoldingsDate.setCalendarPopup(True) self.HoldingsDate.setTimeSpec(Qt.UTC) self.horizontalLayout_8.addWidget(self.HoldingsDate) self.HoldingsCurrencyLbl = QLabel(self.HoldingsParamsFrame) self.HoldingsCurrencyLbl.setObjectName(u"HoldingsCurrencyLbl") self.horizontalLayout_8.addWidget(self.HoldingsCurrencyLbl) self.HoldingsCurrencyCombo = CurrencyComboBox(self.HoldingsParamsFrame) self.HoldingsCurrencyCombo.setObjectName(u"HoldingsCurrencyCombo") self.horizontalLayout_8.addWidget(self.HoldingsCurrencyCombo) self.horizontalSpacer = QSpacerItem(1411, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_8.addItem(self.horizontalSpacer) self.verticalLayout.addWidget(self.HoldingsParamsFrame) self.HoldingsTableView = QTreeView(HoldingsWidget) self.HoldingsTableView.setObjectName(u"HoldingsTableView") self.HoldingsTableView.setFrameShape(QFrame.Panel) self.HoldingsTableView.setAlternatingRowColors(True) self.HoldingsTableView.setAnimated(True) self.HoldingsTableView.setAllColumnsShowFocus(True) self.verticalLayout.addWidget(self.HoldingsTableView) self.retranslateUi(HoldingsWidget) QMetaObject.connectSlotsByName(HoldingsWidget)
def log_text(self, message_type, text): """Logs the given text to the QPlainTextWidget""" current_time = QTime.currentTime().toString() if message_type == MessageType.ERROR: self.log_widget.insertHtml( f'[{current_time}] {ERROR_HTML}{text}<br>') elif message_type == MessageType.GENERIC: self.log_widget.insertHtml(f'[{current_time}] {text}<br>') elif message_type == MessageType.DEBUG and ENABLE_DEBUG: self.log_widget.insertHtml( f'[{current_time}] {DEBUG_HTML}{text}<br>') self.log_widget.moveCursor(QTextCursor.End) if ENABLE_DEBUG: print(text)
def init_settings(): """Time conf """ time_now = QTime.currentTime() time_start = settings_time_start() time_end = settings_time_end() if not time_start: SETTINGS.setValue('time_start', time_now.toString()) if not time_end: SETTINGS.setValue('time_end', time_now.toString()) if not SETTINGS.value('color'): SETTINGS.setValue('color', '#FFFFFF') SETTINGS.sync()
def run(self): width = SETTINGS.value('screen_width') time_delta = settings_time_delta() if time_delta < 1: time_delta = 1 while True: frequency = time_delta / 1000 / width if frequency < 0.0166: frequency = 0.0166 delta = (settings_time_end().msecsSinceStartOfDay() - QTime.currentTime().msecsSinceStartOfDay()) process = 1 - delta / time_delta if process > 100 or process < 0: break pixel = int(process * width) self.countChanged.emit(pixel) sleep(frequency) self.countChanged.emit(width)
def __init__(self, parent=None): super().__init__(parent) self.alarm = QTime() self.timer = QTimer(self) self.timer.setSingleShot(True) self.update_timer = QTimer(self) self.update_timer.setInterval(1000) self.current_label = QLabel('00:00:00') font = QFont() font.setPointSize(50) self.current_label.setFont(font) self.time_edit = QTimeEdit(self) self.time_edit.setDisplayFormat('H:mm') self.set_around_btn = QPushButton('Set around time', self) self.set_ui() self.set_connection() self.reset() self.update_timer.start() self.update_label() self.set_around_time()
def updateProgramEstimatedTime(self, lines: List[LineSegment]) -> QTime: time = 0 for line in lines: ls = LineSegment(line) # foreach (LineSegment *ls, lines) { length = (ls.getEnd() - ls.getStart()).length() if not qIsNaN(length) and not qIsNaN( ls.getSpeed()) and ls.getSpeed() != 0: cond1 = self.ui.slbFeedOverride.isChecked( ) and not ls.isFastTraverse() cond2 = self.ui.slbRapidOverride.isChecked( ) and ls.isFastTraverse() speed = ls.getSpeed() val1 = (speed * self.ui.slbFeedOverride.value() / 100) val2 = speed if cond1: time += val1 else: if cond2: time += val1 else: time += val2 # Update for rapid override time *= 60 t = QTime() t.setHMS(0, 0, 0) t = t.addSecs(time) self.ui.glwVisualizer.setSpendTime(QTime(0, 0, 0)) self.ui.glwVisualizer.setEstimatedTime(t) return t
def showEvent(self, event): self.time_editor_start.setTime( QTime.fromString(SETTINGS.value('time_start'))) self.time_editor_end.setTime( QTime.fromString(SETTINGS.value('time_end')))
def __init__(self, parent, callback, gid, persepolis_setting, video_finder_dictionary=None): super().__init__(persepolis_setting) self.parent = parent self.persepolis_setting = persepolis_setting self.video_finder_dictionary = video_finder_dictionary self.download_later_pushButton.hide() # hide download_later_pushButton self.change_name_checkBox.hide() # hide change_name_checkBox self.change_name_lineEdit.hide() # hide change_name_lineEdit # add new QLineEdit and QLineEdit for audio link if we have video finder links if self.video_finder_dictionary: self.link_label_2 = QLabel(self.link_frame) self.link_horizontalLayout.addWidget(self.link_label_2) self.link_lineEdit_2 = QLineEdit(self.link_frame) self.link_horizontalLayout.addWidget(self.link_lineEdit_2) self.link_lineEdit_2.textChanged.connect(self.linkLineChanged) self.link_label.setText( QCoreApplication.translate("addlink_ui_tr", "Video Link: ")) self.link_label_2.setText( QCoreApplication.translate("addlink_ui_tr", "Audio Link: ")) # gid_1 >> video_gid , gid_2 >> audio_gid self.gid_1 = self.video_finder_dictionary['video_gid'] self.gid_2 = self.video_finder_dictionary['audio_gid'] else: self.gid_1 = gid self.callback = callback # detect_proxy_pushButton self.detect_proxy_pushButton.clicked.connect(self.detectProxy) # connect folder_pushButton self.folder_pushButton.clicked.connect(self.changeFolder) self.download_folder_lineEdit.setEnabled(False) self.ok_pushButton.setEnabled(False) self.link_lineEdit.textChanged.connect(self.linkLineChanged) # connect OK and cancel button self.cancel_pushButton.clicked.connect(self.close) self.ok_pushButton.clicked.connect(self.okButtonPressed) #frames and checkBoxes self.proxy_frame.setEnabled(False) self.proxy_checkBox.toggled.connect(self.proxyFrame) self.download_frame.setEnabled(False) self.download_checkBox.toggled.connect(self.downloadFrame) self.limit_frame.setEnabled(False) self.limit_checkBox.toggled.connect(self.limitFrame) self.start_frame.setEnabled(False) self.start_checkBox.toggled.connect(self.startFrame) self.end_frame.setEnabled(False) self.end_checkBox.toggled.connect(self.endFrame) # get information from data base self.add_link_dictionary_1 = self.parent.persepolis_db.searchGidInAddLinkTable( self.gid_1) self.download_table_dict_1 = self.parent.persepolis_db.searchGidInDownloadTable( self.gid_1) if video_finder_dictionary: self.add_link_dictionary_2 = self.parent.persepolis_db.searchGidInAddLinkTable( self.gid_2) self.download_table_dict_2 = self.parent.persepolis_db.searchGidInDownloadTable( self.gid_2) # create a copy from add_link_dictionary for checking changes finally! self.add_link_dictionary_1_backup = {} for key in self.add_link_dictionary_1.keys(): self.add_link_dictionary_1_backup[ key] = self.add_link_dictionary_1[key] if video_finder_dictionary: self.add_link_dictionary_2_backup = {} for key in self.add_link_dictionary_2.keys(): self.add_link_dictionary_2_backup[ key] = self.add_link_dictionary_2[key] # initialization # disable folder_frame when download is complete if self.video_finder_dictionary: if self.video_finder_dictionary[ 'video_completed'] == 'yes' or self.video_finder_dictionary[ 'audio_completed'] == 'yes': self.folder_frame.setEnabled(False) else: if self.download_table_dict_1['status'] == 'complete': self.folder_frame.setEnabled(False) # link self.link_lineEdit.setText(self.add_link_dictionary_1['link']) if self.video_finder_dictionary: self.link_lineEdit_2.setText(self.add_link_dictionary_2['link']) # ip_lineEdit initialization if self.add_link_dictionary_1['ip']: self.proxy_checkBox.setChecked(True) self.ip_lineEdit.setText(self.add_link_dictionary_1['ip']) # port_spinBox initialization try: self.port_spinBox.setValue( int(self.add_link_dictionary_1['port'])) except: pass # proxy user lineEdit initialization try: self.proxy_user_lineEdit.setText( self.add_link_dictionary_1['proxy_user']) except: pass # proxy pass lineEdit initialization try: self.proxy_pass_lineEdit.setText( self.add_link_dictionary_1['proxy_passwd']) except: pass # download UserName initialization if self.add_link_dictionary_1['download_user']: self.download_checkBox.setChecked(True) self.download_user_lineEdit.setText( self.add_link_dictionary_1['download_user']) # download PassWord initialization try: self.download_pass_lineEdit.setText( self.add_link_dictionary_1['download_passwd']) except: pass # folder_path try: self.download_folder_lineEdit.setText( self.add_link_dictionary_1['download_path']) except: pass # connections try: self.connections_spinBox.setValue( int(self.add_link_dictionary_1['connections'])) except: pass # get categories name and add them to add_queue_comboBox categories_list = self.parent.persepolis_db.categoriesList() for queue in categories_list: if queue != 'All Downloads': self.add_queue_comboBox.addItem(queue) # finding current queue and setting it! self.current_category = self.download_table_dict_1['category'] current_category_index = self.add_queue_comboBox.findText( self.current_category) self.add_queue_comboBox.setCurrentIndex(current_category_index) # add_queue_comboBox event self.add_queue_comboBox.currentIndexChanged.connect(self.queueChanged) # limit speed limit = str(self.add_link_dictionary_1['limit_value']) if limit != '0': self.limit_checkBox.setChecked(True) limit_number = limit[0:-1] limit_unit = limit[-1] self.limit_spinBox.setValue(float(limit_number)) if limit_unit == "K": self.limit_comboBox.setCurrentIndex(0) else: self.limit_comboBox.setCurrentIndex(1) # start_time if self.add_link_dictionary_1['start_time']: # get hour and minute hour, minute = self.add_link_dictionary_1['start_time'].split(':') # set time q_time = QTime(int(hour), int(minute)) self.start_time_qDataTimeEdit.setTime(q_time) self.start_checkBox.setChecked(True) # end_time if self.add_link_dictionary_1['end_time']: # get hour and minute hour, minute = self.add_link_dictionary_1['end_time'].split(':') # set time q_time = QTime(int(hour), int(minute)) self.end_time_qDateTimeEdit.setTime(q_time) self.end_checkBox.setChecked(True) # referer if self.add_link_dictionary_1['referer']: self.referer_lineEdit.setText( str(self.add_link_dictionary_1['referer'])) if self.add_link_dictionary_1['header']: self.header_lineEdit.setText( str(self.add_link_dictionary_1['header'])) if self.add_link_dictionary_1['user_agent']: self.user_agent_lineEdit.setText( str(self.add_link_dictionary_1['user_agent'])) if self.add_link_dictionary_1['load_cookies']: self.load_cookies_lineEdit.setText( (self.add_link_dictionary_1['load_cookies'])) # set window size and position size = self.persepolis_setting.value('PropertiesWindow/size', QSize(520, 425)) position = self.persepolis_setting.value('PropertiesWindow/position', QPoint(300, 300)) self.resize(size) self.move(position)
def set_around_time(self): current = QTime.currentTime() if current.minute() < 29: self.time_edit.setTime(QTime(current.hour(), 30)) else: self.time_edit.setTime(QTime(current.hour() + 1, 0))
def updateTimes(self): # function which is called to update labels self.elapsedTime.setText(time.strftime('%H:%M:%S', time.gmtime(self.counter // 2))) self.localTime.setText("{}{}{} {}".format(str(QTime.currentTime().hour() % 12).zfill(2) if QTime.currentTime().hour() % 12 != 0 else "12", ":" if self.counter % 2 == 0 else " ", str(QTime.currentTime().minute()).zfill(2), "PM" if QTime.currentTime().hour() >= 12 else "AM")) self.counter = self.counter % (2*86400) + 1
def get_config(self) -> tuple[JobConfig, bool]: return JobConfig(Path(self.source_dir.text()), Path(self.target_dir.text()), self.run_at_startup.isChecked(), QTime(0, 0, 0).secsTo(self.sleep_time.time()), self.recursive_search.isChecked()), self.start_job
def settings_time_end() -> QTime: return QTime.fromString(SETTINGS.value('time_end'))
def update_label(self): current = QTime.currentTime() self.current_label.setText('{hour:02}:{min:02}:{sec:02}'.format( hour=current.hour(), min=current.minute(), sec=current.second()))
def start(self): self.time_edit.setEnabled(False) self.alarm = self.time_edit.time() self.timer.start(QTime.currentTime().msecsTo(self.alarm)) self.started.emit()
def defaultsPushButtonPressed(self, button): self.persepolis_setting.beginGroup('settings') self.setting_dict = returnDefaultSettings() self.tries_spinBox.setValue(int(self.setting_dict['max-tries'])) self.wait_spinBox.setValue(int(self.setting_dict['retry-wait'])) self.time_out_spinBox.setValue(int(self.setting_dict['timeout'])) self.connections_spinBox.setValue(int( self.setting_dict['connections'])) self.rpc_port_spinbox.setValue(int(self.setting_dict['rpc-port'])) self.aria2_path_lineEdit.setText('') self.aria2_path_checkBox.setChecked(False) # wait-queue wait_queue_list = self.setting_dict['wait-queue'] q_time = QTime(wait_queue_list[0], wait_queue_list[1]) self.wait_queue_time.setTime(q_time) # dont_check_certificate_checkBox self.dont_check_certificate_checkBox.setChecked(False) # save_as_tab self.download_folder_lineEdit.setText( str(self.setting_dict['download_path'])) self.temp_download_lineEdit.setText( str(self.setting_dict['download_path_temp'])) self.subfolder_checkBox.setChecked(True) # notifications_tab self.volume_label.setText('Volume : ' + str(self.setting_dict['sound-volume'])) self.volume_dial.setValue(int(self.setting_dict['sound-volume'])) # set style current_style_index = self.style_comboBox.findText( str(self.setting_dict['style'])) self.style_comboBox.setCurrentIndex(current_style_index) # set language current_locale = self.lang_comboBox.findData( str(self.setting_dict['locale'])) self.lang_comboBox.setCurrentIndex(current_locale) # set color_scheme current_color_index = self.color_comboBox.findText( str(self.setting_dict['color-scheme'])) self.color_comboBox.setCurrentIndex(current_color_index) # set icons current_icons_index = self.icon_comboBox.findText( str(self.setting_dict['icons'])) self.icon_comboBox.setCurrentIndex(current_icons_index) # set icons size current_icons_size_index = self.icons_size_comboBox.findText( str(self.setting_dict['toolbar_icon_size'])) self.icons_size_comboBox.setCurrentIndex(current_icons_size_index) # set notification current_notification_index = self.notification_comboBox.findText( str(self.setting_dict['notification'])) self.notification_comboBox.setCurrentIndex(current_notification_index) # set font self.font_checkBox.setChecked(False) font_setting = QFont() font_setting.setFamily(str(self.setting_dict['font'])) self.fontComboBox.setCurrentFont(font_setting) self.font_size_spinBox.setValue(int(self.setting_dict['font-size'])) # sound frame self.enable_notifications_checkBox.setChecked(True) # start_persepolis_if_browser_executed_checkBox self.start_persepolis_if_browser_executed_checkBox.setChecked(True) # hide window self.hide_window_checkBox.setChecked(True) # tray icon self.enable_system_tray_checkBox.setChecked(True) # after_download_checkBox self.after_download_checkBox.setChecked(True) # hide menubar for linux if platform.system == 'Darwin': self.show_menubar_checkbox.setChecked(True) else: self.show_menubar_checkbox.setChecked(False) # show side panel self.show_sidepanel_checkbox.setChecked(True) # show progress window self.show_progress_window_checkbox.setChecked(True) # run persepolis at startup checkBox self.startup_checkbox.setChecked(False) # keep_awake_checkBox self.keep_awake_checkBox.setChecked(False) # columns_tab self.column0_checkBox.setChecked(True) self.column1_checkBox.setChecked(True) self.column2_checkBox.setChecked(True) self.column3_checkBox.setChecked(True) self.column4_checkBox.setChecked(True) self.column5_checkBox.setChecked(True) self.column6_checkBox.setChecked(True) self.column7_checkBox.setChecked(True) self.column10_checkBox.setChecked(True) self.column11_checkBox.setChecked(True) self.column12_checkBox.setChecked(True) # video finder self.max_links_spinBox.setValue(3) # shortcuts self.shortcuts_list = [ self.setting_dict['shortcuts/quit_shortcut'], self.setting_dict['shortcuts/hide_window_shortcut'], self.setting_dict['shortcuts/remove_shortcut'], self.setting_dict['shortcuts/delete_shortcut'], self.setting_dict['shortcuts/move_up_selection_shortcut'], self.setting_dict['shortcuts/move_down_selection_shortcut'], self.setting_dict['shortcuts/add_new_download_shortcut'], self.setting_dict['shortcuts/video_finder_shortcut'], self.setting_dict['shortcuts/import_text_shortcut'] ] # add shortcuts to the shortcut_table j = 0 for shortcut in self.shortcuts_list: item = QTableWidgetItem(shortcut) # align center item.setTextAlignment(0x0004 | 0x0080) # insert item in shortcut_table self.shortcut_table.setItem(j, 1, item) j = j + 1 self.persepolis_setting.endGroup()
def __init__(self, parent, persepolis_setting): super().__init__(persepolis_setting) self.persepolis_setting = persepolis_setting self.parent = parent self.grandparent = parent.persepolis_main self.persepolis_setting.beginGroup('settings') # initialization self.tries_spinBox.setValue( int(self.persepolis_setting.value('max-tries'))) self.wait_spinBox.setValue( int(self.persepolis_setting.value('retry-wait'))) self.time_out_spinBox.setValue( int(self.persepolis_setting.value('timeout'))) self.connections_spinBox.setValue( int(self.persepolis_setting.value('connections'))) self.rpc_port_spinbox.setValue( int(self.persepolis_setting.value('rpc-port'))) if str(self.persepolis_setting.value( 'dont-check-certificate')) == 'yes': self.dont_check_certificate_checkBox.setChecked(True) else: self.dont_check_certificate_checkBox.setChecked(False) # add support for other languages locale = str(self.persepolis_setting.value('settings/locale')) QLocale.setDefault(QLocale(locale)) self.translator = QTranslator() if self.translator.load(':/translations/locales/ui_' + locale, 'ts'): QCoreApplication.installTranslator(self.translator) # wait_queue wait_queue_list = self.persepolis_setting.value('wait-queue') try: q_time = QTime(int(wait_queue_list[0]), int(wait_queue_list[1])) except: q_time = QTime(0, 0) self.wait_queue_time.setTime(q_time) # change aria2 path self.aria2_path_pushButton.clicked.connect(self.changeAria2Path) self.aria2_path_checkBox.toggled.connect(self.ariaCheckBoxToggled) aria2_path = self.persepolis_setting.value('settings/aria2_path') self.aria2_path_lineEdit.setEnabled(False) if aria2_path != None: self.aria2_path_checkBox.setChecked(True) self.aria2_path_lineEdit.setText(str(aria2_path)) self.ariaCheckBoxToggled('aria2') if os_type in OS.UNIX_LIKE: for widget in self.aria2_path_checkBox, self.aria2_path_lineEdit, self.aria2_path_pushButton: widget.hide() # save_as_tab self.download_folder_lineEdit.setText( str(self.persepolis_setting.value('download_path'))) self.temp_download_lineEdit.setText( str(self.persepolis_setting.value('download_path_temp'))) # subfolder if str(self.persepolis_setting.value('subfolder')) == 'yes': self.subfolder_checkBox.setChecked(True) else: self.subfolder_checkBox.setChecked(False) # notifications_tab self.volume_label.setText( 'Volume : ' + str(self.persepolis_setting.value('sound-volume'))) self.volume_dial.setValue( int(self.persepolis_setting.value('sound-volume'))) # set style # find available styles(It's depends on operating system and desktop environments). available_styles = QStyleFactory.keys() for style in available_styles: # 'bb10dark', 'GTK', 'gtk' styles may cause to crashing! Eliminate them! style_black_list = ['bb10dark', 'bb10bright', 'GTK', 'gtk', 'gtk2'] if style not in style_black_list: self.style_comboBox.addItem(style) # System >> for system default style # when user select System for style section, the default system style is using. self.style_comboBox.addItem('System') current_style_index = self.style_comboBox.findText( str(self.persepolis_setting.value('style'))) if current_style_index != -1: self.style_comboBox.setCurrentIndex(current_style_index) # available language available_language = [ 'en_US', 'fa_IR', 'ar', 'zh_CN', 'fr_FR', 'pl_PL', 'nl_NL', 'pt_BR', 'es_ES', 'hu', 'tr', 'tr_TR' ] for lang in available_language: self.lang_comboBox.addItem(str(QLocale(lang).nativeLanguageName()), lang) current_locale = self.lang_comboBox.findData( str(self.persepolis_setting.value('locale'))) self.lang_comboBox.setCurrentIndex(current_locale) self.current_icon = self.persepolis_setting.value('icons') # icon size size = ['128', '64', '48', '32', '24', '16'] self.icons_size_comboBox.addItems(size) current_icons_size_index = self.icons_size_comboBox.findText( str(self.persepolis_setting.value('toolbar_icon_size'))) self.icons_size_comboBox.setCurrentIndex(current_icons_size_index) # call setDarkLightIcon if index is changed self.icons_size_comboBox.currentIndexChanged.connect( self.setDarkLightIcon) # set notification notifications = ['Native notification', 'QT notification'] self.notification_comboBox.addItems(notifications) current_notification_index = self.notification_comboBox.findText( str(self.persepolis_setting.value('notification'))) self.notification_comboBox.setCurrentIndex(current_notification_index) # set font font_setting = QFont() font_setting.setFamily(str(self.persepolis_setting.value('font'))) self.fontComboBox.setCurrentFont(font_setting) self.font_size_spinBox.setValue( int(self.persepolis_setting.value('font-size'))) # sound frame self.sound_frame.setEnabled(False) self.enable_notifications_checkBox.toggled.connect(self.soundFrame) if str(self.persepolis_setting.value('sound')) == 'yes': self.enable_notifications_checkBox.setChecked(True) else: self.enable_notifications_checkBox.setChecked(False) # connect folder buttons self.download_folder_lineEdit.setEnabled(False) self.download_folder_pushButton.clicked.connect( self.downloadFolderPushButtonClicked) self.temp_download_lineEdit.setEnabled(False) self.temp_download_pushButton.clicked.connect( self.tempDownloadPushButtonClicked) # dial self.volume_dial.setNotchesVisible(True) self.volume_dial.valueChanged.connect(self.dialChanged) # start_persepolis_if_browser_executed_checkBox if str(self.persepolis_setting.value('browser-persepolis')) == 'yes': self.start_persepolis_if_browser_executed_checkBox.setChecked(True) else: self.start_persepolis_if_browser_executed_checkBox.setChecked( False) # hide window if str(self.persepolis_setting.value('hide-window')) == 'yes': self.hide_window_checkBox.setChecked(True) else: self.hide_window_checkBox.setChecked(False) # tray icon if str(self.persepolis_setting.value('tray-icon')) == 'yes': self.enable_system_tray_checkBox.setChecked(True) else: self.enable_notifications_checkBox.setChecked(False) # show_menubar if str(self.persepolis_setting.value('show-menubar')) == 'yes': self.show_menubar_checkbox.setChecked(True) else: self.show_menubar_checkbox.setChecked(False) if platform.system() == 'Darwin': self.show_menubar_checkbox.setChecked(True) self.show_menubar_checkbox.hide() # show_sidepanel if str(self.persepolis_setting.value('show-sidepanel')) == 'yes': self.show_sidepanel_checkbox.setChecked(True) else: self.show_sidepanel_checkbox.setChecked(False) # show ProgressWindow if str(self.persepolis_setting.value('show-progress')) == 'yes': self.show_progress_window_checkbox.setChecked(True) else: self.show_progress_window_checkbox.setChecked(False) # after download dialog if str(self.persepolis_setting.value('after-dialog')) == 'yes': self.after_download_checkBox.setChecked(True) else: self.after_download_checkBox.setChecked(False) # run persepolis at startup checkBox if str(self.persepolis_setting.value('startup')) == 'yes': self.startup_checkbox.setChecked(True) else: self.startup_checkbox.setChecked(False) # font_checkBox if str(self.persepolis_setting.value('custom-font')) == 'yes': self.font_checkBox.setChecked(True) else: self.font_checkBox.setChecked(False) self.fontCheckBoxState(self.font_checkBox) # keep_awake_checkBox if str(self.persepolis_setting.value('awake')) == 'yes': self.keep_awake_checkBox.setChecked(True) else: self.keep_awake_checkBox.setChecked(False) # columns_tab if str(self.persepolis_setting.value('column0')) == 'yes': self.column0_checkBox.setChecked(True) else: self.column0_checkBox.setChecked(False) if str(self.persepolis_setting.value('column1')) == 'yes': self.column1_checkBox.setChecked(True) else: self.column1_checkBox.setChecked(False) if str(self.persepolis_setting.value('column2')) == 'yes': self.column2_checkBox.setChecked(True) else: self.column2_checkBox.setChecked(False) if str(self.persepolis_setting.value('column3')) == 'yes': self.column3_checkBox.setChecked(True) else: self.column3_checkBox.setChecked(False) if str(self.persepolis_setting.value('column4')) == 'yes': self.column4_checkBox.setChecked(True) else: self.column4_checkBox.setChecked(False) if str(self.persepolis_setting.value('column5')) == 'yes': self.column5_checkBox.setChecked(True) else: self.column5_checkBox.setChecked(False) if str(self.persepolis_setting.value('column6')) == 'yes': self.column6_checkBox.setChecked(True) else: self.column6_checkBox.setChecked(False) if str(self.persepolis_setting.value('column7')) == 'yes': self.column7_checkBox.setChecked(True) else: self.column7_checkBox.setChecked(False) if str(self.persepolis_setting.value('column10')) == 'yes': self.column10_checkBox.setChecked(True) else: self.column10_checkBox.setChecked(False) if str(self.persepolis_setting.value('column11')) == 'yes': self.column11_checkBox.setChecked(True) else: self.column11_checkBox.setChecked(False) if str(self.persepolis_setting.value('column12')) == 'yes': self.column12_checkBox.setChecked(True) else: self.column12_checkBox.setChecked(False) # video_finder try: # Integer casting may raise exception. self.max_links_spinBox.setValue( int(persepolis_setting.value('video_finder/max_links', 3))) except: pass # shortcuts self.qshortcuts_list = [ self.parent.exitAction_shortcut, self.parent.minimizeAction_shortcut, self.parent.removeSelectedAction_shortcut, self.parent.deleteSelectedAction_shortcut, self.parent.moveUpSelectedAction_shortcut, self.parent.moveDownSelectedAction_shortcut, self.parent.addlinkAction_shortcut, self.parent.videoFinderAddLinkAction_shortcut, self.parent.addtextfileAction_shortcut ] self.shortcuts_list = [ self.parent.exitAction_shortcut.key().toString(), self.parent.minimizeAction_shortcut.key().toString(), self.parent.removeSelectedAction_shortcut.key().toString(), self.parent.deleteSelectedAction_shortcut.key().toString(), self.parent.moveUpSelectedAction_shortcut.key().toString(), self.parent.moveDownSelectedAction_shortcut.key().toString(), self.parent.addlinkAction_shortcut.key().toString(), self.parent.videoFinderAddLinkAction_shortcut.key().toString(), self.parent.addtextfileAction_shortcut.key().toString() ] # add shortcuts to the shortcut_table j = 0 for shortcut in self.shortcuts_list: item = QTableWidgetItem(shortcut) # align center item.setTextAlignment(0x0004 | 0x0080) # insert item in shortcut_table self.shortcut_table.setItem(j, 1, item) j = j + 1 # If user doubleclicks on a row, then run showCaptureKeyboardWindow method self.shortcut_table.itemDoubleClicked.connect( self.showCaptureKeyboardWindow) # ok cancel default button self.cancel_pushButton.clicked.connect(self.close) self.defaults_pushButton.clicked.connect( self.defaultsPushButtonPressed) self.ok_pushButton.clicked.connect(self.okPushButtonPressed) # font_checkBox connect self.font_checkBox.stateChanged.connect(self.fontCheckBoxState) # saving initial value of self.persepolis_setting in self.first_key_value_dict # at the end! in the okPushButtonPressed method, first_key_value_dict will compared with second_key_value_dict. # if any thing changed , then a message box notify user about "some changes take effect after restarting persepolis". self.first_key_value_dict = {} for member in self.persepolis_setting.allKeys(): self.first_key_value_dict[member] = str( self.persepolis_setting.value(member)) # if style_comboBox is changed, self.styleComboBoxChanged is called. self.style_comboBox.currentIndexChanged.connect( self.styleComboBoxChanged) self.styleComboBoxChanged() self.color_comboBox.currentIndexChanged.connect(self.setDarkLightIcon) self.persepolis_setting.endGroup() # setting window size and position size = self.persepolis_setting.value('PreferencesWindow/size', QSize(578, 565)) position = self.persepolis_setting.value('PreferencesWindow/position', QPoint(300, 300)) self.resize(size) self.move(position)
def setupUi(self, OperationsWidget): if not OperationsWidget.objectName(): OperationsWidget.setObjectName(u"OperationsWidget") OperationsWidget.resize(1232, 552) self.verticalLayout_4 = QVBoxLayout(OperationsWidget) self.verticalLayout_4.setSpacing(0) self.verticalLayout_4.setObjectName(u"verticalLayout_4") self.verticalLayout_4.setContentsMargins(0, 0, 0, 0) self.BalanceOperationsSplitter = QSplitter(OperationsWidget) self.BalanceOperationsSplitter.setObjectName( u"BalanceOperationsSplitter") sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.BalanceOperationsSplitter.sizePolicy().hasHeightForWidth()) self.BalanceOperationsSplitter.setSizePolicy(sizePolicy) self.BalanceOperationsSplitter.setOrientation(Qt.Horizontal) self.BalanceBox = QGroupBox(self.BalanceOperationsSplitter) self.BalanceBox.setObjectName(u"BalanceBox") sizePolicy1 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) sizePolicy1.setHorizontalStretch(1) sizePolicy1.setVerticalStretch(0) sizePolicy1.setHeightForWidth( self.BalanceBox.sizePolicy().hasHeightForWidth()) self.BalanceBox.setSizePolicy(sizePolicy1) self.BalanceBox.setMaximumSize(QSize(16777215, 16777215)) self.verticalLayout = QVBoxLayout(self.BalanceBox) self.verticalLayout.setObjectName(u"verticalLayout") self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.BalanceConfigFrame = QFrame(self.BalanceBox) self.BalanceConfigFrame.setObjectName(u"BalanceConfigFrame") self.BalanceConfigFrame.setMinimumSize(QSize(408, 0)) self.BalanceConfigFrame.setMaximumSize(QSize(16777215, 44)) self.BalanceConfigFrame.setFrameShape(QFrame.Panel) self.BalanceConfigFrame.setFrameShadow(QFrame.Plain) self.BalanceConfigFrame.setLineWidth(0) self.horizontalLayout_2 = QHBoxLayout(self.BalanceConfigFrame) self.horizontalLayout_2.setObjectName(u"horizontalLayout_2") self.horizontalLayout_2.setContentsMargins(2, 2, 2, 2) self.BalanceDate = QDateEdit(self.BalanceConfigFrame) self.BalanceDate.setObjectName(u"BalanceDate") self.BalanceDate.setDateTime( QDateTime(QDate(2020, 11, 25), QTime(21, 0, 0))) self.BalanceDate.setCalendarPopup(True) self.BalanceDate.setTimeSpec(Qt.UTC) self.horizontalLayout_2.addWidget(self.BalanceDate) self.CurrencyLbl = QLabel(self.BalanceConfigFrame) self.CurrencyLbl.setObjectName(u"CurrencyLbl") self.CurrencyLbl.setLayoutDirection(Qt.LeftToRight) self.CurrencyLbl.setAlignment(Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter) self.horizontalLayout_2.addWidget(self.CurrencyLbl) self.BalancesCurrencyCombo = CurrencyComboBox(self.BalanceConfigFrame) self.BalancesCurrencyCombo.setObjectName(u"BalancesCurrencyCombo") self.horizontalLayout_2.addWidget(self.BalancesCurrencyCombo) self.ShowInactiveCheckBox = QCheckBox(self.BalanceConfigFrame) self.ShowInactiveCheckBox.setObjectName(u"ShowInactiveCheckBox") self.horizontalLayout_2.addWidget(self.ShowInactiveCheckBox) self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_2.addItem(self.horizontalSpacer_2) self.verticalLayout.addWidget(self.BalanceConfigFrame) self.BalancesTableView = QTableView(self.BalanceBox) self.BalancesTableView.setObjectName(u"BalancesTableView") self.BalancesTableView.setFrameShape(QFrame.Panel) self.BalancesTableView.setEditTriggers( QAbstractItemView.EditKeyPressed | QAbstractItemView.SelectedClicked) self.BalancesTableView.setAlternatingRowColors(True) self.BalancesTableView.setSelectionMode(QAbstractItemView.NoSelection) self.BalancesTableView.setGridStyle(Qt.DotLine) self.BalancesTableView.setWordWrap(False) self.BalancesTableView.verticalHeader().setVisible(False) self.BalancesTableView.verticalHeader().setMinimumSectionSize(20) self.BalancesTableView.verticalHeader().setDefaultSectionSize(20) self.verticalLayout.addWidget(self.BalancesTableView) self.BalanceOperationsSplitter.addWidget(self.BalanceBox) self.OperationsBox = QGroupBox(self.BalanceOperationsSplitter) self.OperationsBox.setObjectName(u"OperationsBox") sizePolicy2 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) sizePolicy2.setHorizontalStretch(4) sizePolicy2.setVerticalStretch(0) sizePolicy2.setHeightForWidth( self.OperationsBox.sizePolicy().hasHeightForWidth()) self.OperationsBox.setSizePolicy(sizePolicy2) self.OperationsBox.setContextMenuPolicy(Qt.DefaultContextMenu) self.verticalLayout_2 = QVBoxLayout(self.OperationsBox) self.verticalLayout_2.setObjectName(u"verticalLayout_2") self.verticalLayout_2.setContentsMargins(0, 0, 0, 0) self.OperationConfigFrame = QFrame(self.OperationsBox) self.OperationConfigFrame.setObjectName(u"OperationConfigFrame") self.OperationConfigFrame.setEnabled(True) self.OperationConfigFrame.setMinimumSize(QSize(0, 0)) self.OperationConfigFrame.setFrameShape(QFrame.Panel) self.OperationConfigFrame.setFrameShadow(QFrame.Plain) self.OperationConfigFrame.setLineWidth(0) self.horizontalLayout_3 = QHBoxLayout(self.OperationConfigFrame) self.horizontalLayout_3.setObjectName(u"horizontalLayout_3") self.horizontalLayout_3.setContentsMargins(2, 2, 2, 2) self.DateRange = DateRangeSelector(self.OperationConfigFrame) self.DateRange.setObjectName(u"DateRange") self.DateRange.setProperty("ItemsList", u"week;month;quarter;year;all") self.horizontalLayout_3.addWidget(self.DateRange) self.AccountLbl = QLabel(self.OperationConfigFrame) self.AccountLbl.setObjectName(u"AccountLbl") self.horizontalLayout_3.addWidget(self.AccountLbl) self.ChooseAccountBtn = AccountButton(self.OperationConfigFrame) self.ChooseAccountBtn.setObjectName(u"ChooseAccountBtn") self.horizontalLayout_3.addWidget(self.ChooseAccountBtn) self.SearchLbl = QLabel(self.OperationConfigFrame) self.SearchLbl.setObjectName(u"SearchLbl") self.horizontalLayout_3.addWidget(self.SearchLbl) self.SearchString = QLineEdit(self.OperationConfigFrame) self.SearchString.setObjectName(u"SearchString") self.horizontalLayout_3.addWidget(self.SearchString) self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_3.addItem(self.horizontalSpacer) self.verticalLayout_2.addWidget(self.OperationConfigFrame) self.OperationsDetailsSplitter = QSplitter(self.OperationsBox) self.OperationsDetailsSplitter.setObjectName( u"OperationsDetailsSplitter") self.OperationsDetailsSplitter.setOrientation(Qt.Vertical) self.OperationsTableView = QTableView(self.OperationsDetailsSplitter) self.OperationsTableView.setObjectName(u"OperationsTableView") sizePolicy3 = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) sizePolicy3.setHorizontalStretch(0) sizePolicy3.setVerticalStretch(4) sizePolicy3.setHeightForWidth( self.OperationsTableView.sizePolicy().hasHeightForWidth()) self.OperationsTableView.setSizePolicy(sizePolicy3) self.OperationsTableView.setAlternatingRowColors(True) self.OperationsTableView.setSelectionMode( QAbstractItemView.ExtendedSelection) self.OperationsTableView.setSelectionBehavior( QAbstractItemView.SelectRows) self.OperationsTableView.setWordWrap(False) self.OperationsDetailsSplitter.addWidget(self.OperationsTableView) self.OperationsTableView.verticalHeader().setVisible(False) self.OperationsTableView.verticalHeader().setMinimumSectionSize(20) self.OperationsTableView.verticalHeader().setDefaultSectionSize(20) self.OperationDetails = QFrame(self.OperationsDetailsSplitter) self.OperationDetails.setObjectName(u"OperationDetails") sizePolicy4 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) sizePolicy4.setHorizontalStretch(0) sizePolicy4.setVerticalStretch(1) sizePolicy4.setHeightForWidth( self.OperationDetails.sizePolicy().hasHeightForWidth()) self.OperationDetails.setSizePolicy(sizePolicy4) self.OperationDetails.setMinimumSize(QSize(0, 100)) self.OperationDetails.setMaximumSize(QSize(16777215, 300)) self.OperationDetails.setFrameShape(QFrame.Panel) self.OperationDetails.setFrameShadow(QFrame.Sunken) self.OperationDetails.setLineWidth(1) self.horizontalLayout_4 = QHBoxLayout(self.OperationDetails) self.horizontalLayout_4.setObjectName(u"horizontalLayout_4") self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0) self.OperationsTabs = QStackedWidget(self.OperationDetails) self.OperationsTabs.setObjectName(u"OperationsTabs") self.NoOperation = QWidget() self.NoOperation.setObjectName(u"NoOperation") self.OperationsTabs.addWidget(self.NoOperation) self.IncomeSpending = IncomeSpendingWidget() self.IncomeSpending.setObjectName(u"IncomeSpending") self.OperationsTabs.addWidget(self.IncomeSpending) self.Dividend = DividendWidget() self.Dividend.setObjectName(u"Dividend") self.OperationsTabs.addWidget(self.Dividend) self.Trade = TradeWidget() self.Trade.setObjectName(u"Trade") self.OperationsTabs.addWidget(self.Trade) self.Transfer = TransferWidget() self.Transfer.setObjectName(u"Transfer") self.OperationsTabs.addWidget(self.Transfer) self.CorporateAction = CorporateActionWidget() self.CorporateAction.setObjectName(u"CorporateAction") self.OperationsTabs.addWidget(self.CorporateAction) self.horizontalLayout_4.addWidget(self.OperationsTabs) self.OperationsButtons = QFrame(self.OperationDetails) self.OperationsButtons.setObjectName(u"OperationsButtons") self.verticalLayout_3 = QVBoxLayout(self.OperationsButtons) self.verticalLayout_3.setSpacing(2) self.verticalLayout_3.setObjectName(u"verticalLayout_3") self.verticalLayout_3.setContentsMargins(2, 2, 2, 2) self.NewOperationBtn = QPushButton(self.OperationsButtons) self.NewOperationBtn.setObjectName(u"NewOperationBtn") self.verticalLayout_3.addWidget(self.NewOperationBtn) self.CopyOperationBtn = QPushButton(self.OperationsButtons) self.CopyOperationBtn.setObjectName(u"CopyOperationBtn") self.verticalLayout_3.addWidget(self.CopyOperationBtn) self.DeleteOperationBtn = QPushButton(self.OperationsButtons) self.DeleteOperationBtn.setObjectName(u"DeleteOperationBtn") self.verticalLayout_3.addWidget(self.DeleteOperationBtn) self.verticalSpacer_4 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) self.verticalLayout_3.addItem(self.verticalSpacer_4) self.horizontalLayout_4.addWidget(self.OperationsButtons) self.OperationsDetailsSplitter.addWidget(self.OperationDetails) self.verticalLayout_2.addWidget(self.OperationsDetailsSplitter) self.BalanceOperationsSplitter.addWidget(self.OperationsBox) self.verticalLayout_4.addWidget(self.BalanceOperationsSplitter) self.retranslateUi(OperationsWidget) self.OperationsTabs.setCurrentIndex(5) QMetaObject.connectSlotsByName(OperationsWidget)
class MineSweeper(QMainWindow): def __init__(self): super().__init__() self.undiscovered_color: str = "#000000" self.discovered_color: str = "#d9d9d9" self.win_timer_color: str = "#e30e0e" self.lose_timer_color: str = "#0cc431" self.curr_time = QTime(00,00,00) self.timer = QTimer() self.timer.timeout.connect(self.time) self.timer_already_started = False self.solved: bool = False self.player_ended: bool = False self.theme: str = "dark" self.list_of_mines: list = [] self.difficulty_slider_default_value: int = 2 self.number_of_mines: int = mines_number(NUMBER_OF_LABELS, self.difficulty_slider_default_value) self.create_GUI() def create_GUI(self) -> None: self.setWindowTitle("MineSweeper 1.1") self.win_massage = QMessageBox(self) self.win_massage.setText("Gratuluji, dokázal jsi nalézt všechny miny") self.setMouseTracking(True) centralWidget = QWidget(self) centralWidget.setStyleSheet("background: white") self.setCentralWidget(centralWidget) self.setFixedSize(X_WINDOW_SIZE + 20, Y_WINDOW_SIZE) layout = QGridLayout(centralWidget) layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) centralWidget.setLayout(layout) self.list_of_labels: list = [] self.list_of_mines = generate_mines(self.number_of_mines, X_SIZE, Y_SIZE) # RESET BUTTON self.reset_button = QPushButton(centralWidget) self.reset_button.setText("RESET") self.reset_button.clicked.connect(self.reset) self.reset_button.setStyleSheet("margin: 3px") self.reset_button.setMinimumSize(0, 50) # TIMER LABEL self.timer_label = QLabel(centralWidget) self.timer_label.setText(f"{self.curr_time.minute():0>2}:{self.curr_time.second():0>2}") self.timer_label.setAlignment(Qt.AlignHCenter) self.timer_label.setStyleSheet("font: 34px") # DIFFICULTY SLIDER self.difficulty_slider = QSlider(centralWidget) self.difficulty_slider.setOrientation(Qt.Horizontal) self.difficulty_slider.setFixedHeight(30) self.difficulty_slider.setRange(1, 10) self.difficulty_slider.setTickInterval(1) self.difficulty_slider.setValue(self.difficulty_slider_default_value) self.difficulty_slider.valueChanged.connect(self.difficulty_label_set) self.difficulty_slider.sliderReleased.connect(self.new_mines_set) # DIFFICULTY LABEL self.difficulty_label = QLabel(centralWidget) self.difficulty_label.setText(str(self.difficulty_slider_default_value)) self.difficulty_label.setAlignment(Qt.AlignCenter) self.difficulty_label.setStyleSheet("font: 20px") for i in range(Y_SIZE): row = [] for j in range(X_SIZE): if (i, j) in self.list_of_mines: mine = True else: mine = False label = Chunk(j, i, mine) label.setFixedSize(FIELD_SQUARE_SIZE, FIELD_SQUARE_SIZE) label.setStyleSheet(f"background: {self.undiscovered_color}; border: 1px solid grey") layout.addWidget(label, i, j) row.append(label) self.list_of_labels.append(row) self.color_theme_combobox = QComboBox(centralWidget) self.color_theme_combobox.addItem("Dark theme", "dark") self.color_theme_combobox.addItem("Light theme", "light") self.color_theme_combobox.addItem("Color theme", "colorful") self.color_theme_combobox.currentIndexChanged.connect(self.theme_change) self.color_theme_combobox.setMinimumHeight(FIELD_SQUARE_SIZE * 2) if self.theme == "dark": self.color_theme_combobox.setCurrentIndex(0) elif self.theme == "light": self.color_theme_combobox.setCurrentIndex(1) else: self.color_theme_combobox.setCurrentIndex(2) layout.addWidget(self.color_theme_combobox, Y_SIZE - 2, X_SIZE, 2, 1) layout.addWidget(self.timer_label, 0, X_SIZE, 3, 1) layout.addWidget(self.reset_button, 2, X_SIZE, 3, 1) layout.addWidget(self.difficulty_slider, Y_SIZE, 1, 1, X_SIZE - 2) layout.addWidget(self.difficulty_label, Y_SIZE, X_SIZE, 1, 1) self.mines_number_surroundings_calculate() def theme_change(self) -> None: if self.color_theme_combobox.currentData() == "light": self.undiscovered_color = LIGHT_THEME["undiscovered_color"] self.discovered_color = LIGHT_THEME["discovered_color"] self.win_timer_color = LIGHT_THEME["win_timer_color"] self.lose_timer_color = LIGHT_THEME["lose_timer_color"] self.theme = "light" if self.color_theme_combobox.currentData() == "dark": self.undiscovered_color = DARK_THEME["undiscovered_color"] self.discovered_color = DARK_THEME["discovered_color"] self.win_timer_color = DARK_THEME["win_timer_color"] self.lose_timer_color = DARK_THEME["lose_timer_color"] self.theme = "dark" if self.color_theme_combobox.currentData() == "colorful": self.undiscovered_color = COLOR_THEME["undiscovered_color"] self.discovered_color = COLOR_THEME["discovered_color"] self.win_timer_color = COLOR_THEME["win_timer_color"] self.lose_timer_color = COLOR_THEME["lose_timer_color"] self.theme = "colorful" for y in range(Y_SIZE): for x in range(X_SIZE): if self.list_of_labels[y][x].marked: pass elif not self.list_of_labels[y][x].discovered: self.list_of_labels[y][x].setStyleSheet(f"background: {self.undiscovered_color}; border: 1px solid grey") elif self.list_of_labels[y][x].discovered: self.list_of_labels[y][x].setStyleSheet(f"background: {self.discovered_color}; border: 1px solid grey") def difficulty_label_set(self): self.difficulty_label.setText(str(self.difficulty_slider.value())) def mousePressEvent(self, QMouseEvent) -> None: if not self.player_ended: y = QMouseEvent.pos().x() x = QMouseEvent.pos().y() if not (x > X_GRID_SIZE or y > Y_GRID_SIZE): x = closest_smaller_number(x, Y_POSSIBLE_VALUES) y = closest_smaller_number(y, X_POSSIBLE_VALUES) x = int(x // FIELD_SQUARE_SIZE) y = int(y // FIELD_SQUARE_SIZE) if QMouseEvent.button() == Qt.LeftButton: if self.list_of_labels[x][y].mine: self.stop_timer() if not self.player_ended: self.list_of_labels[x][y].discovered = True self.list_of_labels[x][y].setStyleSheet(f"background: {self.discovered_color}; border: 1px solid grey") self.list_of_labels[x][y].setPixmap(QPixmap("C:/Data/python/miny/pracovní verze/pictures/bomb_small.png")) self.win_massage.about(self, "PROHRA", "Tentokrát se to bohužel nepovedlo, snad to vyjde příště.") self.player_ended = True else: if not self.timer_already_started: self.start_timer() self.timer_already_started = True self.list_of_labels[x][y].discovered = True self.list_of_labels[x][y].setStyleSheet(f"background: {self.discovered_color}; border: 1px solid grey") self.reveal_area(y, x) self.solved_check() else: if not self.list_of_labels[x][y].discovered: if self.list_of_labels[x][y].marked: self.list_of_labels[x][y].setStyleSheet(f"background: {self.undiscovered_color}; border: 1px solid grey") self.list_of_labels[x][y].marked = False else: self.list_of_labels[x][y].setStyleSheet("background: orange; border: 1px solid grey") self.list_of_labels[x][y].marked = True def mines_number_surroundings_calculate(self) -> None: for x in range(X_SIZE): for y in range(Y_SIZE): self.list_of_labels[x][y].mines_number_surroundings = 0 for i in range(x - 1, x + 2): for j in range(y - 1, y + 2): try: if self.list_of_labels[i][j].mine and i >= 0 and j >= 0: if not (i == x and j == y): self.list_of_labels[x][y].mines_number_surroundings += 1 except IndexError: pass def new_mines_set(self): self.number_of_mines = mines_number(NUMBER_OF_LABELS, self.difficulty_slider.value()) self.list_of_mines = generate_mines(self.number_of_mines, X_SIZE, Y_SIZE) for y in range(Y_SIZE): for x in range(X_SIZE): if (y, x) in self.list_of_mines: self.list_of_labels[y][x].mine = True else: self.list_of_labels[y][x].mine = False self.mines_number_surroundings_calculate() self.label_set() def label_set(self) -> None: for y in range(Y_SIZE): for x in range(X_SIZE): if self.list_of_labels[y][x].discovered: if self.list_of_labels[y][x].mines_number_surroundings == 0: pass else: self.list_of_labels[y][x].setText(str(self.list_of_labels[y][x].mines_number_surroundings)) def reveal_area(self, x: int, y: int) -> None: if self.list_of_labels[y][x].mines_number_surroundings == 0: try: extract = self.list_of_labels[y - 1][x] if not extract.mine and Y_SIZE > y - 1 >= 0 and not extract.discovered: self.list_of_labels[y - 1][x].setStyleSheet(f"background: {self.discovered_color}; border: 1px solid grey") self.list_of_labels[y - 1][x].discovered = True if extract.mines_number_surroundings == 0: self.reveal_area(x, y - 1) except IndexError: pass try: extract = self.list_of_labels[y + 1][x] if not extract.mine and Y_SIZE > y + 1 >= 0 and not extract.discovered: self.list_of_labels[y + 1][x].setStyleSheet(f"background: {self.discovered_color}; border: 1px solid grey") self.list_of_labels[y + 1][x].discovered = True if extract.mines_number_surroundings == 0: self.reveal_area(x, y + 1) except IndexError: pass try: extract = self.list_of_labels[y][x + 1] if not extract.mine and X_SIZE > x + 1 >= 0 and not extract.discovered: self.list_of_labels[y][x + 1].setStyleSheet(f"background: {self.discovered_color}; border: 1px solid grey") self.list_of_labels[y][x + 1].discovered = True if extract.mines_number_surroundings == 0: self.reveal_area(x + 1, y) except IndexError: pass try: extract = self.list_of_labels[y][x - 1] if not extract.mine and X_SIZE - 1 > x - 1 >= 0 and not extract.discovered: self.list_of_labels[y][x - 1].setStyleSheet(f"background: {self.discovered_color}; border: 1px solid grey") self.list_of_labels[y][x - 1].discovered = True if extract.mines_number_surroundings == 0: self.reveal_area(x - 1, y) except IndexError: pass self.label_set() def solved_check(self) -> None: for element in self.list_of_labels: for part in element: if not part.mine and not part.discovered: return self.solved = True self.stop_timer() if not self.player_ended: self.player_ended = True self.win_massage.about(self, "VÝHRA", f"Gratuluji, zvládl/a jsi vyřešit tento problém. Zvládl/a jsi to za {self.curr_time.minute():0>2}:{self.curr_time.second():0>2}") # TIMER FUNCIONS def start_timer(self) -> None: self.difficulty_slider.setDisabled(True) self.timer.start(1000) def stop_timer(self) -> None: self.timer.stop() if not self.solved: self.timer_label.setStyleSheet(f"font: 34px; color: {self.win_timer_color}") else: self.timer_label.setStyleSheet(f"font: 34px; color: {self.lose_timer_color}") def time(self) -> None: self.curr_time = self.curr_time.addSecs(1) self.timer_label.setText(f"{self.curr_time.minute():0>2}:{self.curr_time.second():0>2}") #RESET def reset(self) -> None: self.timer = QTimer() self.curr_time = QTime(00,00,00) self.timer.timeout.connect(self.time) self.solved = False self.timer_already_started = False self.player_ended = False self.difficulty_slider.setDisabled(False) self.difficulty_slider_default_value = self.difficulty_slider.value() self.create_GUI()
def currentRangeBegin(self, datetime): dt = QDateTime(datetime) dt.setTime( QTime(dt.time().hour(), (dt.time().minute() / 10) * 10, 0, 0)) return dt
def keyPressEvent(self, event: QKeyEvent) -> None: if event.key() == Qt.Key_Minus: self.setDateTime( QDateTime(QDate(1970, 1, 1), QTime(0, 0, 0), Qt.UTC)) # = 0 timestamp super().keyPressEvent(event)
def settings_time_start() -> QTime: return QTime.fromString(SETTINGS.value('time_start'))