示例#1
0
    def test_dynamic_toolbar(self):
        logging.basicConfig(level=logging.DEBUG)

        w = toolbar.DynamicResizeToolBar(None)
        w.setStyleSheet("QToolButton { border: 1px solid red; }")

        w.addAction(QAction("1", w))
        w.addAction(QAction("2", w))
        w.addAction(QAction("A long name", w))
        actions = list(w.actions())

        self.assertSequenceEqual([str(action.text()) for action in actions],
                                 ["1", "2", "A long name"])

        w.resize(100, 30)
        w.show()

        w.raise_()

        w.removeAction(actions[1])
        w.insertAction(actions[2], actions[1])

        self.assertSequenceEqual(actions,
                                 list(w.actions()),
                                 msg="insertAction does not preserve "
                                 "action order")

        self.singleShot(2000, lambda: w.setOrientation(Qt.Vertical))
        self.singleShot(5000, lambda: w.removeAction(actions[1]))

        self.app.exec_()
示例#2
0
 def __init__(self,parent):
     QAction.__init__(self,parent)
     self.webview = parent
     self.setIcon(QIcon(getPath('iconDir','heditor/table.png')))
     self.setIconVisibleInMenu(True)
     self.setText("table")
     
     self.infolabel = QLabel("Insert a table")
     menu = QMenu(self.webview)
     
     action = QWidgetAction(self)
     action.setDefaultWidget(self.infolabel)
     menu.addAction(action)
     
     
     action = QWidgetAction(self)
     action.setDefaultWidget(RichHtmlTableQWidget(self))
     menu.addAction(action)
     
     
     #action = QAction(QIcon(getPath('iconDir','heditor/table1.png')),"insert styled table",self)
     #action.setIconVisibleInMenu(True)
     #menu.addAction(action)
     
     action = QAction("insert table...",self,triggered=lambda:RichHtmlTableQDialog(self.webview).show())
     action.setIconVisibleInMenu(True)
     action.setIcon(QIcon(getPath('iconDir','heditor/table.png')))
     
     menu.addAction(action)
     
     self.setMenu(menu)
示例#3
0
    def __init__(self, parent):
        QAction.__init__(self, parent)
        self.webview = parent
        self.setIcon(QIcon(getPath('iconDir', 'heditor/table.png')))
        self.setIconVisibleInMenu(True)
        self.setText("table")

        self.infolabel = QLabel("Insert a table")
        menu = QMenu(self.webview)

        action = QWidgetAction(self)
        action.setDefaultWidget(self.infolabel)
        menu.addAction(action)

        action = QWidgetAction(self)
        action.setDefaultWidget(RichHtmlTableQWidget(self))
        menu.addAction(action)

        #action = QAction(QIcon(getPath('iconDir','heditor/table1.png')),"insert styled table",self)
        #action.setIconVisibleInMenu(True)
        #menu.addAction(action)

        action = QAction(
            "insert table...",
            self,
            triggered=lambda: RichHtmlTableQDialog(self.webview).show())
        action.setIconVisibleInMenu(True)
        action.setIcon(QIcon(getPath('iconDir', 'heditor/table.png')))

        menu.addAction(action)

        self.setMenu(menu)
    def test_dialog(self):
        d = WelcomeDialog()
        loader = icon_loader()
        icon = loader.get("icons/default-widget.svg")
        action1 = QAction(decorate_welcome_icon(icon, "light-green"),
                          "one", self.app)
        action2 = QAction(decorate_welcome_icon(icon, "orange"),
                          "two", self.app)
        d.addRow([action1, action2])

        action3 = QAction(decorate_welcome_icon(icon, "light-green"),
                          "three", self.app)
        d.addRow([action3])

        self.assertTrue(d.buttonAt(1, 0).defaultAction() == action3)

        d.show()
        action = [None]

        def p(a):
            print(str(a.text()))
            action[0] = a

        d.triggered.connect(p)
        self.app.exec_()
        self.assertIs(action[0], d.triggeredAction())
示例#5
0
    def test_tooltree(self):
        tree = ToolTree()
        role = tree.actionRole()
        model = QStandardItemModel()
        tree.setModel(model)
        item = QStandardItem("One")
        item.setData(QAction("One", tree), role)
        model.appendRow([item])

        cat = QStandardItem("A Category")
        item = QStandardItem("Two")
        item.setData(QAction("Two", tree), role)
        cat.appendRow([item])
        item = QStandardItem("Three")
        item.setData(QAction("Three", tree), role)
        cat.appendRow([item])

        model.appendRow([cat])

        def p(action):
            print("triggered", action.text())

        tree.triggered.connect(p)

        tree.show()

        self.app.exec_()
示例#6
0
文件: uimain.py 项目: lycying/seeking
    def __addBasicActions(self):
        """
        basic action 
        """
        self.regAction("gotohome",\
            QAction(QIcon(getPath("iconDir",'home.png')),QApplication.translate("default", "MainTab"),self,triggered=self.__evt_home))
        self.regAction("close",\
            QAction(QIcon(getPath("iconDir",'close.png')),QApplication.translate("default", "Close"),self,triggered=self.__evt_close_tab))
        self.regAction("perferences",\
            QAction(QIcon(getPath("iconDir",'settings.png')),QApplication.translate("default", "Preferences..."),self,triggered=self.__evt_preferences))
        self.regAction("plguinInfos", \
            QAction(QApplication.translate("default","Plugin Infos..."),self,triggered=lambda : PluginInfoDialog(self).show()))
        self.regAction("plguinRequest", \
            QAction(QApplication.translate("default","Available plugins..."),self,triggered=lambda : PluginRequestDialog(self).show()))

        self.getAction("gotohome").setShortcut(Prefs.new().getShortcut(
            "gotohome", "Ctrl+H"))
        self.getAction("close").setShortcut(Prefs.new().getShortcut(
            "close", "Ctrl+W"))
        self.getAction("perferences").setShortcut(Prefs.new().getShortcut(
            "perferences", ""))
        self.getAction("plguinInfos").setShortcut(Prefs.new().getShortcut(
            "plguinInfos", ""))
        self.getAction("plguinRequest").setShortcut(Prefs.new().getShortcut(
            "plguinRequest", ""))
示例#7
0
    def initializeOperationActions(self):

        self.showAllAction = QAction(KIcon(("applications-other", "package_applications")), i18n("All Packages"), self)
        self.connect(self.showAllAction, SIGNAL("triggered()"), lambda:self.cw.switchState(StateManager.ALL))
        self.cw.stateTab.addTab(QWidget(), KIcon(("applications-other", "package_applications")), i18n("All Packages"))

        self.showInstallAction = QAction(KIcon(("list-add", "add")), i18n("Installable Packages"), self)
        self.connect(self.showInstallAction, SIGNAL("triggered()"), lambda:self.cw.switchState(StateManager.INSTALL))
        self.cw.stateTab.addTab(QWidget(), KIcon(("list-add", "add")), i18n("Installable Packages"))

        self.showRemoveAction = QAction(KIcon(("list-remove", "remove")), i18n("Installed Packages"), self)
        self.connect(self.showRemoveAction, SIGNAL("triggered()"), lambda:self.cw.switchState(StateManager.REMOVE))
        self.cw.stateTab.addTab(QWidget(), KIcon(("list-remove", "remove")), i18n("Installed Packages"))

        self.showUpgradeAction = QAction(KIcon(("system-software-update", "gear")), i18n("Updates"), self)
        self.connect(self.showUpgradeAction, SIGNAL("triggered()"), lambda:self.cw.switchState(StateManager.UPGRADE))
        self.cw.stateTab.addTab(QWidget(), KIcon(("system-software-update", "gear")), i18n("Updates"))

        self.showPreferences = QAction(KIcon(("preferences-system", "package_settings")), i18n("Settings"), self)
        self.connect(self.showPreferences, SIGNAL("triggered()"), self.settingsDialog.show)

        self.actionHelp = QAction(KIcon("help"), i18n("Help"), self)
        self.actionHelp.setShortcuts(QKeySequence.HelpContents)
        self.connect(self.actionHelp, SIGNAL("triggered()"), self.showHelp)

        self.actionQuit = QAction(KIcon("exit"), i18n("Quit"), self)
        self.actionQuit.setShortcuts(QKeySequence.Quit)
        self.connect(self.actionQuit, SIGNAL("triggered()"), qApp.exit)

        self.cw.menuButton.setMenu(QMenu('MainMenu', self.cw.menuButton))
        self.cw.menuButton.setIcon(KIcon(("preferences-system", "package_settings")))
        self.cw.menuButton.menu().clear()

        self.cw.contentHistory.hide()

        self.cw.menuButton.menu().addAction(self.showPreferences)
        self.cw.menuButton.menu().addSeparator()
        self.cw.menuButton.menu().addAction(self.actionHelp)
        self.cw.menuButton.menu().addAction(self.actionQuit)

        self.cw._states = {self.cw.state.ALL    :(0, self.showAllAction),
                           self.cw.state.INSTALL:(1, self.showInstallAction),
                           self.cw.state.REMOVE :(2, self.showRemoveAction),
                           self.cw.state.UPGRADE:(3, self.showUpgradeAction)}

        self.showAllAction.setChecked(True)
        self.cw.checkUpdatesButton.hide()
        self.cw.checkUpdatesButton.setIcon(KIcon(("view-refresh", "reload")))
        self.cw.showBasketButton.clicked.connect(self.cw.showBasket)

        # Little time left for the new ui
        self.menuBar().setVisible(False)
        self.cw.switchState(self.cw.state.ALL)
示例#8
0
 def __evt_contextmenu(self, point):
     """
     show the right menu
     """
     item = self.pluginList.currentItem()
     if item:
         menu = QMenu(self)
         action = QAction(QApplication.translate("default",
                                                 "Install plugins..."),
                          self,
                          triggered=lambda: self.__evt_install_plugin(item))
         menu.addAction(action)
         action = QAction(
             QApplication.translate("default", "Uninstall plugins..."),
             self)
         menu.addAction(action)
         menu.exec_(self.mapToGlobal(self.pluginList.mapTo(self, point)))
示例#9
0
    def __init__(self):
        QSystemTrayIcon.__init__(self)

        self.trayIconMenu = QMenu(Seeking.new())
        self.trayIconMenu.addAction(
            QAction("Mi&nimize", self, triggered=Seeking.new().hide))
        self.trayIconMenu.addAction(
            QAction("Ma&ximize", self, triggered=Seeking.new().showMaximized))
        self.trayIconMenu.addAction(
            QAction("&Restore", self, triggered=Seeking.new().showNormal))
        self.trayIconMenu.addSeparator()
        self.trayIconMenu.addAction(QAction("&Quit", self,
                                            triggered=qApp.quit))
        self.setContextMenu(self.trayIconMenu)

        self.setIcon(QIcon(getPath("iconDir", "logo.png")))
        self.show()
示例#10
0
 def __initActions(self):
     """
     put all actions to dict , so we can use them outside
     """
     self.__editActions = {}
     
     self.__editActions["pre"] = QAction(QIcon(getPath('iconDir','heditor/pre.png')),"back",
                                    self,triggered=lambda:self.page().triggerAction(QWebPage.Back,checked=True))
     self.__editActions["next"] = QAction(QIcon(getPath('iconDir','heditor/next.png')),"forward",
                                    self,triggered=lambda:self.page().triggerAction(QWebPage.Forward,checked=True))
     self.__editActions["stop"] = QAction(QIcon(getPath('iconDir','heditor/stop.png')),"stop",
                                    self,triggered=lambda:self.page().triggerAction(QWebPage.Stop,checked=True))
     self.__editActions["reload"] = QAction(QIcon(getPath('iconDir','heditor/reload.png')),"reload",
                                    self,triggered=lambda:self.page().triggerAction(QWebPage.Stop,checked=True))
     self.__editActions["zoomin"] = QAction(QIcon(getPath('iconDir','heditor/zoomin.png')),"zoomIn",
                                    self,triggered=lambda:self.__evt_zoom(True))
     self.__editActions["zoomreset"] = QAction(QIcon(getPath('iconDir','heditor/zoomreset.png')),"zoomReset",
                                    self,triggered=lambda:self.setZoomFactor(1.0))
     self.__editActions["zoomout"] = QAction(QIcon(getPath('iconDir','heditor/zoomout.png')),"zoomOut",
                                    self,triggered=lambda:self.__evt_zoom(False))
     
     
     
     #Make sure the menu can show their icons
     for key in self.__editActions.keys():
         self.__editActions[key].setIconVisibleInMenu(True)
示例#11
0
    def createActions(self):
        self.boldAct = QAction(self.tr("&Bold"), self)
        self.boldAct.setCheckable(True)
        self.boldAct.setShortcut(self.tr("Ctrl+B"))
        self.boldAct.setStatusTip(self.tr("Make the text bold"))
        self.connect(self.boldAct, SIGNAL("triggered()"), self.setBold)
        self.addAction(self.boldAct)

        boldFont = self.boldAct.font()
        boldFont.setBold(True)
        self.boldAct.setFont(boldFont)

        self.italicAct = QAction(self.tr("&Italic"), self)
        self.italicAct.setCheckable(True)
        self.italicAct.setShortcut(self.tr("Ctrl+I"))
        self.italicAct.setStatusTip(self.tr("Make the text italic"))
        self.connect(self.italicAct, SIGNAL("triggered()"), self.setItalic)
        self.addAction(self.italicAct)
