Esempio n. 1
0
    def addLayerControl(self, item, name, tip=''):
        '''
        add color button in parameter menu if an overlay is added
        '''

        aExport = QtGui.QAction('Export to new display', self._menu.p)
        aExport.triggered.connect(
            lambda c, n=name: self._exportLayerToNewDisplay(n))

        p = self._menu.p.addChild({
            'name': name,
            'highlight': True,
            'type': 'color',
            'tip': tip,
            'removable': True,
            'autoIncrementName': True,
            'addToContextMenu': [aExport],
            #TODO:
            # 'sliding':True
            'item': item
        })
        p.setValue(item.getQColor())
        p.sigValueChanged.connect(
            lambda param, val: param.opts['item'].setQColor(val))

        self.setChecked(True)
Esempio n. 2
0
 def _fillMenuDuplicateToOtherWS(self):
     c = self.centralWidget()
     self._m_duplDisp.clear()
     for i in range(c.count()):
         if i != c.currentIndex():
             t = '[%s]' % str(i + 1)
             a = QtGui.QAction(t, self._m_duplDisp)
             a.triggered.connect(lambda clicked, i=i, self=self: self.
                                 _moveCurrentDiplayToWorkspace(i))
             self._m_duplDisp.addAction(a)
Esempio n. 3
0
    def __init__(self, display):
        Tool.__init__(self, display)

        self.n_slices = 0
        self._ROIs = []

        a_show = QtGui.QAction('show', self)
        a_show.setCheckable(True)
        a_show.setChecked(True)
        a_show.toggled.connect(self.toggleShow)
        self.addAction(a_show)
Esempio n. 4
0
    def __init__(self, imageDisplay):
        Tool.__init__(self, imageDisplay)

        self.scene = self.view.scene()
        
        #MENU:
        self.a_newDisplay = QtGui.QAction('result in new display', self)
        self.a_newDisplay.setCheckable(True)
        self.addAction(self.a_newDisplay)
     
        a_show = QtGui.QAction('show', self)
        a_show.setCheckable(True)
        a_show.setChecked(True)
        a_show.toggled.connect(self.toggleShow)
        self.addAction(a_show)

        self.n_slices = 0
        self.slave = None
        
        self._POIS = []
Esempio n. 5
0
    def __init__(self, display):
        Tool.__init__(self, display)

        self.poiTextList = []
        self.scene = self.view.scene()
        self._first_time = True

        self.actionHide = QtGui.QAction('show', self)
        self.actionHide.setCheckable(True)
        self.actionHide.setChecked(True)
        self.actionHide.triggered.connect(self.toggleShow)
        self.addAction(self.actionHide)

        areset = QtGui.QAction('reset', self)
        areset.triggered.connect(self.reset)
        self.addAction(areset)

        self.actionShowCoord = QtGui.QAction('show coordinates', self)
        self.actionShowCoord.setCheckable(True)
        self.actionShowCoord.setChecked(True)
        self.addAction(self.actionShowCoord)
Esempio n. 6
0
    def _openContextMenu(self, pos):
        #show toolbar name and action[remove] on right click
        m = QtGui.QMenu()
        #title:
        a = QtGui.QAction('Toolbar:   %s' % self.name, self)
        a.setSoftKeyRole(QtGui.QAction.NoSoftKey)
        f = a.font()
        f.setBold(True)
        a.setFont(f)
        m.addAction(a)
        m.addSeparator()

        m.addAction("Remove").triggered.connect(self.actionSelect.trigger)
        m.exec_(self.mapToGlobal(pos))
Esempio n. 7
0
    def _buildMenu(self):
        self._menu.clear()
        self._actions = []
        
        for d in self.display.otherDisplaysOfSameType():
            # add an action for all imageDisplays:
#             if d != self.display and d.__class__ == self.display.__class__:
            a = QtGui.QAction(d.name(),self._menu, checkable=True)
            self._menu.addAction(a)
            self._actions.append(a)

            if d in self._linked_displays:
                a.setChecked(True)

            a.triggered.connect(lambda checked, d=d, self=self: 
                                self._linkColorbar(d, checked))
Esempio n. 8
0
    def _buildMenu(self):
        '''
        Add an action for all other displays and connect it to
        self._linkView
        '''
        self._menu.clear()
                
        ag = QtGui.QActionGroup(self._menu, exclusive=True)

        for d in self.display.workspace.displays():
            if d != self.display:
                
                a = ag.addAction(QtGui.QAction(d.name(),self._menu, checkable=True))
                self._menu.addAction(a)

                a.triggered.connect(lambda checked, d=d, self=self: 
                                    self._linkView(d, checked))
                if d == self._linked_display:
                    a.setChecked(True)
