| 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 |
from fltk import * |
| 29 |
|
| 30 |
|
| 31 |
class DNDWidget(Fl_Widget): |
| 32 |
text_string = "" |
| 33 |
|
| 34 |
def __init__(self, x, y, w, h, label): |
| 35 |
Fl_Widget.__init__(self, x, y, w, h, label) |
| 36 |
|
| 37 |
def draw(self): |
| 38 |
fl_rect(self.x(), self.y(), self.w(), self.h(), FL_RED) |
| 39 |
|
| 40 |
def handle(self, event): |
| 41 |
if event == FL_DND_ENTER: |
| 42 |
print("FL_DND_ENTER ", self.text_string) |
| 43 |
return 1 |
| 44 |
elif event == FL_DND_LEAVE: |
| 45 |
print("FL_DND_LEAVE ", self.text_string) |
| 46 |
return 1 |
| 47 |
elif event == FL_DND_DRAG: |
| 48 |
print(f"FL_DND_DRAG {self.text_string} ({Fl.event_x()}, {Fl.event_y()})") |
| 49 |
return 1 |
| 50 |
elif event == FL_DND_RELEASE: |
| 51 |
print(f"FL_DND_RELEASE {self.text_string} ({Fl.event_x()}, {Fl.event_y()})") |
| 52 |
return 1 |
| 53 |
elif event == FL_PUSH: |
| 54 |
print("PREPUSH ", self.text_string) |
| 55 |
Fl.copy("text", 5, 0) |
| 56 |
Fl.dnd() |
| 57 |
print("POSTPUSH ", self.text_string) |
| 58 |
return 1 |
| 59 |
elif event == FL_PASTE: |
| 60 |
cl = Fl.event_text() |
| 61 |
ln = Fl.event_length() |
| 62 |
print("PASTE ", self.text_string) |
| 63 |
print(f" text = {cl}, length = {ln}") |
| 64 |
return 1 |
| 65 |
else: |
| 66 |
return 0 |
| 67 |
|
| 68 |
def text(self, t): |
| 69 |
self.text_string = t |
| 70 |
return |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
if __name__=='__main__': |
| 76 |
window = Fl_Window(50, 50, 200, 200) |
| 77 |
w1 = DNDWidget(5, 5, 90, 90, "DND") |
| 78 |
w1.text("A") |
| 79 |
w2 = DNDWidget(105, 105, 90, 90, "DND") |
| 80 |
w2.text("B") |
| 81 |
window.end() |
| 82 |
|
| 83 |
window.show() |
| 84 |
|
| 85 |
Fl.run() |