Beispiel #1
0
 def test_write(self):
     tmp_file = tempfile.NamedTemporaryFile()
     fedis = object_file.EdisFile(tmp_file.name)
     fedis.write("Testing write file function. íñÑó")
     expected = "Testing write file function. íñÑó"
     with open(tmp_file.name, mode='r') as f:
         self.assertEqual(f.read(), expected)
    def create_editor(self, obj_file=None, filename=""):
        if obj_file is None:
            obj_file = object_file.EdisFile(filename)
        self.stack.addWidget(self.editor_widget)
        # Quito la página de inicio, si está
        _start_page = self.stack.widget(0)
        if isinstance(_start_page, start_page.StartPage):
            self.remove_widget(_start_page)
            # Detengo el tiimer
            _start_page.timer.stop()
        weditor = editor.Editor(obj_file)
        self.editor_widget.add_widget(weditor)
        self.editor_widget.add_item_combo(obj_file.filename)
        lateral = Edis.get_component("tab_container")
        if not lateral.isVisible():
            lateral.show()

        # Conexiones
        self.connect(obj_file, SIGNAL("fileChanged(PyQt_PyObject)"),
                     self._file_changed)
        self.connect(weditor, SIGNAL("cursorPositionChanged(int, int)"),
                     self.update_cursor)
        self.connect(weditor, SIGNAL("modificationChanged(bool)"),
                     self._file_modified)
        self.connect(weditor, SIGNAL("fileSaved(QString)"),
                     self._file_saved)
        self.connect(weditor, SIGNAL("linesChanged(int)"),
                     self.editor_widget.combo.move_to_symbol)
        self.connect(weditor, SIGNAL("dropEvent(PyQt_PyObject)"),
                     self._drop_editor)
        self.emit(SIGNAL("fileChanged(QString)"), obj_file.filename)

        weditor.setFocus()

        return weditor
    def open_file(self, filename="", cursor_position=None):
        filter_files = "Archivos C(*.cpp *.c);;ASM(*.s);;HEADERS(*.h);;(*.*)"
        if not filename:
            working_directory = os.path.expanduser("~")
            weditor = self.get_active_editor()
            if weditor and weditor.filename:
                working_directory = self._last_folder(weditor.filename)
            filenames = QFileDialog.getOpenFileNames(self,
                                                     self.tr("Abrir Archivo"),
                                                     working_directory,
                                                     filter_files)
        else:
            filenames = [filename]
        try:
            for _file in filenames:
                if not self._is_open(_file):
                    #self.editor_widget.not_open = False
                    # Creo el objeto Edis File
                    obj_file = object_file.EdisFile(_file)
                    content = obj_file.read()
                    weditor = self.create_editor(obj_file, _file)
                    weditor.setText(content)
                    # Cuando se setea el contenido en el editor
                    # se emite la señal textChanged() por lo tanto se agrega
                    # el marker, entonces se procede a borrarlo
                    weditor.markerDelete(0, 3)
                    # FIXME: Cursor position not found
                    #if cursor_position is not None:
                        #line, row = cursor_position
                        #weditor.setCursorPosition(line, row)
                    weditor.setModified(False)
                    obj_file.run_system_watcher()
                else:
                    # Se cambia el índice del stacked
                    # para mostrar el archivo que ya fué abierto
                    for index in range(self.editor_widget.count()):
                        editor = self.editor_widget.widget(index)
                        if editor.filename == _file:
                            self.change_widget(index)

                self.emit(SIGNAL("fileChanged(QString)"), _file)
                self.emit(SIGNAL("openedFile(QString)"), _file)
                self.emit(SIGNAL("updateSymbols(QString)"), _file)
        except EdisIOError as error:
            ERROR('Error al intentar abrir archivo: %s', error)
            QMessageBox.critical(self, self.tr('No se pudo abrir el archivo'),
                                 str(error))
Beispiel #4
0
 def test_is_not_new_file(self):
     fedis = object_file.EdisFile()
     self.assertTrue(fedis.is_new)
Beispiel #5
0
 def test_is_new_file(self):
     fedis = object_file.EdisFile(self._filename)
     self.assertFalse(fedis.is_new)
Beispiel #6
0
 def test_read(self):
     fedis = object_file.EdisFile(self._filename)
     expected = "#include <stdio.h>\n/* qwertyuiopasdfghjklñzxcvbnm */\n" \
                "int main( void ) {\n    return 0\n}"
     content = fedis.read()
     self.assertEqual(expected, content)