1 |
james |
17 |
# !NewsStats.py.MainW/py |
2 |
|
|
|
3 |
|
|
import os |
4 |
|
|
import string |
5 |
|
|
import swi |
6 |
|
|
import time |
7 |
|
|
import types |
8 |
|
|
import wimp |
9 |
|
|
import Analyse |
10 |
|
|
import Iconbar |
11 |
|
|
import Newsbase |
12 |
|
|
|
13 |
|
|
temps = [] |
14 |
|
|
group = None |
15 |
|
|
analysing = 0 |
16 |
|
|
|
17 |
|
|
|
18 |
|
|
class main_window(wimp.window): |
19 |
|
|
|
20 |
|
|
def __init__(self): |
21 |
|
|
wimp.window.__init__(self, 'main') |
22 |
|
|
|
23 |
|
|
def click(self, icon, buttons = 0, x = 0, y = 0, sx = 0, sy = 0): |
24 |
|
|
"Mouse click in main window" |
25 |
|
|
global temps |
26 |
|
|
if icon == 1: |
27 |
|
|
group_menu() |
28 |
|
|
elif icon == 2: |
29 |
|
|
self.close() |
30 |
|
|
elif icon == 3 and not group is None: |
31 |
|
|
temp = '<Wimp$ScrapDir>.NewsStats.' + hex(int(time.time()))[2:] |
32 |
|
|
temps.append(temp) |
33 |
|
|
if analyse(group, temp): |
34 |
|
|
if group == 0: |
35 |
|
|
swi.swi(0x400de, 's', 'Filer_OpenDir ' + temp) |
36 |
|
|
else: |
37 |
|
|
swi.swi(0x400de, 's', 'Filer_Run ' + temp + '.index/html') |
38 |
|
|
elif icon == 4 and not group is None: |
39 |
|
|
window_save.path(group_dir(group)) |
40 |
|
|
window_save.open_centred(-1) |
41 |
|
|
|
42 |
|
|
def key(self, icon, key): |
43 |
|
|
"Key pressed in main window" |
44 |
|
|
# enter |
45 |
|
|
if key == 0xd: |
46 |
|
|
self.click(3) |
47 |
|
|
# ctrl-f2 / esc |
48 |
|
|
elif key == 0x1a2 or key == 0x1b: |
49 |
|
|
self.close() |
50 |
|
|
# pass on other interesting keys |
51 |
|
|
elif key > 0xff: |
52 |
|
|
# Wimp_ProcessKey |
53 |
|
|
swi.swi(0x400dc, 'i', key) |
54 |
|
|
|
55 |
|
|
|
56 |
|
|
def init(): |
57 |
|
|
global w, window_status, window_save |
58 |
|
|
w = main_window() |
59 |
|
|
window_status = wimp.window('status') |
60 |
|
|
window_save = wimp.save_window(save, 0x1000) |
61 |
|
|
|
62 |
|
|
|
63 |
|
|
def group_menu(): |
64 |
|
|
global group, groups |
65 |
|
|
login = Newsbase.SetUser(w.icon_text(8), w.icon_text(10)) |
66 |
|
|
if login: |
67 |
|
|
wimp.warning(login) |
68 |
|
|
return |
69 |
|
|
groups = Newsbase.ListGroups(w.icon_text(8)) |
70 |
|
|
if isinstance(groups, types.StringType): |
71 |
|
|
wimp.warning(groups) |
72 |
|
|
return |
73 |
|
|
menu_popup = wimp.menu('groups', ['groups', 'all'] + groups) |
74 |
|
|
reopen = 1 |
75 |
|
|
while reopen: |
76 |
|
|
selection, reopen = menu_popup.popup(w, 1) |
77 |
|
|
if not selection is None: |
78 |
|
|
if selection[0] == 0: |
79 |
|
|
group = 0 |
80 |
|
|
w.icon_text(0, wimp.m['all']) |
81 |
|
|
else: |
82 |
|
|
group = groups[selection[0] - 1] |
83 |
|
|
w.icon_text(0, group) |
84 |
|
|
w.icon_ungrey(3) |
85 |
|
|
w.icon_ungrey(4) |
86 |
|
|
|
87 |
|
|
|
88 |
|
|
def set_status(group = '', message = '', of = ''): |
89 |
|
|
window_status.icon_text(0, group) |
90 |
|
|
window_status.icon_text(1, message) |
91 |
|
|
window_status.icon_text(2, of) |
92 |
|
|
|
93 |
|
|
|
94 |
|
|
def group_dir(group): |
95 |
|
|
if group == 0: |
96 |
|
|
return wimp.m['dir'] |
97 |
|
|
else: |
98 |
|
|
return string.replace(group, '.', '-') |
99 |
|
|
|
100 |
|
|
|
101 |
|
|
def save(path, unsafe): |
102 |
|
|
if unsafe: |
103 |
|
|
return 0 |
104 |
|
|
window_save.close() |
105 |
|
|
analyse(group, path) |
106 |
|
|
|
107 |
|
|
|
108 |
|
|
def analyse(group, path): |
109 |
|
|
global analysing |
110 |
|
|
analysing = 1 |
111 |
|
|
fast = not w.icon_set(7) |
112 |
|
|
ok = 1 |
113 |
|
|
set_status() |
114 |
|
|
window_status.open_centred(-1) |
115 |
|
|
w.close() |
116 |
|
|
wimp.handle(wimp.poll(0)) |
117 |
|
|
if group == 0: |
118 |
|
|
for group in groups: |
119 |
|
|
result = Analyse.group(group, os.path.join(path, group_dir(group)), fast) |
120 |
|
|
if result == 0: |
121 |
|
|
pass |
122 |
|
|
elif isinstance(result, types.StringType): |
123 |
|
|
wimp.warning(result) |
124 |
|
|
else: |
125 |
|
|
result = Analyse.group(group, path, fast) |
126 |
|
|
if result == 0: |
127 |
|
|
wimp.warning(wimp.m['warning.noarticles']) |
128 |
|
|
ok = 0 |
129 |
|
|
elif isinstance(result, types.StringType): |
130 |
|
|
wimp.warning(result) |
131 |
|
|
ok = 0 |
132 |
|
|
window_status.close() |
133 |
|
|
analysing = 0 |
134 |
|
|
return ok |