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
|
import FrameWork
import EasyDialogs
import Res
import sys
import Qd
import Evt
import Events
import Dlg
import Win
# Resource-id (for checking existence)
ID_MODULES=512
ID_ABOUT=515
_arrow = Qd.qd.arrow
_watch = Qd.GetCursor(4).data
# Made available to TwitCore:
AskString = EasyDialogs.AskString
ShowMessage = EasyDialogs.Message
def SetCursor():
Qd.SetCursor(_arrow)
def SetWatch():
Qd.SetCursor(_watch)
# Exception for temporarily exiting the loop and program
ExitMainloop = 'ExitMainloop'
ExitFully = 'ExitFully'
class Application(FrameWork.Application):
"""The twit main class - mac-dependent part"""
def __init__(self, run_args, pm_args):
# First init menus, etc.
FrameWork.Application.__init__(self)
self._quitting = 0
self.real_quit = 0
# Next create our dialogs
self.mi_init(run_args, pm_args)
if self.real_quit:
return
if not run_args:
# Go into mainloop once
self.one_mainloop()
if self.real_quit:
return
if not pm_args:
# And give the debugger control.
self.to_debugger()
def makeusermenus(self):
self.filemenu = m = FrameWork.Menu(self.menubar, "File")
self._quititem = FrameWork.MenuItem(m, "Quit", "Q", self.do_quit)
def do_about(self, id, item, window, event):
import time
d = Dlg.GetNewDialog(ID_ABOUT, -1)
if not d:
return
w = d.GetDialogWindow()
port = w.GetWindowPort()
l, t, r, b = port.portRect
sl, st, sr, sb = Qd.qd.screenBits.bounds
x = ((sr-sl) - (r-l)) / 2
y = ((sb-st-16) - (b-t)) / 5
w.MoveWindow(x, y, 0)
w.ShowWindow()
d.DrawDialog()
tp, h, rect = d.GetDialogItem(2)
x0, y0, x1, y1 = rect
ybot = y0 + 32
rgn = Qd.NewRgn()
Qd.SetPort(d)
ok, evt = self.getevent(Events.mDownMask|Events.keyDownMask, 1)
if ok: return
(what, message, when, where, modifiers) = event
delta_t = 128
nexttime = when+delta_t
while ybot < y1:
# Do the animation, if it is time
if when > nexttime:
Qd.ScrollRect((x0, y0, x1, ybot), 0, 1, rgn)
y0 = y0 + 1
ybot = ybot + 1
# And update next time
delta_t = int(delta_t*0.6)-1
if delta_t < 0:
delta_t = 0
nexttime = when + delta_t
# Check for an event.
ok, evt = self.getevent(Events.mDownMask|Events.keyDownMask, 0)
if ok: return
(what, message, when, where, modifiers) = evt
while 1:
ok, evt = self.getevent(Events.mDownMask|Events.keyDownMask, -1)
if ok: return
def do_quit(self, *args):
self._quit() # Signal FrameWork.Application to stop
self.real_quit = 1
self.quit_bdb() # Tell debugger to quit.
def exit_mainloop(self):
self._quit() # Signal FrameWork.Application to stop
self.real_quit = 0
def one_mainloop(self):
self.quitting = 0
self.mainloop()
def Initialize():
try:
# if this doesn't raise an error, we are an applet containing the
# necessary resources or we have been initialized already
# so we don't have to bother opening the resource file
dummy = Res.GetResource('DLOG', ID_MODULES)
except Res.Error:
try:
Res.OpenResFile("Twit.rsrc")
except Res.Error, arg:
EasyDialogs.Message("Cannot open Twit.rsrc: "+arg[1])
sys.exit(1)
|