Esempio n. 9
0
    def __init__(self, name, widget, pkg, toolClasses):
        QtGui.QToolBar.__init__(self, name)

        self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(self._openContextMenu)
        #make ToolBar smaller:
        self.setIconSize(QtCore.QSize(16, 16))
        self.layout().setContentsMargins(0, 0, 0, 0)
        self.setAllowedAreas(QtCore.Qt.TopToolBarArea)

        #measure toolbar width in order to find best place when added
        self.width = 9  #9=handle width

        # whether position of toolbar should be
        #found depending on available space:
        #         self.needPositioning = False

        name[0].islower()
        f = name[0]
        if f.islower():
            name = f.upper() + name[1:]
        self.name = name

        self.widget = widget
        self.toolClasses = toolClasses
        self._toolsCreated = False

        # there is a central setup for the visibility of all
        # toolbars that have the same display widget:
        show = getattr(pkg, 'show', True)
        if isinstance(show, dict):
            #whether to show/hide a toolbar depends on the chosen profile:
            session = QtGui.QApplication.instance().session
            profile = session.app_opts.get('profile', None)
            show = show.get(profile, False)
        if self.widget.__class__.selectedToolbars.get(name, None) is None:
            self.widget.__class__.selectedToolbars[name] = [
                show,
                #                             QtCore.Qt.TopToolBarArea,
                #                             TO_QT_POSITION[getattr(pkg, 'position','top')],
                False
            ]  #->hasBreak

            #         #add logo to toolbar:
            #         icon  = getattr(pkg, 'icon', None)
            #         if icon:
            #             #icon can ge given as direct path
            #             if not os.path.exists(icon):
            #                 #otherwise it is assumed that
            #                 #the icon is to be found in the icon directory:
            #                 icon = ICONFOLDER.join(icon)
            #             s = ToolBarIcon(self, icon)

            tip = getattr(pkg, '__doc__', None)
            ttname = name
            if tip:
                ttname += '\n\t%s' % tip
            self.setToolTip(ttname)

        #BACKGROUND COLOR:
        c = getattr(pkg, 'color', None)
        if not c is None:
            #create a semi-transparent colour from
            #normal background color (grey)
            #and given color:
            a = 0.9
            b = 1 - a
            p = self.palette()
            bg = p.color(self.backgroundRole())
            c = QtGui.QColor(c)
            bg.setRed(a * bg.red() + b * c.red())
            bg.setGreen(a * bg.green() + b * c.green())
            bg.setBlue(a * bg.blue() + b * c.blue())
            self.setBackgroundRole(QtGui.QPalette.Window)
            p.setColor(self.backgroundRole(), bg)
            self.setPalette(p)
            self.setAutoFillBackground(True)

        self.actionSelect = a = QtGui.QAction(name, self)
        s = 'contains...'
        for cls in self.toolClasses:
            s += '\n     %s' % cls.__name__
        a.setToolTip(s)
        a.setCheckable(True)
        a.setChecked(show)
        a.triggered.connect(self.setSelected)
