コード例 #1
0
ファイル: groups.py プロジェクト: irl/gajim
    def on_send_button_clicked(self, w):
        """
        Gather info from widgets and send it as a message
        """
        # constructing item to publish... that's atom:entry element
        item = Node('entry', {'xmlns':'http://www.w3.org/2005/Atom'})
        author = item.addChild('author')
        author.addChild('name', {}, [self.from_entry.get_text()])
        item.addChild('generator', {}, ['Gajim'])
        item.addChild('title', {}, [self.subject_entry.get_text()])

        buf = self.contents_textview.get_buffer()
        item.addChild('content', {}, [buf.get_text(buf.get_start_iter(), buf.get_end_iter(), True)])

        # publish it to node
        gajim.connections[self.account].send_pb_publish(self.servicejid, self.groupid, item, '0')

        # close the window
        self.window.destroy()
コード例 #2
0
    def on_send_button_clicked(self, w):
        """
        Gather info from widgets and send it as a message
        """
        # constructing item to publish... that's atom:entry element
        item = Node('entry', {'xmlns': 'http://www.w3.org/2005/Atom'})
        author = item.addChild('author')
        author.addChild('name', {}, [self.from_entry.get_text()])
        item.addChild('generator', {}, ['Gajim'])
        item.addChild('title', {}, [self.subject_entry.get_text()])

        buf = self.contents_textview.get_buffer()
        item.addChild(
            'content', {},
            [buf.get_text(buf.get_start_iter(), buf.get_end_iter(), True)])

        # publish it to node
        gajim.connections[self.account].send_pb_publish(
            self.servicejid, self.groupid, item, '0')

        # close the window
        self.window.destroy()
