def main(): # Create the Qt Application app = QApplication(sys.argv) # load sytle with open("style.qss", "r") as f: _style = f.read() app.setStyleSheet(_style) # Create and show taplist = TapList() taplist.show() # Run the main Qt loop sys.exit(app.exec())
def set_dark_theme(active: bool, compact: bool = False, *, app: QtWidgets.QApplication = None): global _current_dark_theme if _current_dark_theme == active: return if app is None: app = QtWidgets.QApplication.instance() new_palette = QtGui.QPalette(app.palette()) import qdarktheme style = qdarktheme.load_stylesheet(theme="dark" if active else "light") if compact: style += """ QGroupBox { padding: 0px; } QGroupBox::title { padding-bottom: 12px; } QComboBox { padding-right: 10px; } QPushButton { min-width: 60px; } QToolButton { border: 1px solid #32414B; } """ style += "QScrollArea { border: default; }" if active: new_palette.setColor(QtGui.QPalette.Link, Qt.cyan) new_palette.setColor(QtGui.QPalette.LinkVisited, Qt.cyan) else: new_palette.setColor(QtGui.QPalette.Link, Qt.blue) _current_dark_theme = active app.setStyleSheet(style) app.setPalette(new_palette)
if self.loading_widget is not None: self.loading_widget.close() if load_data: self.load_data() def set_blocks_thread_func(self, week, force_download): blocks = self.scraper.get_week_blocks(self, week, force_download) self.set_blocks_signal.emit(blocks, week) def set_blocks_slot(self, blocks, week): self.blocks = blocks self.get_week(week) def closeEvent(self, event): self.scraper.save_data() event.accept() if __name__ == "__main__": app = QApplication([]) widget = MainWindow() apply_stylesheet(app, theme='dark_green.xml') stylesheet = app.styleSheet() with open('custom.css') as file: app.setStyleSheet(stylesheet + file.read()) widget.setWindowTitle("College Schedule") widget.setWindowIcon(QtGui.QIcon("Icons/timetable.png")) widget.move(QtGui.QGuiApplication.primaryScreen().geometry().center() - widget.window.rect().center()) widget.show() sys.exit(app.exec_())
is_mix_words = bool(int(param.lstrip("is_mix_words="))) elif "is_smart_offer=" in param: is_smart_offer = bool(int(param.lstrip("is_smart_offer="))) # elif "triggering_threshold=" in param: # triggering_threshold = int(param.lstrip("triggering_threshold=")) def clear_globals(): """Очищает глобальные переменные, приводя их к значениям по умолчанию (исключая глобальные переменные).""" global main_window, training_window, questions_amount, bad_words, is_repeat, score main_window = None training_window = None questions_amount = 0 bad_words = [] is_repeat = False score = 0 # НАЧАЛО ПРОГРАММЫ if __name__ == "__main__": app = QApplication(sys.argv) main_window = MainWindow() main_window.show() with open("style.qss", "r") as f: _style = f.read() app.setStyleSheet(_style) sys.exit(app.exec_())
def run(): initialization_result = initialize() conf = config() window_config = conf['window'] WIDTH = window_config['width'] HEIGHT = window_config['height'] app = QApplication(sys.argv) app.setStyleSheet(style) geometry = app.screens()[0].size() clipboard = app.clipboard() widget = MainWidget(clipboard) widget.setWindowOpacity(window_config['opacity']) widget.resize(WIDTH, HEIGHT) widget.move(0, geometry.height() - HEIGHT - 280) widget.setWindowTitle('Albion Online Stats') widget.setWindowIcon(QtGui.QIcon(path('albion-stats-icon.png'))) if window_config['always_on_top']: widget.setWindowFlag(Qt.WindowStaysOnTopHint) if window_config['frameless']: widget.setWindowFlag(Qt.FramelessWindowHint) widget.show() current_version, latest_version = (get_current_version(), get_latest_version()) if latest_version and current_version != latest_version: msg = QMessageBox() msg.setIcon(QMessageBox.Warning) msg.setWindowTitle("Update available!") msg.setText("Another version of app is avaliable.") msg.setInformativeText( "You are using app in version {}, latest version is {}".format( current_version, latest_version)) msg.setStandardButtons(QMessageBox.Ok) msg.show() if initialization_result == InitializationResult.NetworkInterfaceListMissing: msg = QMessageBox() msg.setIcon(QMessageBox.Critical) msg.setWindowTitle("Unable to track network traffic data!") msg.setText( "On windows make sure that WinPcap is installed in your system.") msg.setInformativeText( "WinPcap can be installed from <a href='{}'>here</a> <br>\ <b>Make sure to install with the \"Install Npcap in WinPcap API-compatible Mode\"<b> option<br><br>\ In case where npcap is installed try to fix npcap and restart the app" .format('https://nmap.org/npcap/dist/npcap-0.9990.exe')) msg.setStandardButtons(QMessageBox.Ok) button = QPushButton("Fix npcap") button.clicked.connect(fix_npcap) msg.addButton(button, QMessageBox.NoRole) msg.show() sys.exit(app.exec_())
#------------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------------ STYLESHEET = """ QWidget { background-color: #2F2F2F; color: white; font-family: "Calibri"; } QTextEdit { border: 1px solid #92B4A7; background-color: grey; color: #2F2F2F; } QPushButton { min-height: 30px; } """ if __name__ == "__main__": app = QApplication(sys.argv) app.setStyleSheet(STYLESHEET) window = CsgoBindGenerator() window.show() center = QScreen.availableGeometry(QApplication.primaryScreen()).center() geo = window.frameGeometry() geo.moveCenter(center) window.move(geo.topLeft()) sys.exit(app.exec_())
self.ui.gameSquare20 ])) winningMoves = list( filter(lambda square: square is not None, winningMoves)) return winningMoves def getWinningMove(self, token, squares): winningMove = None pattern = "" for square in squares: pattern += square.text() if pattern == token + token: winningMove = list( filter(lambda square: square.text() == "", squares))[0] return winningMove if __name__ == '__main__': app = QApplication(sys.argv) window = MainWindow() app.setStyleSheet(qdarkstyle.load_stylesheet_pyside2()) window.show() sys.exit(app.exec_())
def main(gamePath: Optional[str] = None, configPath: Optional[str] = None, startupMode: StartupMode = StartupMode.Main) -> NoReturn: from w3modmanager.util.util import getRuntimePath from w3modmanager.core.model import Model from w3modmanager.core.errors import OtherInstanceError, InvalidGamePath, InvalidConfigPath from w3modmanager.ui.graphical.mainwindow import MainWindow from w3modmanager.domain.web.nexus import closeSession from w3modmanager.domain.system.permissions import \ getWritePermissions, setWritePermissions from PySide6.QtCore import Qt, QSettings from PySide6.QtWidgets import QApplication, QMessageBox from PySide6.QtGui import QIcon, QPalette, QFont from qasync import QEventLoop QApplication.setOrganizationName(w3modmanager.ORG_NAME) QApplication.setOrganizationDomain(w3modmanager.ORG_URL) QApplication.setApplicationName(w3modmanager.TITLE) QApplication.setApplicationVersion(w3modmanager.VERSION) QApplication.setApplicationDisplayName('') QApplication.setAttribute(Qt.AA_NativeWindows) app = QApplication(sys.argv) app.setStyleSheet(''' Link { text-decoration: none; } ''') eventloop = QEventLoop(app) asyncio.set_event_loop(eventloop) palette = QPalette(QApplication.palette()) palette.setColor(QPalette.Link, Qt.red) palette.setColor(QPalette.LinkVisited, Qt.red) palette.setColor(QPalette.PlaceholderText, Qt.gray) app.setPalette(palette) font = QFont('Segoe UI') font.setStyleHint(QFont.System) font.setWeight(QFont.Normal) font.setStyleStrategy(QFont.PreferDevice) font.setPointSize(9) app.setFont(font) icon = QIcon() icon.addFile(str(getRuntimePath('resources/icons/w3b.ico'))) app.setWindowIcon(icon) pool = ThreadPoolExecutor() asyncio.get_running_loop().set_default_executor(pool) # configure startup overrides settings = QSettings() if gamePath: settings.setValue('gamePath', gamePath) if configPath: settings.setValue('configPath', configPath) if startupMode == StartupMode.About: MainWindow.showAboutDialog(None).exec_() sys.exit() if startupMode == StartupMode.Settings: MainWindow.showSettingsDialog(None).exec_() sys.exit() exception_hook_set = False def createModel(ignorelock: bool = False) -> Model: nonlocal settings return Model( Path(str(settings.value('gamePath'))), Path(str(settings.value('configPath'))), Path( appdirs.user_data_dir(w3modmanager.NAME, w3modmanager.ORG_NAME)), ignorelock) try: # try to initialize the mod management model try: model = createModel() # if another instance is already open, inform and ask to open anyway except OtherInstanceError as e: if MainWindow.showOtherInstanceDialog( None).exec_() == QMessageBox.Yes: model = createModel(True) else: raise e # if game path or config path is invalid or not set, # show a special settings dialog and retry except (InvalidGamePath, InvalidConfigPath): MainWindow.showSettingsDialog(None, True).exec_() model = createModel() # check for write access to the game and config directories for path in ( model.gamepath, model.configpath, model.cachepath, ): if not getWritePermissions(path): if MainWindow.showInvalidPermissionsDialog(None, path).exec_() != QMessageBox.Yes \ or not setWritePermissions(path): raise PermissionError(f'Not enough permissions for {path}') window = MainWindow(model) app.setActiveWindow(window) def show_exception_hook(exctype, value, tb) -> None: # noqa nonlocal window MainWindow.showCritcalErrorDialog( window, value, ''.join(traceback.format_exception(exctype, value, tb))).exec_() exception_hook(exctype, value, tb) sys.excepthook = show_exception_hook exception_hook_set = True with eventloop: status = eventloop.run_forever() eventloop.run_until_complete(closeSession()) sys.exit(status) except OtherInstanceError as e: sys.exit(f'error: {str(e)}') except (InvalidGamePath, InvalidConfigPath) as e: MainWindow.showInvalidConfigErrorDialog(None).exec_() sys.exit(f'error: {str(e)}') except PermissionError as e: MainWindow.showInvalidPermissionsErrorDialog(None).exec_() sys.exit(f'error: {str(e)}') except Exception as e: if not exception_hook_set: MainWindow.showCritcalErrorDialog(None, str(e)).exec_() raise e sys.exit()
""" Change the combo box value. Values represent the different file extensions. """ self.cb_value = text def renameFiles(self): """ Create instance of worker thread to handle the file renaming process. """ prefix_text = self.change_name_edit.text() if self.directory != "" and prefix_text != "": self.worker = Worker(self.directory, self.cb_value, prefix_text) self.worker.updateValueSignal.connect(self.updateProgressBar) self.worker.updateTextEditSignal.connect(self.updateTextEdit) self.worker.start() else: pass def updateProgressBar(self, value): self.progress_bar.setValue(value) def updateTextEdit(self, old_text, new_text): self.display_files_edit.append("[INFO] {} changed to{}.".format(old_text, new_text)) if __name__ == "__main__": app = QApplication(sys.argv) app.setStyleSheet(style_sheet) window = RenameFilesGUI() sys.exit(app.exec())
from PySide6.QtUiTools import QUiLoader from qt_material import apply_stylesheet import os ######################################################################## class RuntimeStylesheets(QMainWindow): # ---------------------------------------------------------------------- def __init__(self): """""" super().__init__() self.main = QUiLoader().load('main_window.ui', self) self.main.pushButton_2.setProperty('class', 'big_button') if __name__ == "__main__": app = QApplication() apply_stylesheet(app, theme='light_blue.xml') stylesheet = app.styleSheet() # app.setStyleSheet(stylesheet + "QPushButton{color: red; text-transform: none;}") with open('custom.css') as file: app.setStyleSheet(stylesheet + file.read().format(**os.environ)) frame = RuntimeStylesheets() frame.main.show() app.exec_()