Mercurial > code > home > repos > light9
annotate light8/uihelpers.py @ 30:e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
author | drewp |
---|---|
date | Sun, 07 Jul 2002 10:48:38 +0000 |
parents | 219d6fcbc28d |
children | 411de8b46aef |
rev | line source |
---|---|
0 | 1 """all the tiny tk helper functions""" |
2 | |
3 from Tkinter import * | |
4 | |
5 def make_frame(parent): | |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
0
diff
changeset
|
6 f = Frame(parent, bd=0) |
0 | 7 f.pack(side='left') |
8 return f | |
9 | |
10 def bindkeys(root,key, func): | |
11 root.bind(key, func) | |
12 for w in root.winfo_children(): | |
13 w.bind(key, func) | |
14 | |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
0
diff
changeset
|
15 def toplevelat(x,y,w=None,h=None): |
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
0
diff
changeset
|
16 tl=Toplevel() |
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
0
diff
changeset
|
17 if w and h: |
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
0
diff
changeset
|
18 tl.wm_geometry("%dx%d+%d+%d"%(w,h,x,y)) |
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
0
diff
changeset
|
19 else: |
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
0
diff
changeset
|
20 tl.wm_geometry("+%d+%d"%(x,y)) |
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
0
diff
changeset
|
21 return tl |
0 | 22 |
23 def toggle_slider(s): | |
24 if s.get() == 0: | |
25 s.set(100) | |
26 else: | |
27 s.set(0) | |
28 | |
29 # for lambda callbacks | |
30 def printout(t): | |
31 print t | |
32 | |
33 def colorlabel(label): | |
34 """color a label based on its own text""" | |
35 txt=label['text'] or "0" | |
36 lev=float(txt)/100 | |
37 low=(80,80,180) | |
38 high=(255,55,050) | |
39 out = [int(l+lev*(h-l)) for h,l in zip(high,low)] | |
40 col="#%02X%02X%02X" % tuple(out) | |
41 label.config(bg=col) | |
30
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
42 |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
43 class Togglebutton(Button): |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
44 """works like a single radiobutton, but it's a button so the label's on the button face, not to the side""" |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
45 def __init__(self,parent,**kw): |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
46 if kw['variable']: |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
47 self.variable = kw['variable'] |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
48 self.variable.trace('w',self.varchanged) |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
49 del kw['variable'] |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
50 else: |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
51 self.variable=None |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
52 self.oldcommand = kw.get('command',None) |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
53 kw['command'] = self.invoke |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
54 Button.__init__(self,parent,**kw) |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
55 |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
56 self.origbkg = self.cget('bg') |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
57 |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
58 self.state=0 |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
59 if self.variable: |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
60 self.state = self.variable.get() |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
61 |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
62 self.setstate(self.state) |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
63 |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
64 self.bind("<Enter>",lambda ev: self.setstate) |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
65 self.bind("<Leave>",lambda ev: self.setstate) |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
66 |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
67 def varchanged(self,*args): |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
68 self.setstate(self.variable.get()) |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
69 |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
70 def invoke(self): |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
71 self.setstate(not self.state) |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
72 |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
73 if self.oldcommand: |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
74 self.oldcommand() |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
75 |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
76 def setstate(self,newstate): |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
77 self.variable.set(newstate) |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
78 if newstate: # set |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
79 self.tk.call('tkButtonDown',self) |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
80 self.config(bg='green') |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
81 else: # unset |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
82 self.tk.call('tkButtonUp',self) |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
83 self.config(bg=self.origbkg) |
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
26
diff
changeset
|
84 return "break" |