コード例 #3
0
class SVGObject():
    ''' A class to store the svg document and make changes to it.'''
    def __init__(self, root, session, height=300, width=300):
        # Will be {ID: {type:'element', data:[node, goocanvas]}, ID2: {}} instance
        self.items = {}
        self.root = root
        self.draw_tool = 'brush'

        # sxe session
        self.session = session

        # initialize svg document
        self.svg = Node(node='<svg/>')
        self.svg.setAttr('version', '1.1')
        self.svg.setAttr('height', str(height))
        self.svg.setAttr('width', str(width))
        self.svg.setAttr('xmlns', 'http://www.w3.org/2000/svg')
        # TODO: make this settable
        self.g = self.svg.addChild(name='g')
        self.g.setAttr('fill', 'none')
        self.g.setAttr('stroke-linecap', 'round')

    def add_path(self, data, line_width, color):
        ''' adds the path to the items listing, both minidom node and goocanvas
        object in a tuple '''

        goocanvas_obj = goocanvas.Path(parent=self.root,
                                       data=data,
                                       line_width=line_width,
                                       stroke_color=color)
        goocanvas_obj.connect('button-press-event',
                              self.item_button_press_events)

        node = self.g.addChild(name='path')
        node.setAttr('d', data)
        node.setAttr('stroke-width', str(line_width))
        node.setAttr('stroke', color)
        self.g.addChild(node=node)

        rids = self.session.generate_rids(4)
        self.items[rids[0]] = {
            'type': 'element',
            'data': [node, goocanvas_obj],
            'children': rids[1:]
        }
        self.items[rids[1]] = {'type': 'attr', 'data': 'd', 'parent': node}
        self.items[rids[2]] = {
            'type': 'attr',
            'data': 'stroke-width',
            'parent': node
        }
        self.items[rids[3]] = {
            'type': 'attr',
            'data': 'stroke',
            'parent': node
        }

        self.session.send_items(self.items, rids)

    def add_recieved(self, parent_rid, new_items):
        ''' adds the path to the items listing, both minidom node and goocanvas
        object in a tuple '''
        node = new_items[parent_rid]['data'][0]

        self.items[parent_rid] = new_items[parent_rid]
        for x in new_items[parent_rid]['children']:
            self.items[x] = new_items[x]

        if node.getName() == 'path':
            goocanvas_obj = goocanvas.Path(parent=self.root,
                                           data=node.getAttr('d'),
                                           line_width=int(
                                               node.getAttr('stroke-width')),
                                           stroke_color=node.getAttr('stroke'))

        if node.getName() == 'ellipse':
            goocanvas_obj = goocanvas.Ellipse(
                parent=self.root,
                center_x=float(node.getAttr('cx')),
                center_y=float(node.getAttr('cy')),
                radius_x=float(node.getAttr('rx')),
                radius_y=float(node.getAttr('ry')),
                stroke_color=node.getAttr('stroke'),
                line_width=float(node.getAttr('stroke-width')))

        self.items[parent_rid]['data'].append(goocanvas_obj)
        goocanvas_obj.connect('button-press-event',
                              self.item_button_press_events)

    def add_ellipse(self, cx, cy, rx, ry, line_width, stroke_color):
        ''' adds the ellipse to the items listing, both minidom node and goocanvas
        object in a tuple '''

        goocanvas_obj = goocanvas.Ellipse(parent=self.root,
                                          center_x=cx,
                                          center_y=cy,
                                          radius_x=rx,
                                          radius_y=ry,
                                          stroke_color=stroke_color,
                                          line_width=line_width)
        goocanvas_obj.connect('button-press-event',
                              self.item_button_press_events)

        node = self.g.addChild(name='ellipse')
        node.setAttr('cx', str(cx))
        node.setAttr('cy', str(cy))
        node.setAttr('rx', str(rx))
        node.setAttr('ry', str(ry))
        node.setAttr('stroke-width', str(line_width))
        node.setAttr('stroke', stroke_color)
        self.g.addChild(node=node)

        rids = self.session.generate_rids(7)
        self.items[rids[0]] = {
            'type': 'element',
            'data': [node, goocanvas_obj],
            'children': rids[1:]
        }
        self.items[rids[1]] = {'type': 'attr', 'data': 'cx', 'parent': node}
        self.items[rids[2]] = {'type': 'attr', 'data': 'cy', 'parent': node}
        self.items[rids[3]] = {'type': 'attr', 'data': 'rx', 'parent': node}
        self.items[rids[4]] = {'type': 'attr', 'data': 'ry', 'parent': node}
        self.items[rids[5]] = {
            'type': 'attr',
            'data': 'stroke-width',
            'parent': node
        }
        self.items[rids[6]] = {
            'type': 'attr',
            'data': 'stroke',
            'parent': node
        }

        self.session.send_items(self.items, rids)

    def del_item(self, item):
        rids = []
        for x in self.items.keys():
            if self.items[x]['type'] == 'element':
                if self.items[x]['data'][1] == item:
                    for y in self.items[x]['children']:
                        rids.append(y)
                        self.del_rid(y)
                    rids.append(x)
                    self.del_rid(x)
                    break
        self.session.del_item(rids)

    def clear_canvas(self):
        for x in self.items.keys():
            if self.items[x]['type'] == 'element':
                self.del_rid(x)

    def del_rid(self, rid):
        if self.items[rid]['type'] == 'element':
            self.items[rid]['data'][1].remove()
        del self.items[rid]

    def export_svg(self, filename):
        f = open(filename, 'w')
        f.writelines(str(self.svg))
        f.close()

    def item_button_press_events(self, item, target_item, event):
        self.del_item(item)
