Esempio n. 1
0
 def showWebPreview(self):
     """ Show web preview
         and stop timer
     """
     self.web = WebPreviewWidget(self)
     self.web.webpreview.load(self.url)
     self.web.show()
     self.web.move(QtGui.QCursor.pos())
     self.timer.stop()
Esempio n. 2
0
class TreeView(QtGui.QTreeView):
    def __init__(self, parent=None):
        QtGui.QTreeView.__init__(self, parent)
        self.parent = parent
        
        self.timer = QtCore.QTimer(self)
        # Load proxy
        self.proxyModel = proxyVault(self)
        # Set view properties
        self.setSortingEnabled(1)
        self.setModel(self.proxyModel)
        self.sortByColumn(0,QtCore.Qt.AscendingOrder)
        # Load context actions
        self.createActions()
        # Active mouse tracking
        self.setMouseTracking(1)
        # SIGNALS
#        self.connect(self,QtCore.SIGNAL("entered (const QModelIndex&)"), self.startTimer)
#        self.connect(self.timer, QtCore.SIGNAL("timeout ()"), self.showWebPreview)
#        self.connect(self,QtCore.SIGNAL("viewportEntered ()"), self.timerStop)

    def timerStop(self):
        """ Stop timer if mouse go
            out rows
        """
        self.timer.stop()
        if hasattr(self,"web"):
            self.web.close()

    def showWebPreview(self):
        """ Show web preview
            and stop timer
        """
        self.web = WebPreviewWidget(self)
        self.web.webpreview.load(self.url)
        self.web.show()
        self.web.move(QtGui.QCursor.pos())
        self.timer.stop()
    
    def startTimer(self, index):
        """ Timer management
        """
        if hasattr(self,"web"):
            self.web.close()
        self.url = QtCore.QUrl(index.data().toString())
        if self.url.scheme().startsWith("http") and self.url.isValid():
            if self.timer.isActive():
                self.timer.stop()
            self.timer.start(500)
        else:
            self.timer.stop()


    def setGeometries(self):
        """
            Set headers size
        """
        h = self.header()
        h.setResizeMode(0, QtGui.QHeaderView.Stretch)
        h.setStretchLastSection(0)
        self.setColumnWidth(1,65)

    def search(self, research, groups_ids=None):
        # Get minimum number of caracters to search
        minsearch = self.parent.settings.value("SFLvault-qt4/minsearch").toInt()[0]
        # Test if research if not null or if it contains just empty unicode
        if research and not research == [u'']:
            # Join all research words
            research_length = len("".join(research))
            # If not null, test if the length if < minsearch
            if research_length < minsearch:
                # If yes, do nothing
                return None
        # Load model
        self.sourcemodel = TreeModel(research, groups_ids, self)
        # Load proxy
        self.proxyModel.setSourceModel(self.sourcemodel)
        if research and not research == [u''] :
            self.expandAll()
        else:
            self.collapseAll()
        # Sort by name
        self.sortByColumn(0)

    def contextMenuEvent(self, event):
        """
            Create contextMenu on right click
        """
        if len(self.selectedIndexes()) < 1:
            return event.ignore()
        menu = QtGui.QMenu(self)
        if self.selectedIndexes()[0].parent().parent().isValid():
            menu.addAction(self.connectAct)
            menu.addAction(self.showAct)
            menu.addAction(self.editAct)
            menu.addAction(self.bookmarkAct)
            index = self.selectedIndexes()[0]
            self.url = QtCore.QUrl(index.data().toString())
            if self.url.scheme() == "ssh":
                menu.addAction(self.tunnelAct)
        elif self.selectedIndexes()[0].parent().isValid():
            menu.addAction(self.newServiceAct)
            menu.addAction(self.editAct)
        elif self.selectedIndexes()[0].isValid():
            menu.addAction(self.newMachineAct)
            menu.addAction(self.editAct)
        menu.addAction(self.delAct)
        menu.exec_(event.globalPos())

    def createActions(self):
        """
            Create actions for contextMenu
        """
        self.newMachineAct = QtGui.QAction(self.tr("New machine"), self)
        self.newMachineAct.setStatusTip(self.tr("New machine"))

        self.newServiceAct = QtGui.QAction(self.tr("New service"), self)
        self.newServiceAct.setStatusTip(self.tr("New service"))

        self.newAct = QtGui.QAction(self.tr("&New..."), self)
        self.newAct.setShortcut(self.tr("Ctrl+N"))
        self.newAct.setStatusTip(self.tr("New item"))

        self.connectAct = QtGui.QAction(self.tr("&Connect..."), self)
#        self.connectAct.setShortcut(self.tr("Ctrl+D"))
        self.connectAct.setStatusTip(self.tr("Connect to this service or show password"))

        self.showAct = QtGui.QAction(self.tr("&Show password"), self)
        self.showAct.setStatusTip(self.tr("Show password of this service"))

        self.editAct = QtGui.QAction(self.tr("&Edit..."), self)
        self.editAct.setShortcut(self.tr("Ctrl+E"))
        self.editAct.setStatusTip(self.tr("Edit item"))

        self.bookmarkAct = QtGui.QAction(self.tr("&Create alias..."), self)
        self.bookmarkAct.setShortcut(self.tr("Ctrl+D"))
        self.bookmarkAct.setStatusTip(self.tr("Create an alias from this item"))

        self.tunnelAct = QtGui.QAction(self.tr("&Create tunnel..."), self)
        self.tunnelAct.setStatusTip(self.tr("Create a ssh connection with tunnel"))

        self.delAct = QtGui.QAction(self.tr("&Delete..."), self)
        self.delAct.setStatusTip(self.tr("Delete item"))

    def filter(self, pattern):
        """
            Filter and expand
        """
        self.proxyModel.setFilterRegExp(pattern)
        self.expandAll()
        # Sort by name
        self.sortByColumn(0)
        
    def expandCollapse(self):
        """
            Expand or collapse selected item
        """
        indexes = self.selectedIndexes()
        # Check if an item if selected
        if indexes:
            # Check if is a node
            if indexes[0].child(0,0).isValid():
                if self.isExpanded(indexes[0]):
                    self.collapse(indexes[0])
                else:
                    self.expand(indexes[0])

    def enterShortcut(self):
        """
            Expand-collapse if selected item is a customer/machine
            Launch connection if service
        """
        indexes = self.selectedIndexes()
        # Check if an item if selected
        if indexes:
            # if item is a service
            if indexes[0].parent().parent().isValid():
                self.parent.GetIdByTree(indexes[0])
            # if item is a customer or machine
            else:
                self.expandCollapse()