Beispiel #1
0
    def load_from_xml_path(self, path):
        """load from the old xml format """
        # path = os.getenv('PYTHONEDITOR_AUTOSAVE_FILE', '')

        # subscript_data = parsexml('subscripts', path=path) # TODO:
        roow, current_index_elements = parsexml('current_index', path=path)
        for index in current_index_elements:
            current_index = int(index.text)

        root, subscripts = parsexml('subscript', path=path)

        data_list = []
        for subscript in sorted(subscripts,
                                key=lambda s: int(s.attrib.get('tab_index'))):
            uid = uuid.UUID(subscript.attrib.get('uuid'))
            data = {
                'text': subscript.text,
                'name': subscript.attrib.get('name', ''),
                'path': subscript.attrib.get('path', ''),
                'saved': subscript.attrib.get('saved', False),
            }
            for key, value in subscript.attrib.items():
                if key in data.keys():
                    continue
                elif key == 'uuid':
                    continue
                elif key == 'tab_index':
                    continue
                else:
                    data[key] = value
            data_list.append([uid, data])
            if int(subscript.attrib.get('tab_index')) == current_index:
                self.set_current_uid(uid)

        self.append_data(data_list)
def test_writexml(setup_and_teardown_autosave_file):
    """Test that the writexml function writes back sensible data."""
    # make sure we have an autosave file
    if not os.path.isfile(autosavexml.AUTOSAVE_FILE):
        autosavexml.create_autosave_file()

    # read the file, then write it back.
    root, elements = autosavexml.parsexml("subscript")
    autosavexml.writexml(root, path=autosavexml.AUTOSAVE_FILE)

    # does the file still exist?
    assert os.path.isfile(autosavexml.AUTOSAVE_FILE)

    # the file may have had some characters sanitized,
    # but the number of elements should be the same.
    new_root, new_elements = autosavexml.parsexml("subscript")
    assert len(new_elements) == len(elements)

    try:
        unicode
    except NameError:
        # no unicode function in python 3
        def unicode(text):
            return text

    from PythonEditor.ui.features.autosavexml import sanitize

    # none of the element attributes should have changed
    for old_element, new_element in zip(elements, new_elements):
        assert old_element.attrib == new_element.attrib
        old_text = unicode(old_element.text)
        new_text = unicode(new_element.text)
        assert sanitize(old_text) == sanitize(new_text)
def test_fix_broken_xml(setup_and_teardown_autosave_file):
    if not os.path.isfile(autosavexml.AUTOSAVE_FILE):
        autosavexml.create_autosave_file()
    autosavexml.fix_broken_xml(path=autosavexml.AUTOSAVE_FILE)
    # test that the file can be parsed correctly now
    root, elements = autosavexml.parsexml("subscript",
                                          path=autosavexml.AUTOSAVE_FILE)
Beispiel #4
0
 def load_xml(self):
     root, elements = autosavexml.parsexml('subscript')
     for element in elements:
         item1 = QStandardItem(element.attrib['name'])
         item2 = QStandardItem(element.text)
         item3 = QStandardItem(element.attrib['uuid'])
         self.appendRow([item1, item2, item3])
Beispiel #5
0
def check_changed():
    """
    Check in with our little tab to see if anything's new.
    """
    root, subscripts = autosavexml.parsexml('subscript')
    for s in subscripts:
        if s.attrib.get('uuid') == tabs['uuid'] and tabs['text'] != s.text:
            print('updated text!')
Beispiel #6
0
    def __init__(self):
        super(SingleTab, self).__init__()
        l = LoaderList()
        self.l = l
        root, subscripts = autosavexml.parsexml('subscript')
        for s in subscripts:
            name = s.attrib.get('name')
            a = s.attrib.copy()
            a['text'] = s.text
            l[name] = a

        self.t = edittabs.EditTabs()
        self.l.emit_tab.connect(self.receive_tab)

        self._layout = QtWidgets.QHBoxLayout(self)
        self.splitter = QtWidgets.QSplitter(self)
        self._layout.addWidget(self.splitter)
        self.setLayout(self._layout)

        self.splitter.addWidget(self.l)
        self.splitter.addWidget(self.t)
Beispiel #7
0
stylesheet = """
QTabBar::tab {
    height: 24px;
    //border-top-right-radius: -15px;
}
/*
QTabBar::tab:selected {
    padding-right: 14px;
}
*/
"""
tabs.setStyleSheet(stylesheet)
#tabs = QtWidgets.QTabBar()
#tabs.setExpanding(True)

root, subscripts = autosavexml.parsexml('subscript')

autosaves = []
i = 0
for s in subscripts:
    name = s.attrib.get('name')
    if name is None:
        continue
    autosaves.append((i, s))
    i += 1

for i, s in autosaves:
    name = s.attrib.get('name')
    data = s.attrib.copy()
    tabs.addTab(name + ' ' * 5)  # hax for enough space for close button :'(
    path = data.get('path')
def test_parsexml(setup_and_teardown_autosave_file):
    root, elements = autosavexml.parsexml("subscript",
                                          path=autosavexml.AUTOSAVE_FILE)
    assert isinstance(elements, list)
    assert root is not None