コード例 #4
0
class SVGObject():
    ''' A class to store the svg document and make changes to it.'''

    def __init__(self, root, session, height=300, width=300):
        # Will be {ID: {type:'element', data:[node, goocanvas]}, ID2: {}} instance
        self.items = {}
        self.root = root
        self.draw_tool = 'brush'

        # sxe session
        self.session = session

        # initialize svg document
        self.svg = Node(node='<svg/>')
        self.svg.setAttr('version', '1.1')
        self.svg.setAttr('height', str(height))
        self.svg.setAttr('width', str(width))
        self.svg.setAttr('xmlns', 'http://www.w3.org/2000/svg')
        # TODO: make this settable
        self.g = self.svg.addChild(name='g')
        self.g.setAttr('fill', 'none')
        self.g.setAttr('stroke-linecap', 'round')

    def add_path(self, data, line_width, color):
        ''' adds the path to the items listing, both minidom node and goocanvas
        object in a tuple '''

        goocanvas_obj = goocanvas.Path(parent=self.root, data=data,
                line_width=line_width, stroke_color=color)
        goocanvas_obj.connect('button-press-event', self.item_button_press_events)

        node = self.g.addChild(name='path')
        node.setAttr('d', data)
        node.setAttr('stroke-width', str(line_width))
        node.setAttr('stroke', color)
        self.g.addChild(node=node)

        rids = self.session.generate_rids(4)
        self.items[rids[0]] = {'type':'element', 'data':[node, goocanvas_obj], 'children':rids[1:]}
        self.items[rids[1]] = {'type':'attr', 'data':'d', 'parent':node}
        self.items[rids[2]] = {'type':'attr', 'data':'stroke-width', 'parent':node}
        self.items[rids[3]] = {'type':'attr', 'data':'stroke', 'parent':node}

        self.session.send_items(self.items, rids)

    def add_recieved(self, parent_rid, new_items):
        ''' adds the path to the items listing, both minidom node and goocanvas
        object in a tuple '''
        node = new_items[parent_rid]['data'][0]

        self.items[parent_rid] = new_items[parent_rid]
        for x in new_items[parent_rid]['children']:
            self.items[x] = new_items[x]

        if node.getName() == 'path':
            goocanvas_obj = goocanvas.Path(parent=self.root,
                            data=node.getAttr('d'),
                            line_width=int(node.getAttr('stroke-width')),
                            stroke_color=node.getAttr('stroke'))

        if node.getName() == 'ellipse':
            goocanvas_obj = goocanvas.Ellipse(parent=self.root,
                            center_x=float(node.getAttr('cx')),
                            center_y=float(node.getAttr('cy')),
                            radius_x=float(node.getAttr('rx')),
                            radius_y=float(node.getAttr('ry')),
                            stroke_color=node.getAttr('stroke'),
                            line_width=float(node.getAttr('stroke-width')))

        self.items[parent_rid]['data'].append(goocanvas_obj)
        goocanvas_obj.connect('button-press-event', self.item_button_press_events)

    def add_ellipse(self, cx, cy, rx, ry, line_width, stroke_color):
        ''' adds the ellipse to the items listing, both minidom node and goocanvas
        object in a tuple '''

        goocanvas_obj = goocanvas.Ellipse(parent=self.root,
                                center_x=cx,
                                center_y=cy,
                                radius_x=rx,
                                radius_y=ry,
                                stroke_color=stroke_color,
                                line_width=line_width)
        goocanvas_obj.connect('button-press-event', self.item_button_press_events)

        node = self.g.addChild(name='ellipse')
        node.setAttr('cx', str(cx))
        node.setAttr('cy', str(cy))
        node.setAttr('rx', str(rx))
        node.setAttr('ry', str(ry))
        node.setAttr('stroke-width', str(line_width))
        node.setAttr('stroke', stroke_color)
        self.g.addChild(node=node)

        rids = self.session.generate_rids(7)
        self.items[rids[0]] = {'type':'element', 'data':[node, goocanvas_obj], 'children':rids[1:]}
        self.items[rids[1]] = {'type':'attr', 'data':'cx', 'parent':node}
        self.items[rids[2]] = {'type':'attr', 'data':'cy', 'parent':node}
        self.items[rids[3]] = {'type':'attr', 'data':'rx', 'parent':node}
        self.items[rids[4]] = {'type':'attr', 'data':'ry', 'parent':node}
        self.items[rids[5]] = {'type':'attr', 'data':'stroke-width', 'parent':node}
        self.items[rids[6]] = {'type':'attr', 'data':'stroke', 'parent':node}

        self.session.send_items(self.items, rids)

    def del_item(self, item):
        rids = []
        for x in self.items.keys():
            if self.items[x]['type'] == 'element':
                if self.items[x]['data'][1] == item:
                    for y in self.items[x]['children']:
                        rids.append(y)
                        self.del_rid(y)
                    rids.append(x)
                    self.del_rid(x)
                    break
        self.session.del_item(rids)

    def clear_canvas(self):
        for x in self.items.keys():
            if self.items[x]['type'] == 'element':
                self.del_rid(x)

    def del_rid(self, rid):
        if self.items[rid]['type'] == 'element':
            self.items[rid]['data'][1].remove()
        del self.items[rid]

    def export_svg(self, filename):
        f = open(filename, 'w')
        f.writelines(str(self.svg))
        f.close()

    def item_button_press_events(self, item, target_item, event):
        self.del_item(item)