/
dialogues.py
362 lines (289 loc) · 11.2 KB
/
dialogues.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#!/usr/bin/env python
# chase
# Copyright (C) 2003 Bruce Woodward
# chase is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# chase is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with chase; see the file COPYING. If not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
from gtk import *
import GtkExtra
parent_window = None
def set_our_parent_window(our_window):
global parent_window
if parent_window != None:
our_window.set_parent_window(parent_window.get_window())
class _selection_dialogue(GtkDialog):
selection = ''
list = []
def __init__(self, title, list):
GtkDialog.__init__(self)
self.connect("destroy", self.quit)
self.connect("delete_event", self.quit)
self.set_modal(1)
self.list = list
set_our_parent_window(self)
scrolled_win = GtkScrolledWindow()
scrolled_win.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
self.vbox.pack_start(scrolled_win)
scrolled_win.show()
sellist = GtkCList(cols=1)
sellist.set_selection_mode(SELECTION_BROWSE)
scrolled_win.add_with_viewport(sellist)
sellist.connect("select_row", self.clist_select)
sellist.show()
for x in self.list:
sellist.append([x])
button_box = GtkHBox(spacing=10)
self.vbox.pack_start(button_box, expand=FALSE)
button_box.show()
select_button = GtkButton("Select")
select_button.connect("clicked", self.select_button, sellist)
button_box.pack_start(select_button)
select_button.show()
cancel_button = GtkButton("Cancel")
cancel_button.connect("clicked", self.cancel_button)
button_box.pack_start(cancel_button)
cancel_button.show()
return None
def quit(self, *args):
self.hide()
self.destroy()
mainquit()
def clist_select(self, _clist, r, c, event):
self.selection = self.list[r]
def select_button(self, _button, sellist):
self.quit()
def cancel_button(self, _button):
self.quit
def get_selected_value(self):
return self.selection
def selection_dialogue(win, title, list):
s = _selection_dialogue(title, list)
# s is a GtkDialog object
s.show()
mainloop()
return s.selection
#############################################################################
# called by the SMA and EMA class' configure method.
class _ma_configure_dialogue(GtkDialog):
def __init__(self):
GtkDialog.__init__(self)
self.set_usize(200, 300)
self.set_title("Configure Moving Average")
self.set_modal(1)
set_our_parent_window(self)
frame1 = GtkFrame("Data Source")
frame1.show()
frame1.set_border_width(4)
self.vbox.pack_start(frame1)
combo2 = GtkCombo()
combo2.show()
frame1.add(combo2)
entry1 = combo2.entry
entry1.set_text('Select Data Series')
entry1.show()
hbox2 = GtkHBox()
hbox2.show()
hbox2.set_border_width(5)
label5 = GtkLabel('Time Period')
label5.show()
hbox2.pack_start(label5, gtk.TRUE, gtk.TRUE, 0)
spinbutton2_adj = GtkAdjustment(1, 0, 100, 1, 10, 10)
spinbutton2 = GtkSpinButton(spinbutton2_adj, 1, 0)
spinbutton2.show()
hbox2.pack_start(spinbutton2, gtk.TRUE, gtk.TRUE, 0)
frame2 = GtkFrame('Shift Moving Average')
frame2.show()
self.vbox.pack_start(frame2, gtk.TRUE, gtk.TRUE, 1)
frame2.set_border_width(5)
vbox2 = GtkVBox(FALSE, 5)
vbox2.show()
frame2.add(vbox2)
vbox2.set_border_width(7)
togglebutton3 = GtkToggleButton('Shift Moving Average')
togglebutton3.show()
vbox2.pack_start(togglebutton3, gtk.FALSE, gtk.FALSE, 0)
togglebutton4 = GtkToggleButton('Shift Moving Average Left')
togglebutton4.show()
vbox2.pack_start(togglebutton4, gtk.FALSE, gtk.FALSE, 0)
togglebutton5 = GtkToggleButton('Shift Moving Average Right')
togglebutton5.show()
vbox2.pack_start(togglebutton5, gtk.FALSE, gtk.FALSE, 0)
hbox3 = GtkHBox(gtk.FALSE, 5)
hbox3.show()
vbox2.pack_start(hbox2, gtk.TRUE, gtk.TRUE, 0)
hbox3.set_border_width(10)
label6 = GtkLabel('Number of Bars to Shift')
label6.show()
hbox3.pack_start(label6, gtk.FALSE, gtk.FALSE, 0)
spinbutton3_adj = GtkAdjustment(1,0,100,1,10,10)
spinbutton3 = GtkSpinButton(spinbutton3_adk,1,0)
spinbutton3.show()
hbox3.pack_start(spinbutton3, gtk.TRUE, gtk.TRUE, 0)
frame3 = GtkFrame('Select Subchart')
frame3.show()
self.vbox.pack_start(frame3, gtk.TRUE, gtk.TRUE, 0)
frame3.set_border_width(5)
combo1 = GtkCombo()
combo1.show()
frame3.add(combo1)
combo1.set_border_width(10)
combo_entry1 = combo1.entry
combo_entry1.show()
hbox1 = GtkHBox(gtk.TRUE, 0)
def ma_configure_dialogue(dataseries_list, subchart_list):
""" returns
1. the name of dataseries to use.
2. Time Period as number of bars
3. Shift direction (if any)
4. Number of bars to shift if any.
5. Name of the subchart to display in.
"""
m = _ma_configure_dialogue(dataseries_list, subchart_list)
m.show()
mainloop()
return None
##############################################################################
# Format -> Chart dialogue.
VALID_COMBO_ITEMS = ['Daily', 'Weekly', 'Monthly']
class _chart_format(GtkDialog):
def __init__(self):
self.selection = {'scale': None, 'extrabars': None} # values returned
self.combo_entry = 0
GtkDialog.__init__(self)
set_our_parent_window(self)
self.set_usize(235, 115)
self.set_position(WIN_POS_CENTER)
self.set_policy(TRUE, FALSE, FALSE)
self.set_title('Chart Properties')
self.connect("destroy", self.quit)
self.connect("delete_event", self.quit)
self.set_modal(1)
hbox1 = GtkHBox(FALSE, 0)
hbox1.show()
self.vbox.pack_start(hbox1, FALSE, FALSE, 0)
hbox1.set_border_width(5)
label1 = GtkLabel(label="Scale")
label1.show()
hbox1.pack_start(label1, TRUE, TRUE, 0)
self.combo1 = GtkCombo()
self.combo1.show()
hbox1.pack_start(self.combo1, TRUE, TRUE, 0)
self.combo1.set_value_in_list(FALSE, FALSE)
combo1_items = VALID_COMBO_ITEMS
self.combo1.set_popdown_strings(combo1_items)
self.combo_entry =self.combo1.entry
self.combo_entry.show()
self.combo_entry.set_text("Weekly")
hbox2 = GtkHBox(FALSE, 0)
hbox2.show()
self.vbox.pack_start(hbox2, FALSE, FALSE, 0)
hbox2.set_border_width(3)
label2 = GtkLabel(label="Extra Bars")
label2.show()
hbox2.pack_start(label2, TRUE, TRUE, 0)
spinbutton1_adj = GtkAdjustment(0, 0, 100, 1, 10, 10)
self.spinbutton1 = GtkSpinButton(spinbutton1_adj)
self.spinbutton1.show()
hbox2.pack_start(self.spinbutton1, TRUE, TRUE, 0)
hbox3 = GtkHBox(TRUE, 0)
hbox3.show()
self.action_area.pack_start(hbox3, FALSE, FALSE, 10)
hbox3.set_border_width(5)
ok_button = GtkButton(label="OK")
ok_button.show()
hbox3.pack_start(ok_button, TRUE, TRUE, 0)
ok_button.set_border_width(5)
ok_button.connect("clicked", self.ok_button)
cancel_button = GtkButton(label="Cancel")
cancel_button.show()
hbox3.pack_start(cancel_button, TRUE, TRUE, 0)
cancel_button.set_border_width(5)
cancel_button.connect("clicked", self.cancel_button)
def quit(self, *args):
self.hide()
mainquit()
def cancel_button(self, _button):
self.quit()
def ok_button(self, _button):
entry = self.combo1.entry.get_text()
bars = self.spinbutton1.get_value_as_int()
if bars < 0:
bars = 0
if entry not in VALID_COMBO_ITEMS:
GtkExtra.message_box(title='Bad Value', message='Scale is invalid',
buttons=('OK',), pixmap=None, modal=TRUE)
self.selection['extrabars'] = None
self.selection['scale'] = None
else:
self.selection['extrabars'] = bars
self.selection['scale'] = entry
self.quit()
def format_chart_dialogue(win):
s = _chart_format()
s.show()
mainloop()
return (s.selection['scale'], s.selection['extrabars'])
class _assisted_trendline_chose_point(GtkDialog):
# expect drawables_names to a list of the drawables that are on the
# selected subchart.
def __init__(self, drawables_names):
GtkDialog.__init__(self)
self.set_title("Select Point")
self.set_modal(1)
self.set_position(WIN_POS_CENTER)
self.set_policy(TRUE, FALSE, FALSE)
self.connect("destory", self.quit)
self.connect("delete_event", self.quit)
set_our_parent_window(self)
self.checkboxes = {}
self.cancelled = 0
tmp_widget = None
previousButton = None
for d in drawables_names:
tmp_widget = self.checkboxes[d] = \
GtkRadioButton(label=d, group=previousButton)
previousButton= tmp_widget
tmp_widget.show()
tmp_widget.set_border_width(1)
tmp_widget.set_active(FALSE)
self.vbox.pack_start(tmp_widget, FALSE, FALSE, 0)
self.checkboxes[drawables_names[0]].set_active(TRUE)
butHBox = GtkHBox(FALSE,0)
butHBox.show()
self.action_area.pack_start(butHBox, FALSE, FALSE, 10)
butHBox.set_border_width(3)
ok_button = GtkButton(label="OK")
ok_button.show()
butHBox.pack_start(ok_button, TRUE, TRUE, 0)
ok_button.connect('clicked',self.ok_button)
cancel_button = GtkButton(label="Cancel")
cancel_button.show()
butHBox.pack_start(cancel_button, TRUE, TRUE, 0)
cancel_button.connect('clicked',self.cancel_button)
def quit(self, *args):
self.hide()
mainquit()
def ok_button(self, _button):
for i in self.checkboxes.keys():
if self.checkboxes[i].get_active():
self.selection = i
self.quit()
def cancel_button(self, _button):
self.cancelled = 1
self.quit()
def chose_point(drawables): # drawables is a list of the names of the drawables
c = _assisted_trendline_chose_point(drawables)
c.show()
mainloop()
if c.cancelled == 1:
return "cancelled"
else:
return c.selection