Esempio n. 10
0
    def buildLayer(self,
                   fname,
                   label,
                   name,
                   data,
                   origin=None,
                   index=None,
                   info=None,
                   changes=None):
        '''
        for every layer of the stack add a parameter containing ...
        * it's stack value
        * an layer info field
        * a layer changed field
        '''
        info, changes = self._extractFromOrigin(origin, index, info, changes)
        try:
            self.sigChildAdded.disconnect(self._fnInsertRemovedLayer)
        except TypeError:
            pass

        #ADD OPTIONS TO THE CONTEXT MENU:
        mCopy = QtGui.QMenu('Copy')
        mMove = QtGui.QMenu('Move')

        if not fname or not PathStr(fname).isfile():
            fname = None

        menu_entries = [mCopy, mMove]
        if self.display.reader is not None:
            aFile = QtGui.QAction('Change File', self)
            aFile.triggered.connect(lambda checked, i=len(self.childs): self.
                                    display.changeLayerFile(i))
            menu_entries.append(aFile)
        #CREATE AND ADD COPY-LAYER-TO OPTION TO PARAMETER:
        pLayer = self.addChild({
            'type':
            'float',
            'highlight':
            True,
            'name':
            name,
            'value':
            self.display.axes.stackAxis.getNextStackValue(
                PathStr(fname).basename()),
            'expanded':
            False,
            'removable':
            True,
            'autoIncrementName':
            True,
            'renamable':
            True,
            'readonly':
            True,
            'addToContextMenu':
            menu_entries,
            'filename':
            fname,
            'layername':
            label,
        })
        mCopy.aboutToShow.connect(
            lambda pLayer=pLayer, mCopy=mCopy, self=self: self.
            buildCopyToDisplayMenu(mCopy, pLayer, 'copy'))
        mMove.aboutToShow.connect(
            lambda pLayer=pLayer, mMove=mMove, self=self: self.
            buildCopyToDisplayMenu(mMove, pLayer, 'move'))

        #UPDATE STACK VALUES:
        pLayer.sigValueChanged.connect(self._valuesChanged)
        #EMIT LAYERNAMESCHANGED:
        pLayer.sigNameChanged.connect(
            lambda param, val, self=self: self.sigLayerNameChanged.emit(
                param.parent().children().index(param), val))
        #CHECK WHETHER INSERTED LAYER COMES FROM A MOVED ONE:
        self.sigChildAdded.connect(self._fnInsertRemovedLayer)
        #ADD LAYER INFO
        if info is None:
            finfo = ''
            if fname is not None:
                try:
                    #read info from file:
                    finfo += self.getFileInfo(
                        fname) + '\n'  # + self.getMetaData(name)
                except AttributeError:
                    pass
                #    finfo = '' #not possible to read from file because maybe not a filename
            dinfo = ''
            if data is not None:
                try:
                    dinfo = 'shape:\t%s\ndtype:\t%s' % (data.shape, data.dtype)
                except AttributeError:
                    #data in not array
                    dinfo = 'length: %s' % len(data)
            info = '%s---\n%s' % (finfo, dinfo)

        if isinstance(info, Parameter):
            #CASE: layer was duplicated and [info] is a parameter
            for ch in info.children():
                pLayer.addChild(ch.duplicate())
        else:
            #info is given as text
            #LAYER INFO
            pLayer.addChild({
                'type': 'text',
                'name': 'Info',
                'value': info if info != None else '',
                'readonly': True
            })
        #LAYER CHANGES
        pLayer.addChild({
            'type': 'text',
            'name': 'Changes',
            #'TODO: every change through a tool/scripts operation to be added here',
            'value': changes if changes else '',
            #'readonly':True
            'expanded': bool(changes)
        })
