Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Printrun
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
Printrun
Commits
1df3c16e
Commit
1df3c16e
authored
Mar 25, 2014
by
Guillaume Seguin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor rework to XYButtons to prepare mini controls
parent
cb7dd322
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
24 deletions
+34
-24
xybuttons.py
printrun/xybuttons.py
+34
-24
No files found.
printrun/xybuttons.py
View file @
1df3c16e
...
@@ -41,9 +41,16 @@ class XYButtons(BufferedCanvas):
...
@@ -41,9 +41,16 @@ class XYButtons(BufferedCanvas):
concentric_circle_radii
=
[
11
,
45
,
69
,
94
,
115
]
concentric_circle_radii
=
[
11
,
45
,
69
,
94
,
115
]
center
=
(
124
,
121
)
center
=
(
124
,
121
)
spacer
=
7
spacer
=
7
imagename
=
"control_xy.png"
corner_to_axis
=
{
0
:
"x"
,
1
:
"z"
,
2
:
"y"
,
3
:
"all"
,
}
def
__init__
(
self
,
parent
,
moveCallback
=
None
,
cornerCallback
=
None
,
spacebarCallback
=
None
,
bgcolor
=
"#FFFFFF"
,
ID
=-
1
,
zcallback
=
None
):
def
__init__
(
self
,
parent
,
moveCallback
=
None
,
cornerCallback
=
None
,
spacebarCallback
=
None
,
bgcolor
=
"#FFFFFF"
,
ID
=-
1
,
zcallback
=
None
):
self
.
bg_bmp
=
wx
.
Image
(
imagefile
(
"control_xy.png"
),
wx
.
BITMAP_TYPE_PNG
)
.
ConvertToBitmap
()
self
.
bg_bmp
=
wx
.
Image
(
imagefile
(
self
.
imagename
),
wx
.
BITMAP_TYPE_PNG
)
.
ConvertToBitmap
()
self
.
keypad_bmp
=
wx
.
Image
(
imagefile
(
"arrow_keys.png"
),
wx
.
BITMAP_TYPE_PNG
)
.
ConvertToBitmap
()
self
.
keypad_bmp
=
wx
.
Image
(
imagefile
(
"arrow_keys.png"
),
wx
.
BITMAP_TYPE_PNG
)
.
ConvertToBitmap
()
self
.
keypad_idx
=
-
1
self
.
keypad_idx
=
-
1
self
.
quadrant
=
None
self
.
quadrant
=
None
...
@@ -64,6 +71,9 @@ class XYButtons(BufferedCanvas):
...
@@ -64,6 +71,9 @@ class XYButtons(BufferedCanvas):
BufferedCanvas
.
__init__
(
self
,
parent
,
ID
,
size
=
self
.
bg_bmp
.
GetSize
())
BufferedCanvas
.
__init__
(
self
,
parent
,
ID
,
size
=
self
.
bg_bmp
.
GetSize
())
self
.
bind_events
()
def
bind_events
(
self
):
# Set up mouse and keyboard event capture
# Set up mouse and keyboard event capture
self
.
Bind
(
wx
.
EVT_LEFT_DOWN
,
self
.
OnLeftDown
)
self
.
Bind
(
wx
.
EVT_LEFT_DOWN
,
self
.
OnLeftDown
)
self
.
Bind
(
wx
.
EVT_LEFT_DCLICK
,
self
.
OnLeftDown
)
self
.
Bind
(
wx
.
EVT_LEFT_DCLICK
,
self
.
OnLeftDown
)
...
@@ -84,7 +94,7 @@ class XYButtons(BufferedCanvas):
...
@@ -84,7 +94,7 @@ class XYButtons(BufferedCanvas):
if
self
.
lastMove
:
if
self
.
lastMove
:
self
.
moveCallback
(
*
self
.
lastMove
)
self
.
moveCallback
(
*
self
.
lastMove
)
if
self
.
lastCorner
:
if
self
.
lastCorner
:
self
.
cornerCallback
(
self
.
lastCorner
)
self
.
cornerCallback
(
self
.
corner_to_axis
[
self
.
lastCorner
]
)
def
clearRepeat
(
self
):
def
clearRepeat
(
self
):
self
.
lastMove
=
None
self
.
lastMove
=
None
...
@@ -120,15 +130,15 @@ class XYButtons(BufferedCanvas):
...
@@ -120,15 +130,15 @@ class XYButtons(BufferedCanvas):
def
lookupConcentric
(
self
,
radius
):
def
lookupConcentric
(
self
,
radius
):
idx
=
0
idx
=
0
for
r
in
XYButtons
.
concentric_circle_radii
[
1
:]:
for
r
in
self
.
concentric_circle_radii
[
1
:]:
if
radius
<
r
:
if
radius
<
r
:
return
idx
return
idx
idx
+=
1
idx
+=
1
return
len
(
XYButtons
.
concentric_circle_radii
)
return
len
(
self
.
concentric_circle_radii
)
def
getQuadrantConcentricFromPosition
(
self
,
pos
):
def
getQuadrantConcentricFromPosition
(
self
,
pos
):
rel_x
=
pos
[
0
]
-
XYButtons
.
center
[
0
]
rel_x
=
pos
[
0
]
-
self
.
center
[
0
]
rel_y
=
pos
[
1
]
-
XYButtons
.
center
[
1
]
rel_y
=
pos
[
1
]
-
self
.
center
[
1
]
radius
=
math
.
sqrt
(
rel_x
**
2
+
rel_y
**
2
)
radius
=
math
.
sqrt
(
rel_x
**
2
+
rel_y
**
2
)
if
rel_x
>
rel_y
and
rel_x
>
-
rel_y
:
if
rel_x
>
rel_y
and
rel_x
>
-
rel_y
:
quadrant
=
0
# Right
quadrant
=
0
# Right
...
@@ -143,7 +153,7 @@ class XYButtons(BufferedCanvas):
...
@@ -143,7 +153,7 @@ class XYButtons(BufferedCanvas):
return
(
quadrant
,
idx
)
return
(
quadrant
,
idx
)
def
mouseOverKeypad
(
self
,
mpos
):
def
mouseOverKeypad
(
self
,
mpos
):
for
idx
,
kpos
in
XYButtons
.
keypad_positions
.
items
():
for
idx
,
kpos
in
self
.
keypad_positions
.
items
():
radius
=
self
.
distanceToPoint
(
mpos
[
0
],
mpos
[
1
],
kpos
[
0
],
kpos
[
1
])
radius
=
self
.
distanceToPoint
(
mpos
[
0
],
mpos
[
1
],
kpos
[
0
],
kpos
[
1
])
if
radius
<
9
:
if
radius
<
9
:
return
idx
return
idx
...
@@ -163,10 +173,10 @@ class XYButtons(BufferedCanvas):
...
@@ -163,10 +173,10 @@ class XYButtons(BufferedCanvas):
assert
(
quadrant
>=
0
and
quadrant
<=
3
)
assert
(
quadrant
>=
0
and
quadrant
<=
3
)
assert
(
concentric
>=
0
and
concentric
<=
3
)
assert
(
concentric
>=
0
and
concentric
<=
3
)
inner_ring_radius
=
XYButtons
.
concentric_circle_radii
[
0
]
inner_ring_radius
=
self
.
concentric_circle_radii
[
0
]
# fudge = math.pi*0.002
# fudge = math.pi*0.002
fudge
=
-
0.02
fudge
=
-
0.02
center
=
wx
.
Point
(
XYButtons
.
center
[
0
],
XYButtons
.
center
[
1
])
center
=
wx
.
Point
(
self
.
center
[
0
],
self
.
center
[
1
])
if
quadrant
==
0
:
if
quadrant
==
0
:
a1
,
a2
=
(
-
math
.
pi
*
0.25
,
math
.
pi
*
0.25
)
a1
,
a2
=
(
-
math
.
pi
*
0.25
,
math
.
pi
*
0.25
)
center
.
x
+=
inner_ring_radius
center
.
x
+=
inner_ring_radius
...
@@ -180,13 +190,13 @@ class XYButtons(BufferedCanvas):
...
@@ -180,13 +190,13 @@ class XYButtons(BufferedCanvas):
a1
,
a2
=
(
math
.
pi
*
0.25
,
math
.
pi
*
0.75
)
a1
,
a2
=
(
math
.
pi
*
0.25
,
math
.
pi
*
0.75
)
center
.
y
+=
inner_ring_radius
center
.
y
+=
inner_ring_radius
r1
=
XYButtons
.
concentric_circle_radii
[
concentric
]
r1
=
self
.
concentric_circle_radii
[
concentric
]
r2
=
XYButtons
.
concentric_circle_radii
[
concentric
+
1
]
r2
=
self
.
concentric_circle_radii
[
concentric
+
1
]
self
.
drawPartialPie
(
gc
,
center
,
r1
-
inner_ring_radius
,
r2
-
inner_ring_radius
,
a1
+
fudge
,
a2
-
fudge
)
self
.
drawPartialPie
(
gc
,
center
,
r1
-
inner_ring_radius
,
r2
-
inner_ring_radius
,
a1
+
fudge
,
a2
-
fudge
)
def
drawCorner
(
self
,
gc
,
x
,
y
,
angle
=
0.0
):
def
drawCorner
(
self
,
gc
,
x
,
y
,
angle
=
0.0
):
w
,
h
=
XYButtons
.
corner_size
w
,
h
=
self
.
corner_size
gc
.
PushState
()
gc
.
PushState
()
gc
.
Translate
(
x
,
y
)
gc
.
Translate
(
x
,
y
)
...
@@ -203,9 +213,9 @@ class XYButtons(BufferedCanvas):
...
@@ -203,9 +213,9 @@ class XYButtons(BufferedCanvas):
gc
.
PopState
()
gc
.
PopState
()
def
highlightCorner
(
self
,
gc
,
corner
=
0
):
def
highlightCorner
(
self
,
gc
,
corner
=
0
):
w
,
h
=
XYButtons
.
corner_size
w
,
h
=
self
.
corner_size
xinset
,
yinset
=
XYButtons
.
corner_inset
xinset
,
yinset
=
self
.
corner_inset
cx
,
cy
=
XYButtons
.
center
cx
,
cy
=
self
.
center
ww
,
wh
=
self
.
GetSizeTuple
()
ww
,
wh
=
self
.
GetSizeTuple
()
if
corner
==
0
:
if
corner
==
0
:
...
@@ -236,7 +246,7 @@ class XYButtons(BufferedCanvas):
...
@@ -236,7 +246,7 @@ class XYButtons(BufferedCanvas):
gc
.
SetBrush
(
wx
.
Brush
(
wx
.
Colour
(
0
,
0
,
0
,
128
)))
gc
.
SetBrush
(
wx
.
Brush
(
wx
.
Colour
(
0
,
0
,
0
,
128
)))
if
self
.
concentric
is
not
None
:
if
self
.
concentric
is
not
None
:
if
self
.
concentric
<
len
(
XYButtons
.
concentric_circle_radii
):
if
self
.
concentric
<
len
(
self
.
concentric_circle_radii
):
if
self
.
quadrant
is
not
None
:
if
self
.
quadrant
is
not
None
:
self
.
highlightQuadrant
(
gc
,
self
.
quadrant
,
self
.
concentric
)
self
.
highlightQuadrant
(
gc
,
self
.
quadrant
,
self
.
concentric
)
elif
self
.
corner
is
not
None
:
elif
self
.
corner
is
not
None
:
...
@@ -244,14 +254,14 @@ class XYButtons(BufferedCanvas):
...
@@ -244,14 +254,14 @@ class XYButtons(BufferedCanvas):
if
self
.
keypad_idx
>=
0
:
if
self
.
keypad_idx
>=
0
:
padw
,
padh
=
(
self
.
keypad_bmp
.
GetWidth
(),
self
.
keypad_bmp
.
GetHeight
())
padw
,
padh
=
(
self
.
keypad_bmp
.
GetWidth
(),
self
.
keypad_bmp
.
GetHeight
())
pos
=
XYButtons
.
keypad_positions
[
self
.
keypad_idx
]
pos
=
self
.
keypad_positions
[
self
.
keypad_idx
]
pos
=
(
pos
[
0
]
-
padw
/
2
-
3
,
pos
[
1
]
-
padh
/
2
-
3
)
pos
=
(
pos
[
0
]
-
padw
/
2
-
3
,
pos
[
1
]
-
padh
/
2
-
3
)
gc
.
DrawBitmap
(
self
.
keypad_bmp
,
pos
[
0
],
pos
[
1
],
padw
,
padh
)
gc
.
DrawBitmap
(
self
.
keypad_bmp
,
pos
[
0
],
pos
[
1
],
padw
,
padh
)
# Draw label overlays
# Draw label overlays
gc
.
SetPen
(
wx
.
Pen
(
wx
.
Colour
(
255
,
255
,
255
,
128
),
1
))
gc
.
SetPen
(
wx
.
Pen
(
wx
.
Colour
(
255
,
255
,
255
,
128
),
1
))
gc
.
SetBrush
(
wx
.
Brush
(
wx
.
Colour
(
255
,
255
,
255
,
128
+
64
)))
gc
.
SetBrush
(
wx
.
Brush
(
wx
.
Colour
(
255
,
255
,
255
,
128
+
64
)))
for
idx
,
kpos
in
XYButtons
.
label_overlay_positions
.
items
():
for
idx
,
kpos
in
self
.
label_overlay_positions
.
items
():
if
idx
!=
self
.
concentric
:
if
idx
!=
self
.
concentric
:
r
=
kpos
[
2
]
r
=
kpos
[
2
]
gc
.
DrawEllipse
(
kpos
[
0
]
-
r
,
kpos
[
1
]
-
r
,
r
*
2
,
r
*
2
)
gc
.
DrawEllipse
(
kpos
[
0
]
-
r
,
kpos
[
1
]
-
r
,
r
*
2
,
r
*
2
)
...
@@ -260,7 +270,7 @@ class XYButtons(BufferedCanvas):
...
@@ -260,7 +270,7 @@ class XYButtons(BufferedCanvas):
gc
.
SetBrush
(
wx
.
Brush
(
self
.
bgcolormask
))
gc
.
SetBrush
(
wx
.
Brush
(
self
.
bgcolormask
))
gc
.
DrawRectangle
(
0
,
0
,
w
,
h
)
gc
.
DrawRectangle
(
0
,
0
,
w
,
h
)
# Used to check exact position of keypad dots, should we ever resize the bg image
# Used to check exact position of keypad dots, should we ever resize the bg image
# for idx, kpos in
XYButtons
.label_overlay_positions.items():
# for idx, kpos in
self
.label_overlay_positions.items():
# dc.DrawCircle(kpos[0], kpos[1], kpos[2])
# dc.DrawCircle(kpos[0], kpos[1], kpos[2])
## ------ ##
## ------ ##
...
@@ -316,16 +326,16 @@ class XYButtons(BufferedCanvas):
...
@@ -316,16 +326,16 @@ class XYButtons(BufferedCanvas):
self
.
quadrant
=
None
self
.
quadrant
=
None
self
.
concentric
=
None
self
.
concentric
=
None
if
idx
is
None
:
if
idx
is
None
:
center
=
wx
.
Point
(
XYButtons
.
center
[
0
],
XYButtons
.
center
[
1
])
center
=
wx
.
Point
(
self
.
center
[
0
],
self
.
center
[
1
])
riseDist
=
self
.
distanceToLine
(
mpos
,
center
.
x
-
1
,
center
.
y
-
1
,
center
.
x
+
1
,
center
.
y
+
1
)
riseDist
=
self
.
distanceToLine
(
mpos
,
center
.
x
-
1
,
center
.
y
-
1
,
center
.
x
+
1
,
center
.
y
+
1
)
fallDist
=
self
.
distanceToLine
(
mpos
,
center
.
x
-
1
,
center
.
y
+
1
,
center
.
x
+
1
,
center
.
y
-
1
)
fallDist
=
self
.
distanceToLine
(
mpos
,
center
.
x
-
1
,
center
.
y
+
1
,
center
.
x
+
1
,
center
.
y
-
1
)
self
.
quadrant
,
self
.
concentric
=
self
.
getQuadrantConcentricFromPosition
(
mpos
)
self
.
quadrant
,
self
.
concentric
=
self
.
getQuadrantConcentricFromPosition
(
mpos
)
# If mouse hovers in space between quadrants, don't commit to a quadrant
# If mouse hovers in space between quadrants, don't commit to a quadrant
if
riseDist
<=
XYButtons
.
spacer
or
fallDist
<=
XYButtons
.
spacer
:
if
riseDist
<=
self
.
spacer
or
fallDist
<=
self
.
spacer
:
self
.
quadrant
=
None
self
.
quadrant
=
None
cx
,
cy
=
XYButtons
.
center
cx
,
cy
=
self
.
center
if
mpos
.
x
<
cx
and
mpos
.
y
<
cy
:
if
mpos
.
x
<
cx
and
mpos
.
y
<
cy
:
self
.
corner
=
0
self
.
corner
=
0
if
mpos
.
x
>=
cx
and
mpos
.
y
<
cy
:
if
mpos
.
x
>=
cx
and
mpos
.
y
<
cy
:
...
@@ -351,7 +361,7 @@ class XYButtons(BufferedCanvas):
...
@@ -351,7 +361,7 @@ class XYButtons(BufferedCanvas):
if
idx
is
None
:
if
idx
is
None
:
self
.
quadrant
,
self
.
concentric
=
self
.
getQuadrantConcentricFromPosition
(
mpos
)
self
.
quadrant
,
self
.
concentric
=
self
.
getQuadrantConcentricFromPosition
(
mpos
)
if
self
.
concentric
is
not
None
:
if
self
.
concentric
is
not
None
:
if
self
.
concentric
<
len
(
XYButtons
.
concentric_circle_radii
):
if
self
.
concentric
<
len
(
self
.
concentric_circle_radii
):
if
self
.
quadrant
is
not
None
:
if
self
.
quadrant
is
not
None
:
x
,
y
,
z
=
self
.
getMovement
()
x
,
y
,
z
=
self
.
getMovement
()
if
self
.
moveCallback
:
if
self
.
moveCallback
:
...
@@ -362,7 +372,7 @@ class XYButtons(BufferedCanvas):
...
@@ -362,7 +372,7 @@ class XYButtons(BufferedCanvas):
if
self
.
cornerCallback
:
if
self
.
cornerCallback
:
self
.
lastCorner
=
self
.
corner
self
.
lastCorner
=
self
.
corner
self
.
lastMove
=
None
self
.
lastMove
=
None
self
.
cornerCallback
(
self
.
corner
)
self
.
cornerCallback
(
self
.
corner
_to_axis
[
self
.
corner
]
)
else
:
else
:
if
self
.
keypad_idx
==
idx
:
if
self
.
keypad_idx
==
idx
:
self
.
setKeypadIndex
(
-
1
)
self
.
setKeypadIndex
(
-
1
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment