1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """
19 List options, these classes will display all sorts of crazy shit.
20 """
21
22 import gtk
23
24 from screenlets.options import _
25 from base import Option
26
28 """An Option for string options."""
30 """When a list is imported from the config."""
31 return eval(strvalue)
32
34 """When a list is exported to the config."""
35 return str(value)
36
55
69
71 """Set the list string value as required."""
72 self._entry.set_text(str(value))
73 self.value = value
74
79
80
82 """An editing dialog used for editing options of the ListOption-type."""
83 model = None
84 tree = None
85 buttonbox = None
86
87
89 super(ListOptionDialog, self).__init__(
90 "Edit List",
91 flags=gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_NO_SEPARATOR,
92 buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
93 gtk.STOCK_OK, gtk.RESPONSE_OK)
94 )
95
96 self.resize(300, 370)
97 self.set_keep_above(True)
98
99 self.model = gtk.ListStore(str)
100
101 self.create_ui()
102
104 """Create the user-interface for this dialog."""
105
106 hbox = gtk.HBox()
107 hbox.set_border_width(10)
108 hbox.set_spacing(10)
109
110 self.tree = gtk.TreeView(model=self.model)
111 self.tree.set_headers_visible(False)
112 self.tree.set_reorderable(True)
113
114 col = gtk.TreeViewColumn('')
115 cell = gtk.CellRendererText()
116
117 cell.set_property('foreground', 'black')
118 col.pack_start(cell, False)
119 col.set_attributes(cell, text=0)
120 self.tree.append_column(col)
121 self.tree.show()
122 hbox.pack_start(self.tree, True, True)
123
124
125
126
127 self.buttonbox = bb = gtk.VButtonBox()
128 self.buttonbox.set_layout(gtk.BUTTONBOX_START)
129 b1 = gtk.Button(stock=gtk.STOCK_ADD)
130 b2 = gtk.Button(stock=gtk.STOCK_EDIT)
131 b3 = gtk.Button(stock=gtk.STOCK_REMOVE)
132 b1.connect('clicked', self.button_callback, 'add')
133 b2.connect('clicked', self.button_callback, 'edit')
134 b3.connect('clicked', self.button_callback, 'remove')
135 bb.add(b1)
136 bb.add(b2)
137 bb.add(b3)
138 self.buttonbox.show_all()
139
140 hbox.pack_end(self.buttonbox, False)
141
142 hbox.show()
143 self.vbox.add(hbox)
144
146 """Set the list to be edited in this editor."""
147 for el in lst:
148 self.model.append([el])
149
151 """Return the list that is currently being edited in this editor."""
152 lst = []
153 for i in self.model:
154 lst.append(i[0])
155 return lst
156
158 """Remove the currently selected item."""
159 sel = self.tree.get_selection()
160 if sel:
161 it = sel.get_selected()[1]
162 if it:
163 print self.model.get_value(it, 0)
164 self.model.remove(it)
165
166 - def entry_dialog (self, default = ''):
167 """Show entry-dialog and return string."""
168 entry = gtk.Entry()
169 entry.set_text(default)
170 entry.show()
171 dlg = gtk.Dialog("Add/Edit Item", flags=gtk.DIALOG_DESTROY_WITH_PARENT,
172 buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK,
173 gtk.RESPONSE_OK))
174 dlg.set_keep_above(True)
175 dlg.vbox.add(entry)
176 resp = dlg.run()
177 ret = None
178 if resp == gtk.RESPONSE_OK:
179 ret = entry.get_text()
180 dlg.destroy()
181 return ret
182
200
201
202 """dlg = ListOptionDialog()
203 dlg.set_list(['test1', 'afarew34s', 'fhjh23faj', 'yxcdfs58df', 'hsdf7jsdfh'])
204 dlg.run()
205 print "RESULT: " + str(dlg.get_list())
206 dlg.destroy()
207 import sys
208 sys.exit(1)"""
209
210