def main(): logmodule = qrainbowstyle.extras.OutputLogger() qInstallMessageHandler(qt_message_handler) QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) app = QApplication(sys.argv) app.setStyleSheet(qrainbowstyle.load_stylesheet()) win = FramelessWindow() groupbox = QWidget(win) groupbox_layout = QGridLayout(groupbox) groupbox.setLayout(groupbox_layout) groupbox_layout.addWidget(QLabel("StylePickerGrid:", groupbox), *(1, 1)) groupbox_layout.addWidget(StylePickerGrid(2, groupbox), *(1, 2)) groupbox_layout.addWidget(QLabel("StylePickerVertical:", groupbox), *(2, 1)) groupbox_layout.addWidget(StylePickerVertical(groupbox), *(2, 2)) groupbox_layout.addWidget(QLabel("StylePickerHorizontal:", groupbox), *(3, 1)) groupbox_layout.addWidget(StylePickerHorizontal(groupbox), *(3, 2)) win.addContentWidget(groupbox) win.show() sys.exit(app.exec())
def main(): logmodule = qrainbowstyle.extras.OutputLogger() qInstallMessageHandler(qrainbowstyle.extras.qt_message_handler) QtWidgets.QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) QtWidgets.QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) app = QtWidgets.QApplication(sys.argv) app.setStyleSheet(qrainbowstyle.load_stylesheet(style="oceanic")) # Package options # qrainbowstyle.align_buttons_left() # qrainbowstyle.use_darwin_buttons() qrainbowstyle.setAppIcon( os.path.join(os.path.dirname(os.path.realpath(__file__)), "github_logo.png")) # Create frameless mainwindow win = qrainbowstyle.windows.FramelessWindow() menu = QMenu(win) menu.setTitle("Some menu") menu.addAction(QAction("TEST ACTION", menu)) win.addMenu(menu) # Example for spinner spinner = qrainbowstyle.widgets.WaitingSpinner(win, centerOnParent=True, modality=Qt.WindowModal, roundness=70.0, fade=70.0, radius=9.0, lines=24, line_length=35.0, line_width=2.0) spinner.start() spinner.fadeIn() t = QTimer() t.setSingleShot(True) t.timeout.connect(spinner.fadeOut) t.start(5000) win.setMinimumSize(QSize(500, 300)) # Example of using signals win.closeClicked.connect(lambda: print("Close clicked!")) # Create content widget and pass reference to main window widget = WidgetGallery(win) # Add widget to main window and show it win.addContentWidget(widget) win.show() # Fullscreen test # win.showFullScreen() sys.exit(app.exec())
def main() -> None: """Startup function.""" global _app t0 = process_time() exit_code = 0 from sys import argv, exit from logging import shutdown from platform import system from pyslvs_ui.info import ARGUMENTS, logger if ARGUMENTS.cmd in {'gui', None}: from qtpy.QtCore import Qt, qInstallMessageHandler from qtpy.QtWidgets import QApplication, QSplashScreen from qtpy.QtGui import QPixmap _app = QApplication(argv) # Depress Qt warning qInstallMessageHandler(lambda _0, _1, _2: None) # Load QRC file from pyslvs_ui.icons_rc import qInitResources qInitResources() # Splash sp = QSplashScreen(QPixmap(":/icons/splash.png")) sp.showMessage(f"{__author__} {__copyright__}", Qt.AlignBottom | Qt.AlignRight) sp.show() # Force enable fusion style on macOS if system() == 'Darwin': ARGUMENTS.fusion = True if ARGUMENTS.fusion: _app.setStyle('fusion') # Main window from .main_window import MainWindow w = MainWindow.new() sp.finish(w) sp.deleteLater() logger.info(f"Startup with: {process_time() - t0:.02f}s") if not ARGUMENTS.debug_mode: w.console_connect() del sp, w exit_code = _app.exec_() elif ARGUMENTS.cmd == 'test': from importlib import import_module import_module('pyslvs_ui.main_window') logger.info("All module loaded successfully.") logger.info(f"Loaded with: {process_time() - t0:.02f}s") elif ARGUMENTS.cmd == 'extract': logger.info(f"Start CLI: {process_time() - t0:.02f}s") # TODO: CLI mode else: raise ValueError(f"unknown command: {ARGUMENTS.cmd}") shutdown() exit(exit_code)
def main(): logmodule = qrainbowstyle.extras.OutputLogger() qInstallMessageHandler(qt_message_handler) QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) app = QApplication(sys.argv) app.setStyleSheet(qrainbowstyle.load_stylesheet(style="darkorange")) win = FramelessWindow() widget = MainWidget(win) win.addContentWidget(widget) win.show() sys.exit(app.exec())
def main(): logmodule = qrainbowstyle.extras.OutputLogger() qInstallMessageHandler(qt_message_handler) QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) app = QApplication(sys.argv) app.setStyleSheet(qrainbowstyle.load_stylesheet(style="oceanic")) qrainbowstyle.setAppIcon( os.path.join(os.path.dirname(os.path.realpath(__file__)), "github_logo.png")) dialog = FramelessWindow() dialog.setWindowTitle("FDialog") dialog.resize(1100, 600) dialog.show() oneMenu = QMenu() oneMenu.setTitle("Tools") oneMenu.addActions( [QAction("Clicker", oneMenu), QAction("Initializer", oneMenu)]) twomenu = QMenu() twomenu.setTitle("File") twomenu.addActions([QAction("Open", twomenu), QAction("Save", twomenu)]) thirdmenu = QMenu() thirdmenu.setTitle("Settings") thirdmenu.addActions([QAction("Network", thirdmenu)]) looper = StyleLooper() style = QAction("Change style", thirdmenu) style.triggered.connect(looper.change) thirdmenu.addAction(style) dialog.addMenu(twomenu) dialog.addMenu(oneMenu) dialog.addMenu(thirdmenu) box = FramelessWarningMessageBox(dialog) box.setText("Warning :)") box.show() sys.exit(app.exec())
def main(): logmodule = qrainbowstyle.extras.OutputLogger() qInstallMessageHandler(qt_message_handler) QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) app = QApplication(sys.argv) app.setStyleSheet(qrainbowstyle.load_stylesheet()) qrainbowstyle.setAppIcon( os.path.join(os.path.dirname(os.path.realpath(__file__)), "github_logo.png")) win = FramelessWindow() widget = mainWidget(win) win.addContentWidget(widget) win.show() sys.exit(app.exec())
def check_image(self, filename): """ Checks a filename to see if the image can be loaded. Parameters ---------- filename : (str) Inputted filename by user Returns ------- tuple : (str, misc) Error message and None if an error is present or None and a QSvgRenderer/QPixmap (depending on file type). """ error = None file_type = None abs_path = os.path.expanduser(os.path.expandvars(filename)) if not os.path.isabs(abs_path): try: if is_qt_designer(): p = self.get_designer_window() if p is not None: ui_dir = p.absoluteDir().absolutePath() abs_path = os.path.join(ui_dir, abs_path) else: parent_display = self.widget.find_parent_display() base_path = None if parent_display: base_path = os.path.dirname( parent_display.loaded_file()) abs_path = find_file(abs_path, base_path=base_path) except Exception as ex: print("Exception: ", ex) error = "Unable to find full filepath for {}".format(filename) abs_path = filename # First, lets try SVG. We have to try SVG first, otherwise # QPixmap will happily load the SVG and turn it into a raster image. # Really annoying: We have to try to load the file as SVG, # and we expect it will fail often (because many images aren't SVG). # Qt prints a warning message to stdout any time SVG loading fails. # So we have to temporarily silence Qt warning messages here. qInstallMessageHandler(self.qt_message_handler) svg = QSvgRenderer() if svg.load(abs_path): file_type = svg qInstallMessageHandler(None) return error, file_type qInstallMessageHandler(None) # SVG didn't work, lets try QPixmap image = QPixmap(abs_path) if not image.isNull(): file_type = image return error, file_type # If we get this far, the file specified could not be loaded at all. if error is None: error = "Could not load image \n{}".format(filename) return error, file_type
def imageFiles(self, new_files): """ JSON-formatted dictionary keyed on states (integers), with filenames of the image file to display for the state. Parameters ---------- new_files : str """ self._state_images_string = str(new_files) try: new_file_dict = json.loads(self._state_images_string) except Exception: self._state_images = {} return self._sizeHint = QSize(0, 0) for (state, filename) in new_file_dict.items(): if is_pydm_app(): try: file_path = self.app.get_path(filename) except Exception as e: logger.exception("Couldn't get file with path %s", filename) file_path = filename else: file_path = filename # First, lets try SVG. We have to try SVG first, otherwise # QPixmap will happily load the SVG and turn it into a raster image. # Really annoying: We have to try to load the file as SVG, # and we expect it will fail often (because many images aren't SVG). # Qt prints a warning message to stdout any time SVG loading fails. # So we have to temporarily silence Qt warning messages here. qInstallMessageHandler(self.qt_message_handler) svg = QSvgRenderer() svg.repaintNeeded.connect(self.update) if svg.load(file_path): self._state_images[int(state)] = (filename, svg) self._sizeHint = self._sizeHint.expandedTo(svg.defaultSize()) qInstallMessageHandler(None) continue qInstallMessageHandler(None) # SVG didn't work, lets try QPixmap image = QPixmap(file_path) if not image.isNull(): self._state_images[int(state)] = (filename, image) self._sizeHint = self._sizeHint.expandedTo(image.size()) continue # If we get this far, the file specified could not be loaded at all. logger.error("Could not load image: {}".format(filename)) self._state_images[int(state)] = (filename, None)
self.tableModel.setDiskSize(DISK_SIZE) self.table.setModel(self.tableModel) self.main_widget.addWidget(self.table) for algorithm in self.algorithms: algorithm_instance = algorithm(self.que, START_POS, DISK_SIZE) self.tableModel.addAlgorithm(algorithm_instance) self.start_button = QPushButton("Start", self) self.start_button.clicked.connect(self.tableModel.start) self.main_widget.addWidget(self.start_button) if __name__ == '__main__': log = Logger() qInstallMessageHandler(qt_message_handler) def exception_hook(exctype, value, tb): logging.critical(''.join(traceback.format_exception( exctype, value, tb))) sys.exit(1) sys.excepthook = exception_hook QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) QApplication.setQuitOnLastWindowClosed(True) app = QApplication(sys.argv) app.setStyleSheet(qrainbowstyle.load_stylesheet(style="oceanic"))