def install_translator(qapp): """Install Qt translator to the QApplication instance""" global QT_TRANSLATOR if QT_TRANSLATOR is None: qt_translator = QTranslator() if qt_translator.load("qt_" + QLocale.system().name(), QLibraryInfo.location(QLibraryInfo.TranslationsPath)): QT_TRANSLATOR = qt_translator # Keep reference alive if QT_TRANSLATOR is not None: qapp.installTranslator(QT_TRANSLATOR)
def install_translator(qapp): """Install Qt translator to the QApplication instance""" global QT_TRANSLATOR if QT_TRANSLATOR is None: qt_translator = QTranslator() if qt_translator.load("qt_"+QLocale.system().name(), QLibraryInfo.location(QLibraryInfo.TranslationsPath)): QT_TRANSLATOR = qt_translator # Keep reference alive if QT_TRANSLATOR is not None: qapp.installTranslator(QT_TRANSLATOR)
def install_translator(qapp): """Install Qt translator to the QApplication instance""" global QT_TRANSLATOR if QT_TRANSLATOR is None: from qtpy.QtCore import QLocale, QTranslator, QLibraryInfo locale = QLocale.system().name() # Qt-specific translator qt_translator = QTranslator() paths = QLibraryInfo.location(QLibraryInfo.TranslationsPath) if qt_translator.load("qt_" + locale, paths): QT_TRANSLATOR = qt_translator # Keep reference alive if QT_TRANSLATOR is not None: qapp.installTranslator(QT_TRANSLATOR)
def __init__(self, parent=None, hide_nav_bar=False, hide_menu_bar=False, hide_status_bar=False): super(PyDMMainWindow, self).__init__(parent) self.app = QApplication.instance() self.font_factor = 1 self.iconFont = IconFont() self._display_widget = None self._showing_file_path_in_title_bar = False self._saved_menu_geometry = None self._saved_menu_height = None self._new_widget_size = None self.default_font_size = QApplication.instance().font().pointSizeF() self.home_file = None self.home_widget = None self.designer_path = None self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.navbar.setIconSize(QSize(24, 24)) self.ui.navbar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) self.ui.actionHome.triggered.connect(self.home_triggered) self.ui.actionHome.setIcon(self.iconFont.icon("home")) self.ui.actionBack.triggered.connect(self.back_triggered) self.ui.actionBack.setIcon(self.iconFont.icon("angle-left")) self.ui.actionForward.triggered.connect(self.forward_triggered) self.ui.actionForward.setIcon(self.iconFont.icon("angle-right")) self.ui.actionEdit_in_Designer.triggered.connect(self.edit_in_designer) self.ui.actionOpen_File.triggered.connect(self.open_file_action) self.ui.actionReload_Display.triggered.connect(self.reload_display) self.ui.actionIncrease_Font_Size.triggered.connect( self.increase_font_size) self.ui.actionDecrease_Font_Size.triggered.connect( self.decrease_font_size) self.ui.actionDefault_Font_Size.triggered.connect(self.reset_font_size) self.ui.actionEnter_Fullscreen.triggered.connect(self.enter_fullscreen) self.ui.actionShow_File_Path_in_Title_Bar.triggered.connect( self.toggle_file_path_in_title_bar) self.ui.actionShow_Navigation_Bar.triggered.connect( self.toggle_nav_bar) self.ui.actionShow_Menu_Bar.triggered.connect(self.toggle_menu_bar) self.ui.actionShow_Status_Bar.triggered.connect(self.toggle_status_bar) self.ui.actionShow_Connections.triggered.connect(self.show_connections) self.ui.actionAbout_PyDM.triggered.connect(self.show_about_window) self.ui.actionLoadTool.triggered.connect(self.load_tool) self.ui.actionLoadTool.setIcon(self.iconFont.icon("rocket")) self.ui.actionQuit.triggered.connect(self.quit_main_window) if hide_nav_bar: self.toggle_nav_bar(False) if hide_menu_bar: # Toggle the menu bar via the QAction so that the menu item # stays in sync with menu visibility. self.ui.actionShow_Menu_Bar.activate(QAction.Trigger) if hide_status_bar: self.toggle_status_bar(False) #Try to find the designer binary. self.ui.actionEdit_in_Designer.setEnabled(False) possible_designer_bin_paths = ( QLibraryInfo.location(QLibraryInfo.BinariesPath), QLibraryInfo.location(QLibraryInfo.LibraryExecutablesPath)) for bin_path in possible_designer_bin_paths: if platform.system() == 'Darwin': designer_path = os.path.join( bin_path, 'Designer.app/Contents/MacOS/Designer') elif platform.system() == 'Linux': designer_path = os.path.join(bin_path, 'designer') else: designer_path = os.path.join(bin_path, 'designer.exe') if os.path.isfile(designer_path): self.designer_path = designer_path break self.update_tools_menu() self.enable_disable_navigation()
from ._abstract import (_AbstractDock, _AbstractToolBar, _AbstractMenuBar, _AbstractStatusBar, _AbstractLayout, _AbstractWidget, _AbstractWindow, _AbstractMplCanvas, _AbstractPlayback, _AbstractBrainMplCanvas, _AbstractMplInterface, _AbstractWidgetList, _AbstractAction, _AbstractDialog, _AbstractKeyPress) from ._utils import (_qt_disable_paint, _qt_get_stylesheet, _qt_is_dark, _qt_detect_theme, _qt_raise_window) from ..utils import safe_event from ...utils import _check_option, get_config from ...fixes import _compare_version # Adapted from matplotlib if (sys.platform == 'darwin' and _compare_version(platform.mac_ver()[0], '>=', '10.16') and QLibraryInfo.version().segments() <= [5, 15, 2]): os.environ.setdefault("QT_MAC_WANTS_LAYER", "1") class _QtKeyPress(_AbstractKeyPress): _widget_id = 0 _callbacks = dict() _to_qt = dict( escape=Qt.Key_Escape, up=Qt.Key_Up, down=Qt.Key_Down, left=Qt.Key_Left, right=Qt.Key_Right, comma=Qt.Key_Comma, period=Qt.Key_Period, page_up=Qt.Key_PageUp,
def __init__(self, parent=None, hide_nav_bar=False, hide_menu_bar=False, hide_status_bar=False): super(PyDMMainWindow, self).__init__(parent) self.app = QApplication.instance() self.font_factor = 1 self.iconFont = IconFont() self.ui = Ui_MainWindow() self.ui.setupUi(self) self._display_widget = None self._showing_file_path_in_title_bar = False self.default_font_size = QApplication.instance().font().pointSizeF() self.ui.navbar.setIconSize(QSize(24, 24)) self.ui.navbar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) # No search bar for now, since there isn't really any capability to search yet. # self.searchBar = QLineEdit(self) # self.searchBar.setPlaceholderText("Search") # self.searchBar.setMinimumWidth(150) # self.searchAction = self.ui.navbar.insertWidget(self.ui.actionHome, self.searchBar) self.ui.actionHome.triggered.connect(self.home) self.ui.actionHome.setIcon(self.iconFont.icon("home")) self.home_file = None self.back_stack = [] self.forward_stack = [] self.ui.actionBack.triggered.connect(self.back) self.ui.actionBack.setIcon(self.iconFont.icon("angle-left")) self.ui.actionForward.triggered.connect(self.forward) self.ui.actionForward.setIcon(self.iconFont.icon("angle-right")) # self.ui.goButton.clicked.connect(self.go_button_pressed) self.ui.actionEdit_in_Designer.triggered.connect(self.edit_in_designer) self.ui.actionOpen_File.triggered.connect(self.open_file_action) self.ui.actionReload_Display.triggered.connect(self.reload_display) self.ui.actionIncrease_Font_Size.triggered.connect(self.increase_font_size) self.ui.actionDecrease_Font_Size.triggered.connect(self.decrease_font_size) self.ui.actionDefault_Font_Size.triggered.connect(self.reset_font_size) self.ui.actionEnter_Fullscreen.triggered.connect(self.enter_fullscreen) self.ui.actionShow_File_Path_in_Title_Bar.triggered.connect(self.toggle_file_path_in_title_bar) self.ui.actionShow_Navigation_Bar.triggered.connect(self.toggle_nav_bar) self.ui.actionShow_Menu_Bar.triggered.connect(self.toggle_menu_bar) self.ui.actionShow_Status_Bar.triggered.connect(self.toggle_status_bar) self.ui.actionShow_Connections.triggered.connect(self.show_connections) self.ui.actionAbout_PyDM.triggered.connect(self.show_about_window) self.ui.actionLoadTool.triggered.connect(self.load_tool) self.ui.actionLoadTool.setIcon(self.iconFont.icon("rocket")) self._saved_menu_geometry = None self._saved_menu_height = None self._new_widget_size = None if hide_nav_bar: self.toggle_nav_bar(False) if hide_menu_bar: # Toggle the menu bar via the QAction so that the menu item # stays in sync with menu visibility. self.ui.actionShow_Menu_Bar.activate(QAction.Trigger) if hide_status_bar: self.toggle_status_bar(False) #Try to find the designer binary. self.ui.actionEdit_in_Designer.setEnabled(False) self.designer_path = None possible_designer_bin_paths = (QLibraryInfo.location(QLibraryInfo.BinariesPath), QLibraryInfo.location(QLibraryInfo.LibraryExecutablesPath)) for bin_path in possible_designer_bin_paths: if platform.system() == 'Darwin': designer_path = os.path.join(bin_path, 'Designer.app/Contents/MacOS/Designer') elif platform.system() == 'Linux': designer_path = os.path.join(bin_path, 'designer') else: designer_path = os.path.join(bin_path, 'designer.exe') if os.path.isfile(designer_path): self.designer_path = designer_path break self.update_tools_menu()