Beispiel #1
0
    def openFile(self):
        filename, _ = QFileDialog.getOpenFileName(self, 'Open File',
                os.getenv('HOME'))

        if not filename:
            return

        fh = ''

        if QFile.exists(filename):
            fh = QFile(filename)

        if not fh.open(QFile.ReadOnly):
            QtGui.qApp.quit()

        data = fh.readAll()
        codec = QTextCodec.codecForUtfText(data)
        unistr = codec.toUnicode(data)

        tmp = ('Nopepad: %s' % filename)
        self.setWindowTitle(tmp)

        basename = QFileInfo(fh).baseName()
        self.statusBar().showMessage('File \'%s\' loaded' % basename)

        self.textEdit.setText(unistr)
Beispiel #2
0
            def on_load():
                file = QFile(filename)
                fileinfo = QFileInfo(file)

                file.open(QFile.ReadOnly)
                data = file.readAll()
                codec = QTextCodec.codecForUtfText(data)
                unistr = codec.toUnicode(data)

                self.page().mainFrame().findFirstElement("#editor").setInnerXml(unistr)
                self.page().mainFrame().evaluateJavaScript("init()")

                suffix = fileinfo.suffix()
                self.page().mainFrame().evaluateJavaScript("editor.getSession().setMode('%s');" % (
                    self.SUFIX_2_MODE[suffix] if suffix in self.SUFIX_2_MODE else self.SUFIX_2_MODE[None]
                ))
Beispiel #3
0
    def open(self, filename):
        if not QFile.exists(filename):
            return

        file = QFile(filename)

        file.open(QFile.ReadOnly)
        data = file.readAll()
        codec = QTextCodec.codecForUtfText(data)
        unistr = codec.toUnicode(data)

        self._set_window_title(filename)

        self.webView.page().mainFrame().findFirstElement("#editor").setInnerXml(unistr)
        self.webView.page().mainFrame().evaluateJavaScript("init()")

        self._set_mode_by_filename(filename)