示例#12
0
    def __setupToolBarAction(self):
        #find action
        findAction = QAction(QIcon(getPath('iconDir','heditor/find.png')),"Find",
                        self,triggered=self.__evt_find)
        findAction.setIconVisibleInMenu(True)
        findAction.setShortcut("Ctrl+F")

        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["undo"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["redo"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["selectall"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["copy"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["cut"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["paste"])
        self.__toolBar.addSeparator()
        
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["bold"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["italic"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["underline"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["subscript"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["superscript"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["strikethrough"])
        
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["justify"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["left"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["center"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["right"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["orderedlist"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["unorderedlist"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["indent"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["outdent"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["h1"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["h2"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["h3"])

        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["fgcolor"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["bgcolor"]) 
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["removeformat"])
        self.__toolBar.addSeparator()
        
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["image"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["linkpage"])
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["table"])
         
        
        self.__toolBar.addSeparator()
        action = QAction(QIcon(getPath('iconDir','heditor/inspector.png')),"WebInspector",
                                       self,triggered=self.__evt_inspector)

        action.setIconVisibleInMenu(True)
        self.__toolBar.addAction(action) 
        self.__toolBar.addAction(findAction)
        
        self.__toolBar.addSeparator()
        self.__toolBar.addAction(self.__htmlEditorArea.editActions()["htmlclean"])
示例#13
0
 def __init__(self,parent,attr="forecolor"):
     QAction.__init__(self,parent)
     self.webview = parent
     self.attr = attr
     self.setIcon(QIcon(getPath('iconDir','heditor/paintbrush.png')))
     self.setIconVisibleInMenu(True)
     self.setText("fgcolor")
     
     menu = QMenu(self.webview)
     
     action = QWidgetAction(self)
     action.setDefaultWidget(RichHtmlColorSelectorQWidget(self,self.webview))
     
     menu.addAction(action)
     
     action = QAction("more...",self,triggered = self.__evt_color)
     menu.addAction(action)
     
     self.setMenu(menu)
示例#14
0
    def __init__(self, parent, attr="forecolor"):
        QAction.__init__(self, parent)
        self.webview = parent
        self.attr = attr
        self.setIcon(QIcon(getPath('iconDir', 'heditor/paintbrush.png')))
        self.setIconVisibleInMenu(True)
        self.setText("fgcolor")

        menu = QMenu(self.webview)

        action = QWidgetAction(self)
        action.setDefaultWidget(
            RichHtmlColorSelectorQWidget(self, self.webview))

        menu.addAction(action)

        action = QAction("more...", self, triggered=self.__evt_color)
        menu.addAction(action)

        self.setMenu(menu)
示例#15
0
 def __evt_contextmenu(self,point):
     """
     show the right menu
     """
     item = self.pluginList.currentItem()
     if item:
         menu = QMenu(self)
        
         
         if item.text(4)=="True":
             
             action = QAction(QApplication.translate("PluginInfoDialog", "DeActive"),self,\
                              triggered=lambda re,name=item.text(0):self.__evt_toggle_active(name, False))
             #core plugin not allowed disabled
             action.setEnabled(not PluginAdapter.new().getPluginByName(item.text(0)).packageName == "__core__")
         else:
             action = QAction(QApplication.translate("PluginInfoDialog", "Active"),self,\
                              triggered=lambda re,name=item.text(0):self.__evt_toggle_active(name, True))
             
         menu.addAction(action)
         menu.exec_(self.mapToGlobal(self.pluginList.mapTo(self,point)))
示例#16
0
文件: uimain.py 项目: lycying/seeking
 def __evt_navigation(self):
     menu = QMenu()
     actions = {}
     for i in range(self.count()):
         actions[i] = QAction(self.tabBar().tabIcon(i),self.tabBar().tabText(i),self,\
                         triggered=lambda re,i=i:self.setCurrentIndex(i) and self.navigationButton)
     for key in actions.keys():
         actions[key].setIconVisibleInMenu(True)
         menu.addAction(actions[key])
     self.navigationButton.setMenu(menu)
     self.navigationButton.showMenu()
     menu.clear()
示例#17
0
    def test_lineedit(self):
        """test LineEdit
        """
        line = LineEdit()
        line.show()

        action1 = QAction(
            QIcon(line.style().standardPixmap(QStyle.SP_ArrowBack)), "Search",
            line)
        menu = QMenu()
        menu.addAction("Regex")
        menu.addAction("Wildcard")
        action1.setMenu(menu)

        line.setAction(action1, LineEdit.LeftPosition)
        self.assertIs(line.actionAt(LineEdit.LeftPosition), action1)
        self.assertTrue(line.button(LineEdit.LeftPosition) is not None)
        self.assertTrue(line.button(LineEdit.RightPosition) is None)

        with self.assertRaises(ValueError):
            line.removeActionAt(100)

        line.removeActionAt(LineEdit.LeftPosition)
        self.assertIs(line.actionAt(LineEdit.LeftPosition), None)

        line.setAction(action1, LineEdit.LeftPosition)

        action2 = QAction(
            QIcon(line.style().standardPixmap(QStyle.SP_TitleBarCloseButton)),
            "Delete", line)
        line.setAction(action2, LineEdit.RightPosition)

        line.setPlaceholderText("Search")
        self.assertEqual(line.placeholderText(), "Search")

        b = line.button(LineEdit.RightPosition)
        b.setFlat(False)
        self.app.exec_()
示例#18
0
文件: uimain.py 项目: lycying/seeking
 def __evt_showContextMenu(self,point):
     _tabbar = self.tabBar()
     for index in range(_tabbar.count()):
         rect = _tabbar.tabRect(index)
         if rect.contains(point):
             menu = QMenu(self)
             action = QAction("close",self,triggered=lambda:self.__evt_close_tab_click(index))
             action.setEnabled(self.count()>1 and index is not 0)
             menu.addAction(action)
             
             action = QAction("close others",self,triggered=lambda:self.__evt_contextMenuCloseOthers(index))
             action.setEnabled(self.count()>1)
             menu.addAction(action)
             
             action = QAction("close all",self,triggered=lambda:self.__evt_contextMenuCloseOthers(0))
             action.setEnabled(self.count()>1)
             menu.addAction(action)
             
             menu.exec_(self.mapToGlobal(point))
示例#19
0
    def __setupToolBarAction(self):
        
        self.__toolBar.addAction(self.__htmlBrowserView.getActions()["pre"])
        self.__toolBar.addAction(self.__htmlBrowserView.getActions()["next"])
        self.__toolBar.addAction(self.__htmlBrowserView.getActions()["stop"])
        self.__toolBar.addAction(self.__htmlBrowserView.getActions()["reload"])
        self.__toolBar.addWidget(self.__loadlabel)
        self.__toolBar.addWidget(self.__addressinput)
        
        action = QAction(QIcon(getPath('iconDir','heditor/go.png')),"go",self,triggered=self.__evt_load)
        
        self.__toolBar.addAction(action)

        self.__toolBar.addAction(self.__htmlBrowserView.getActions()["zoomin"])
        self.__toolBar.addAction(self.__htmlBrowserView.getActions()["zoomreset"])
        self.__toolBar.addAction(self.__htmlBrowserView.getActions()["zoomout"])
示例#20
0
    def initGui(self):
        """Called by QGIS to set up the GUI.

        Interactions with the Qt/GUI environment, like messing with menus,
        dialogs, actions, and signals, should be isolated to this method
        instead of __init__. The corresponding cleanups should happen in
        unload().
        """
        # Define names and implementations for each demo dialog
        dialog_classes = {
            "Basemaps": BasemapsDialog,
            "Geocoding": GeocodingDialog,
            "Routing": RoutingDialog,
        }

        # Get the window to use as the Qt parent for actions and dialogs
        window = self.iface.mainWindow()

        # Create instances of each demo dialog class
        dialogs = {}
        for dialog_name, dialog_cls in sorted(dialog_classes.items()):
            dialogs[dialog_name] = dialog_cls(window, self.iface, self.client)

        # Create QActions for triggering each dialog
        actions = {}
        for dialog_name in sorted(dialogs.keys()):
            actions[dialog_name] = QAction(dialog_name, window)

        # Connect QAction triggered signals to activate methods on dialogs
        for name, action in actions.items():
            dialog = dialogs[name]
            action.triggered.connect(dialog.activate)

        # Create the menu and add all the actions to it, in sort order
        for _, action in sorted(actions.items()):
            self.iface.addPluginToWebMenu(self.menu_name, action)

        # Hold references to Qt objects
        self.dialogs = dialogs
        self.actions = actions
示例#21
0
文件: uimain.py 项目: lycying/seeking
    def __updateWindows(self):
        """
        when we open a new window or close a exist window . this function will be called 
        we refresh the window menu according the tab's item
        """
        self.getMenu("window").clear()
        self.getMenu("window").addAction(self.getAction("close"))
        self.getMenu("window").addSeparator()

        actions = {}
        for i in range(self.tabs.count()):
            actions[i] = QAction(self.tabs.tabBar().tabIcon(i),self.tabs.tabBar().tabText(i),self,\
                                                     triggered=lambda re,i=i:self.tabs.setCurrentIndex(i))

        for key in actions.keys():
            actions[key].setIconVisibleInMenu(True)
            self.getMenu("window").addAction(actions[key])
        #if only maintab . disable the close action
        if self.tabs.count() <= 1:
            self.getAction("close").setEnabled(False)
        else:
            self.getAction("close").setEnabled(True)
示例#22
0
    def __evt_contextmenu(self, point):
        """
        show the right menu
        """
        item = self.pluginList.currentItem()
        if item:
            menu = QMenu(self)

            if item.text(4) == "True":

                action = QAction(QApplication.translate("PluginInfoDialog", "DeActive"),self,\
                                 triggered=lambda re,name=item.text(0):self.__evt_toggle_active(name, False))
                #core plugin not allowed disabled
                action.setEnabled(not PluginAdapter.new().getPluginByName(
                    item.text(0)).packageName == "__core__")
            else:
                action = QAction(QApplication.translate("PluginInfoDialog", "Active"),self,\
                                 triggered=lambda re,name=item.text(0):self.__evt_toggle_active(name, True))

            menu.addAction(action)
            menu.exec_(self.mapToGlobal(self.pluginList.mapTo(self, point)))
示例#23
0
class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, app=None):
        QMainWindow.__init__(self, None)
        self.setupUi(self)

        self.app = app
        self.iface = backend.pm.Iface()

        self.busy = QProgressIndicator(self)
        self.busy.setFixedSize(QSize(20, 20))

        self.setWindowIcon(QIcon(":/data/package-manager.png"))

        self.setCentralWidget(MainWidget(self))
        self.cw = self.centralWidget()

        self.settingsDialog = SettingsDialog(self)

        self.initializeActions()
        self.initializeStatusBar()
        self.initializeTray()
        self.connectMainSignals()

        self.pdsMessageBox = PMessageBox(self)

    def connectMainSignals(self):
        self.cw.connectMainSignals()
        self.connect(QShortcut(QKeySequence(Qt.CTRL + Qt.Key_Tab), self),
                     SIGNAL("activated()"), lambda: self.moveTab('next'))
        self.connect(
            QShortcut(QKeySequence(Qt.SHIFT + Qt.CTRL + Qt.Key_Tab), self),
            SIGNAL("activated()"), lambda: self.moveTab('prev'))
        self.connect(QShortcut(QKeySequence(Qt.CTRL + Qt.Key_F), self),
                     SIGNAL("activated()"), self.cw.searchLine.setFocus)
        self.connect(QShortcut(QKeySequence(Qt.Key_F3), self),
                     SIGNAL("activated()"), self.cw.searchLine.setFocus)

        self.connect(self.settingsDialog, SIGNAL("packagesChanged()"),
                     self.cw.initialize)
        self.connect(self.settingsDialog, SIGNAL("packageViewChanged()"),
                     self.cw.updateSettings)
        self.connect(self.settingsDialog, SIGNAL("traySettingChanged()"),
                     self.tray.settingsChanged)
        self.connect(self.cw.state, SIGNAL("repositoriesChanged()"),
                     self.tray.populateRepositoryMenu)
        self.connect(self.cw, SIGNAL("repositoriesUpdated()"),
                     self.tray.updateTrayUnread)
        self.connect(qApp, SIGNAL("shutDown()"), self.slotQuit)

    def moveTab(self, direction):
        new_index = self.cw.stateTab.currentIndex() - 1
        if direction == 'next':
            new_index = self.cw.stateTab.currentIndex() + 1
        if new_index not in range(self.cw.stateTab.count()):
            new_index = 0
        self.cw.stateTab.setCurrentIndex(new_index)

    def initializeTray(self):
        self.tray = Tray(self, self.iface)
        self.connect(self.cw.operation, SIGNAL("finished(QString)"),
                     self.trayAction)
        self.connect(self.cw.operation, SIGNAL("finished(QString)"),
                     self.tray.stop)
        self.connect(self.cw.operation, SIGNAL("operationCancelled()"),
                     self.tray.stop)
        self.connect(self.cw.operation, SIGNAL("started(QString)"),
                     self.tray.animate)
        self.connect(self.tray, SIGNAL("showUpdatesSelected()"),
                     self.trayShowUpdates)

    def trayShowUpdates(self):
        self.showUpgradeAction.setChecked(True)

        self.cw.switchState(StateManager.UPGRADE)

        KApplication.kApplication().updateUserTimestamp()

        self.show()
        self.raise_()

    def trayAction(self, operation):
        if not self.isVisible() and operation in [
                "System.Manager.updateRepository",
                "System.Manager.updateAllRepositories"
        ]:
            self.tray.showPopup()
        if self.tray.isVisible() and operation in [
                "System.Manager.updatePackage",
                "System.Manager.installPackage", "System.Manager.removePackage"
        ]:
            self.tray.updateTrayUnread()

    def initializeStatusBar(self):
        self.cw.mainLayout.insertWidget(0, self.busy)
        self.statusBar().addPermanentWidget(self.cw.actions, 1)
        self.statusBar().show()

        self.updateStatusBar('')

        self.connect(self.cw, SIGNAL("selectionStatusChanged(QString)"),
                     self.updateStatusBar)
        self.connect(self.cw, SIGNAL("updatingStatus()"), self.statusWaiting)

    def initializeActions(self):
        self.initializeOperationActions()

    def initializeOperationActions(self):

        self.showAllAction = QAction(
            KIcon(("applications-other", "package_applications")),
            i18n("All Packages"), self)
        self.connect(self.showAllAction, SIGNAL("triggered()"),
                     lambda: self.cw.switchState(StateManager.ALL))
        self.cw.stateTab.addTab(
            QWidget(), KIcon(("applications-other", "package_applications")),
            i18n("All Packages"))

        self.showInstallAction = QAction(KIcon(("list-add", "add")),
                                         i18n("Installable Packages"), self)
        self.connect(self.showInstallAction, SIGNAL("triggered()"),
                     lambda: self.cw.switchState(StateManager.INSTALL))
        self.cw.stateTab.addTab(QWidget(), KIcon(("list-add", "add")),
                                i18n("Installable Packages"))

        self.showRemoveAction = QAction(KIcon(("list-remove", "remove")),
                                        i18n("Installed Packages"), self)
        self.connect(self.showRemoveAction, SIGNAL("triggered()"),
                     lambda: self.cw.switchState(StateManager.REMOVE))
        self.cw.stateTab.addTab(QWidget(), KIcon(("list-remove", "remove")),
                                i18n("Installed Packages"))

        self.showUpgradeAction = QAction(
            KIcon(("system-software-update", "gear")), i18n("Updates"), self)
        self.connect(self.showUpgradeAction, SIGNAL("triggered()"),
                     lambda: self.cw.switchState(StateManager.UPGRADE))
        self.cw.stateTab.addTab(QWidget(),
                                KIcon(("system-software-update", "gear")),
                                i18n("Updates"))

        self.showPreferences = QAction(
            KIcon(("preferences-system", "package_settings")),
            i18n("Settings"), self)
        self.connect(self.showPreferences, SIGNAL("triggered()"),
                     self.settingsDialog.show)

        self.actionHelp = QAction(KIcon("help"), i18n("Help"), self)
        self.actionHelp.setShortcuts(QKeySequence.HelpContents)
        self.connect(self.actionHelp, SIGNAL("triggered()"), self.showHelp)

        self.actionQuit = QAction(KIcon("exit"), i18n("Quit"), self)
        self.actionQuit.setShortcuts(QKeySequence.Quit)
        self.connect(self.actionQuit, SIGNAL("triggered()"), qApp.exit)

        self.cw.menuButton.setMenu(QMenu('MainMenu', self.cw.menuButton))
        self.cw.menuButton.setIcon(
            KIcon(("preferences-system", "package_settings")))
        self.cw.menuButton.menu().clear()

        self.cw.contentHistory.hide()

        self.cw.menuButton.menu().addAction(self.showPreferences)
        self.cw.menuButton.menu().addSeparator()
        self.cw.menuButton.menu().addAction(self.actionHelp)
        self.cw.menuButton.menu().addAction(self.actionQuit)

        self.cw._states = {
            self.cw.state.ALL: (0, self.showAllAction),
            self.cw.state.INSTALL: (1, self.showInstallAction),
            self.cw.state.REMOVE: (2, self.showRemoveAction),
            self.cw.state.UPGRADE: (3, self.showUpgradeAction)
        }

        self.showAllAction.setChecked(True)
        self.cw.checkUpdatesButton.hide()
        self.cw.checkUpdatesButton.setIcon(KIcon(("view-refresh", "reload")))
        self.cw.showBasketButton.clicked.connect(self.cw.showBasket)

        # Little time left for the new ui
        self.menuBar().setVisible(False)
        self.cw.switchState(self.cw.state.ALL)

    def statusWaiting(self):
        self.updateStatusBar(i18n('Calculating dependencies...'), busy=True)

    def showHelp(self):
        self.Pds = pds.Pds()
        self.lang = localedata.setSystemLocale(justGet=True)

        if self.lang in os.listdir("/usr/share/package-manager/help"):
            pass
        else:
            self.lang = "en"

        if self.Pds.session == pds.Kde3:
            os.popen(
                "khelpcenter /usr/share/package-manager/help/%s/main_help.html"
                % (self.lang))
        else:
            helpdialog.HelpDialog(self, helpdialog.MAINAPP)

    def updateStatusBar(self, text, busy=False):
        if text == '':
            text = i18n("Currently your basket is empty.")
            self.busy.hide()
            self.cw.showBasketButton.hide()
        else:
            self.cw.showBasketButton.show()

        if busy:
            self.busy.busy()
            self.cw.showBasketButton.hide()
        else:
            self.busy.hide()

        self.cw.statusLabel.setText(text)
        self.cw.statusLabel.setToolTip(text)

    def queryClose(self):
        if config.PMConfig().systemTray():
            self.hide()
            return False
        return True

    def queryExit(self):
        if not self.iface.operationInProgress():
            if self.tray:
                del self.tray.notification
            return True
        return False

    def slotQuit(self):
        if self.iface.operationInProgress():
            return
示例#24
0
 def _addMenu(self):
     """Adds the WakaTime menu item under the File menu."""
     self.action = QAction(QIcon(), 'WakaTime', self)
     self.action.triggered.connect(self._promptForApiKey)
     fileMenu = e5App().getObject('UserInterface').getMenu('file')
     fileMenu.addAction(self.action)
示例#25
0
 def contextMenuEvent (self, e):
     """
     right click . table oprerators etc...
     """
     menu = QMenu(self)
     
     tag = self.page().mainFrame().hitTestContent(e.pos()).element()
     
     #some table operations
     if tag and tag.tagName().lower() == "td":
         hasPre =  tag.parent().previousSibling().tagName().lower()=="tr"
         hasNext =  tag.parent().nextSibling().tagName().lower()=="tr"
         #move up
         action = QAction(QIcon(getPath('iconDir','heditor/row_up.png')),"Move row up",self,triggered=lambda :self._table_tr_moveup(tag))
         action.setDisabled(not hasPre)
         action.setIconVisibleInMenu(True)
         menu.addAction(action)
         #move down
         action = QAction(QIcon(getPath('iconDir','heditor/row_down.png')),"Move row down",self,triggered=lambda :self._table_tr_movedown(tag))
         action.setDisabled(not hasNext)
         action.setIconVisibleInMenu(True)
         menu.addAction(action)
 
         
         menu.addAction(QAction("Copy row to above",self,triggered=lambda :self._table_tr_insert_above(tag)))
         menu.addAction(QAction("Copy row to below",self,triggered=lambda :self._table_tr_insert_below(tag)))
         menu.addAction(QAction(QIcon(getPath('iconDir','heditor/col_left.png')),"Insert column left",self,triggered=lambda :self._table_column_left(tag)))
         menu.addAction(QAction(QIcon(getPath('iconDir','heditor/col_right.png')),"Insert column right",self,triggered=lambda :self._table_column_right(tag)))
         
         action = QAction("Delete row",self,triggered=lambda :self._table_tr_remove(tag))
         action.setDisabled(not hasPre and not hasNext)
         menu.addAction(action)
         
         menu.addAction(QAction("Delete column",self,triggered=lambda :self._table_column_remove(tag)))
         
         action = QAction("Set Table Style",self,triggered=lambda :self._table_style_change(tag))
         menu.addAction(action)
         
         action = QAction(QIcon(getPath('iconDir','heditor/delete.png')),"Delete table",self,triggered=lambda :self._table_delete(tag))
         action.setIconVisibleInMenu(True)
         menu.addAction(action)
         
         menu.addSeparator()
          
     #Common content menu
     menu.addAction(self.__editActions["selectall"])
     menu.addAction(self.__editActions["copy"])
     menu.addAction(self.__editActions["cut"])
     menu.addAction(self.__editActions["paste"])
     menu.addSeparator()
     
     menuEdit = QMenu("Edit")
     menuEdit.addAction(self.__editActions["bold"])
     menuEdit.addAction(self.__editActions["italic"])
     menuEdit.addAction(self.__editActions["underline"])
     menuEdit.addAction(self.__editActions["strikethrough"])
     menuEdit.addAction(self.__editActions["removeformat"])
     menuEdit.addSeparator()
     menuEdit.addAction(self.__editActions["left"])
     menuEdit.addAction(self.__editActions["center"])
     menuEdit.addAction(self.__editActions["right"])
     menuEdit.addAction(self.__editActions["justify"])
     menuEdit.addSeparator()
     menuEdit.addAction(self.__editActions["indent"])
     menuEdit.addAction(self.__editActions["outdent"]) 
     menuEdit.addAction(self.__editActions["subscript"])
     menuEdit.addAction(self.__editActions["superscript"])
     
     
     menu.addMenu(menuEdit)
     menu.addSeparator()
     
     menuInsert = QMenu("Insert")
     menuInsert.addAction(self.__editActions["image"])
     menuInsert.addAction(self.__editActions["table"])
     menuInsert.addAction(self.__editActions["linkpage"])
     
     menu.addMenu(menuInsert)
     
         
     menu.exec_(e.globalPos())
示例#26
0
文件: uimain.py 项目: lycying/seeking
    def beginFinalInit(self):
        """
        @see: startup
        Notice the __init__ method . we just setup the basic widget.
        And after the language , style ,plugins etc had loaded .
        we call this method . 
        
        Never call it unless you know what's it
        """
        #when at linux platform . the icon is not visible at menu .
        for key in self.__actions.keys():
            self.__actions.get(key).setIconVisibleInMenu(True)

        #--------------->>Seeking init <<-----------------#
        # __init__ menu
        self.getMenu("settings").addAction(self.getAction("perferences"))

        #i18n , must restart program to make it in use
        action_languages = QAction(
            QIcon(getPath('iconDir', 'languages.png')),
            QApplication.translate("default", "Languages"), self)
        action_languages.setIconVisibleInMenu(True)
        menu_languages = QMenu(self)

        trans_dir = QDir(getPrccisePath("transDir", "", "coredir"))
        fileNames = trans_dir.entryList(['i18n*.qm'], QDir.Files, QDir.Name)
        qmFiles = [trans_dir.filePath(fn) for fn in fileNames]

        for qmf in qmFiles:
            translator = QTranslator()
            translator.load(qmf)
            action = menu_languages.addAction(
                translator.translate("default", "English"))
            action.triggered.connect(lambda re, locale=translator.translate(
                "default", "locale"): self.__evt_changeLanguage(locale))

        action_languages.setMenu(menu_languages)
        self.getMenu("settings").addAction(action_languages)

        #style menu use signalmapper
        action_style = QAction(QIcon(getPath('iconDir', 'style.png')),
                               QApplication.translate("default", "Style"),
                               self)
        action_style.setIconVisibleInMenu(True)
        menu_style = QMenu(self)
        for style_item in QStyleFactory.keys():
            action = menu_style.addAction(style_item)
            action.triggered.connect(
                lambda re, style_item=style_item: changeStyle(style_item))
        action_style.setMenu(menu_style)
        self.getMenu("settings").addAction(action_style)

        menu_plugin = self.getMenu("plugins")

        menu_plugin.addAction(self.getAction("plguinInfos"))

        menu_plugin.addSeparator()
        menu_plugin.addAction(self.getAction("plguinRequest"))

        #--------------->>Seeking init <<-----------------#
        # __init__ toolbar
        toolBar = self.addToolBar(QApplication.translate("default", "common"))

        toolBar.addAction(self.getAction("perferences"))
        toolBar.addAction(self.getAction("close"))
        toolBar.addAction(self.getAction("gotohome"))
        toolBar.addAction(self.getAction("help"))

        #--------------->>Seeking init <<-----------------#
        # __init__ status bar
        self.statusBar().showMessage("Seeking ...")

        #--------------->>Seeking init <<-----------------#
        #Effects of a loading progress .
        #Results appear in the tab of the interior, the window has no effect on the global
        self.overlay = Overlay(self.centralWidget())
        self.overlay.hide()

        #--------------->>Seeking init <<-----------------#
        #other
        self.emit(SIGNAL('updateWindows()'))
示例#27
0
文件: uimain.py 项目: lycying/seeking
    def beginFinalInit(self):
        """
        @see: startup
        Notice the __init__ method . we just setup the basic widget.
        And after the language , style ,plugins etc had loaded .
        we call this method . 
        
        Never call it unless you know what's it
        """
        #when at linux platform . the icon is not visible at menu .
        for key in self.__actions.keys():
            self.__actions.get(key).setIconVisibleInMenu(True)
            
        #--------------->>Seeking init <<-----------------#
        # __init__ menu
        self.getMenu("settings").addAction(self.getAction("perferences"))
        
        
        #i18n , must restart program to make it in use
        action_languages = QAction(QIcon(getPath('iconDir','languages.png')),QApplication.translate("default", "Languages"),self)
        action_languages.setIconVisibleInMenu(True)
        menu_languages = QMenu(self)
        
        trans_dir = QDir(getPrccisePath("transDir","","coredir"))
        fileNames = trans_dir.entryList(['i18n*.qm'], QDir.Files,QDir.Name)
        qmFiles = [trans_dir.filePath(fn) for fn in fileNames]
    
        for qmf in qmFiles: 
            translator = QTranslator() 
            translator.load(qmf)
            action = menu_languages.addAction(translator.translate("default", "English"))
            action.triggered.connect(lambda re,locale=translator.translate("default", "locale"):self.__evt_changeLanguage(locale))
        
        action_languages.setMenu(menu_languages)
        self.getMenu("settings").addAction(action_languages)
        
        #style menu use signalmapper
        action_style = QAction(QIcon(getPath('iconDir','style.png')),QApplication.translate("default", "Style"),self)
        action_style.setIconVisibleInMenu(True)
        menu_style = QMenu(self)
        for style_item in QStyleFactory.keys():
            action = menu_style.addAction(style_item)
            action.triggered.connect(lambda re,style_item=style_item:changeStyle(style_item))
        action_style.setMenu(menu_style)
        self.getMenu("settings").addAction(action_style)
        
        menu_plugin = self.getMenu("plugins")
        
        menu_plugin.addAction(self.getAction("plguinInfos"))
        
        menu_plugin.addSeparator()
        menu_plugin.addAction(self.getAction("plguinRequest"))
        
        #--------------->>Seeking init <<-----------------#
        # __init__ toolbar
        toolBar = self.addToolBar(QApplication.translate("default","common"))
        
        toolBar.addAction(self.getAction("perferences"))
        toolBar.addAction(self.getAction("close"))
        toolBar.addAction(self.getAction("gotohome"))
        toolBar.addAction(self.getAction("help"))
        
        #--------------->>Seeking init <<-----------------#
        # __init__ status bar
        self.statusBar().showMessage("Seeking ...")
        
        
        #--------------->>Seeking init <<-----------------#
        #Effects of a loading progress .
        #Results appear in the tab of the interior, the window has no effect on the global
        self.overlay = Overlay(self.centralWidget())
        self.overlay.hide()

        #--------------->>Seeking init <<-----------------#
        #other
        self.emit(SIGNAL('updateWindows()'))
示例#28
0
    def initializeOperationActions(self):

        self.showAllAction = QAction(
            KIcon(("applications-other", "package_applications")),
            i18n("All Packages"), self)
        self.connect(self.showAllAction, SIGNAL("triggered()"),
                     lambda: self.cw.switchState(StateManager.ALL))
        self.cw.stateTab.addTab(
            QWidget(), KIcon(("applications-other", "package_applications")),
            i18n("All Packages"))

        self.showInstallAction = QAction(KIcon(("list-add", "add")),
                                         i18n("Installable Packages"), self)
        self.connect(self.showInstallAction, SIGNAL("triggered()"),
                     lambda: self.cw.switchState(StateManager.INSTALL))
        self.cw.stateTab.addTab(QWidget(), KIcon(("list-add", "add")),
                                i18n("Installable Packages"))

        self.showRemoveAction = QAction(KIcon(("list-remove", "remove")),
                                        i18n("Installed Packages"), self)
        self.connect(self.showRemoveAction, SIGNAL("triggered()"),
                     lambda: self.cw.switchState(StateManager.REMOVE))
        self.cw.stateTab.addTab(QWidget(), KIcon(("list-remove", "remove")),
                                i18n("Installed Packages"))

        self.showUpgradeAction = QAction(
            KIcon(("system-software-update", "gear")), i18n("Updates"), self)
        self.connect(self.showUpgradeAction, SIGNAL("triggered()"),
                     lambda: self.cw.switchState(StateManager.UPGRADE))
        self.cw.stateTab.addTab(QWidget(),
                                KIcon(("system-software-update", "gear")),
                                i18n("Updates"))

        self.showPreferences = QAction(
            KIcon(("preferences-system", "package_settings")),
            i18n("Settings"), self)
        self.connect(self.showPreferences, SIGNAL("triggered()"),
                     self.settingsDialog.show)

        self.actionHelp = QAction(KIcon("help"), i18n("Help"), self)
        self.actionHelp.setShortcuts(QKeySequence.HelpContents)
        self.connect(self.actionHelp, SIGNAL("triggered()"), self.showHelp)

        self.actionQuit = QAction(KIcon("exit"), i18n("Quit"), self)
        self.actionQuit.setShortcuts(QKeySequence.Quit)
        self.connect(self.actionQuit, SIGNAL("triggered()"), qApp.exit)

        self.cw.menuButton.setMenu(QMenu('MainMenu', self.cw.menuButton))
        self.cw.menuButton.setIcon(
            KIcon(("preferences-system", "package_settings")))
        self.cw.menuButton.menu().clear()

        self.cw.contentHistory.hide()

        self.cw.menuButton.menu().addAction(self.showPreferences)
        self.cw.menuButton.menu().addSeparator()
        self.cw.menuButton.menu().addAction(self.actionHelp)
        self.cw.menuButton.menu().addAction(self.actionQuit)

        self.cw._states = {
            self.cw.state.ALL: (0, self.showAllAction),
            self.cw.state.INSTALL: (1, self.showInstallAction),
            self.cw.state.REMOVE: (2, self.showRemoveAction),
            self.cw.state.UPGRADE: (3, self.showUpgradeAction)
        }

        self.showAllAction.setChecked(True)
        self.cw.checkUpdatesButton.hide()
        self.cw.checkUpdatesButton.setIcon(KIcon(("view-refresh", "reload")))
        self.cw.showBasketButton.clicked.connect(self.cw.showBasket)

        # Little time left for the new ui
        self.menuBar().setVisible(False)
        self.cw.switchState(self.cw.state.ALL)
示例#29
0
文件: uimain.py 项目: lycying/seeking
    def __evt_showContextMenu(self, point):
        _tabbar = self.tabBar()
        for index in range(_tabbar.count()):
            rect = _tabbar.tabRect(index)
            if rect.contains(point):
                menu = QMenu(self)
                action = QAction(
                    "close",
                    self,
                    triggered=lambda: self.__evt_close_tab_click(index))
                action.setEnabled(self.count() > 1 and index is not 0)
                menu.addAction(action)

                action = QAction(
                    "close others",
                    self,
                    triggered=lambda: self.__evt_contextMenuCloseOthers(index))
                action.setEnabled(self.count() > 1)
                menu.addAction(action)

                action = QAction(
                    "close all",
                    self,
                    triggered=lambda: self.__evt_contextMenuCloseOthers(0))
                action.setEnabled(self.count() > 1)
                menu.addAction(action)

                menu.exec_(self.mapToGlobal(point))
示例#30
0
    def __initActions(self):
        """
        put all actions to dict , so we can use them outside
        """
        self.__editActions = {}

        self.__editActions["undo"] = QAction(
            QIcon(getPath('iconDir', 'heditor/undo.png')),
            "undo",
            self,
            triggered=lambda: self.__evt_webpage_emit(QWebPage.Undo))

        self.__editActions["redo"] = QAction(
            QIcon(getPath('iconDir', 'heditor/redo.png')),
            "redo",
            self,
            triggered=lambda: self.__evt_webpage_emit(QWebPage.Redo))

        self.__editActions["copy"] = QAction(
            QIcon(getPath('iconDir', 'heditor/copy.png')),
            "copy",
            self,
            triggered=lambda: self.__evt_webpage_emit(QWebPage.Copy))

        self.__editActions["selectall"] = QAction(
            QIcon(getPath('iconDir', 'heditor/selectall.png')),
            "Select All",
            self,
            triggered=lambda: self.__evt_webpage_emit(QWebPage.SelectAll))

        self.__editActions["cut"] = QAction(
            QIcon(getPath('iconDir', 'heditor/cut.png')),
            "cut",
            self,
            triggered=lambda: self.__evt_webpage_emit(QWebPage.Cut))

        self.__editActions["paste"] = QAction(
            QIcon(getPath('iconDir', 'heditor/paste_plain.png')),
            "paste",
            self,
            triggered=lambda: self.__evt_webpage_emit(QWebPage.
                                                      PasteAndMatchStyle))

        self.__editActions["removeformat"] = QAction(
            QIcon(getPath('iconDir', 'heditor/removeformat.png')),
            "removeformat",
            self,
            triggered=lambda: self.__evt_webpage_emit(QWebPage.RemoveFormat))

        self.__editActions["bold"] = QAction(
            QIcon(getPath('iconDir', 'heditor/text_bold.png')),
            "bold",
            self,
            triggered=lambda: self.__evt_webpage_emit(QWebPage.ToggleBold))

        self.__editActions["italic"] = QAction(
            QIcon(getPath('iconDir', 'heditor/text_italic.png')),
            "italic",
            self,
            triggered=lambda: self.__evt_webpage_emit(QWebPage.ToggleItalic))

        self.__editActions["underline"] = QAction(
            QIcon(getPath('iconDir', 'heditor/text_underline.png')),
            "underline",
            self,
            triggered=lambda: self.__evt_webpage_emit(QWebPage.ToggleUnderline
                                                      ))

        self.__editActions["strikethrough"] = QAction(QIcon(getPath("iconDir", "heditor/strikethrough.png")),"strikethrough",\
                                        self,triggered=lambda:self.__evt_webpage_emit(QWebPage.ToggleStrikethrough))

        self.__editActions["subscript"] = QAction(QIcon(getPath("iconDir", "heditor/subscript.png")),"subscript",\
                                        self,triggered=lambda:self.__evt_webpage_emit(QWebPage.ToggleSubscript))

        self.__editActions["superscript"] = QAction(QIcon(getPath("iconDir", "heditor/superscript.png")),"superscript",\
                                        self,triggered=lambda:self.__evt_webpage_emit(QWebPage.ToggleSuperscript))

        self.__editActions["left"] = QAction(
            QIcon(getPath('iconDir', 'heditor/text_align_left.png')),
            "left",
            self,
            triggered=lambda: self.__evt_webpage_emit(QWebPage.AlignLeft))

        self.__editActions["center"] = QAction(
            QIcon(getPath('iconDir', 'heditor/text_align_center.png')),
            "center",
            self,
            triggered=lambda: self.__evt_webpage_emit(QWebPage.AlignCenter))

        self.__editActions["right"] = QAction(
            QIcon(getPath('iconDir', 'heditor/text_align_right.png')),
            "right",
            self,
            triggered=lambda: self.__evt_webpage_emit(QWebPage.AlignRight))

        self.__editActions["justify"] = QAction(
            QIcon(getPath('iconDir', 'heditor/text_align_justify.png')),
            "justify",
            self,
            triggered=lambda: self.__evt_webpage_emit(QWebPage.AlignJustified))

        self.__editActions["indent"] = QAction(
            QIcon(getPath('iconDir', 'heditor/text_indent.png')),
            "indent",
            self,
            triggered=lambda: self.__evt_webpage_emit(QWebPage.Indent))

        self.__editActions["outdent"] = QAction(
            QIcon(getPath('iconDir', 'heditor/text_indent_remove.png')),
            "outdent",
            self,
            triggered=lambda: self.__evt_webpage_emit(QWebPage.Outdent))

        self.__editActions["linkpage"] = QAction(
            QIcon(getPath('iconDir', 'heditor/linkpage.png')),
            "link page",
            self,
            triggered=lambda: LinkDialog(self).show())

        self.__editActions["image"] = QAction(
            QIcon(getPath('iconDir', 'heditor/image.png')),
            "insert image",
            self,
            triggered=lambda: ImageDialog(self).show())

        self.__editActions["orderedlist"] = QAction(
            QIcon(getPath('iconDir', 'heditor/orderedlist.png')),
            "InsertOrderedList",
            self,
            triggered=lambda: self.__evt_webpage_emit(QWebPage.
                                                      InsertOrderedList))

        self.__editActions["unorderedlist"] = QAction(
            QIcon(getPath('iconDir', 'heditor/unorderedlist.png')),
            "InsertUnorderedList",
            self,
            triggered=lambda: self.__evt_webpage_emit(QWebPage.
                                                      InsertUnorderedList))

        self.__editActions["h1"] = QAction(
            QIcon(getPath('iconDir', 'heditor/h1.png')),
            "H1",
            self,
            triggered=lambda: self.__evt_formatblock(1))

        self.__editActions["h2"] = QAction(
            QIcon(getPath('iconDir', 'heditor/h2.png')),
            "H2",
            self,
            triggered=lambda: self.__evt_formatblock(2))

        self.__editActions["h3"] = QAction(
            QIcon(getPath('iconDir', 'heditor/h3.png')),
            "H3",
            self,
            triggered=lambda: self.__evt_formatblock(3))

        self.__editActions["htmlclean"] = QAction(
            QIcon(getPath('iconDir', 'heditor/html.png')),
            "Clean HTML",
            self,
            triggered=self.__evt_cleanhtml)

        self.__editActions["table"] = RichHtmlTableAction(self)

        self.__editActions["fgcolor"] = RichHtmlColorSelectorAction(self)

        action = RichHtmlColorSelectorAction(self, "backcolor")
        action.setIcon(QIcon(getPath('iconDir', 'heditor/paintcan.png')))
        action.setText("bgcolor")
        self.__editActions["bgcolor"] = action

        #Make sure the menu can show their icons
        for key in self.__editActions.keys():
            self.__editActions[key].setIconVisibleInMenu(True)
            self.__editActions[key].setCheckable(True)
        #below actions are not checkable
        for key in ["table", "fgcolor", "bgcolor", "image", "linkpage"]:
            self.__editActions[key].setCheckable(False)
示例#31
0
    def contextMenuEvent(self, e):
        """
        right click . table oprerators etc...
        """
        menu = QMenu(self)

        tag = self.page().mainFrame().hitTestContent(e.pos()).element()

        #some table operations
        if tag and tag.tagName().lower() == "td":
            hasPre = tag.parent().previousSibling().tagName().lower() == "tr"
            hasNext = tag.parent().nextSibling().tagName().lower() == "tr"
            #move up
            action = QAction(QIcon(getPath('iconDir', 'heditor/row_up.png')),
                             "Move row up",
                             self,
                             triggered=lambda: self._table_tr_moveup(tag))
            action.setDisabled(not hasPre)
            action.setIconVisibleInMenu(True)
            menu.addAction(action)
            #move down
            action = QAction(QIcon(getPath('iconDir', 'heditor/row_down.png')),
                             "Move row down",
                             self,
                             triggered=lambda: self._table_tr_movedown(tag))
            action.setDisabled(not hasNext)
            action.setIconVisibleInMenu(True)
            menu.addAction(action)

            menu.addAction(
                QAction("Copy row to above",
                        self,
                        triggered=lambda: self._table_tr_insert_above(tag)))
            menu.addAction(
                QAction("Copy row to below",
                        self,
                        triggered=lambda: self._table_tr_insert_below(tag)))
            menu.addAction(
                QAction(QIcon(getPath('iconDir', 'heditor/col_left.png')),
                        "Insert column left",
                        self,
                        triggered=lambda: self._table_column_left(tag)))
            menu.addAction(
                QAction(QIcon(getPath('iconDir', 'heditor/col_right.png')),
                        "Insert column right",
                        self,
                        triggered=lambda: self._table_column_right(tag)))

            action = QAction("Delete row",
                             self,
                             triggered=lambda: self._table_tr_remove(tag))
            action.setDisabled(not hasPre and not hasNext)
            menu.addAction(action)

            menu.addAction(
                QAction("Delete column",
                        self,
                        triggered=lambda: self._table_column_remove(tag)))

            action = QAction("Set Table Style",
                             self,
                             triggered=lambda: self._table_style_change(tag))
            menu.addAction(action)

            action = QAction(QIcon(getPath('iconDir', 'heditor/delete.png')),
                             "Delete table",
                             self,
                             triggered=lambda: self._table_delete(tag))
            action.setIconVisibleInMenu(True)
            menu.addAction(action)

            menu.addSeparator()

        #Common content menu
        menu.addAction(self.__editActions["selectall"])
        menu.addAction(self.__editActions["copy"])
        menu.addAction(self.__editActions["cut"])
        menu.addAction(self.__editActions["paste"])
        menu.addSeparator()

        menuEdit = QMenu("Edit")
        menuEdit.addAction(self.__editActions["bold"])
        menuEdit.addAction(self.__editActions["italic"])
        menuEdit.addAction(self.__editActions["underline"])
        menuEdit.addAction(self.__editActions["strikethrough"])
        menuEdit.addAction(self.__editActions["removeformat"])
        menuEdit.addSeparator()
        menuEdit.addAction(self.__editActions["left"])
        menuEdit.addAction(self.__editActions["center"])
        menuEdit.addAction(self.__editActions["right"])
        menuEdit.addAction(self.__editActions["justify"])
        menuEdit.addSeparator()
        menuEdit.addAction(self.__editActions["indent"])
        menuEdit.addAction(self.__editActions["outdent"])
        menuEdit.addAction(self.__editActions["subscript"])
        menuEdit.addAction(self.__editActions["superscript"])

        menu.addMenu(menuEdit)
        menu.addSeparator()

        menuInsert = QMenu("Insert")
        menuInsert.addAction(self.__editActions["image"])
        menuInsert.addAction(self.__editActions["table"])
        menuInsert.addAction(self.__editActions["linkpage"])

        menu.addMenu(menuInsert)

        menu.exec_(e.globalPos())
示例#32
0
class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, app = None):
        QMainWindow.__init__(self, None)
        self.setupUi(self)

        self.app = app
        self.iface = backend.pm.Iface()

        self.busy = QProgressIndicator(self)
        self.busy.setFixedSize(QSize(20, 20))

        self.setWindowIcon(QIcon(":/data/package-manager.png"))

        self.setCentralWidget(MainWidget(self))
        self.cw = self.centralWidget()

        self.settingsDialog = SettingsDialog(self)

        self.initializeActions()
        self.initializeStatusBar()
        self.initializeTray()
        self.connectMainSignals()

        self.pdsMessageBox = PMessageBox(self)

    def connectMainSignals(self):
        self.cw.connectMainSignals()
        self.connect(QShortcut(QKeySequence(Qt.CTRL + Qt.Key_Tab),self),
                SIGNAL("activated()"), lambda: self.moveTab('next'))
        self.connect(QShortcut(QKeySequence(Qt.SHIFT + Qt.CTRL + Qt.Key_Tab),self),
                SIGNAL("activated()"), lambda: self.moveTab('prev'))
        self.connect(QShortcut(QKeySequence(Qt.CTRL + Qt.Key_F),self),
                SIGNAL("activated()"), self.cw.searchLine.setFocus)
        self.connect(QShortcut(QKeySequence(Qt.Key_F3),self),
                SIGNAL("activated()"), self.cw.searchLine.setFocus)

        self.connect(self.settingsDialog, SIGNAL("packagesChanged()"), self.cw.initialize)
        self.connect(self.settingsDialog, SIGNAL("packageViewChanged()"), self.cw.updateSettings)
        self.connect(self.settingsDialog, SIGNAL("traySettingChanged()"), self.tray.settingsChanged)
        self.connect(self.cw.state, SIGNAL("repositoriesChanged()"), self.tray.populateRepositoryMenu)
        self.connect(self.cw, SIGNAL("repositoriesUpdated()"), self.tray.updateTrayUnread)
        self.connect(qApp, SIGNAL("shutDown()"), self.slotQuit)

    def moveTab(self, direction):
        new_index = self.cw.stateTab.currentIndex() - 1
        if direction == 'next':
            new_index = self.cw.stateTab.currentIndex() + 1
        if new_index not in range(self.cw.stateTab.count()):
            new_index = 0
        self.cw.stateTab.setCurrentIndex(new_index)

    def initializeTray(self):
        self.tray = Tray(self, self.iface)
        self.connect(self.cw.operation, SIGNAL("finished(QString)"), self.trayAction)
        self.connect(self.cw.operation, SIGNAL("finished(QString)"), self.tray.stop)
        self.connect(self.cw.operation, SIGNAL("operationCancelled()"), self.tray.stop)
        self.connect(self.cw.operation, SIGNAL("started(QString)"), self.tray.animate)
        self.connect(self.tray, SIGNAL("showUpdatesSelected()"), self.trayShowUpdates)

    def trayShowUpdates(self):
        self.showUpgradeAction.setChecked(True)

        self.cw.switchState(StateManager.UPGRADE)

        KApplication.kApplication().updateUserTimestamp()

        self.show()
        self.raise_()

    def trayAction(self, operation):
        if not self.isVisible() and operation in ["System.Manager.updateRepository", "System.Manager.updateAllRepositories"]:
            self.tray.showPopup()
        if self.tray.isVisible() and operation in ["System.Manager.updatePackage",
                                                   "System.Manager.installPackage",
                                                   "System.Manager.removePackage"]:
            self.tray.updateTrayUnread()

    def initializeStatusBar(self):
        self.cw.mainLayout.insertWidget(0, self.busy)
        self.statusBar().addPermanentWidget(self.cw.actions, 1)
        self.statusBar().show()

        self.updateStatusBar('')

        self.connect(self.cw, SIGNAL("selectionStatusChanged(QString)"), self.updateStatusBar)
        self.connect(self.cw, SIGNAL("updatingStatus()"), self.statusWaiting)

    def initializeActions(self):
        self.initializeOperationActions()

    def initializeOperationActions(self):

        self.showAllAction = QAction(KIcon(("applications-other", "package_applications")), i18n("All Packages"), self)
        self.connect(self.showAllAction, SIGNAL("triggered()"), lambda:self.cw.switchState(StateManager.ALL))
        self.cw.stateTab.addTab(QWidget(), KIcon(("applications-other", "package_applications")), i18n("All Packages"))

        self.showInstallAction = QAction(KIcon(("list-add", "add")), i18n("Installable Packages"), self)
        self.connect(self.showInstallAction, SIGNAL("triggered()"), lambda:self.cw.switchState(StateManager.INSTALL))
        self.cw.stateTab.addTab(QWidget(), KIcon(("list-add", "add")), i18n("Installable Packages"))

        self.showRemoveAction = QAction(KIcon(("list-remove", "remove")), i18n("Installed Packages"), self)
        self.connect(self.showRemoveAction, SIGNAL("triggered()"), lambda:self.cw.switchState(StateManager.REMOVE))
        self.cw.stateTab.addTab(QWidget(), KIcon(("list-remove", "remove")), i18n("Installed Packages"))

        self.showUpgradeAction = QAction(KIcon(("system-software-update", "gear")), i18n("Updates"), self)
        self.connect(self.showUpgradeAction, SIGNAL("triggered()"), lambda:self.cw.switchState(StateManager.UPGRADE))
        self.cw.stateTab.addTab(QWidget(), KIcon(("system-software-update", "gear")), i18n("Updates"))

        self.showPreferences = QAction(KIcon(("preferences-system", "package_settings")), i18n("Settings"), self)
        self.connect(self.showPreferences, SIGNAL("triggered()"), self.settingsDialog.show)

        self.actionHelp = QAction(KIcon("help"), i18n("Help"), self)
        self.actionHelp.setShortcuts(QKeySequence.HelpContents)
        self.connect(self.actionHelp, SIGNAL("triggered()"), self.showHelp)

        self.actionQuit = QAction(KIcon("exit"), i18n("Quit"), self)
        self.actionQuit.setShortcuts(QKeySequence.Quit)
        self.connect(self.actionQuit, SIGNAL("triggered()"), qApp.exit)

        self.cw.menuButton.setMenu(QMenu('MainMenu', self.cw.menuButton))
        self.cw.menuButton.setIcon(KIcon(("preferences-system", "package_settings")))
        self.cw.menuButton.menu().clear()

        self.cw.contentHistory.hide()

        self.cw.menuButton.menu().addAction(self.showPreferences)
        self.cw.menuButton.menu().addSeparator()
        self.cw.menuButton.menu().addAction(self.actionHelp)
        self.cw.menuButton.menu().addAction(self.actionQuit)

        self.cw._states = {self.cw.state.ALL    :(0, self.showAllAction),
                           self.cw.state.INSTALL:(1, self.showInstallAction),
                           self.cw.state.REMOVE :(2, self.showRemoveAction),
                           self.cw.state.UPGRADE:(3, self.showUpgradeAction)}

        self.showAllAction.setChecked(True)
        self.cw.checkUpdatesButton.hide()
        self.cw.checkUpdatesButton.setIcon(KIcon(("view-refresh", "reload")))
        self.cw.showBasketButton.clicked.connect(self.cw.showBasket)

        # Little time left for the new ui
        self.menuBar().setVisible(False)
        self.cw.switchState(self.cw.state.ALL)

    def statusWaiting(self):
        self.updateStatusBar(i18n('Calculating dependencies...'), busy = True)

    def showHelp(self):
        self.Pds = pds.Pds()
        self.lang = localedata.setSystemLocale(justGet = True)

        if self.lang in os.listdir("/usr/share/package-manager/help"):
            pass
        else:
            self.lang = "en"

        if self.Pds.session == pds.Kde3 :
            os.popen("khelpcenter /usr/share/package-manager/help/%s/main_help.html" %(self.lang))
        else:
            helpdialog.HelpDialog(self,helpdialog.MAINAPP)


    def updateStatusBar(self, text, busy = False):
        if text == '':
            text = i18n("Currently your basket is empty.")
            self.busy.hide()
            self.cw.showBasketButton.hide()
        else:
            self.cw.showBasketButton.show()

        if busy:
            self.busy.busy()
            self.cw.showBasketButton.hide()
        else:
            self.busy.hide()

        self.cw.statusLabel.setText(text)
        self.cw.statusLabel.setToolTip(text)

    def queryClose(self):
        if config.PMConfig().systemTray():
            self.hide()
            return False
        return True

    def queryExit(self):
        if not self.iface.operationInProgress():
            if self.tray:
                del self.tray.notification
            return True
        return False

    def slotQuit(self):
        if self.iface.operationInProgress():
            return
示例#33
0
class SimpleRichText(QTextEdit):
    def __init__(self, focusin, focusout):
        QTextEdit.__init__(self)        
        self.focusin = focusin
        self.focusout = focusout
        self.createActions()

        #self.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)

    def focusOutEvent ( self, event ):
        #print "focus out"
        self.focusout()

    def focusInEvent ( self, event ):        
        self.focusin()


    def closeEvent(self, event):
        event.accept()        

    def createActions(self):
        self.boldAct = QAction(self.tr("&Bold"), self)
        self.boldAct.setCheckable(True)
        self.boldAct.setShortcut(self.tr("Ctrl+B"))
        self.boldAct.setStatusTip(self.tr("Make the text bold"))
        self.connect(self.boldAct, SIGNAL("triggered()"), self.setBold)
        self.addAction(self.boldAct)

        boldFont = self.boldAct.font()
        boldFont.setBold(True)
        self.boldAct.setFont(boldFont)

        self.italicAct = QAction(self.tr("&Italic"), self)
        self.italicAct.setCheckable(True)
        self.italicAct.setShortcut(self.tr("Ctrl+I"))
        self.italicAct.setStatusTip(self.tr("Make the text italic"))
        self.connect(self.italicAct, SIGNAL("triggered()"), self.setItalic)
        self.addAction(self.italicAct)

    def setBold(self):
        format = QTextCharFormat()
        if self.boldAct.isChecked():
            weight = QFont.Bold
        else:
            weight = QFont.Normal
        format.setFontWeight(weight)
        self.setFormat(format)

    def setItalic(self):
        format = QTextCharFormat()
        #format.setFontItalic(self.__italic.isChecked())
        format.setFontItalic(self.italicAct.isChecked())
        self.setFormat(format)

    def setUnderline(self):
        format = QTextCharFormat()
        format.setFontUnderline(self.__underline.isChecked())
        self.setFormat(format)

    def setFormat(self, format):
        self.textCursor().mergeCharFormat(format)
        self.mergeCurrentCharFormat(format)

    def bold(self):
        print("bold")

    def italic(self):
        print("italic")
示例#34
0
    def test_tool_grid(self):
        w = ToolGrid()

        w.show()
        self.app.processEvents()

        def buttonsOrderedVisual():
            # Process layout events so the buttons have right positions
            self.app.processEvents()
            buttons = w.findChildren(QToolButton)
            return list(sorted(buttons, key=lambda b: (b.y(), b.x())))

        def buttonsOrderedLogical():
            return list(map(w.buttonForAction, w.actions()))

        def assertOrdered():
            self.assertSequenceEqual(buttonsOrderedLogical(),
                                     buttonsOrderedVisual())

        action_a = QAction("A", w)
        action_b = QAction("B", w)
        action_c = QAction("C", w)
        action_d = QAction("D", w)

        w.addAction(action_b)
        w.insertAction(0, action_a)
        self.assertSequenceEqual(w.actions(), [action_a, action_b])
        assertOrdered()

        w.addAction(action_d)
        w.insertAction(action_d, action_c)

        self.assertSequenceEqual(w.actions(),
                                 [action_a, action_b, action_c, action_d])
        assertOrdered()

        w.removeAction(action_c)
        self.assertSequenceEqual(w.actions(), [action_a, action_b, action_d])

        assertOrdered()

        w.removeAction(action_a)
        self.assertSequenceEqual(w.actions(), [action_b, action_d])

        assertOrdered()

        w.insertAction(0, action_a)
        self.assertSequenceEqual(w.actions(), [action_a, action_b, action_d])

        assertOrdered()

        w.setColumnCount(2)
        self.assertSequenceEqual(w.actions(), [action_a, action_b, action_d])

        assertOrdered()

        w.insertAction(2, action_c)
        self.assertSequenceEqual(w.actions(),
                                 [action_a, action_b, action_c, action_d])
        assertOrdered()

        w.clear()
        # test no 'before' action edge case
        w.insertAction(0, action_a)
        self.assertIs(action_a, w.actions()[0])
        w.insertAction(1, action_b)
        self.assertSequenceEqual(w.actions(), [action_a, action_b])

        w.clear()
        w.setActions([action_a, action_b, action_c, action_d])
        self.assertSequenceEqual(w.actions(),
                                 [action_a, action_b, action_c, action_d])
        assertOrdered()

        triggered_actions = []

        def p(action):
            print(action.text())

        w.actionTriggered.connect(p)
        w.actionTriggered.connect(triggered_actions.append)
        action_a.trigger()

        w.show()
        self.app.exec_()