Ejemplo n.º 1
0
    def __init__(self, parent, document):
        VeuszDialog.__init__(self, parent, 'dataedit.ui')
        self.document = document

        # set up dataset list
        self.dsbrowser = DatasetBrowser(document, parent, parent)
        self.splitter.insertWidget(0, self.dsbrowser)

        # actions for data table
        for text, slot in (
            (_('Copy'), self.slotCopy),
            (_('Delete row'), self.slotDeleteRow),
            (_('Insert row'), self.slotInsertRow),
        ):
            act = qt4.QAction(text, self)
            self.connect(act, qt4.SIGNAL('triggered()'), slot)
            self.datatableview.addAction(act)
        self.datatableview.setContextMenuPolicy(qt4.Qt.ActionsContextMenu)

        # layout edit dialog improvement
        self.splitter.setStretchFactor(0, 3)
        self.splitter.setStretchFactor(1, 4)

        # don't want text to look editable or special
        self.linkedlabel.setFrameShape(qt4.QFrame.NoFrame)
        self.linkedlabel.viewport().setBackgroundRole(qt4.QPalette.Window)

        # document changes
        self.connect(document, qt4.SIGNAL('sigModified'),
                     self.slotDocumentModified)

        # select first item, if any or initialise if none
        if len(self.document.data) > 0:
            self.selectDataset(sorted(self.document.data.keys())[0])
        else:
            self.slotDatasetSelected("")

        self.connect(self.dsbrowser.navtree, qt4.SIGNAL("selecteditem"),
                     self.slotDatasetSelected)

        # connect buttons
        for btn, slot in (
            (self.deletebutton, self.slotDatasetDelete),
            (self.unlinkbutton, self.slotDatasetUnlink),
            (self.duplicatebutton, self.slotDatasetDuplicate),
            (self.importbutton, self.slotDatasetImport),
            (self.createbutton, self.slotDatasetCreate),
            (self.editbutton, self.slotDatasetEdit),
        ):
            self.connect(btn, qt4.SIGNAL('clicked()'), slot)

        # menu for new button
        self.newmenu = qt4.QMenu()
        for text, slot in ((_('Numerical dataset'),
                            self.slotNewNumericalDataset),
                           (_('Text dataset'), self.slotNewTextDataset),
                           (_('Date/time dataset'), self.slotNewDateDataset)):
            a = self.newmenu.addAction(text)
            self.connect(a, qt4.SIGNAL('triggered()'), slot)
        self.newbutton.setMenu(self.newmenu)
Ejemplo n.º 2
0
    def settingMenu(self, pos):
        """Pop up menu for each setting."""

        # forces settings to be updated
        self.parentWidget().setFocus()
        # get it back straight away
        self.setFocus()

        # get widget, with its type and name
        widget = self.setting.parent
        while widget is not None and not isinstance(widget, widgets.Widget):
            widget = widget.parent
        if widget is None:
            return
        self._clickwidget = widget

        wtype = widget.typename
        name = widget.name

        popup = qt4.QMenu(self)
        popup.addAction(_('Reset to default'),
                        self.actionResetDefault)

        copyto = popup.addMenu(_('Copy to'))
        copyto.addAction(_("all '%s' widgets") % wtype,
                         self.actionCopyTypedWidgets)
        copyto.addAction(_("'%s' siblings") % wtype,
                         self.actionCopyTypedSiblings)
        copyto.addAction(_("'%s' widgets called '%s'") % (wtype, name),
                         self.actionCopyTypedNamedWidgets)
        copyto.addSeparator()
        self.addCopyToWidgets(copyto)

        popup.addAction(_('Use as default style'),
                        self.actionSetStyleSheet)

        # special actions for references
        if self.setting.isReference():
            popup.addSeparator()
            popup.addAction(_('Unlink setting'), self.actionUnlinkSetting)

        self.inmenu = True
        self.updateHighlight()
        popup.exec_(pos)
        self.inmenu = False
        self.updateHighlight()
