Ejemplo n.º 1
0
    def openProject(self, directory = None):
        if not directory:
            directory = QtGui.QFileDialog.getExistingDirectory(self,
                    'Open project folder',
                    self.lastUsedDirectory)
            if not directory:
                return

        self.saveProject()

        self.addToRecentMenu(self.sessionDirectory, True)

        self.sessionDirectory = directory
        self.lastUsedDirectory = directory

        # Load tab data
        self.tabWidget.clear()
        for i, subFileName in enumerate(sorted( \
                [os.path.join(self.sessionDirectory, fn) for fn in os.listdir(self.sessionDirectory) if fn.startswith(self.tabPrefix)])):
            _, _, originalTitle, tabName = os.path.basename(subFileName).split('_')
            tabName = tabName.rsplit(".", 1)[0]
            self.newTab(self.originalNameToTabType[originalTitle])
            getRealWidget(self.tabWidget.widget(i)).importFile(subFileName)
            self.tabWidget.setTabText(i, tabName.split('+')[0])

        self.setTitleBar('RadTrack - ' + self.sessionDirectory)
Ejemplo n.º 2
0
 def get_tab_by_name(self, tab_name):
     """Returns an app tab widget by text value"""
     tab = self.parent.tabWidget
     for i in range(tab.count()):
         if tab.tabText(i) == tab_name:
             return getRealWidget(tab.widget(i))
     return None
Ejemplo n.º 3
0
    def saveProject(self):
        # Delete previous tab data in self.sessionDirectory
        for fileName in os.listdir(self.sessionDirectory):
            if fileName.startswith(self.tabPrefix):
                os.remove(os.path.join(self.sessionDirectory, fileName))

        saveProgress = QtGui.QProgressDialog('Saving project ...', 'Cancel', 0, self.tabWidget.count()-1, self)
        saveProgress.setValue(0)
        padding = len(str(self.tabWidget.count()))
        for i in range(self.tabWidget.count()):
            if saveProgress.wasCanceled():
                return

            self.ui.statusbar.showMessage('Saving ' + self.tabWidget.tabText(i) + ' ...')

            widget = getRealWidget(self.tabWidget.widget(i))
            saveProgress.setValue(i)
            subExtension = widget.acceptsFileTypes[0] if widget.acceptsFileTypes else 'save'
            subFileName  = os.path.join(self.sessionDirectory,
                '_'.join([self.tabPrefix,
                          unicode(i).rjust(padding, '0'),
                          widget.defaultTitle,
                          self.tabWidget.tabText(i) + '.' + subExtension]))
            widget.exportToFile(subFileName)
        self.ui.statusbar.clearMessage()
Ejemplo n.º 4
0
    def checkMenus(self):
        menuMap = dict()
        menuMap['exportToFile'] = self.ui.actionExport_Current_Tab
        menuMap['undo'] = self.ui.actionUndo
        menuMap['redo'] = self.ui.actionRedo
        for function in menuMap:
            realWidget = getRealWidget(self.tabWidget.currentWidget())
            menuMap[function].setEnabled(hasattr(realWidget, function) and type(realWidget) not in [RbIntroTab, RbDcp, RbEle])

        self.ui.actionReopen_Closed_Tab.setEnabled(len(self.closedTabs) > 0)

        # Configure Elegant tab to use tabs for simulation input
        for widget in self.allWidgets():
            if type(widget) == RbEle:
                widget.update_sources_from_tabs()
Ejemplo n.º 5
0
 def _new_tab(self, tab_type, file_name):
     """Create a new parent tab and load the data from the specified file"""
     self.parent.newTab(tab_type)
     getRealWidget(self.parent.tabWidget.currentWidget()).importFile(file_name)
Ejemplo n.º 6
0
 def redo(self):
     if self.ui.actionRedo.isEnabled():
         getRealWidget(self.tabWidget.currentWidget()).redo()
