Пример #1
0
    def __init__(self):
        super(MainWidget, self).__init__()

        #self.setAttribute(Qt.WA_MacBrushedMetal) # doesn't show well

        self.ui = Ui_MainWidget()
        self.ui.setupUi(self)

        # dict of canonical file names to 
        self.opendocuments = []
        self.documentwidgets = {}

        # current latex mode
        self.latexmode = None
        # current file naming convention
        self.filenamingconvention = None
        # load the settings
        self.loadsettings()

        # the settings dialog will be instanciated only upon need
        self.settingsdialog = None
Пример #2
0
class MainWidget(QMainWindow):
    def __init__(self):
        super(MainWidget, self).__init__()

        #self.setAttribute(Qt.WA_MacBrushedMetal) # doesn't show well

        self.ui = Ui_MainWidget()
        self.ui.setupUi(self)

        # dict of canonical file names to 
        self.opendocuments = []
        self.documentwidgets = {}

        # current latex mode
        self.latexmode = None
        # current file naming convention
        self.filenamingconvention = None
        # load the settings
        self.loadsettings()

        # the settings dialog will be instanciated only upon need
        self.settingsdialog = None


    @pyqtSlot()
    def on_aOpenFile_triggered(self):
        fname = str(QFileDialog.getOpenFileName(self, 'Open LaTeX/ethuebung File', QString(),
                                                'LaTeX Files (*.tex *.latex);;All Files (*)'))
        if not fname:
            return

        self.openFile(fname)

    @pyqtSlot()
    def on_aCloseFile_triggered(self):
        self.closeCurrentFile()

    @pyqtSlot()
    def on_aQuit_triggered(self):
        self.close()

    @pyqtSlot(QString)
    def openFile(self, fn):
        fn = os.path.realpath(str(fn))
        fnbase = os.path.basename(fn)

        if not pdflatexex.rx_latex.search(fn):
            QMessageBox.critical(self, "Not a LaTeX file",
                                 "The file `%s' does not look like a latex file. Please select a file "
                                 "with extension `.tex' or `.latex'.")
            return

        if fn in self.documentwidgets:
            self.ui.tabs.setCurrentWidget(self.documentwidgets[fn])
            return

        w = compilerwidget.CompilerWidget(self.ui.tabs)
        w.setMainWin(self)
        w.setOpenFile(fn)
        self.ui.tabs.addTab(w, fnbase)
        self.ui.tabs.setCurrentWidget(w)
        self.opendocuments.append(fn)
        self.documentwidgets[fn] = w

    @pyqtSlot()
    def closeCurrentFile(self):
        self.closeTab(self.ui.tabs.currentIndex())

    @pyqtSlot(int)
    def closeTab(self, index):
        if (index == 0):
            # can't close `Home' tab
            return
        
        fn = self.opendocuments[index-1]
        del self.documentwidgets[fn]
        del self.opendocuments[index-1]
        self.ui.tabs.removeTab(index)

    @pyqtSlot(int)
    def on_tabs_tabCloseRequested(self, index):
        self.closeTab(index)



    def loadsettings(self):
        settings = QSettings()

        settings.beginGroup('latexstuff')
        latexmodecls = str(settings.value("latexmode").toString())
        self.latexmode = next(iter( (mode for mode in latexmodes.latex_modes
                                     if mode.__class__.__name__ == latexmodecls) ),
                              None)
        if not self.latexmode:
            if latexmodecls:
                sys.stderr.write("Can't find latex mode: %s\n"%(latexmodecls))
            self.latexmode = latexmodes.latex_modes[0]

        filenamingconventioncls = str(settings.value("filenamingconvention").toString())
        self.filenamingconvention = next(
            iter( (filenaming for filenaming in filenamingconventions.naming_conventions
                   if filenaming.__class__.__name__ == filenamingconventioncls)
                  ),
            None)
        if not self.filenamingconvention:
            if filenamingconventioncls:
                sys.stderr.write("Can't find file naming convention: %s\n"%(filenamingconventioncls))
            self.filenamingconvention = filenamingconventions.get_naming_convention('ConvenientNamingConvention')
        settings.endGroup()

        settings.beginGroup('openfiles')
        arraylen = settings.beginReadArray('file_list')
        for ind in range(arraylen):
            settings.setArrayIndex(ind)
            fn = str(settings.value('filename').toString())
            self.openFile(fn)
        settings.endArray()
        settings.endGroup()

    def savesettings(self):
        settings = QSettings()

        settings.beginGroup('latexstuff')
        settings.setValue('latexmode', QString(self.latexmode.__class__.__name__))
        settings.setValue('filenamingconvention', QString(self.filenamingconvention.__class__.__name__))
        settings.endGroup()

        settings.beginGroup('openfiles')
        settings.beginWriteArray('file_list', len(self.opendocuments))
        for ind in range(len(self.opendocuments)):
            settings.setArrayIndex(ind)
            settings.setValue('filename', QString(self.opendocuments[ind]))
        settings.endArray()
        settings.endGroup()

    @pyqtSlot()
    def on_aSettingsDialog_triggered(self):
        if self.settingsdialog is None:
            self.settingsdialog = SettingsDialog(mainwin=self)

        self.settingsdialog.showSettings()

    def closeEvent(self, closeevent):
        print "Closing!"
        self.savesettings()
        super(MainWidget, self).closeEvent(closeevent)