| 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 |
from fltk import * |
| 32 |
import sys, math |
| 33 |
|
| 34 |
|
| 35 |
class EnterExit(Fl_Box): |
| 36 |
def __init__(self, x, y, w, h, l): |
| 37 |
Fl_Box.__init__(self,FL_BORDER_BOX,x,y,w,h,l) |
| 38 |
print(self) |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
def handle(self, e): |
| 45 |
print("event = ", e) |
| 46 |
if e == FL_ENTER: |
| 47 |
try: |
| 48 |
print("FL_ENTER") |
| 49 |
self.color(FL_RED) |
| 50 |
self.redraw() |
| 51 |
except: |
| 52 |
print('uncaught!', sys.exc_info()[0], sys.exc_info()[1]) |
| 53 |
return 1 |
| 54 |
elif e == FL_LEAVE: |
| 55 |
try: |
| 56 |
print("FL_LEAVE") |
| 57 |
self.color(FL_GRAY) |
| 58 |
self.redraw() |
| 59 |
except: |
| 60 |
print('uncaught!', sys.exc_info()[0], sys.exc_info()[1]) |
| 61 |
return 1 |
| 62 |
else: |
| 63 |
return 0 |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
class testwindow(Fl_Window): |
| 68 |
cx = 0 |
| 69 |
cy = 0 |
| 70 |
key = '0' |
| 71 |
def __init__(self, b, x, y, w, h, l): |
| 72 |
Fl_Window.__init__(self,x,y,w, h,l) |
| 73 |
self.box(b) |
| 74 |
key = 0 |
| 75 |
|
| 76 |
def draw(self): |
| 77 |
print(self.label(), " :draw") |
| 78 |
Fl_Window.draw(self) |
| 79 |
if self.key: |
| 80 |
fl_draw(self.key, 1, self.cx, self.cy) |
| 81 |
|
| 82 |
def handle(self, e): |
| 83 |
if e != FL_MOVE: |
| 84 |
print(self.label()) |
| 85 |
if Fl_Window.handle(self, e): |
| 86 |
return 1; |
| 87 |
if e == FL_FOCUS: |
| 88 |
return 1 |
| 89 |
if e == FL_PUSH: |
| 90 |
Fl.focus(self.this) |
| 91 |
return 1 |
| 92 |
if e == FL_KEYDOWN and Fl.event_text()[0]: |
| 93 |
self.key = Fl.event_text()[0] |
| 94 |
self.cx = Fl.event_x() |
| 95 |
self.y = Fl.event_y() |
| 96 |
self.redraw() |
| 97 |
return 1 |
| 98 |
return 0 |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
popup = None |
| 103 |
|
| 104 |
bigmess = "this|is|only|a test" |
| 105 |
|
| 106 |
window = testwindow(FL_UP_BOX,0,0,400,400,"outer") |
| 107 |
|
| 108 |
tn1 = Fl_Toggle_Button(310,310,80,80,"&outer") |
| 109 |
|
| 110 |
ee1 = EnterExit(10,310,80,80,"enterexit") |
| 111 |
|
| 112 |
fi1 = Fl_Input(150,310,150,25,"input:") |
| 113 |
|
| 114 |
mb1 = Fl_Menu_Button(5,150,80,25,"menu&1") |
| 115 |
|
| 116 |
mb1.menu(( ("this",), ("is",), ("only",), ("a test",), (None,))) |
| 117 |
|
| 118 |
subwindow = testwindow(FL_DOWN_BOX,100,100,200,200,"inner") |
| 119 |
|
| 120 |
tn2 = Fl_Toggle_Button(310,310,80,80,"&outer") |
| 121 |
subwindow.add(tn2) |
| 122 |
|
| 123 |
ee2 = EnterExit(10,310,80,80,"enterexit") |
| 124 |
subwindow.add(ee2) |
| 125 |
|
| 126 |
fi2 = Fl_Input(150,310,150,25,"input:") |
| 127 |
subwindow.add(fi2) |
| 128 |
|
| 129 |
mb2 = Fl_Menu_Button(5,150,80,25,"menu&2") |
| 130 |
|
| 131 |
|
| 132 |
mb2.menu(( ("this",), ("is",), ("only",), ("a test",), (None,))) |
| 133 |
subwindow.end() |
| 134 |
subwindow.resizable(subwindow) |
| 135 |
window.resizable(subwindow) |
| 136 |
window.add(subwindow) |
| 137 |
|
| 138 |
fb = Fl_Box(FL_NO_BOX,0,0,400,100, |
| 139 |
"A child Fl_Window with children of it's own may " |
| 140 |
"be useful for imbedding controls into a GL or display " |
| 141 |
"that needs a different visual. There are bugs with the " |
| 142 |
"origins being different between drawing and events, " |
| 143 |
"which I hope I have solved." |
| 144 |
) |
| 145 |
fb.align(FL_ALIGN_WRAP) |
| 146 |
|
| 147 |
popup = Fl_Menu_Button(0,0,400,400) |
| 148 |
popup.type(Fl_Menu_Button.POPUP3) |
| 149 |
|
| 150 |
popup.menu(( ("This",), ("is",), ("a popup",), ("menu",), ("this",), ("is",), ("only",), ("a test",), (None,))) |
| 151 |
|
| 152 |
|
| 153 |
window.add(fb) |
| 154 |
window.add(popup) |
| 155 |
window.end() |
| 156 |
|
| 157 |
|
| 158 |
window.show() |
| 159 |
|
| 160 |
print("rec = ", sys.getrecursionlimit()) |
| 161 |
|
| 162 |
|
| 163 |
Fl.run() |