| 1 |
# -*- coding: utf-8 -*- |
|---|
| 2 |
HANDLE_SIZE = 8 |
|---|
| 3 |
import dabo |
|---|
| 4 |
dabo.ui.loadUI("wx") |
|---|
| 5 |
import dabo.dEvents as dEvents |
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
class DragHandle(dabo.ui.dPanel): |
|---|
| 9 |
""" The class for all the handles used to indicate the selected control |
|---|
| 10 |
that are dragged to resize the control. It has properties indicating |
|---|
| 11 |
whether it controls resizing the control in the up, right, down or left |
|---|
| 12 |
directions. These values are determined from the name of the handle, |
|---|
| 13 |
which follows a simple naming convention: |
|---|
| 14 |
First character: T, M, B => Top, Middle or Bottom |
|---|
| 15 |
Second character: L, M, R = > Left, Middle or Right |
|---|
| 16 |
When the contol is dragged, it passes the event up to its parent. The |
|---|
| 17 |
parent object then determines the affected control, and passes the |
|---|
| 18 |
event on to that control. |
|---|
| 19 |
""" |
|---|
| 20 |
def __init__(self, parent, handleName): |
|---|
| 21 |
sz = (HANDLE_SIZE, HANDLE_SIZE) |
|---|
| 22 |
super(DragHandle, self).__init__(parent, Size=sz, Visible=False, |
|---|
| 23 |
BackColor="blue") |
|---|
| 24 |
self.handleName = handleName |
|---|
| 25 |
|
|---|
| 26 |
if self.handleName in ("TL", "BR"): |
|---|
| 27 |
cursor = dabo.ui.dUICursors.Cursor_Size_NWSE |
|---|
| 28 |
elif self.handleName in ("TR", "BL"): |
|---|
| 29 |
cursor = dabo.ui.dUICursors.Cursor_Size_NESW |
|---|
| 30 |
elif self.handleName in ("TM", "BM"): |
|---|
| 31 |
cursor = dabo.ui.dUICursors.Cursor_Size_NS |
|---|
| 32 |
else: |
|---|
| 33 |
cursor = dabo.ui.dUICursors.Cursor_Size_WE |
|---|
| 34 |
self.MousePointer = dabo.ui.dUICursors.getStockCursor(cursor) |
|---|
| 35 |
|
|---|
| 36 |
self.selection = None |
|---|
| 37 |
|
|---|
| 38 |
ud = handleName[0] |
|---|
| 39 |
lr = handleName[1] |
|---|
| 40 |
self.up = (ud == "T") |
|---|
| 41 |
self.down = (ud == "B") |
|---|
| 42 |
self.left = (lr == "L") |
|---|
| 43 |
self.right = (lr == "R") |
|---|
| 44 |
|
|---|
| 45 |
self.bindEvent(dEvents.MouseLeftDown, self.onLeftDown) |
|---|
| 46 |
self.bindEvent(dEvents.MouseLeftUp, self.onLeftUp) |
|---|
| 47 |
self.bindEvent(dEvents.MouseMove, self.onMouseDrag) |
|---|
| 48 |
self.dragging = False |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
def onLeftDown(self, evt): |
|---|
| 52 |
self.dragging = True |
|---|
| 53 |
self.Form.startResize(self, evt) |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
def onLeftUp(self, evt): |
|---|
| 57 |
self.dragging = False |
|---|
| 58 |
self.Form.processLeftUp(self, evt) |
|---|
| 59 |
evt.stop() |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
def onMouseDrag(self, evt, shft=None): |
|---|
| 63 |
if shft is None: |
|---|
| 64 |
try: |
|---|
| 65 |
shft = evt.EventData["shiftDown"] |
|---|
| 66 |
except AttributeError: |
|---|
| 67 |
shft = False |
|---|
| 68 |
if self.dragging: |
|---|
| 69 |
self.Form.resizeCtrl(self, evt) |
|---|