Ejemplo n.º 7
0
 def undo(self):
     if self.ui.actionUndo.isEnabled():
         getRealWidget(self.tabWidget.currentWidget()).undo()
Ejemplo n.º 8
0
 def allWidgets(self):
     return [getRealWidget(self.tabWidget.widget(i)) for i in range(self.tabWidget.count())]
Ejemplo n.º 9
0
 def exportCurrentTab(self):
     self.ui.statusbar.showMessage('Saving ' + self.tabWidget.tabText(self.tabWidget.currentIndex()) + ' ...')
     getRealWidget(self.tabWidget.currentWidget()).exportToFile()
     self.ui.statusbar.clearMessage()
Ejemplo n.º 10
0
    def importFile(self, openFile = None):
        if not openFile:
            openFile = QtGui.QFileDialog.getOpenFileName(self, 'Open file', self.lastUsedDirectory, fileTypeList(self.allExtensions))
            if not openFile:
                return
        self.lastUsedDirectory = os.path.dirname(openFile)

        ext = os.path.splitext(openFile)[-1].lower().lstrip(".") # lowercased extension after '.'

        # Find all types of tabs that accept file type "ext"
        choices = []
        for tabType in self.availableTabTypes:
            try:
                if ext in tabType.acceptsFileTypes:
                    choices.append(tabType)
            except AttributeError:
                pass

        if len(choices) == 0:
            QtGui.QMessageBox.warning(self, 'Import Error', 'No suitable tab for file:\n' + openFile)
            return
        elif len(choices) == 1:
            destinationType = choices[0]
        else: # len(choices) > 1
            box = QtGui.QMessageBox(QtGui.QMessageBox.Question, 'Ambiguous Import Destination', 'Multiple tab types can import this file.\nWhich kind of tab should be used?')
            responses = [box.addButton(widgetType.defaultTitle, QtGui.QMessageBox.ActionRole) for widgetType in choices] + [box.addButton(QtGui.QMessageBox.Cancel)]
            box.exec_()
            try:
                destinationType = choices[responses.index(box.clickedButton())]
            except IndexError:
                return # Cancel selected

        # Check if a tab of this type is already open
        openWidgetIndexes = [i for i in range(self.tabWidget.count()) if type(getRealWidget(self.tabWidget.widget(i))) == destinationType]
        newTabLabel = 'New ' + destinationType.defaultTitle + ' Tab'
        if openWidgetIndexes:
            choices = [self.tabWidget.tabText(i) for i in openWidgetIndexes] + [newTabLabel]
            box = QtGui.QMessageBox(QtGui.QMessageBox.Question, 'Choose Import Destination', 'Which tab should receive the data?')
            responses = [box.addButton(widgetType, QtGui.QMessageBox.ActionRole) for widgetType in choices] + [box.addButton(QtGui.QMessageBox.Cancel)]

            box.exec_()
            destinationIndex = responses.index(box.clickedButton())
            try:
                choice = choices[destinationIndex]
            except IndexError: # Cancel was pressed
                return
        else:
            choice = newTabLabel

        try:
            if choice == newTabLabel: # Make a new tab
                self.newTab(destinationType)
            else: # Pre-existing tab
                tabIndex = openWidgetIndexes[destinationIndex]
                self.tabWidget.setCurrentIndex(tabIndex)

            QtGui.QApplication.processEvents()

            self.ui.statusbar.showMessage('Importing ' + openFile + ' ...')
            getRealWidget(self.tabWidget.currentWidget()).importFile(openFile)
            self.addToRecentMenu(openFile, True)
            if os.path.dirname(openFile) != self.sessionDirectory:
                shutil.copy2(openFile, self.sessionDirectory)
        except IndexError: # Cancel was pressed
            pass
        self.ui.statusbar.clearMessage()
Ejemplo n.º 11
0
 def exportCurrentTab(self):
     getRealWidget(self.tabWidget.currentWidget()).exportToFile()