Beispiel #1
0
 def save(self, file=None):
     if file == None:
         file = self.file
     e = ET.Element(self.name)
     for key, value in self.items():
         if isinstance(value, (dict, list)):
             e.append(value.to_element())
         else:
             s = ET.SubElement(e, key)
             if isinstance(value, basestring):
                 s.text = value
             else:
                 s.text = str(value)
     indent(e)
     db = ET.ElementTree(e)
     db.write(file, encoding='utf-8')
Beispiel #2
0
 def save(self,file=None):
     if file == None:
         file = self.file
     e = ET.Element(self.name)
     for key, value in self.items():
         if isinstance(value, (dict,list)):
             e.append(value.to_element())
         else:
             s = ET.SubElement(e,key)
             if isinstance(value, basestring):
                 s.text = value
             else:
                 s.text = str(value)
     indent(e)
     db = ET.ElementTree(e)
     db.write(file, encoding='utf-8')
Beispiel #3
0
    def button_action(self, widget, event):
        x = int(event.x)
        y = int(event.y)
        path = self.treeview.get_path_at_pos(x, y)
        if path == None:
            return True
        row_path,column,_,_ = path
        if event.button == 3:
            clipboard = Gtk.clipboard_get(Gdk.SELECTION_CLIPBOARD)
            iter = self.store.get_iter(row_path)
            menu = Gtk.Menu()
            item = Gtk.MenuItem("copy value")
            value,= self.store.get(iter,4)
            item.connect("activate", lambda w: clipboard.set_text(value))
            menu.append(item)

            item = Gtk.MenuItem("copy raw event")
            raw,= self.store.get(iter,5)
            try:
                from coherence.extern.et import ET, indent, parse_xml
                xml = parse_xml(raw)
                xml = xml.getroot()
                indent(xml,0)
                raw = ET.tostring(xml, encoding='utf-8')
            except:
                import traceback
                print traceback.format_exc()

            item.connect("activate", lambda w: clipboard.set_text(raw))
            menu.append(item)


            menu.show_all()
            menu.popup(None,None,None,event.button,event.time)
            return True

        return False
Beispiel #4
0
    def button_action(self, widget, event):
        x = int(event.x)
        y = int(event.y)
        path = self.treeview.get_path_at_pos(x, y)
        if path == None:
            return True
        row_path, column, _, _ = path
        if event.button == 3:
            clipboard = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD)
            iter = self.store.get_iter(row_path)
            menu = gtk.Menu()
            item = gtk.MenuItem("Copy value")
            value, = self.store.get(iter, 4)
            item.connect("activate", lambda w: clipboard.set_text(value))
            menu.append(item)

            item = gtk.MenuItem("Copy raw event XML")
            raw, = self.store.get(iter, 5)
            try:
                from coherence.extern.et import ET, indent, parse_xml
                xml = parse_xml(raw)
                xml = xml.getroot()
                indent(xml, 0)
                raw = ET.tostring(xml, encoding='utf-8')
            except:
                import traceback
                print traceback.format_exc()

            item.connect("activate", lambda w: clipboard.set_text(raw))
            menu.append(item)

            menu.show_all()
            menu.popup(None, None, None, event.button, event.time)
            return True

        return False
 def tostring(self):
     root = ConvertDictToXml(self.db)
     tree = ElementTree.ElementTree(root).getroot()
     indent(tree,0)
     xml = self.preamble + ElementTree.tostring(tree, encoding='utf-8')
     return xml