/[james]/currency/!Currency/py/ConvrtW.py
ViewVC logotype

Contents of /currency/!Currency/py/ConvrtW.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 53 - (show annotations) (download) (as text)
Tue Mar 9 18:41:28 2004 UTC (20 years, 9 months ago) by james
File MIME type: text/x-python
File size: 5702 byte(s)
Fix FutureWarning.

1 # !Currency.py.ConvrtW/py
2
3 import string
4 import swi
5 import wimp
6 import Rates
7 import Update
8
9
10 window_dp = menu_convert = None
11 convert_windows = []
12
13
14 class convert_window(wimp.window):
15
16 def __init__(self):
17 global window_dp, menu_convert
18 wimp.window.__init__(self, 'convert')
19 self.pane = _pane(self)
20 convert_windows.append(self)
21 if window_dp is None:
22 window_dp = dp_window()
23 menu_convert = wimp.menu('convert', ('task', 'update', ('dp', window_dp)))
24 self.init()
25
26 def remove(self):
27 wimp.window.remove(self)
28 self.pane.remove()
29 convert_windows.remove(self)
30
31 def redraw_start(self):
32 # Font_FindFont
33 self.font = swi.swi(0x40081, '.sii00;i', 'Homerton.Medium', 160, 160)
34 # ColourTrans_SetFontColours
35 swi.swi(0x4074f, 'iiii', self.font, -256, 0x00000000, 14)
36
37 def redraw_stop(self):
38 # Font_LoseFont
39 swi.swi(0x40082, 'i', self.font)
40
41 def open(self, minx, miny, maxx, maxy, scrollx, scrolly, behind):
42 self.pane.open(minx, maxy - 80, maxx, maxy, 0, 0, behind)
43 wimp.window.open(self, minx, miny, maxx, maxy, scrollx, scrolly, self.pane.handle)
44 bb = swi.block(20)
45 bb[0] = self.handle
46 # Wimp_GetWindowState
47 swi.swi(0x400cb, '.b', bb)
48 if bb[1] != minx or bb[3] != maxx or bb[4] != maxy:
49 self.pane.open(bb[1], bb[4] - 80, bb[3], bb[4], 0, 0, behind)
50
51 close = remove
52
53 def click(self, icon, buttons, x, y, sx, sy):
54 if buttons == 2:
55 window_dp.parent = self
56 window_dp.icon_text(0, str(self.dp))
57 reopen = 1
58 while reopen:
59 selection, reopen = menu_convert.menu(sx - 64, sy)
60 if selection is None:
61 pass
62 elif selection[0] == 0:
63 Update.update()
64 reopen = 0
65 elif selection[0] == 1:
66 window_dp.open_as_menu()
67 reopen = 0
68 else:
69 wimp.window.click(self, icon, buttons, x, y, sx, sy)
70
71 def init(self):
72 self.dp = 3
73 c = 0
74 for currency in Rates.currencies(wimp.lookup('format')):
75 self.add_content(_line(self, c, currency))
76 c = c + 1
77 self.set_extent(0, 0, 800, 80 + c * 32)
78 self.title(wimp.lookup('title') % Rates.date())
79 self.table = [1.0]
80 self.set_conv(0)
81 self.convert()
82
83 def set_conv(self, no):
84 self.conv_from = no
85 self.pane.icon_text(0, Rates.currency(wimp.lookup('format'), self.conv_from))
86 self.pane.icon_text(1, '%.*f' % (self.dp, self.table[no]))
87
88 def convert(self):
89 a = self.pane.icon_text(1)
90 if not '.' in a:
91 a = a + '.0'
92 try:
93 amount = eval(a)
94 except SyntaxError:
95 return 0
96 self.table = Rates.convert(self.conv_from, amount)
97 return 1
98
99
100 class _pane(wimp.window):
101
102 def __init__(self, parent):
103 wimp.window.__init__(self, 'pane')
104 self.parent = parent
105
106 def key(self, icon, key):
107 if key in range(48, 58) + [0x8, 0x7f, 0x18b]:
108 if self.parent.convert():
109 self.parent.refresh(500, 80, 800, 10000)
110 elif key in (0x18e, 0x18f, 0x19e, 0x19f, 0x1ae, 0x1af):
111 bb = swi.block(20)
112 bb[0] = self.parent.handle
113 swi.swi('Wimp_GetWindowState', '.b', bb)
114 if key == 0x18e:
115 scroll = bb[6] - 32
116 elif key == 0x18f:
117 scroll = bb[6] + 32
118 elif key == 0x19e:
119 scroll = bb[6] - (bb[4] - bb[2])
120 elif key == 0x19f:
121 scroll = bb[6] + (bb[4] - bb[2])
122 elif key == 0x1ae:
123 scroll = -0x7fffffff
124 elif key == 0x1af:
125 scroll = 0
126 self.parent.open(bb[1], bb[2], bb[3], bb[4], bb[5], scroll, bb[7])
127 elif key == 0x1a2:
128 self.parent.close()
129 else:
130 swi.swi('Wimp_ProcessKey', 'i', key)
131
132
133 class _line(wimp.content):
134
135 def __init__(self, w, no, name):
136 wimp.content.__init__(self, w, 12, 80 + no * 32, 788, 112 + no * 32)
137 self.no = no
138 self.name = string.replace(name, ' ', chr(160))
139
140 def redraw(self, ox, oy):
141 # OS_Plot
142 swi.swi(0x45, '4i0', ox + 784)
143 # Font_Paint
144 swi.swi(0x40086, 'isiii', self.window.font, '%s %.*f' % (self.name, self.window.dp, self.window.table[self.no]), 0x311, ox + 16, oy - self.pos[3] + 8)
145
146 def click(self, buttons, x, y):
147 self.window.set_conv(self.no)
148 self.window.pane.put_caret(1)
149 return 1
150
151
152 class dp_window(wimp.window):
153
154 def __init__(self):
155 wimp.window.__init__(self, 'dp')
156
157 def key(self, icon, key):
158 if key == 0xd:
159 self.click(3, 4, 0, 0, 0, 0)
160 elif key == 0x18e:
161 self.click(1, 4, 0, 0, 0, 0)
162 elif key == 0x18f:
163 self.click(2, 4, 0, 0, 0, 0)
164 else:
165 swi.swi('Wimp_ProcessKey', 'i', key)
166
167 def click(self, icon, buttons, x, y, sx, sy):
168 if icon == 1:
169 self.icon_crement(0, 0, 9, -1 + 2 * (buttons == 1))
170 elif icon == 2:
171 self.icon_crement(0, 0, 9, 1 - 2 * (buttons == 1))
172 elif icon == 3:
173 self.parent.dp = eval(self.icon_text(0))
174 self.parent.refresh(500, 80, 800, 0x7fffffff)
175 if buttons != 1:
176 wimp.close_menus()
177
178
179 def update():
180 for w in convert_windows:
181 w.contents = []
182 w.init()
183 w.refresh(0, 80, 800, 0x7fffffff)

  ViewVC Help
Powered by ViewVC 1.1.26