コード例 #1
0
ファイル: hdftreewidget.py プロジェクト: whigg/h5browse
 def showContextMenu(self, point):
     menu = QtGui.QMenu()
     if isinstance(self.model().getItem(self.currentIndex()), EditableItem):
         menu.addAction(self.insertDatasetAction)
         menu.addAction(self.insertGroupAction)
         menu.addAction(self.deleteNodeAction)
     menu.exec_(self.mapToGlobal(point))
コード例 #2
0
    def _menu(self, pos):
        index = self.indexAt(pos)
        if index.isValid():
            node = index.internalPointer()
            menu = QtGui.QMenu()

            removeAttribute = None
            addAttribute = None
            addChild = None
            addParent = None
            remove = None
            delete = None

            if isinstance(node, AttributeNode):
                removeAttribute = menu.addAction(self.tr('Remove Attribute'))
            elif isinstance(node, ElementNode):
                addAttribute = menu.addAction(self.tr("Add Attribute"))
                addChild = menu.addAction(self.tr("Add Child"))
                addParent = menu.addAction(self.tr("Add Parent"))
                remove = menu.addAction(self.tr("Remove"))
                delete = menu.addAction(self.tr("Delete"))

            foo = menu.exec_(self.viewport().mapToGlobal(pos))
            if foo is not None:
                if foo is removeAttribute:
                    parentIndex = self.model().parent(index)
                    self.model().removeAttribute(parentIndex, node.key)
                elif foo is addAttribute:
                    attributeName = 'NewAttribute'
                    self.model().addAttribute(index, attributeName, '')
                elif foo is addChild:
                    self.model().addChildElement(index)
                elif foo is addParent:
                    self.model().addParentElement(index)
                elif foo is remove:
                    self.model().removeElement(index)
                elif foo is delete:
                    self.model().deleteElement(index)
コード例 #3
0
    def __init__(self, *args, **kwds):
        pg.ViewBox.__init__(self, *args, **kwds)

        def addAction(text, parentMenu, triggered, insertBefore=None):
            action = QtGui.QAction(text, parentMenu)
            action.triggered.connect(triggered)
            if insertBefore:
                parentMenu.insertAction(insertBefore, action)
            else:
                parentMenu.addAction(action)

        insertBefore = self.menu.actions()[0]
        insertBefore.setText(
            'View &All')  # Add keyboard shortcut to the View All option

        def addSeperator():
            action = QtGui.QAction('', self.menu)
            action.setSeparator(True)
            self.menu.insertAction(insertBefore, action)

        self.menuSearch = QtGui.QMenu('&Search Markets', self.menu)
        self.menu.insertMenu(insertBefore, self.menuSearch)

        action = QtGui.QAction('&All', self.menuSearch)
        action.triggered.connect(lambda _: self.cg.openSearchMenu(None))
        self.menuSearch.addAction(action)
        for exchange in sorted(exchanges.EXCHANGES, key=lambda e: e.name):
            if exchange.__class__.__base__ != exchanges.ExchangeWithSearch:
                continue
            addAction(exchange.nameWithShortcut,
                      self.menuSearch,
                      lambda _, e=exchange: self.cg.openSearchMenu(e))

        def openWatchlist():
            watchlist = self.cg.watchlist = watchlists.WatchlistWindow(self.cg)
            # Default position of watchlist at top right or parent chart window
            geo = watchlist.geometry()
            parentGeo = self.cg.window.geometry().topRight()
            geo.moveTo(parentGeo)
            watchlist.setGeometry(geo)
            watchlist.show()
            watchlist.startWatchlist()

        addAction('Open Watch&list', self.menu, openWatchlist, insertBefore)

        addSeperator()

        # Add interval submenu to context menu
        timeframeMenu = QtGui.QMenu('&Timeframe', self.menu)

        # Create the interval options depending on what chart group we are looking at.
        def onTimeframeMenuShow():
            timeframeMenu.clear()
            data = self.cg.data
            if not data.count():
                return
            intervals = data.exchange.intervals
            sortedBySeconds = sorted(intervals,
                                     key=lambda i: intervalSeconds(i))
            lastIntervalLetter = ''
            for timeframe in sortedBySeconds:
                interval = timeframe
                if interval == '5m':
                    interval = '&5m'
                elif interval[-1] != lastIntervalLetter:
                    lastIntervalLetter = interval[-1]
                    interval = interval[:-1] + '&' + lastIntervalLetter
                addAction(interval,
                          timeframeMenu,
                          lambda _, timeframe=timeframe: self.cg.
                          changeTimeInterval(timeframe))

        timeframeMenu.aboutToShow.connect(onTimeframeMenuShow)
        self.menu.insertMenu(insertBefore, timeframeMenu)

        # Add links submenu to context menu
        linksMenu = QtGui.QMenu('Links', self.menu)

        def onLinksMenuShow():
            linksMenu.clear()
            for desc, url in sorted(self.cg.links.items()):
                addAction(desc,
                          linksMenu,
                          lambda _, url=url: QtGui.QDesktopServices.openUrl(
                              QtCore.QUrl(url)))

        linksMenu.aboutToShow.connect(onLinksMenuShow)
        self.menu.insertMenu(insertBefore, linksMenu)

        # Add resample submenu to context menu
        resampleMenu = QtGui.QMenu('R&esample Time', self.menu)

        def onResampleMenuShow():
            resampleMenu.clear()
            data = self.cg.data
            if not data.count():
                return

            resampleTable = {
                '4&h': ['m', 'h'],
                '1&w': ['d'],
                '1&M': ['d'],
                '1&d': ['h']
            }
            for toTime, fromTime in resampleTable.items():
                if data.timeframe[-1] in fromTime:
                    addAction(toTime,
                              resampleMenu,
                              lambda _, toTime=toTime: self.cg.resampleData(
                                  toTime.replace('&', '')))

        resampleMenu.aboutToShow.connect(onResampleMenuShow)
        self.menu.insertMenu(insertBefore, resampleMenu)

        optionsMenu = QtGui.QMenu('Chart &Options', self.menu)
        self.menu.insertMenu(insertBefore, optionsMenu)

        def addToggle(showMember, text):
            def toggle(cg, showMember):
                showVar = 'show' + showMember
                value = not getattr(cg, showVar)
                setattr(cg, showVar, value)
                gSettings.setValue(showVar, value)
                if value and showMember == 'Orderwall':
                    # Toggling the orderwall requires downloading the orderbook
                    cg.downloadNewData()
                else:
                    cg.reAddPlotItems()

            addAction(text, optionsMenu, lambda: toggle(self.cg, showMember))

        for var, desc in SHOW_OPTIONS:
            addToggle(var, desc)

        addAction('&Refresh Chart', self.menu,
                  lambda: self.cg.downloadNewData(), insertBefore)

        addSeperator()

        def newChart(cg, incRowOrCol):
            newCoord = [cg.coord[0], cg.coord[1]]
            newCoord[incRowOrCol] += 1
            cg.window.setChartAt(None, newCoord)

        addAction('New Chart &Horizontally', self.menu,
                  lambda: newChart(self.cg, COL), insertBefore)
        addAction('New Chart &Vertically', self.menu,
                  lambda: newChart(self.cg, ROW), insertBefore)

        addAction('Co&py Chart', self.menu,
                  lambda: self.cg.copyMarketToAdjacentChart(None),
                  insertBefore)
        addAction('&Close Chart', self.menu,
                  lambda: self.cg.window.removeChart(self.cg), insertBefore)

        addSeperator()