Ejemplo n.º 3
0
    def contextMenuEvent(self, event):
        """Bring up context menu."""

        # no widgets selected
        if not self.selwidgets:
            return

        m = qt4.QMenu(self)

        # selection
        m.addMenu(self.parentwin.menus['edit.select'])
        m.addSeparator()

        # actions on widget(s)
        for act in ('edit.cut', 'edit.copy', 'edit.paste',
                    'edit.moveup', 'edit.movedown', 'edit.delete',
                    'edit.rename'):
            m.addAction(self.vzactions[act])

        # allow show or hides of selected widget
        anyhide = False
        anyshow = False
        for w in self.selwidgets:
            if 'hide' in w.settings:
                if w.settings.hide:
                    anyshow = True
                else:
                    anyhide = True

        for (enabled, menutext, showhide) in (
            (anyhide, 'Hide', True), (anyshow, 'Show', False) ):
            if enabled:
                m.addSeparator()
                act = qt4.QAction(menutext, self)
                self.connect(act, qt4.SIGNAL('triggered()'),
                             utils.BoundCaller(self.slotWidgetHideShow,
                                               self.selwidgets, showhide))
                m.addAction(act)

        m.exec_(self.mapToGlobal(event.pos()))
        event.accept()
Ejemplo n.º 4
0
    def contextMenuEvent(self, event):
        """Show context menu."""

        menu = qt4.QMenu(self)

        # add some useful entries
        menu.addAction(self.vzactions['view.zoommenu'])
        menu.addSeparator()
        menu.addAction(self.vzactions['view.prevpage'])
        menu.addAction(self.vzactions['view.nextpage'])
        menu.addSeparator()

        # force an update now menu item
        menu.addAction(_('Force update'), self.actionForceUpdate)

        if self.isfullscreen:
            menu.addAction(_('Close full screen'), self.slotFullScreen)
        else:
            menu.addAction(self.vzactions['view.fullscreen'])

        # Update policy submenu
        submenu = menu.addMenu(_('Updates'))
        intgrp = qt4.QActionGroup(self)

        # bind interval options to actions
        for intv, text in self.updateintervals:
            act = intgrp.addAction(text)
            act.setCheckable(True)
            fn = utils.BoundCaller(self.actionSetTimeout, intv)
            self.connect(act, qt4.SIGNAL('triggered(bool)'), fn)
            if intv == self.interval:
                act.setChecked(True)
            submenu.addAction(act)

        # antialias
        menu.addSeparator()
        act = menu.addAction(_('Antialias'), self.actionAntialias)
        act.setCheckable(True)
        act.setChecked(self.antialias)

        menu.exec_(qt4.QCursor.pos())
Ejemplo n.º 5
0
    def showContextMenu(self, pt):
        """Context menu for nodes."""

        # get selected nodes
        idxs = self.selectionModel().selection().indexes()
        nodes = [self.model.objFromIndex(i) for i in idxs if i.column() == 0]

        # unique list of types of nodes
        types = utils.unique([type(n) for n in nodes])

        menu = qt4.QMenu()
        # put contexts onto submenus if multiple types selected
        if DatasetNode in types:
            thismenu = menu
            if len(types) > 1:
                thismenu = menu.addMenu(_("Datasets"))
            self.datasetContextMenu(
                [n for n in nodes if isinstance(n, DatasetNode)], thismenu)
        elif FilenameNode in types:
            thismenu = menu
            if len(types) > 1:
                thismenu = menu.addMenu(_("Files"))
            self.filenameContextMenu(
                [n for n in nodes if isinstance(n, FilenameNode)], thismenu)

        def _paste():
            """Paste dataset(s)."""
            if document.isDataMime():
                mime = qt4.QApplication.clipboard().mimeData()
                self.doc.applyOperation(document.OperationDataPaste(mime))

        # if there is data to paste, add menu item
        if document.isDataMime():
            menu.addAction(_("Paste"), _paste)

        if len(menu.actions()) != 0:
            menu.exec_(self.mapToGlobal(pt))
