def __init__(self, argv): CanvasApplication.__args, argv_ = self.parseArguments(argv) ns = CanvasApplication.__args fix_qt_plugins_path() self.__fileOpenUrls = [] self.__in_exec = False if ns.enable_high_dpi_scaling \ and hasattr(Qt, "AA_EnableHighDpiScaling"): # Turn on HighDPI support when available QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) if ns.use_high_dpi_pixmaps \ and hasattr(Qt, "AA_UseHighDpiPixmaps"): QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) if ns.style: argv_ = argv_ + ["-style", self.__args.style] super().__init__(argv_) # Make sure there is an asyncio event loop that runs on the # Qt event loop. _ = get_event_loop() argv[:] = argv_ self.setAttribute(Qt.AA_DontShowIconsInMenus, True) if hasattr(self, "styleHints"): sh = self.styleHints() if hasattr(sh, 'setShowShortcutsInContextMenus'): # PyQt5.13 and up sh.setShowShortcutsInContextMenus(True) if QT_VERSION_INFO < (5, 15): # QTBUG-61707 macos_set_nswindow_tabbing(False) self.configureStyle()
def main(argv=sys.argv): if len(argv) == 1: filename = None else: if argv[1] in ["-h", "--help"]: usage(argv) return 0 else: filename = argv[1] app = QApplication(argv) app.setAttribute(Qt.AA_EnableHighDpiScaling) app.setAttribute(Qt.AA_UseHighDpiPixmaps) if filename is None: filename, _ = QFileDialog.getOpenFileName( None, "Image file", os.path.expanduser("~/Documents"), "Image (*.png)") if not filename: return 1 print(filename) form = MainForm(filename=filename) rect = QApplication.desktop().availableGeometry() form.show() form.raise_() return app.exec_()
def main(): if getattr(sys, 'frozen', False): import httplib2 httplib2.CA_CERTS = os.environ['REQUESTS_CA_BUNDLE'] = \ os.path.join(os.path.dirname(sys.executable), 'cacert.pem') QApplication.setAttribute(Qt.AA_X11InitThreads) app = QApplication(sys.argv) app.setQuitOnLastWindowClosed(False) app.clipboard().mimeData() # Sometimes first try to acquire clipboard fails. So be it. wnd = MainWindow() wnd.hide() app.exec_()
def __init__(self, argv): fix_qt_plugins_path() if hasattr(Qt, "AA_EnableHighDpiScaling"): # Turn on HighDPI support when available QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) CanvasApplication.__args, argv_ = self.parse_style_arguments(argv) if self.__args.style: argv_ = argv_ + ["-style", self.__args.style] super().__init__(argv_) argv[:] = argv_ self.setAttribute(Qt.AA_DontShowIconsInMenus, True) self.configureStyle()
def __init__(self, argv): fix_qt_plugins_path() if hasattr(Qt, "AA_EnableHighDpiScaling"): # Turn on HighDPI support when available QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) CanvasApplication.__args, argv_ = self.parse_style_arguments(argv) if self.__args.style: argv_ = argv_ + ["-style", self.__args.style] super().__init__(argv_) # Make sure there is an asyncio event loop that runs on the # Qt event loop. _ = get_event_loop() argv[:] = argv_ self.setAttribute(Qt.AA_DontShowIconsInMenus, True) if hasattr(self, "styleHints"): sh = self.styleHints() if hasattr(sh, 'setShowShortcutsInContextMenus'): # PyQt5.13 and up sh.setShowShortcutsInContextMenus(True) self.configureStyle()
def __init__(self, output_dir, categories, doc_dir): self.output_dir = output_dir self.categories = categories self.doc_dir = doc_dir QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) QApplication.setAttribute(Qt.AA_ShareOpenGLContexts) self.app = QApplication([]) print("Generating widget repository") self.registry = self.__get_widget_registry() print("Locating help files") self.help = get_documentation(doc_dir) print("Ready to go")
def __init__(self, output_dir, image_url_prefix): self.output_dir = output_dir self.image_url_prefix = image_url_prefix QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) QApplication.setAttribute(Qt.AA_ShareOpenGLContexts) self.app = QApplication([]) print("Generating widget repository") self.registry = self.__get_widget_registry() print("Locating help files") self.help_manager = HelpManager() self.help_manager.set_registry(self.registry) # Help manager needs QApplication running to get the urls # of widget documentation. 5 seconds should be enough. QTimer.singleShot(5000, self.app.quit) self.app.exec() self.__scene = QGraphicsScene() self.__nodes = [] print("Ready to go")
class WidgetCatalog: def __init__(self, output_dir, image_url_prefix): self.output_dir = output_dir self.image_url_prefix = image_url_prefix self.app = QApplication([]) self.app.setAttribute(Qt.AA_EnableHighDpiScaling) self.app.setAttribute(Qt.AA_UseHighDpiPixmaps) print("Generating widget repository") self.registry = self.__get_widget_registry() print("Locating help files") self.help_manager = HelpManager() self.help_manager.set_registry(self.registry) # Help manager needs QApplication running to get the urls # of widget documentation. 5 seconds should be enough. QTimer.singleShot(5000, self.app.quit) self.app.exec() self.__scene = QGraphicsScene() self.__nodes = [] print("Ready to go") def create(self): print("Generating catalog") try: makedirs(path.join(self.output_dir, "icons")) except FileExistsError: pass result = [] for category in self.registry.categories(): widgets = [] result.append((category.name, widgets)) for widget in category.widgets: widgets.append({ "text": widget.name, "doc": self.__get_help(widget), "img": self.__get_icon(widget, category), "keyword": widget.keywords, }) with open(path.join(self.output_dir, "widgets.json"), "wt") as f: json.dump(result, f, indent=1) print("Done") @staticmethod def __get_widget_registry(): widget_discovery = QtWidgetDiscovery() widget_registry = QtWidgetRegistry() widget_discovery.found_category.connect( widget_registry.register_category) widget_discovery.found_widget.connect(widget_registry.register_widget) widget_discovery.run(config.widgets_entry_points()) # Fixup category.widgets list for cat, widgets in widget_registry._categories_dict.values(): cat.widgets = widgets return widget_registry def __get_icon(self, widget, category=None): # Set remove inputs/outputs so the "ears" are not drawn widget = copy(widget) widget.inputs = [] widget.outputs = [] w = IconWidget() w.set_widget(widget, category) w.show() # self.app.processEvents() filename = "icons/{}.png".format(widget.qualified_name) w.render_as_png(path.join(self.output_dir, filename)) w.hide() if self.image_url_prefix: return self.image_url_prefix + filename else: return filename def __get_help(self, widget): query = dict(id=widget.qualified_name) try: return self.help_manager.search(query).url() except KeyError: return None
def __init__(self, argv): if hasattr(Qt, "AA_EnableHighDpiScaling"): # Turn on HighDPI support when available QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) QApplication.__init__(self, argv) self.setAttribute(Qt.AA_DontShowIconsInMenus, True)