Esempio n. 11
0
    def _appendMenubarAndPreferences(self):
        m = self.menuBar()
        m.setFixedHeight(25)
        #         m.setMaximumHeight(25)

        m.aboutWidget.setModule(dataArtist)
        m.aboutWidget.setInstitutionLogo(
            MEDIA_FOLDER.join('institution_logo.svg'))

        #hide the menu so toolbars can only be show/hidden via gui->view->toolbars:
        m.setContextMenuPolicy(QtCore.Qt.PreventContextMenu)

        self.undoRedo = UndoRedo(MEDIA_FOLDER)

        self.gTools = GlobalTools()
        self.gTools.addWidget(self.undoRedo)

        m.setCornerWidget(self.gTools)

        #APPEND PREFERENCES
        t = m.file_preferences.tabs
        t.addTab(PreferencesView(self), 'View')
        t.addTab(self.pref_import, 'Import')
        t.addTab(PreferencesCommunication(self), 'Communication')
        #APPEND MENUBAR
        #MENU - FILE
        f = m.menu_file
        p = f.action_preferences
        action_file = QtGui.QAction('&Import', f)
        action_file.triggered.connect(self.openFile)
        action_file.setShortcut(
            QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_I))
        f.insertAction(p, action_file)
        f.insertSeparator(p)
        #MENU VIEW
        v = m.menu_view
        #ACTION PRINT VIEW
        aPrintView = QtGui.QAction('Print view', v)
        aPrintView.setCheckable(True)
        aPrintView.triggered.connect(
            lambda checked: self.currentWorkspace().setPrintView(checked))
        v.addAction(aPrintView)

        #SHOW/HIDE history
        aHistory = QtGui.QAction('Program history', v)
        aHistory.setShortcut(QtCore.Qt.Key_F4)

        aHistory.setCheckable(True)

        def showhideHistory(checked):
            s = self.currentWorkspace().middle_splitter
            r = s.getRange(1)[1]
            if checked:
                r /= 1.5
            return s.moveSplitter(r, 1)

        def isHistoryVisible():
            s = self.currentWorkspace().middle_splitter
            aHistory.setChecked(s.sizes()[1] != 0)

        aHistory.triggered.connect(showhideHistory)
        v.aboutToShow.connect(isHistoryVisible)
        v.addAction(aHistory)

        #SHOW/HIDE preferences
        aPref = QtGui.QAction('Dock preferences', v)
        aPref.setShortcut(QtCore.Qt.Key_F3)
        aPref.setCheckable(True)

        def showhidePref(checked):
            s = self.currentWorkspace().vert_splitter
            r = s.getRange(1)[1]
            if checked:
                r /= 3
            else:
                r = 0
            return s.moveSplitter(r, 1)

        def isPrefVisible():
            w = self.currentWorkspace()
            s = w.vert_splitter
            aPref.setChecked(s.sizes()[0] != 0)
            aPref.setEnabled(w.displayPrefTabs.isVisible())

        aPref.triggered.connect(showhidePref)
        v.aboutToShow.connect(isPrefVisible)
        v.addAction(aPref)

        #ACTION VIEW2CLIPBOARD
        aClipboard = QtGui.QAction('Copy view to clipboard', v)
        aClipboard.triggered.connect(
            lambda checked: self.currentWorkspace().copyViewToClipboard())
        v.addAction(aClipboard)
        #ACTION Display2CLIPBOARD
        aClipboard = QtGui.QAction('Copy active display to clipboard', v)
        aClipboard.triggered.connect(lambda checked: self.currentWorkspace().
                                     copyCurrentDisplayToClipboard())
        v.addAction(aClipboard)
        #MENU - TOOLS
        t = m.menu_tools = QtGui.QMenu('Dock')
        m.insertMenuBefore(m.menu_workspace, t)
        #ADD DISPLAY
        mDisplay = t.addMenu('Add Display')
        for i, name in (  #(1, 'Dot'), 
            (2, 'Graph'),
            (3, 'Image/Video'),
                #(4, 'Surface')
                #TODO:
                #(4, 'TODO: Surface'),
                #(5, 'TODO: Volume')
        ):
            mDisplay.addAction('%sD - %s' % (i - 1, name)).triggered.connect(
                lambda checked, i=i: self.currentWorkspace().addDisplay(axes=i
                                                                        ))
        #ADD TABLE
        t.addAction('Add Table').triggered.connect(
            lambda: self.currentWorkspace().addTableDock())
        #ADD NOTEPAD
        t.addAction('Add Notepad').triggered.connect(
            lambda: self.currentWorkspace().addTextDock())
        t.addSeparator()
        #DUPLICATE CURRENT DOCK
        t.addAction('Duplicate current display').triggered.connect(
            self._duplicateCurrentDiplay)
        self._m_duplDisp = t.addMenu('Move current display to other workspace')
        self._m_duplDisp.aboutToShow.connect(self._fillMenuDuplicateToOtherWS)
        #MENU - TOOLBARS
        self.menu_toolbars = QtGui.QMenu('Toolbars', m)
        self.connect(self.menu_toolbars,
                     QtCore.SIGNAL("hovered(QAction *)"),
                     lambda action, m=self.menu_toolbars:
                     _showActionToolTipInMenu(m, action))

        #SHOW ALL TOOLBARS - ACTION
        a = self.menu_toolbars.a_show = QtGui.QAction('show', m)
        f = a.font()
        f.setBold(True)
        a.setFont(f)
        a.setCheckable(True)
        a.setChecked(True)
        a.triggered.connect(self._toggleShowSelectedToolbars)

        self.menu_toolbars.aboutToShow.connect(self._listToolbarsInMenu)
        m.insertMenuBefore(m.menu_workspace, self.menu_toolbars)
        #MENU HELP
        m.menu_help.addAction('User manual').triggered.connect(
            lambda checked: os.startfile(HELP_FILE))
        #TUTORIALS
        ####not used at the moment
        #         self.m_tutorials = TutorialMenu(
        #                         tutorialFolder=PathStr.getcwd('dataArtist').join('tutorials'),
        #                         openFunction=self._openFnForTutorial,
        #                         saveFunction=self.app.session.blockingSave)
        #         m.menu_help.addMenu(self.m_tutorials)

        m.menu_help.addAction('Online tutorials').triggered.connect(
            lambda checked: os.startfile(
                'http://www.youtube.com/channel/UCjjngrC3jPdx1HL8zJ8yqLQ'))
        m.menu_help.addAction('Support').triggered.connect(
            lambda checked: os.startfile(
                'https://github.com/radjkarl/dataArtist/issues'))