Ejemplo n.º 6
0
    def __init__(self, *args):
        qt4.QPushButton.__init__(self, *args)

        self.menu = qt4.QMenu()
        self.setMenu(self.menu)
        self.settingname = None
Ejemplo n.º 7
0
    def createToolbar(self, parent, menu=None):
        """Make a view toolbar, and optionally update menu."""

        self.viewtoolbar = qt4.QToolBar(_("View toolbar - Veusz"), parent)
        self.viewtoolbar.setObjectName('veuszviewtoolbar')
        iconsize = setting.settingdb['toolbar_size']
        self.viewtoolbar.setIconSize(qt4.QSize(iconsize, iconsize))
        self.viewtoolbar.hide()
        if parent:
            parent.addToolBar(qt4.Qt.TopToolBarArea, self.viewtoolbar)

        if parent and hasattr(parent, 'vzactions'):
            # share actions with parent if possible
            # as plot windows can be isolated from mainwindows, we need this
            self.vzactions = actions = parent.vzactions
        else:
            self.vzactions = actions = {}

        a = utils.makeAction
        actions.update({
            'view.zoomin':
            a(self,
              _('Zoom into the plot'),
              _('Zoom &In'),
              self.slotViewZoomIn,
              icon='kde-zoom-in',
              key='Ctrl++'),
            'view.zoomout':
            a(self,
              _('Zoom out of the plot'),
              _('Zoom &Out'),
              self.slotViewZoomOut,
              icon='kde-zoom-out',
              key='Ctrl+-'),
            'view.zoom11':
            a(self,
              _('Restore plot to natural size'),
              _('Zoom 1:1'),
              self.slotViewZoom11,
              icon='kde-zoom-1-veuszedit',
              key='Ctrl+1'),
            'view.zoomwidth':
            a(self,
              _('Zoom plot to show whole width'),
              _('Zoom to width'),
              self.slotViewZoomWidth,
              icon='kde-zoom-width-veuszedit'),
            'view.zoomheight':
            a(self,
              _('Zoom plot to show whole height'),
              _('Zoom to height'),
              self.slotViewZoomHeight,
              icon='kde-zoom-height-veuszedit'),
            'view.zoompage':
            a(self,
              _('Zoom plot to show whole page'),
              _('Zoom to page'),
              self.slotViewZoomPage,
              icon='kde-zoom-page-veuszedit'),
            'view.zoommenu':
            a(self,
              _('Zoom functions menu'),
              _('Zoom'),
              self.doZoomMenuButton,
              icon='kde-zoom-veuszedit'),
            'view.prevpage':
            a(self,
              _('Move to the previous page'),
              _('&Previous page'),
              self.slotViewPreviousPage,
              icon='kde-go-previous',
              key='Ctrl+PgUp'),
            'view.nextpage':
            a(self,
              _('Move to the next page'),
              _('&Next page'),
              self.slotViewNextPage,
              icon='kde-go-next',
              key='Ctrl+PgDown'),
            'view.select':
            a(self,
              _('Select items from the graph or scroll'),
              _('Select items or scroll'),
              None,
              icon='kde-mouse-pointer'),
            'view.pick':
            a(self,
              _('Read data points on the graph'),
              _('Read data points'),
              None,
              icon='veusz-pick-data'),
            'view.zoomgraph':
            a(self,
              _('Zoom into graph'),
              _('Zoom graph'),
              None,
              icon='veusz-zoom-graph'),
            'view.fullscreen':
            a(self,
              _('View plot full screen'),
              _('Full screen'),
              self.slotFullScreen,
              icon='veusz-view-fullscreen',
              key='Ctrl+F11'),
        })

        if menu:
            # only construct menu if required
            menuitems = [
                ('view', '', [
                    'view.zoomin',
                    'view.zoomout',
                    'view.zoom11',
                    'view.zoomwidth',
                    'view.zoomheight',
                    'view.zoompage',
                    '',
                    'view.prevpage',
                    'view.nextpage',
                    'view.fullscreen',
                    '',
                    'view.select',
                    'view.pick',
                    'view.zoomgraph',
                ]),
            ]
            utils.constructMenus(menu, {'view': menu}, menuitems, actions)

        # populate menu on zoom menu toolbar icon
        zoommenu = qt4.QMenu(self)
        zoomag = qt4.QActionGroup(self)
        for act in ('view.zoomin', 'view.zoomout', 'view.zoom11',
                    'view.zoomwidth', 'view.zoomheight', 'view.zoompage'):
            a = actions[act]
            zoommenu.addAction(a)
            zoomag.addAction(a)
            a.vzname = act
        actions['view.zoommenu'].setMenu(zoommenu)
        self.connect(zoomag, qt4.SIGNAL('triggered(QAction*)'),
                     self.zoomActionTriggered)

        lastzoom = setting.settingdb.get('view_defaultzoom', 'view.zoompage')
        self.updateZoomMenuButton(actions[lastzoom])

        # add items to toolbar
        utils.addToolbarActions(
            self.viewtoolbar, actions,
            ('view.prevpage', 'view.nextpage', 'view.fullscreen',
             'view.select', 'view.pick', 'view.zoomgraph', 'view.zoommenu'))

        # define action group for various different selection models
        grp = self.selectactiongrp = qt4.QActionGroup(self)
        grp.setExclusive(True)
        for a in ('view.select', 'view.pick', 'view.zoomgraph'):
            actions[a].setActionGroup(grp)
            actions[a].setCheckable(True)
        actions['view.select'].setChecked(True)
        self.connect(grp, qt4.SIGNAL('triggered(QAction*)'),
                     self.slotSelectMode)

        return self.viewtoolbar
