Esempio n. 1
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'))
Esempio n. 2
0
    def activate(self):  
        w = self.display.widget
        self.camera = LD()
        self.camera.calibrate(
                   method=self.pMethod.value(),
                   board_size=(self.pChessbX.value(), 
                               self.pChessbY.value()), 
                   max_images=self.pLiveStopAfter.value(),
                   sensorSize_mm=(self.pApertureX.value(), 
                                  self.pApertureY.value()),
                   detect_sensible=True )

        if self.pLive.value():  
            if self.pDrawChessboard.value() and not self.cItem:
                self.cItem = w.addColorLayer(name='Chessboard')
            if self.pLiveActivateTrigger.value():
                self.pLiveTrigger.setOpts(visible=True)
                self.pLiveTrigger.sigActivated.connect(self._addImgStream)
                if not self.key:
                    #ACTIVATE ON KEY [+]
                    self.key = QtGui.QShortcut(self.display.workspace)
                    self.key.setKey(QtGui.QKeySequence(QtCore.Qt.Key_Plus))
                    self.key.setContext(QtCore.Qt.ApplicationShortcut)
                self.key.activated.connect(self.pLiveTrigger.activate)     
            else:
                #ACTIVATE WHEN IMAGE CHANGES
                w.item.sigImageChanged.connect(self._addImgStream)
        else:
            #READ IMAGE STACK
                #check conditions:
            if len(self.display.filenames) < 10:
                print 'having less than 10 images can result in erroneous results'

            img = w.image
            img_loaded = True
            if img is None: #calibration images not loaded
                img_loaded = False
                img = self.display.filenames
            
            out = []
            d = self.pDrawChessboard.value()
            found_indices = []
            for n, i in enumerate(img):
                try:
                    #MANUAL ADDING POINTS
                    if self._rois:
                        print self._rois[n].points()
                        self.camera.addPoints(self._rois[n].points())
                        self.camera.setImgShape(i.shape)
                    else:
                        self.camera.addImg(i)
                    #draw chessboard
                    if d:
                        out.append(self.camera.drawChessboard(
                                False if img_loaded else None))
                        found_indices.append(n)
                except NothingFound, errm:
                    print 'Layer %s: ' %n, errm
            if d:
                if img_loaded:
                    w.addColorLayer(np.array(out), name='chessboard')#, indices=found_indices) 
                else:
                    self.display.addLayers(out, ['Chessboard']*len(out))
            
            self._end()