def run(self): #TODO parse command line for addition arguments msmlgui.shared.msml_app = MsmlApp( add_search_path=["/home/weigl/workspace/msml/share/"]) app = QtGui.QApplication(sys.argv) app.setAttribute(Qt.AA_DontShowIconsInMenus, False) QIcon.setThemeName("tango") for path in QtGui.QIcon.themeSearchPaths(): print "%s/%s" % (path, QtGui.QIcon.themeName()) print QIcon.hasThemeIcon("document-open") #TODO parse command line for open files frame = MSMLMainFrame() from path import path f = path( "/home/weigl/workspace/msml/examples/BunnyExample/bunny.msml.xml") frame.open_file(f) frame.show() # frame.save_file_as() # from .helper.scene_text import scene_to_text # print scene_to_text(frame.msml_model) sys.exit(app.exec_())
def run(self): #TODO parse command line for addition arguments msmlgui.shared.msml_app = MsmlApp(add_search_path=["/home/weigl/workspace/msml/share/"]) app = QtGui.QApplication(sys.argv) app.setAttribute(Qt.AA_DontShowIconsInMenus, False) QIcon.setThemeName("tango") for path in QtGui.QIcon.themeSearchPaths(): print "%s/%s" % (path, QtGui.QIcon.themeName()) print QIcon.hasThemeIcon("document-open") #TODO parse command line for open files frame = MSMLMainFrame() from path import path f = path("/home/weigl/workspace/msml/examples/BunnyExample/bunny.msml.xml") frame.open_file(f) frame.show() # frame.save_file_as() # from .helper.scene_text import scene_to_text # print scene_to_text(frame.msml_model) sys.exit(app.exec_())
def initialize(): """Initialize support for the icons. Called on app startup.""" QDir.setSearchPaths("icons", __path__) # use our icon theme (that builds on Tango) if there are no system icons if (not QIcon.themeName() or QIcon.themeName() == "hicolor" or not QSettings().value("system_icons", True, bool)): QIcon.setThemeSearchPaths(QIcon.themeSearchPaths() + __path__) QIcon.setThemeName("TangoExt")
def __init__(self): QDialog.__init__(self) QIcon.setThemeName("Adwaita") self.setWindowIcon(QIcon.fromTheme("document-print")) self.setupUi(self) self.resize(640, 480) self.setWindowTitle("QuikPrint " + __version__) self.settings = QSettings(self) # Create and setup widgets self.widthSpin.setHidden(True) self.heightSpin.setHidden(True) rangeValidator = QRegExpValidator(self.pagerangeEdit) rangeValidator.setRegExp( QRegExp('([0-9,-])*')) # TODO : check validity of whole string self.pagerangeEdit.setValidator(rangeValidator) # Set values printers = self.getPrinters() if printers == []: QMessageBox.critical(self, 'Error !', 'No Printers added', 'Close') return QDialog.accept(self) self.printersCombo.addItems(printers) # select default printer options default_printer = get_default_printer() selected_index = 0 for i, printer in enumerate(printers): if printer == default_printer: selected_index = i break self.printersCombo.setCurrentIndex(selected_index) self.selectPrinter(selected_index) # get printer independent options fit_to_page = True if self.settings.value("FitToPage", "false") == 'true' else False self.fitToPageBtn.setChecked(fit_to_page) brightness = int(self.settings.value("Brightness", 100)) gamma = int(self.settings.value("Gamma", 1000)) ppi = int(self.settings.value("PPI", 300)) natural_scaling = int(self.settings.value("NaturalScaling", 100)) scaling = int(self.settings.value("Scaling", 100)) paper_w = int(self.settings.value("PaperW", 100)) paper_h = int(self.settings.value("PaperH", 100)) self.brightnessSpin.setValue(brightness) self.gammaSpin.setValue(gamma) self.ppiSpin.setValue(ppi) self.naturalScalingSpin.setValue(natural_scaling) self.scalingSpin.setValue(scaling) self.widthSpin.setValue(paper_w) self.heightSpin.setValue(paper_h) # Connect Signals self.printersCombo.currentIndexChanged.connect(self.selectPrinter) self.paperSizeCombo.currentIndexChanged.connect(self.onPaperSizeChange) self.pixelDensityBtn.clicked.connect(self.onDensityBtnClick) self.printBtn.clicked.connect(self.accept) self.quitBtn.clicked.connect(self.reject) self.cancelJobsBtn.clicked.connect(self.cancelPrintJobs)
def __init__(self): QMainWindow.__init__(self) self.setWindowIcon(QIcon(":/scanner.png")) QIcon.setThemeName("Adwaita") self.setupUi(self) close_icon = QApplication.style().standardIcon(QStyle.SP_DialogCloseButton) self.closeBtn.setIcon(close_icon) # connect signals self.comboDevice.currentIndexChanged.connect(self.onDeviceChange) self.comboColor.currentIndexChanged.connect(self.onColorModeChange) self.scanBtn.clicked.connect(self.startScanning) self.closeBtn.clicked.connect(self.close) self.process = QProcess(self) QTimer.singleShot(100, self.updateDeviceList)
def accept(self): Mikibook.settings.setValue('recentNotesNumber', self.recentNotesCount.value()) Mikibook.settings.setValue('editorFont', self.editorFont.font.family()) Mikibook.settings.setValue('editorFontSize', self.editorFont.font.pointSize()) if self.headerScalesFont.isChecked(): Mikibook.settings.setValue('headerScaleFont', True) else: Mikibook.settings.setValue('headerScaleFont', False) Mikibook.settings.setValue('tabWidth', self.tabWidth.value()) Mikibook.settings.setValue('iconTheme', self.iconTheme.text()) if self.tabToSpaces.isChecked(): Mikibook.settings.setValue('tabInsertsSpaces', True) else: Mikibook.settings.setValue('tabInsertsSpaces', False) Mikibook.setHighlighterColors(self.hltCfg.configToList()) QIcon.setThemeName(self.iconTheme.text()) #then make mikidown use these settings NOW self.parent().loadHighlighter() QDialog.accept(self)
def __init__(self, *args, **kwargs): try: appdir = kwargs.pop('appdir') except KeyError: pass CadAppQt.__init__(self) # set application directory appdata.set('APPDIR', appdir) # Search for icons in './icons/kubos'. if appdata.get('APPDIR') is not None: ip = _QIcon.themeSearchPaths() + [ _path.join(appdata.get('APPDIR'), 'icons') ] _QIcon.setThemeSearchPaths(ip) _QIcon.setThemeName('kubos') if appdata.get('mode'): if _QIcon.hasThemeIcon('kubos-' + appdata.get('mode')): appdata.set('icon', _QIcon.fromTheme('kubos-' + appdata.get('mode'))) else: appdata.set('icon', _QIcon.fromTheme('kubos')) else: appdata.set('icon', _QIcon.fromTheme('kubos')) appdata.set('AUTHORS', 'Marko Knöbl') appdata.set('VERSION', '0.2b2') self.doc = doc_ctrl # 'win' cannot be imported before creating a QApplication from gui import win self.win = win self.update_title() self.viewer = win.viewer_3d self._menu_bar = self.win.menuBar() self._menus = {} self._actiongroups = {} self._toolbars = {}
def initialize(): """Initialize support for the icons. Called on app startup.""" # find the icons in this directory, after that also search in the included # icon theme folders (this fallback is used if the "Use system icons" # setting is enabled, but the system does not provide a certain icon. d = __path__[0] path = [] path.extend(__path__) for p in (os.path.join(d, 'TangoExt', 'scalable'), os.path.join(d, 'TangoExt'), os.path.join(d, 'Tango', 'scalable'), os.path.join(d, 'Tango')): if os.path.isdir(p): path.append(p) QDir.setSearchPaths("icons", path) # use our icon theme (that builds on Tango) if there are no system icons if (not QIcon.themeName() or QIcon.themeName() == "hicolor" or not QSettings().value("system_icons", True, bool)): QIcon.setThemeSearchPaths(QIcon.themeSearchPaths() + __path__) QIcon.setThemeName("TangoExt")
def initialize(): """Initialize support for the icons. Called on app startup.""" # find the icons in this directory, after that also search in the included # icon theme folders (this fallback is used if the "Use system icons" # setting is enabled, but the system does not provide a certain icon. d = __path__[0] path = [] path.extend(__path__) for p in (os.path.join(d, 'TangoExt', 'scalable'), os.path.join(d, 'TangoExt'), os.path.join(d, 'Tango', 'scalable'), os.path.join(d, 'Tango')): if os.path.isdir(p): path.append(p) QDir.setSearchPaths("icons", path) # use our icon theme (that builds on Tango) if there are no system icons if (not QIcon.themeName() or QIcon.themeName() == "hicolor" or not QSettings().value("system_icons", True, bool)): QIcon.setThemeSearchPaths(QIcon.themeSearchPaths() + __path__) QIcon.setThemeName("TangoExt")
def accept(self): Mikibook.settings.setValue('recentNotesNumber', self.recentNotesCount.value()) Mikibook.settings.setValue('editorFont', self.editorFont.font.family()) Mikibook.settings.setValue('editorFontSize', self.editorFont.font.pointSize()) if self.headerScalesFont.isChecked(): Mikibook.settings.setValue('headerScaleFont', True) else: Mikibook.settings.setValue('headerScaleFont', False) Mikibook.settings.setValue('tabWidth', self.tabWidth.value()) Mikibook.settings.setValue('iconTheme', self.iconTheme.text()) if self.tabToSpaces.isChecked(): Mikibook.settings.setValue('tabInsertsSpaces', True) else: Mikibook.settings.setValue('tabInsertsSpaces', False) Mikibook.setHighlighterColors(self.hltCfg.configToList()) QIcon.setThemeName(self.iconTheme.text()) #then make mikidown use these settings NOW self.parent().loadHighlighter() QDialog.accept(self)
def __init__(self): QMainWindow.__init__(self) QIcon.setThemeName('Adwaita') self.setupUi(self) self.settings = QtCore.QSettings(1, 0, "daaq-mail","daaq", self) self.emails = [unicode(x) for x in self.settings.value('Emails', []).toStringList()] self.types = [unicode(x) for x in self.settings.value('Types', []).toStringList()] self.initUi() self.resize(1024, 714) self.show() # create imap client self.thread = QtCore.QThread(self) self.imapClient = GmailImap() self.thread.finished.connect(self.imapClient.deleteLater) self.imapClient.moveToThread(self.thread) self.imapClient.loggedIn.connect( self.onLogin) self.imapClient.mailboxListLoaded.connect( self.setMailboxes) self.imapClient.mailboxSelected.connect( self.onMailboxSelect) self.imapClient.uidsListed.connect( self.removeDeleted) self.imapClient.insertMailRequested.connect(self.insertNewMail) self.imapClient.bodystructureLoaded.connect(self.setAttachments) self.imapClient.mailTextLoaded.connect( self.setMailText) self.loginRequested.connect( self.imapClient.login) self.selectMailboxRequested.connect( self.imapClient.selectMailbox) self.uidListRequested.connect( self.imapClient.listUids) self.newMailsRequested.connect( self.imapClient.getNewMails) self.bodystructureRequested.connect( self.imapClient.loadBodystructure) self.mailTextRequested.connect( self.imapClient.loadMailText) self.saveAttachmentRequested.connect( self.imapClient.saveAttachment) self.deleteRequested.connect( self.imapClient.deleteMails) self.thread.start() # init variables self.email_id = '' self.passwd = '' self.mailbox = '' self.total_mails = 0 QtCore.QTimer.singleShot(30, self.setupClient)
def __init__(self): super().__init__() self.setWindowTitle('Yabai') QIcon.setThemeName('oxygenNOT') # TEST if not QIcon.hasThemeIcon('document-open'): QIcon.setThemeSearchPaths(['gui/icons']) QIcon.setThemeName('oxygen_parts') # TODO: This way of checking for the theme's existence is ugly # as f**k, so you'd better think of a better way to do it. self.createActions() self.createMenus() self.createToolBars() self.createStatusBar() for action in Config.checkedActions: if action in View.fitModes: fitMode = action break else: fitMode = 'view_fitBest' self.view = View('core/black.ori', fitMode) self.setCentralWidget(self.view) # Add all the action to the view, so that they can be # triggered even when there are no menus/toolbars # visible as it is in fullscreen mode: for action in self.actions.values(): if not isinstance(action, QActionGroup): self.view.addAction(action) self.show()
def build_ui(self, options, configuration): """ This is all the twisted logic of setting up the UI, which is re-run whenever the browser is "reset" by the user. """ debug("build_ui") inactivity_timeout = options.timeout or int(configuration.get("timeout", 0)) timeout_mode = configuration.get('timeout_mode', 'reset') self.refresh_timer = int(configuration.get("refresh_timer", 0)) self.icon_theme = options.icon_theme or configuration.get("icon_theme", None) self.zoomfactor = options.zoomfactor or float(configuration.get("zoom_factor") or 1.0) self.allow_popups = options.allow_popups or configuration.get("allow_popups", False) self.ssl_mode = (configuration.get("ssl_mode") in ['strict', 'ignore'] and configuration.get("ssl_mode")) or 'strict' self.is_fullscreen = options.is_fullscreen or configuration.get("fullscreen", False) self.show_navigation = not options.no_navigation and configuration.get('navigation', True) self.navigation_layout = configuration.get( "navigation_layout", ['back', 'forward', 'refresh', 'stop', 'zoom_in', 'zoom_out', 'separator', 'bookmarks', 'separator', 'spacer', 'quit']) self.content_handlers = self.configuration.get("content_handlers", {}) self.allow_external_content = options.allow_external_content or self.configuration.get("allow_external_content", False) self.allow_plugins = options.allow_plugins or self.configuration.get("allow_plugins", False) self.privacy_mode = self.configuration.get("privacy_mode", True) self.quit_button_mode = self.configuration.get("quit_button_mode", 'reset') self.quit_button_text = self.configuration.get("quit_button_text", "I'm &Finished") self.quit_button_tooltip = (self.quit_button_mode == 'close' and "Click here to quit the browser.") or \ """Click here when you are done.\nIt will clear your browsing history and return you to the start page.""" self.window_size = options.window_size or self.configuration.get("window_size", None) self.allow_printing = self.configuration.get("allow_printing", False) qb_mode_callbacks = {'close': self.close, 'reset': self.reset_browser} to_mode_callbacks = {'close': self.close, 'reset': self.reset_browser, 'screensaver': self.screensaver} #If the whitelist is activated, add the bookmarks and start_url if self.whitelist: # we can just specify whitelist = True, #which should whitelist just the start_url and bookmark urls. if type(self.whitelist) is not list: self.whitelist = [] self.whitelist.append(str(QUrl(self.start_url).host())) bookmarks = self.configuration.get("bookmarks") if bookmarks: self.whitelist += [str(QUrl(b.get("url")).host()) for k,b in bookmarks.items()] self.whitelist = list(set(self.whitelist)) #uniquify self.whitelist = [item.replace(".", "\.") for item in self.whitelist] #escape dots debug("Generated whitelist: " + str(self.whitelist)) ###Start GUI configuration### self.browser_window = WcgWebView( allow_popups=self.allow_popups, default_user=self.default_user, default_password=self.default_password, zoomfactor=self.zoomfactor, content_handlers=self.content_handlers, allow_external_content=self.allow_external_content, html404=self.html404, html_network_down=self.html_network_down, start_url=self.start_url, ssl_mode=self.ssl_mode, allow_plugins = self.allow_plugins, whitelist = self.whitelist, allow_printing = self.allow_printing, proxy_server = self.proxy_server, privacy_mode = self.privacy_mode ) self.browser_window.setObjectName("web_content") if self.icon_theme is not None and QT_VERSION_STR > '4.6': QIcon.setThemeName(self.icon_theme) self.setCentralWidget(self.browser_window) debug(options) debug("loading %s" % self.start_url) self.browser_window.setUrl(QUrl(self.start_url)) if self.is_fullscreen is True: self.showFullScreen() elif self.window_size and self.window_size.lower() == 'max': self.showMaximized() elif self.window_size: size = re.match(r"(\d+)x(\d+)", self.window_size) if size: width, height = size.groups() self.setFixedSize(int(width), int(height)) else: debug("Ignoring invalid window size \"%s\"" % self.window_size) #Set up the top navigation bar if it's configured to exist if self.show_navigation is True: self.navigation_bar = QToolBar("Navigation") self.navigation_bar.setObjectName("navigation") self.addToolBar(Qt.TopToolBarArea, self.navigation_bar) self.navigation_bar.setMovable(False) self.navigation_bar.setFloatable(False) #Standard navigation tools self.nav_items = {} self.nav_items["back"] = self.browser_window.pageAction(QWebPage.Back) self.nav_items["forward"] = self.browser_window.pageAction(QWebPage.Forward) self.nav_items["refresh"] = self.browser_window.pageAction(QWebPage.Reload) self.nav_items["stop"] = self.browser_window.pageAction(QWebPage.Stop) #The "I'm finished" button. self.nav_items["quit"] = self.createAction( self.quit_button_text, qb_mode_callbacks.get(self.quit_button_mode, self.reset_browser), QKeySequence("Alt+F"), None, self.quit_button_tooltip) #Zoom buttons self.nav_items["zoom_in"] = self.createAction( "Zoom In", self.zoom_in, QKeySequence("Alt++"), "zoom-in", "Increase the size of the text and images on the page") self.nav_items["zoom_out"] = self.createAction( "Zoom Out", self.zoom_out, QKeySequence("Alt+-"), "zoom-out", "Decrease the size of text and images on the page") if self.allow_printing: self.nav_items["print"] = self.createAction("Print", self.browser_window.print_webpage, QKeySequence("Ctrl+p"), "document-print", "Print this page") #Add all the actions to the navigation bar. for item in self.navigation_layout: if item == "separator": self.navigation_bar.addSeparator() elif item == "spacer": #an expanding spacer. spacer = QWidget() spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) self.navigation_bar.addWidget(spacer) elif item == "bookmarks": #Insert bookmarks buttons here. self.bookmark_buttons = [] if configuration.get("bookmarks"): for bookmark in configuration.get("bookmarks").items(): debug("Bookmark:\n" + bookmark.__str__()) #bookmark name will use the "name" attribute, if present #or else just the key: bookmark_name = bookmark[1].get("name") or bookmark[0] #Create a button for the bookmark as a QAction, #which we'll add to the toolbar button = self.createAction( bookmark_name, lambda url=bookmark[1].get("url"): self.browser_window.load(QUrl(url)), QKeySequence.mnemonic(bookmark_name), None, bookmark[1].get("description") ) self.navigation_bar.addAction(button) self.navigation_bar.widgetForAction(button).setObjectName("navigation_button") else: action = self.nav_items.get(item, None) if action: self.navigation_bar.addAction(action) self.navigation_bar.widgetForAction(action).setObjectName("navigation_button") #This removes the ability to toggle off the navigation bar: self.nav_toggle = self.navigation_bar.toggleViewAction() self.nav_toggle.setVisible(False) #End "if show_navigation is True" block # set hidden quit action # For reasons I haven't adequately ascertained, #this shortcut fails now and then claiming "Ambiguous shortcut overload". # No idea why, as it isn't consistent. self.really_quit = self.createAction("", self.close, QKeySequence("Ctrl+Alt+Q"), None, "") self.addAction(self.really_quit) #Call a reset function after timeout if inactivity_timeout != 0: self.event_filter = InactivityFilter(inactivity_timeout) QCoreApplication.instance().installEventFilter(self.event_filter) self.browser_window.page().installEventFilter(self.event_filter) self.connect(self.event_filter, SIGNAL("timeout()"), to_mode_callbacks.get(timeout_mode, self.reset_browser)) else: self.event_filter = None if self.refresh_timer != 0: # Create a QTimer self.timer = QTimer() # Connect it to self.refresh_browser self.timer.timeout.connect(self.refresh_browser) # Call refresh_browser() every self.refresh_timer seconds self.timer.start(self.refresh_timer*1000)
def create_actions(self): """Define the actions.""" self.about_action = QAction("&About", self) self.about_action.setStatusTip("About dame") self.about_action.setMenuRole(QAction.AboutRole) self.about_action.triggered.connect(self.show_about) self.open_action = QAction("&Open", self) self.open_action.setStatusTip("Open a SIR file") self.open_action.setShortcut(QtGui.QKeySequence.Open) self.open_action.triggered.connect(self.open_file) self.close_action = QAction("&Close", self) self.close_action.setStatusTip("Close current SIR file") self.close_action.setShortcut(QtGui.QKeySequence.Close) self.close_action.triggered.connect(self.close_file) self.exit_action = QAction("E&xit", self) self.exit_action.setMenuRole(QAction.QuitRole) self.exit_action.setStatusTip("Exit dame") self.exit_action.setShortcut(QtGui.QKeySequence("Ctrl+Q")) self.exit_action.triggered.connect(self.close) self.prop_action = QAction("SIR header", self) self.prop_action.setStatusTip("Display SIR header information") self.prop_action.triggered.connect(self.print_header) self.range_action = QAction("Image range", self) self.range_action.setStatusTip("Set image display range") self.range_action.triggered.connect(self.show_range) self.zoomer_action = QAction("Enable zoomer window", self) self.zoomer_action.setStatusTip(("Show zoomer window for " "magnified viewing")) self.zoomer_action.setCheckable(True) self.zoomer_action.triggered.connect(self.update_zoomer_opts) self.zoom_factor_label_action = QAction("Zoom factor", self) self.zoom_factor_label_action.setEnabled(False) self.zoom_factor_1_action = QAction("2x zoom", self) self.zoom_factor_2_action = QAction("4x zoom", self) self.zoom_factor_3_action = QAction("8x zoom", self) self.zoom_factor_4_action = QAction("16x zoom", self) self.zoom_factor_1_action.setStatusTip("Magnify zoom region by 2x") self.zoom_factor_2_action.setStatusTip("Magnify zoom region by 4x") self.zoom_factor_3_action.setStatusTip("Magnify zoom region by 8x") self.zoom_factor_4_action.setStatusTip("Magnify zoom region by 16x") self.zoom_factor_1_action.setCheckable(True) self.zoom_factor_2_action.setCheckable(True) self.zoom_factor_3_action.setCheckable(True) self.zoom_factor_4_action.setCheckable(True) self.zoom_size_label_action = QAction("Zoom region size", self) self.zoom_size_label_action.setEnabled(False) self.zoom_size_1_action = QAction("9x9 window", self) self.zoom_size_2_action = QAction("17x17 window", self) self.zoom_size_3_action = QAction("29x29 window", self) self.zoom_size_4_action = QAction("45x45 window", self) self.zoom_size_5_action = QAction("65x65 window", self) self.zoom_size_1_action.setStatusTip("Set zoom region to 9x9 pixels") self.zoom_size_2_action.setStatusTip("Set zoom region to 17x17 pixels") self.zoom_size_3_action.setStatusTip("Set zoom region to 29x29 pixels") self.zoom_size_4_action.setStatusTip("Set zoom region to 45x45 pixels") self.zoom_size_5_action.setStatusTip("Set zoom region to 65x65 pixels") self.zoom_size_1_action.setCheckable(True) self.zoom_size_2_action.setCheckable(True) self.zoom_size_3_action.setCheckable(True) self.zoom_size_4_action.setCheckable(True) self.zoom_size_5_action.setCheckable(True) # Group zoomer actions and connect slots self.zoom_factor_group = QtGui.QActionGroup(self) self.zoom_factor_group.addAction(self.zoom_factor_1_action) self.zoom_factor_group.addAction(self.zoom_factor_2_action) self.zoom_factor_group.addAction(self.zoom_factor_3_action) self.zoom_factor_group.addAction(self.zoom_factor_4_action) self.zoom_factor_group.triggered.connect(self.update_zoomer_opts) self.zoom_size_group = QtGui.QActionGroup(self) self.zoom_size_group.addAction(self.zoom_size_1_action) self.zoom_size_group.addAction(self.zoom_size_2_action) self.zoom_size_group.addAction(self.zoom_size_3_action) self.zoom_size_group.addAction(self.zoom_size_4_action) self.zoom_size_group.addAction(self.zoom_size_5_action) self.zoom_size_group.triggered.connect(self.update_zoomer_opts) # # Mode actions # self.mode_group = QtGui.QActionGroup(self) # self.mode_single_action = QAction("Single image", self.mode_group) # self.mode_dual_action = QAction("Two images", self.mode_group) # self.mode_single_action.setCheckable(True) # self.mode_dual_action.setCheckable(True) # self.mode_single_action.setStatusTip("Display a single image") # self.mode_dual_action.setStatusTip("Display two images for comparison") # self.mode_single_action.setChecked(True) # #self.mode_group.triggered.connect(self.mainview.toggleComparison) # Moved later # http://stackoverflow.com/questions/11643221/are-there-default-icons-in-pyqt-pyside # TODO: Add icons in a better way. See how Picard does it. QIcon.setThemeName("gnome") # TODO: temporary self.open_action.setIcon(QIcon.fromTheme("document-open")) self.close_action.setIcon(QIcon.fromTheme("window-close")) self.exit_action.setIcon(QIcon.fromTheme("application-exit")) self.about_action.setIcon(QIcon.fromTheme("help-about"))
def setupActions(self): # Global Actions actTabIndex = self.act(self.tr('Switch to Index Tab'), lambda: self.raiseDock(self.dockIndex), self.tr('Ctrl+Shift+I')) actTabSearch = self.act(self.tr('Switch to Search Tab'), lambda: self.raiseDock(self.dockSearch), self.tr('Ctrl+Shift+F')) self.addAction(actTabIndex) self.addAction(actTabSearch) ################ Menu Actions ################ # actions in menuFile actionNewPage = self.act(self.tr('&New Page...'), self.notesTree.newPage, QKeySequence.New) self.actions.update(newPage=actionNewPage) actionNewSubpage = self.act(self.tr('New Sub&page...'), self.notesTree.newSubpage, self.tr('Ctrl+Shift+N')) self.actions.update(newSubpage=actionNewSubpage) actionImportPage = self.act(self.tr('&Import Page...'), self.importPage) self.actions.update(importPage=actionImportPage) actionNBSettings = self.act(self.tr('Notebook Set&tings...'), self.notebookSettings) self.actions.update(NBSettings=actionNBSettings) actionMDSettings = self.act(self.tr('&Mikidown Settings...'), self.mikidownSettings) self.actions.update(MDSettings=actionMDSettings) actionOpenNotebook = self.act(self.tr('&Open Notebook...'), self.openNotebook, QKeySequence.Open) self.actions.update(openNotebook=actionOpenNotebook) actionReIndex = self.act(self.tr('Re-index'), self.reIndex) self.actions.update(reIndex=actionReIndex) actionSave = self.act(self.tr('&Save'), self.saveCurrentNote, QKeySequence.Save) actionSave.setEnabled(False) self.actions.update(save=actionSave) actionSaveAs = self.act(self.tr('Save &As...'), self.saveNoteAs, QKeySequence.SaveAs) self.actions.update(saveAs=actionSaveAs) actionHtml = self.act(self.tr('to &HTML'), self.notesEdit.saveAsHtml) self.actions.update(html=actionHtml) actionPrint = self.act(self.tr('&Print'), self.printNote, QKeySequence.Print) self.actions.update(print_=actionPrint) actionRenamePage = self.act(self.tr('&Rename Page...'), self.notesTree.renamePage, 'F2') self.actions.update(renamePage=actionRenamePage) actionDelPage = self.act(self.tr('&Delete Page'), self.notesTree.delPageWrapper, QKeySequence.Delete) self.actions.update(delPage=actionDelPage) actionQuit = self.act(self.tr('&Quit'), self.close, QKeySequence.Quit) actionQuit.setMenuRole(QAction.QuitRole) self.actions.update(quit=actionQuit) # actions in menuEdit actionUndo = self.act(self.tr('&Undo'), lambda: self.notesEdit.undo(), QKeySequence.Undo) actionUndo.setEnabled(False) self.notesEdit.undoAvailable.connect(actionUndo.setEnabled) self.actions.update(undo=actionUndo) actionRedo = self.act(self.tr('&Redo'), lambda: self.notesEdit.redo(), QKeySequence.Redo) actionRedo.setEnabled(False) self.notesEdit.redoAvailable.connect(actionRedo.setEnabled) self.actions.update(redo=actionRedo) actionFindText = self.act(self.tr('&Find Text'), self.findBar.setVisible, QKeySequence.Find, True) self.actions.update(findText=actionFindText) actionFindRepl = self.act(self.tr('Find and Replace'), FindReplaceDialog(self.notesEdit).open, QKeySequence.Replace) self.actions.update(findRepl=actionFindRepl) actionFind = self.act(self.tr('Next'), self.findText, QKeySequence.FindNext) self.actions.update(find=actionFind) actionFindPrev = self.act(self.tr('Previous'), lambda: self.findText(back=True), QKeySequence.FindPrevious) self.actions.update(findPrev=actionFindPrev) actionSortLines = self.act(self.tr('&Sort Lines'), self.sortLines) self.actions.update(sortLines=actionSortLines) actionQuickNav = self.act(self.tr("&Quick Open Note"), self.quickNoteNav.setFocus, self.tr('Ctrl+G')) self.addAction(actionQuickNav) actionInsertImage = self.act(self.tr('&Insert Attachment'), self.notesEdit.insertAttachmentWrapper, self.tr('Ctrl+I')) actionInsertImage.setEnabled(False) self.actions.update(insertImage=actionInsertImage) # actions in menuView QIcon.setThemeName( Mikibook.settings.value('iconTheme', QIcon.themeName())) #print(QIcon.themeName()) actionEdit = self.act(self.tr('Edit'), self.edit, self.tr('Ctrl+E'), True, QIcon.fromTheme('document-edit'), self.tr('Edit mode (Ctrl+E)')) self.actions.update(edit=actionEdit) actionSplit = self.act(self.tr('Split'), self.liveView, self.tr('Ctrl+R'), True, QIcon.fromTheme('view-split-left-right'), self.tr('Split mode (Ctrl+R)')) self.actions.update(split=actionSplit) actionFlipEditAndView = self.act(self.tr('Flip Edit and View'), self.flipEditAndView) actionFlipEditAndView.setEnabled(False) self.actions.update(flipEditAndView=actionFlipEditAndView) #actionLeftAndRight = self.act( # self.tr('Split into Left and Right'), trig=self.leftAndRight) #actionUpAndDown = self.act( # self.tr('Split into Up and Down'), trig=self.upAndDown) # self.actionLeftAndRight.setEnabled(False) # self.actionUpAndDown.setEnabled(False) # actions in menuHelp actionReadme = self.act(self.tr('README'), self.readmeHelp) self.actions.update(readme=actionReadme) actionChangelog = self.act(self.tr('Changelog'), self.changelogHelp) self.actions.update(changelog=actionChangelog) actionAboutQt = self.act(self.tr('About Qt'), qApp.aboutQt) self.actions.update(aboutQt=actionAboutQt)
def main(icon_spec): app = QApplication(sys.argv) main_window = QMainWindow() def sigint_handler(*args): main_window.close() signal.signal(signal.SIGINT, sigint_handler) # the timer enables triggering the sigint_handler signal_timer = QTimer() signal_timer.start(100) signal_timer.timeout.connect(lambda: None) tool_bar = QToolBar() main_window.addToolBar(Qt.TopToolBarArea, tool_bar) table_view = QTableView() table_view.setSelectionBehavior(QAbstractItemView.SelectRows) table_view.setSelectionMode(QAbstractItemView.SingleSelection) table_view.setSortingEnabled(True) main_window.setCentralWidget(table_view) proxy_model = QSortFilterProxyModel() proxy_model.setFilterCaseSensitivity(Qt.CaseInsensitive) proxy_model.setFilterKeyColumn(1) table_view.setModel(proxy_model) proxy_model.layoutChanged.connect(table_view.resizeRowsToContents) item_model = QStandardItemModel() proxy_model.setSourceModel(item_model) # get all icons and their available sizes QIcon.setThemeName("gnome") icons = [] all_sizes = set([]) for context, icon_names in icon_spec: for icon_name in icon_names: icon = QIcon.fromTheme(icon_name) sizes = [] for size in icon.availableSizes(): size = (size.width(), size.height()) sizes.append(size) all_sizes.add(size) sizes.sort() icons.append({ 'context': context, 'icon_name': icon_name, 'icon': icon, 'sizes': sizes, }) all_sizes = list(all_sizes) all_sizes.sort() # input field for filter def filter_changed(value): proxy_model.setFilterRegExp(value) table_view.resizeRowsToContents() filter_line_edit = QLineEdit() filter_line_edit.setMaximumWidth(200) filter_line_edit.setPlaceholderText('Filter name') filter_line_edit.setToolTip('Filter name optionally using regular expressions (' + QKeySequence(QKeySequence.Find).toString() + ')') filter_line_edit.textChanged.connect(filter_changed) tool_bar.addWidget(filter_line_edit) # actions to toggle visibility of available sizes/columns def action_toggled(index): column = 2 + index table_view.setColumnHidden(column, not table_view.isColumnHidden(column)) table_view.resizeColumnsToContents() table_view.resizeRowsToContents() signal_mapper = QSignalMapper() for i, size in enumerate(all_sizes): action = QAction('%dx%d' % size, tool_bar) action.setCheckable(True) action.setChecked(True) tool_bar.addAction(action) action.toggled.connect(signal_mapper.map) signal_mapper.setMapping(action, i) # set tool tip and handle key sequence tool_tip = 'Toggle visibility of column' if i < 10: digit = ('%d' % (i + 1))[-1] tool_tip += ' (%s)' % QKeySequence('Ctrl+%s' % digit).toString() action.setToolTip(tool_tip) signal_mapper.mapped.connect(action_toggled) # label columns header_labels = ['context', 'name'] for width, height in all_sizes: header_labels.append('%dx%d' % (width, height)) item_model.setColumnCount(len(header_labels)) item_model.setHorizontalHeaderLabels(header_labels) # fill rows item_model.setRowCount(len(icons)) for row, icon_data in enumerate(icons): # context item = QStandardItem(icon_data['context']) item.setFlags(item.flags() ^ Qt.ItemIsEditable) item_model.setItem(row, 0, item) # icon name item = QStandardItem(icon_data['icon_name']) item.setFlags(item.flags() ^ Qt.ItemIsEditable) item_model.setItem(row, 1, item) for index_in_all_sizes, size in enumerate(all_sizes): column = 2 + index_in_all_sizes if size in icon_data['sizes']: # icon as pixmap to keep specific size item = QStandardItem('') pixmap = icon_data['icon'].pixmap(size[0], size[1]) item.setData(pixmap, Qt.DecorationRole) item.setFlags(item.flags() ^ Qt.ItemIsEditable) item_model.setItem(row, column, item) else: # single space to be sortable against icons item = QStandardItem(' ') item.setFlags(item.flags() ^ Qt.ItemIsEditable) item_model.setItem(row, column, item) table_view.resizeColumnsToContents() # manually set row heights because resizeRowsToContents is not working properly for row, icon_data in enumerate(icons): if len(icon_data['sizes']) > 0: max_size = icon_data['sizes'][-1] table_view.setRowHeight(row, max_size[1]) # enable focus find (ctrl+f) and toggle columns (ctrl+NUM) def main_window_keyPressEvent(self, event, old_keyPressEvent=QMainWindow.keyPressEvent): if event.matches(QKeySequence.Find): filter_line_edit.setFocus() return if event.modifiers() == Qt.ControlModifier and event.key() >= Qt.Key_0 and event.key() <= Qt.Key_9: index = event.key() - Qt.Key_1 if event.key() == Qt.Key_0: index += 10 action = signal_mapper.mapping(index) if action: action.toggle() return old_keyPressEvent(self, event) main_window.keyPressEvent = new.instancemethod(main_window_keyPressEvent, table_view, None) # enable copy (ctrl+c) name of icon to clipboard def table_view_keyPressEvent(self, event, old_keyPressEvent=QTableView.keyPressEvent): if event.matches(QKeySequence.Copy): selection_model = self.selectionModel() if selection_model.hasSelection(): index = selection_model.selectedRows()[0] source_index = self.model().mapToSource(index) item = self.model().sourceModel().item(source_index.row(), 1) icon_name = item.data(Qt.EditRole) app.clipboard().setText(icon_name.toString()) return old_keyPressEvent(self, event) table_view.keyPressEvent = new.instancemethod(table_view_keyPressEvent, table_view, None) print 'Icon Theme: ', QIcon.themeName() print 'Theme Search Paths:' for item in QIcon.themeSearchPaths(): print item main_window.showMaximized() return app.exec_()
def main(icon_spec): app = QApplication(sys.argv) main_window = QMainWindow() def sigint_handler(*args): main_window.close() signal.signal(signal.SIGINT, sigint_handler) # the timer enables triggering the sigint_handler signal_timer = QTimer() signal_timer.start(100) signal_timer.timeout.connect(lambda: None) tool_bar = QToolBar() main_window.addToolBar(Qt.TopToolBarArea, tool_bar) table_view = QTableView() table_view.setSelectionBehavior(QAbstractItemView.SelectRows) table_view.setSelectionMode(QAbstractItemView.SingleSelection) table_view.setSortingEnabled(True) main_window.setCentralWidget(table_view) proxy_model = QSortFilterProxyModel() proxy_model.setFilterCaseSensitivity(Qt.CaseInsensitive) proxy_model.setFilterKeyColumn(1) table_view.setModel(proxy_model) proxy_model.layoutChanged.connect(table_view.resizeRowsToContents) item_model = QStandardItemModel() proxy_model.setSourceModel(item_model) # get all icons and their available sizes QIcon.setThemeName("gnome") icons = [] all_sizes = set([]) for context, icon_names in icon_spec: for icon_name in icon_names: icon = QIcon.fromTheme(icon_name) sizes = [] for size in icon.availableSizes(): size = (size.width(), size.height()) sizes.append(size) all_sizes.add(size) sizes.sort() icons.append({ 'context': context, 'icon_name': icon_name, 'icon': icon, 'sizes': sizes, }) all_sizes = list(all_sizes) all_sizes.sort() # input field for filter def filter_changed(value): proxy_model.setFilterRegExp(value) table_view.resizeRowsToContents() filter_line_edit = QLineEdit() filter_line_edit.setMaximumWidth(200) filter_line_edit.setPlaceholderText('Filter name') filter_line_edit.setToolTip( 'Filter name optionally using regular expressions (' + QKeySequence(QKeySequence.Find).toString() + ')') filter_line_edit.textChanged.connect(filter_changed) tool_bar.addWidget(filter_line_edit) # actions to toggle visibility of available sizes/columns def action_toggled(index): column = 2 + index table_view.setColumnHidden(column, not table_view.isColumnHidden(column)) table_view.resizeColumnsToContents() table_view.resizeRowsToContents() signal_mapper = QSignalMapper() for i, size in enumerate(all_sizes): action = QAction('%dx%d' % size, tool_bar) action.setCheckable(True) action.setChecked(True) tool_bar.addAction(action) action.toggled.connect(signal_mapper.map) signal_mapper.setMapping(action, i) # set tool tip and handle key sequence tool_tip = 'Toggle visibility of column' if i < 10: digit = ('%d' % (i + 1))[-1] tool_tip += ' (%s)' % QKeySequence('Ctrl+%s' % digit).toString() action.setToolTip(tool_tip) signal_mapper.mapped.connect(action_toggled) # label columns header_labels = ['context', 'name'] for width, height in all_sizes: header_labels.append('%dx%d' % (width, height)) item_model.setColumnCount(len(header_labels)) item_model.setHorizontalHeaderLabels(header_labels) # fill rows item_model.setRowCount(len(icons)) for row, icon_data in enumerate(icons): # context item = QStandardItem(icon_data['context']) item.setFlags(item.flags() ^ Qt.ItemIsEditable) item_model.setItem(row, 0, item) # icon name item = QStandardItem(icon_data['icon_name']) item.setFlags(item.flags() ^ Qt.ItemIsEditable) item_model.setItem(row, 1, item) for index_in_all_sizes, size in enumerate(all_sizes): column = 2 + index_in_all_sizes if size in icon_data['sizes']: # icon as pixmap to keep specific size item = QStandardItem('') pixmap = icon_data['icon'].pixmap(size[0], size[1]) item.setData(pixmap, Qt.DecorationRole) item.setFlags(item.flags() ^ Qt.ItemIsEditable) item_model.setItem(row, column, item) else: # single space to be sortable against icons item = QStandardItem(' ') item.setFlags(item.flags() ^ Qt.ItemIsEditable) item_model.setItem(row, column, item) table_view.resizeColumnsToContents() # manually set row heights because resizeRowsToContents is not working properly for row, icon_data in enumerate(icons): if len(icon_data['sizes']) > 0: max_size = icon_data['sizes'][-1] table_view.setRowHeight(row, max_size[1]) # enable focus find (ctrl+f) and toggle columns (ctrl+NUM) def main_window_keyPressEvent(self, event, old_keyPressEvent=QMainWindow.keyPressEvent): if event.matches(QKeySequence.Find): filter_line_edit.setFocus() return if event.modifiers() == Qt.ControlModifier and event.key( ) >= Qt.Key_0 and event.key() <= Qt.Key_9: index = event.key() - Qt.Key_1 if event.key() == Qt.Key_0: index += 10 action = signal_mapper.mapping(index) if action: action.toggle() return old_keyPressEvent(self, event) main_window.keyPressEvent = new.instancemethod(main_window_keyPressEvent, table_view, None) # enable copy (ctrl+c) name of icon to clipboard def table_view_keyPressEvent(self, event, old_keyPressEvent=QTableView.keyPressEvent): if event.matches(QKeySequence.Copy): selection_model = self.selectionModel() if selection_model.hasSelection(): index = selection_model.selectedRows()[0] source_index = self.model().mapToSource(index) item = self.model().sourceModel().item(source_index.row(), 1) icon_name = item.data(Qt.EditRole) app.clipboard().setText(icon_name.toString()) return old_keyPressEvent(self, event) table_view.keyPressEvent = new.instancemethod(table_view_keyPressEvent, table_view, None) print 'Icon Theme: ', QIcon.themeName() print 'Theme Search Paths:' for item in QIcon.themeSearchPaths(): print item main_window.showMaximized() return app.exec_()
def create_actions(self): """Define the actions.""" self.about_action = QAction("&About", self) self.about_action.setStatusTip("About dame") self.about_action.setMenuRole(QAction.AboutRole) self.about_action.triggered.connect(self.show_about) self.open_action = QAction("&Open", self) self.open_action.setStatusTip("Open a SIR file") self.open_action.setShortcut(QtGui.QKeySequence.Open) self.open_action.triggered.connect(self.open_file) self.close_action = QAction("&Close", self) self.close_action.setStatusTip("Close current SIR file") self.close_action.setShortcut(QtGui.QKeySequence.Close) self.close_action.triggered.connect(self.close_file) self.exit_action = QAction("E&xit", self) self.exit_action.setMenuRole(QAction.QuitRole) self.exit_action.setStatusTip("Exit dame") self.exit_action.setShortcut(QtGui.QKeySequence("Ctrl+Q")) self.exit_action.triggered.connect(self.close) self.prop_action = QAction("SIR header", self) self.prop_action.setStatusTip("Display SIR header information") self.prop_action.triggered.connect(self.print_header) self.range_action = QAction("Image range", self) self.range_action.setStatusTip("Set image display range") self.range_action.triggered.connect(self.show_range) self.zoomer_action = QAction("Enable zoomer window", self) self.zoomer_action.setStatusTip(("Show zoomer window for " "magnified viewing")) self.zoomer_action.setCheckable(True) self.zoomer_action.triggered.connect(self.update_zoomer_opts) self.zoom_factor_label_action = QAction("Zoom factor", self) self.zoom_factor_label_action.setEnabled(False) self.zoom_factor_1_action = QAction("2x zoom", self) self.zoom_factor_2_action = QAction("4x zoom", self) self.zoom_factor_3_action = QAction("8x zoom", self) self.zoom_factor_4_action = QAction("16x zoom", self) self.zoom_factor_1_action.setStatusTip("Magnify zoom region by 2x") self.zoom_factor_2_action.setStatusTip("Magnify zoom region by 4x") self.zoom_factor_3_action.setStatusTip("Magnify zoom region by 8x") self.zoom_factor_4_action.setStatusTip("Magnify zoom region by 16x") self.zoom_factor_1_action.setCheckable(True) self.zoom_factor_2_action.setCheckable(True) self.zoom_factor_3_action.setCheckable(True) self.zoom_factor_4_action.setCheckable(True) self.zoom_size_label_action = QAction("Zoom region size", self) self.zoom_size_label_action.setEnabled(False) self.zoom_size_1_action = QAction("9x9 window", self) self.zoom_size_2_action = QAction("17x17 window", self) self.zoom_size_3_action = QAction("29x29 window", self) self.zoom_size_4_action = QAction("45x45 window", self) self.zoom_size_5_action = QAction("65x65 window", self) self.zoom_size_1_action.setStatusTip("Set zoom region to 9x9 pixels") self.zoom_size_2_action.setStatusTip("Set zoom region to 17x17 pixels") self.zoom_size_3_action.setStatusTip("Set zoom region to 29x29 pixels") self.zoom_size_4_action.setStatusTip("Set zoom region to 45x45 pixels") self.zoom_size_5_action.setStatusTip("Set zoom region to 65x65 pixels") self.zoom_size_1_action.setCheckable(True) self.zoom_size_2_action.setCheckable(True) self.zoom_size_3_action.setCheckable(True) self.zoom_size_4_action.setCheckable(True) self.zoom_size_5_action.setCheckable(True) # Group zoomer actions and connect slots self.zoom_factor_group = QtGui.QActionGroup(self) self.zoom_factor_group.addAction(self.zoom_factor_1_action) self.zoom_factor_group.addAction(self.zoom_factor_2_action) self.zoom_factor_group.addAction(self.zoom_factor_3_action) self.zoom_factor_group.addAction(self.zoom_factor_4_action) self.zoom_factor_group.triggered.connect(self.update_zoomer_opts) self.zoom_size_group = QtGui.QActionGroup(self) self.zoom_size_group.addAction(self.zoom_size_1_action) self.zoom_size_group.addAction(self.zoom_size_2_action) self.zoom_size_group.addAction(self.zoom_size_3_action) self.zoom_size_group.addAction(self.zoom_size_4_action) self.zoom_size_group.addAction(self.zoom_size_5_action) self.zoom_size_group.triggered.connect(self.update_zoomer_opts) # # Mode actions # self.mode_group = QtGui.QActionGroup(self) # self.mode_single_action = QAction("Single image", self.mode_group) # self.mode_dual_action = QAction("Two images", self.mode_group) # self.mode_single_action.setCheckable(True) # self.mode_dual_action.setCheckable(True) # self.mode_single_action.setStatusTip("Display a single image") # self.mode_dual_action.setStatusTip("Display two images for comparison") # self.mode_single_action.setChecked(True) # #self.mode_group.triggered.connect(self.mainview.toggleComparison) # Moved later # http://stackoverflow.com/questions/11643221/are-there-default-icons-in-pyqt-pyside # TODO: Add icons in a better way. See how Picard does it. QIcon.setThemeName("gnome") # TODO: temporary self.open_action.setIcon(QIcon.fromTheme("document-open")) self.close_action.setIcon(QIcon.fromTheme("window-close")) self.exit_action.setIcon(QIcon.fromTheme("application-exit")) self.about_action.setIcon(QIcon.fromTheme("help-about"))
def setupActions(self): # Global Actions actTabIndex = self.act(self.tr('Switch to Index Tab'), lambda: self.raiseDock(self.dockIndex), self.tr('Ctrl+Shift+I')) actTabSearch = self.act(self.tr('Switch to Search Tab'), lambda: self.raiseDock(self.dockSearch), self.tr('Ctrl+Shift+F')) self.addAction(actTabIndex) self.addAction(actTabSearch) ################ Menu Actions ################ # actions in menuFile actionNewPage = self.act(self.tr('&New Page...'), self.notesTree.newPage, QKeySequence.New) self.actions.update(newPage=actionNewPage) actionNewSubpage = self.act(self.tr('New Sub&page...'), self.notesTree.newSubpage, self.tr('Ctrl+Shift+N')) self.actions.update(newSubpage=actionNewSubpage) actionImportPage = self.act(self.tr('&Import Page...'), self.importPage) self.actions.update(importPage=actionImportPage) actionNBSettings = self.act(self.tr('Notebook Set&tings...'), self.notebookSettings) self.actions.update(NBSettings=actionNBSettings) actionMDSettings = self.act(self.tr('&Mikidown Settings...'), self.mikidownSettings) self.actions.update(MDSettings=actionMDSettings) actionOpenNotebook = self.act(self.tr('&Open Notebook...'), self.openNotebook, QKeySequence.Open) self.actions.update(openNotebook=actionOpenNotebook) actionReIndex = self.act(self.tr('Re-index'), self.reIndex) self.actions.update(reIndex=actionReIndex) actionSave = self.act(self.tr('&Save'), self.saveCurrentNote, QKeySequence.Save) actionSave.setEnabled(False) self.actions.update(save=actionSave) actionSaveAs = self.act(self.tr('Save &As...'), self.saveNoteAs, QKeySequence.SaveAs) self.actions.update(saveAs=actionSaveAs) actionHtml = self.act(self.tr('to &HTML'), self.notesEdit.saveAsHtml) self.actions.update(html=actionHtml) actionPrint = self.act(self.tr('&Print'), self.printNote, QKeySequence.Print) self.actions.update(print_=actionPrint) actionRenamePage = self.act(self.tr('&Rename Page...'), self.notesTree.renamePage, 'F2') self.actions.update(renamePage=actionRenamePage) actionDelPage = self.act(self.tr('&Delete Page'), self.notesTree.delPageWrapper, QKeySequence.Delete) self.actions.update(delPage=actionDelPage) actionQuit = self.act(self.tr('&Quit'), self.close, QKeySequence.Quit) actionQuit.setMenuRole(QAction.QuitRole) self.actions.update(quit=actionQuit) # actions in menuEdit actionUndo = self.act(self.tr('&Undo'), lambda: self.notesEdit.undo(), QKeySequence.Undo) actionUndo.setEnabled(False) self.notesEdit.undoAvailable.connect(actionUndo.setEnabled) self.actions.update(undo=actionUndo) actionRedo = self.act(self.tr('&Redo'), lambda: self.notesEdit.redo(), QKeySequence.Redo) actionRedo.setEnabled(False) self.notesEdit.redoAvailable.connect(actionRedo.setEnabled) self.actions.update(redo=actionRedo) actionFindText = self.act(self.tr('&Find Text'), self.findBar.setVisible, QKeySequence.Find, True) self.actions.update(findText=actionFindText) actionFindRepl = self.act(self.tr('Find and Replace'), FindReplaceDialog(self.notesEdit).open, QKeySequence.Replace) self.actions.update(findRepl=actionFindRepl) actionFind = self.act(self.tr('Next'), self.findText, QKeySequence.FindNext) self.actions.update(find=actionFind) actionFindPrev = self.act(self.tr('Previous'), lambda: self.findText(back=True), QKeySequence.FindPrevious) self.actions.update(findPrev=actionFindPrev) actionSortLines = self.act(self.tr('&Sort Lines'), self.sortLines) self.actions.update(sortLines=actionSortLines) actionQuickNav = self.act(self.tr("&Quick Open Note"), self.quickNoteNav.setFocus, self.tr('Ctrl+G')) self.addAction(actionQuickNav) actionInsertImage = self.act(self.tr('&Insert Attachment'), self.notesEdit.insertAttachmentWrapper, self.tr('Ctrl+I')) actionInsertImage.setEnabled(False) self.actions.update(insertImage=actionInsertImage) # actions in menuView QIcon.setThemeName(Mikibook.settings.value('iconTheme', QIcon.themeName())) #print(QIcon.themeName()) actionEdit = self.act(self.tr('Edit'), self.edit, self.tr('Ctrl+E'), True, QIcon.fromTheme('document-edit'), self.tr('Edit mode (Ctrl+E)')) self.actions.update(edit=actionEdit) actionSplit = self.act(self.tr('Split'), self.liveView, self.tr('Ctrl+R'), True, QIcon.fromTheme('view-split-left-right'), self.tr('Split mode (Ctrl+R)')) self.actions.update(split=actionSplit) actionFlipEditAndView = self.act(self.tr('Flip Edit and View'), self.flipEditAndView) actionFlipEditAndView.setEnabled(False) self.actions.update(flipEditAndView=actionFlipEditAndView) #actionLeftAndRight = self.act( # self.tr('Split into Left and Right'), trig=self.leftAndRight) #actionUpAndDown = self.act( # self.tr('Split into Up and Down'), trig=self.upAndDown) # self.actionLeftAndRight.setEnabled(False) # self.actionUpAndDown.setEnabled(False) # actions in menuHelp actionReadme = self.act(self.tr('README'), self.readmeHelp) self.actions.update(readme=actionReadme) actionChangelog = self.act(self.tr('Changelog'), self.changelogHelp) self.actions.update(changelog=actionChangelog) actionAboutQt = self.act(self.tr('About Qt'), qApp.aboutQt) self.actions.update(aboutQt=actionAboutQt)
from __future__ import unicode_literals import os from PyQt4.QtCore import QDir, QFile, QFileInfo, QSettings, QSize from PyQt4.QtGui import QFileIconProvider, QIcon _cache = {} QDir.setSearchPaths("icons", __path__) # use our icon theme (that builds on Tango) if there are no system icons if (not QIcon.themeName() or QIcon.themeName() == "hicolor" or not QSettings().value("system_icons", True, bool)): QIcon.setThemeSearchPaths(QIcon.themeSearchPaths() + __path__) QIcon.setThemeName("TangoExt") def get(name): """Returns an icon with the specified name.""" if QIcon.hasThemeIcon(name): return QIcon.fromTheme(name) try: return _cache[name] except KeyError: icon = _cache[name] = QIcon() # first try SVG fname = 'icons:{0}.svg'.format(name) if QFile(fname).exists(): icon.addFile(fname) else:
import os from PyQt4.QtCore import QDir, QFile, QFileInfo, QSettings, QSize from PyQt4.QtGui import QFileIconProvider, QIcon _cache = {} QDir.setSearchPaths("icons", __path__) # use our icon theme (that builds on Tango) if there are no system icons if (not QIcon.themeName() or QIcon.themeName() == "hicolor" or QSettings().value("system_icons", True) in (False, "false")): QIcon.setThemeSearchPaths(QIcon.themeSearchPaths() + __path__) QIcon.setThemeName("TangoExt") def get(name): """Returns an icon with the specified name.""" if QIcon.hasThemeIcon(name): return QIcon.fromTheme(name) try: return _cache[name] except KeyError: icon = _cache[name] = QIcon() # first try SVG fname = 'icons:{0}.svg'.format(name) if QFile(fname).exists(): icon.addFile(fname) else:
def __init__(self): self.data = None box = gui.vBox(self.controlArea, 'Moving Transform') def _disable_fixed_wlen(): fixed_wlen.setDisabled(not self.non_overlapping) self.view.repaint() self.on_changed() gui.checkBox(box, self, 'non_overlapping', label=self._NON_OVERLAPPING_WINDOWS, callback=_disable_fixed_wlen, tooltip='If this is checked, instead of rolling windows ' 'through the series, they are applied side-to-side, ' 'so the resulting output series will be some ' 'length-of-fixed-window-times shorter.') fixed_wlen = gui.spin(box, self, 'fixed_wlen', 2, 1000, label='Fixed window width:', callback=self.on_changed) fixed_wlen.setDisabled(not self.non_overlapping) # TODO: allow the user to choose left-aligned, right-aligned, or center-aligned window class TableView(gui.TableView): def __init__(self, parent): super().__init__( parent, editTriggers=(self.SelectedClicked | self.CurrentChanged | self.DoubleClicked | self.EditKeyPressed), ) self.horizontalHeader().setStretchLastSection(False) agg_functions = ListModel(AGG_FUNCTIONS + [Cumulative_sum, Cumulative_product], parent=self) self.setItemDelegateForColumn(0, self.VariableDelegate(parent)) self.setItemDelegateForColumn(1, self.SpinDelegate(parent)) self.setItemDelegateForColumn( 2, self.ComboDelegate(self, agg_functions)) class _ItemDelegate(QStyledItemDelegate): def updateEditorGeometry(self, widget, option, _index): widget.setGeometry(option.rect) class ComboDelegate(_ItemDelegate): def __init__(self, parent=None, combo_model=None): super().__init__(parent) self._parent = parent if combo_model is not None: self._combo_model = combo_model def createEditor(self, parent, _QStyleOptionViewItem, index): combo = QComboBox(parent) combo.setModel(self._combo_model) return combo def setEditorData(self, combo, index): var = index.model().data(index, Qt.EditRole) combo.setCurrentIndex(self._combo_model.indexOf(var)) def setModelData(self, combo, model, index): var = self._combo_model[combo.currentIndex()] model.setData(index, var, Qt.EditRole) class VariableDelegate(ComboDelegate): @property def _combo_model(self): return self._parent.var_model class SpinDelegate(_ItemDelegate): def paint(self, painter, option, index): # Don't paint window length if non-overlapping windows set if not self.parent().non_overlapping: super().paint(painter, option, index) def createEditor(self, parent, _QStyleOptionViewItem, _index): # Don't edit window length if non-overlapping windows set if self.parent().non_overlapping: return None spin = QSpinBox(parent, minimum=1, maximum=1000) return spin def setEditorData(self, spin, index): spin.setValue(index.model().data(index, Qt.EditRole)) def setModelData(self, spin, model, index): spin.interpretText() model.setData(index, spin.value(), Qt.EditRole) self.var_model = VariableListModel(parent=self) self.table_model = model = PyTableModel(self.transformations, parent=self, editable=True) model.setHorizontalHeaderLabels( ['Series', 'Window width', 'Aggregation function']) model.dataChanged.connect(self.on_changed) self.view = view = TableView(self) view.setModel(model) box.layout().addWidget(view) hbox = gui.hBox(box) from os.path import dirname, join self.add_button = button = gui.button(hbox, self, 'Add &Transform', callback=self.on_add_transform) button.setIcon( QIcon(join(dirname(__file__), 'icons', 'LineChart-plus.png'))) self.del_button = button = gui.button(hbox, self, '&Delete Selected', callback=self.on_del_transform) QIcon.setThemeName('gnome') # Works for me button.setIcon(QIcon.fromTheme('edit-delete')) gui.auto_commit(box, self, 'autocommit', '&Apply')
def __init__(self): self.data = None box = gui.vBox(self.controlArea, 'Moving Transform') def _disable_fixed_wlen(): fixed_wlen.setDisabled(not self.non_overlapping) self.view.repaint() self.on_changed() gui.checkBox(box, self, 'non_overlapping', label=self._NON_OVERLAPPING_WINDOWS, callback=_disable_fixed_wlen, tooltip='If this is checked, instead of rolling windows ' 'through the series, they are applied side-to-side, ' 'so the resulting output series will be some ' 'length-of-fixed-window-times shorter.') fixed_wlen = gui.spin(box, self, 'fixed_wlen', 2, 1000, label='Fixed window width:', callback=self.on_changed) fixed_wlen.setDisabled(not self.non_overlapping) # TODO: allow the user to choose left-aligned, right-aligned, or center-aligned window class TableView(gui.TableView): def __init__(self, parent): super().__init__(parent, editTriggers=(self.SelectedClicked | self.CurrentChanged | self.DoubleClicked | self.EditKeyPressed), ) self.horizontalHeader().setStretchLastSection(False) agg_functions = ListModel(AGG_FUNCTIONS + [Cumulative_sum, Cumulative_product], parent=self) self.setItemDelegateForColumn(0, self.VariableDelegate(parent)) self.setItemDelegateForColumn(1, self.SpinDelegate(parent)) self.setItemDelegateForColumn(2, self.ComboDelegate(self, agg_functions)) class _ItemDelegate(QStyledItemDelegate): def updateEditorGeometry(self, widget, option, _index): widget.setGeometry(option.rect) class ComboDelegate(_ItemDelegate): def __init__(self, parent=None, combo_model=None): super().__init__(parent) self._parent = parent if combo_model is not None: self._combo_model = combo_model def createEditor(self, parent, _QStyleOptionViewItem, index): combo = QComboBox(parent) combo.setModel(self._combo_model) return combo def setEditorData(self, combo, index): var = index.model().data(index, Qt.EditRole) combo.setCurrentIndex(self._combo_model.indexOf(var)) def setModelData(self, combo, model, index): var = self._combo_model[combo.currentIndex()] model.setData(index, var, Qt.EditRole) class VariableDelegate(ComboDelegate): @property def _combo_model(self): return self._parent.var_model class SpinDelegate(_ItemDelegate): def paint(self, painter, option, index): # Don't paint window length if non-overlapping windows set if not self.parent().non_overlapping: super().paint(painter, option, index) def createEditor(self, parent, _QStyleOptionViewItem, _index): # Don't edit window length if non-overlapping windows set if self.parent().non_overlapping: return None spin = QSpinBox(parent, minimum=1, maximum=1000) return spin def setEditorData(self, spin, index): spin.setValue(index.model().data(index, Qt.EditRole)) def setModelData(self, spin, model, index): spin.interpretText() model.setData(index, spin.value(), Qt.EditRole) self.var_model = VariableListModel(parent=self) self.table_model = model = PyTableModel(self.transformations, parent=self, editable=True) model.setHorizontalHeaderLabels(['Series', 'Window width', 'Aggregation function']) model.dataChanged.connect(self.on_changed) self.view = view = TableView(self) view.setModel(model) box.layout().addWidget(view) hbox = gui.hBox(box) from os.path import dirname, join self.add_button = button = gui.button( hbox, self, 'Add &Transform', callback=self.on_add_transform) button.setIcon(QIcon(join(dirname(__file__), 'icons', 'LineChart-plus.png'))) self.del_button = button = gui.button( hbox, self, '&Delete Selected', callback=self.on_del_transform) QIcon.setThemeName('gnome') # Works for me button.setIcon(QIcon.fromTheme('edit-delete')) gui.auto_commit(box, self, 'autocommit', '&Apply')
# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. from PyQt4.QtGui import QIcon for theme in ('ubuntu-mono-dark', 'gnome', 'oxygen'): if not QIcon.fromTheme('document-save').isNull(): break QIcon.setThemeName(theme) #BackInTime Logo BIT_LOGO = QIcon.fromTheme('document-save') BIT_LOGO_INFO = QIcon.fromTheme('document-save-as') #Main toolbar TAKE_SNAPSHOT = BIT_LOGO REFRESH_SNAPSHOT = QIcon.fromTheme('view-refresh') SNAPSHOT_NAME = QIcon.fromTheme( 'stock_edit', QIcon.fromTheme( 'gtk-edit', QIcon.fromTheme('edit-rename', QIcon.fromTheme('accessories-text-editor')))) REMOVE_SNAPSHOT = QIcon.fromTheme('edit-delete')
# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. from PyQt4.QtGui import QIcon for theme in ('ubuntu-mono-dark', 'gnome', 'oxygen'): if not QIcon.fromTheme('document-save').isNull(): break QIcon.setThemeName(theme) #BackInTime Logo BIT_LOGO = QIcon.fromTheme('document-save') BIT_LOGO_INFO = QIcon.fromTheme('document-save-as') #Main toolbar TAKE_SNAPSHOT = BIT_LOGO REFRESH_SNAPSHOT = QIcon.fromTheme('view-refresh') SNAPSHOT_NAME = QIcon.fromTheme('stock_edit', QIcon.fromTheme('gtk-edit', QIcon.fromTheme('edit-rename', QIcon.fromTheme('accessories-text-editor') ) ) ) REMOVE_SNAPSHOT = QIcon.fromTheme('edit-delete') VIEW_SNAPSHOT_LOG = QIcon.fromTheme('text-plain', QIcon.fromTheme('text-x-generic') )