Ejemplo n.º 8
0
    def __init__(self,
                 thedocument,
                 mainwin,
                 parent,
                 readonly=False,
                 filterdims=None,
                 filterdtype=None):
        """Initialise widget:
        thedocument: document to show
        mainwin: main window of application (or None if readonly)
        parent: parent of widget.
        readonly: for choosing datasets only
        filterdims: if set, only show datasets with dimensions given
        filterdtype: if set, only show datasets with type given
        """

        qt4.QWidget.__init__(self, parent)
        self.layout = qt4.QVBoxLayout()
        self.setLayout(self.layout)

        # options for navigator are in this layout
        self.optslayout = qt4.QHBoxLayout()

        # grouping options - use a menu to choose the grouping
        self.grpbutton = qt4.QPushButton(_("Group"))
        self.grpmenu = qt4.QMenu()
        self.grouping = setting.settingdb.get("navtree_grouping", "filename")
        self.grpact = qt4.QActionGroup(self)
        self.grpact.setExclusive(True)
        for name in self.grpnames:
            a = self.grpmenu.addAction(self.grpentries[name])
            a.grpname = name
            a.setCheckable(True)
            if name == self.grouping:
                a.setChecked(True)
            self.grpact.addAction(a)
        self.connect(self.grpact, qt4.SIGNAL("triggered(QAction*)"),
                     self.slotGrpChanged)
        self.grpbutton.setMenu(self.grpmenu)
        self.grpbutton.setToolTip(_("Group datasets with property given"))
        self.optslayout.addWidget(self.grpbutton)

        # filtering by entering text
        self.optslayout.addWidget(qt4.QLabel(_("Filter")))
        self.filteredit = LineEditWithClear()
        self.filteredit.setToolTip(_("Enter text here to filter datasets"))
        self.connect(self.filteredit,
                     qt4.SIGNAL("textChanged(const QString&)"),
                     self.slotFilterChanged)
        self.optslayout.addWidget(self.filteredit)

        self.layout.addLayout(self.optslayout)

        # the actual widget tree
        self.navtree = DatasetsNavigatorTree(thedocument,
                                             mainwin,
                                             self.grouping,
                                             None,
                                             readonly=readonly,
                                             filterdims=filterdims,
                                             filterdtype=filterdtype)
        self.layout.addWidget(self.navtree)