Example #1
0
    def stateNames(self):
        """Returns:
             list: the names of all saved sessions
        """
#         if self.current_session:
        s = self.tmp_dir_session
        l = [x for x in s.listdir() if s.join(x).isdir()]
        naturalSorting(l)
        # else:
        #    l=[]
        # bring autosave to first position:
        if 'autoSave' in l:
            l.remove('autoSave')
            l.insert(0, 'autoSave')
        return l
Example #2
0
    def addFiles(self, names):
        '''
        check the importPolicy: if = ask: show import dialog to ask user
        if import together: import all files together in one display
        else: import separated
        '''
        if not names:
            return
        # sort by names:
        names = naturalSorting(names)
        # show import dialog, if wished, choose there to take import settings from
        # a)import dialog b)preferences->import
        pref = self.gui.pref_import
        if pref.showImportDialog:
            dial = ImportDialog(pref, names)
            dial.exec_()
            if not dial.result():
                return
        # add files in current display:
        i = pref.importFilesPolicy
        if i in (pref.inCurrentDisplay, pref.inImportDisplay):
            if i == pref.inCurrentDisplay:
                display = self.getCurrentDisplay()
            else:
                # DisplayNumber(pref.displayNumber)
                display = self._import_display
            if display:
                display.addFiles(names, openfiles=pref.loadImportedFiles)
            else:
                # if there is no display yet: create a new one:
                display = self.addDisplay(
                    names=names, openfiles=pref.loadImportedFiles)
                if pref.inImportDisplay:
                    self._setImportDisplay(display)

        # import all files in one new display:
        elif pref.importFilesPolicy == pref.together:
            self.addDisplay(names=names, openfiles=pref.loadImportedFiles)
        # import files in separate displays:
        else:
            for p in names:
                # import each file separate
                # also give a list when there is only one file
                self.addDisplay(names=[p], openfiles=pref.loadImportedFiles)
Example #3
0
    def addFiles(self, names):
        '''
        check the importPolicy: if = ask: show import dialog to ask user
        if import together: import all files together in one display
        else: import separated
        '''
        if not names:
            return
        #sort by names:
        names = naturalSorting(names)
        #show import dialog, if wished, choose there to take import settings from
        #a)import dialog b)preferences->import
        pref = self.gui.pref_import
        if pref.showImportDialog:
            dial = ImportDialog(pref, names)
            dial.exec_()
            if not dial.result():
                return
        #add files in current display:
        i = pref.importFilesPolicy
        if i in (pref.inCurrentDisplay, pref.inImportDisplay):
            if i == pref.inCurrentDisplay:
                display = self.getCurrentDisplay()
            else:
                display = self._import_display  #DisplayNumber(pref.displayNumber)
            if display:
                display.addFiles(names, openfiles=pref.loadImportedFiles)
            else:
                #if there is no display yet: create a new one:
                display = self.addDisplay(names=names,
                                          openfiles=pref.loadImportedFiles)
                if pref.inImportDisplay:
                    self._setImportDisplay(display)

        #import all files in one new display:
        elif pref.importFilesPolicy == pref.together:
            self.addDisplay(names=names, openfiles=pref.loadImportedFiles)
        #import files in separate displays:
        else:
            for p in names:
                # import each file separate
                # also give a list when there is only one file
                self.addDisplay(names=[p], openfiles=pref.loadImportedFiles)
Example #4
0
    def _buildGlobalsMenu(self):

        mg = self._mg
        mg.aboutToShow.disconnect(self._buildGlobalsMenu)

        # GIVEN GLOBALS:
        for gi in naturalSorting(list(self._globals.keys())):
            mg.addAction(gi).triggered.connect(
                lambda checked, n=gi: self._addObject(n))
        if self._globals:
            mg.addSeparator()

        # BUILT-INs
        mb = mg.addMenu('Built-in Objects')
        l = [i for i in dir(__builtin__)]
        # exclude warnings and errors:
        err = []
        war = []
        for i in range(len(l) - 1, -1, -1):
            v = l[i]
            if v.endswith('Error') or v.endswith('Exception'):
                err.append(l.pop(i))
            elif v.endswith('Warning'):
                war.append(l.pop(i))

        self._addMenuEntries(mb, l, self._addObject)
        m = mb.addMenu('Errors')
        self._addMenuEntries(m, err, self._addObject)

        m = mb.addMenu('Warnings')
        self._addMenuEntries(m, war, self._addObject)
        # MODULES
        mm = mg.addMenu('Installed modules')

        self._addMenuEntries(mm, self._getInstalledModules(),
                             self._addImportModule)