root/page.py

Revision 80, 4.5 kB (checked in by ploum@…, 4 weeks ago)

gros commit tout pourri

Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3import sys, string, xml.dom.minidom
4try:
5        import gtk
6        import gobject
7except:
8        sys.exit(1)
9from definitions import *
10
11####################### description_in_the_widget_name hack ##################
12####################### We want to change this ###############################
13
14# functions related but not in the object
15def tab_descr(widget) :
16        # this is part of the ugliest hack
17        # spank me !
18        string = widget.get_name()
19        return string
20
21def read_descr(string) :
22        # return the widget to open
23        # needed when reading bookmarks from file
24        print "to implement"
25
26def read_title(string) :
27        #return the title from a descriptive string
28        doc2 = xml.dom.minidom.parseString(string)
29        bmark = doc2.getElementsByTagName("bookmark")[0]
30        title =  bmark.getAttribute("title")
31        return title
32
33def read_bts(string) :
34        doc2 = xml.dom.minidom.parseString(string)
35        bmark = doc2.getElementsByTagName("bookmark")[0]
36        title =  bmark.getAttribute("bts")
37        return title
38
39def read_type(string) :
40        #return the type from a descriptive string
41        doc2 = xml.dom.minidom.parseString(string)
42        bmark = doc2.getElementsByTagName("bookmark")[0]
43        zetype =  int(bmark.getAttribute("type"))
44        return zetype
45
46def xml2dic(string) :
47        doc2 = xml.dom.minidom.parseString(string)
48        bmark = doc2.getElementsByTagName("bookmark")[0]
49        dic = makedict()
50        dic["method"] = int(bmark.getAttribute("type"))
51        if dic["method"] == 1:
52                element = bmark.getElementsByTagName("bug")[0]
53                dic["bug"] = int(element.childNodes[0].nodeValue)               
54        elif dic["method"] == 2:
55                s_element = bmark.getElementsByTagName("search")[0]
56                dic["search"] = s_element.childNodes[0].nodeValue
57        elif dic["method"] == 3:
58                s_element = bmark.getElementsByTagName("search")
59                p_element = bmark.getElementsByTagName("product")[0]
60                dic["produc"] = p_element.childNodes[0].nodeValue
61                if len(s_element) == 0 :
62                         dic["search"] = None
63                else : 
64                        dic["search"] = s_element[0].childNodes[0].nodeValue
65        return dic
66
67class page :
68
69        def __init__(self, zewidget, args) :
70                self.widget = gtk.VBox()
71                self.widget.show()
72                self.widget.add(zewidget)
73                temp = self.__makeTitle(args)
74                self.title = temp[0]
75                self.descr = temp[1]
76                # The ugliest hack of all time
77                # here in conseil
78                # shame shame shame.. shame on me
79                #Naughty hack : informations about a tab are stored in the wigdet name
80                # naughty naughty zout !
81                self.widget.set_name(self.descr)
82                # in the future, the idea is to create an invisible widget
83                # and put it in a hbox or something with our widget
84                # but, as long as no one complains...
85
86#############################################################################
87############### We are in object "page" #####################################
88
89############## here start how to store description in a string ##############
90############## We also define tab title #####################################
91
92
93        # this function returns two strings in a tuple :
94        # [0] is the "nice" title of the displayed bug.
95        # [1] is the hacky name with all needed informations
96        def __makeTitle(self, args) :
97                zename=''
98                title=''
99                doc = xml.dom.minidom.Document()
100                bmark = doc.createElement("bookmark")
101                bmark.setAttribute('bts', args['bts'])
102                doc.appendChild(bmark)
103                search_type = args["method"]
104                if search_type == 1 :
105                        bmark.setAttribute("type","1")
106                        bug = args["bug"]
107                        title = "bug #%s"%bug
108                        bmark.setAttribute("title", title)
109                        node = doc.createElement("bug")
110                        node_text = doc.createTextNode(str(bug))
111                        node.appendChild(node_text)
112                        bmark.appendChild(node)
113                elif search_type == 2 :
114                        search = args["search"]
115                        title = "%s" %search
116                        bmark.setAttribute("type","2")
117                        bmark.setAttribute("title", title)
118                        node = doc.createElement("search")
119                        node_text = doc.createTextNode(search.strip())
120                        node.appendChild(node_text)
121                        bmark.appendChild(node)         
122                elif search_type == 3 :
123                        bmark.setAttribute("type","3")
124                        search = args["search"]
125                        product = args["product"]
126                        if search == None :
127                                title = "(%s)"%product
128                        else :
129                                title = "(%s) %s"%(product,search)
130                                node = doc.createElement("search")
131                                node_text = doc.createTextNode(search.strip())
132                                node.appendChild(node_text)
133                                bmark.appendChild(node)         
134                       
135                        bmark.setAttribute("title", title)
136                        prod = doc.createElement("product")
137                        prod_text = doc.createTextNode(product.strip())
138                        prod.appendChild(prod_text)
139                        bmark.appendChild(prod)
140
141                zename = doc.toxml()
142                return [title, zename]
143
144
145############## No need to modify below this line, public methods ############
146
147        def get_widget(self) :
148                return self.widget
149
150        def get_descr(self) :
151                return self.descr
152
153        def get_title(self) :
154                return self.title
Note: See TracBrowser for help on using the browser.