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
69c639e6
Commit
69c639e6
authored
Nov 07, 2011
by
Duane Johnson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Functioning xy control
parent
65350244
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
108 additions
and
46 deletions
+108
-46
test.py
test.py
+108
-46
No files found.
test.py
View file @
69c639e6
import
wx
,
os
,
math
import
wx
,
os
,
math
from
bufferedcanvas
import
*
def
imagefile
(
filename
):
def
imagefile
(
filename
):
return
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"images"
,
filename
)
return
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"images"
,
filename
)
class
XYButtons
(
BufferedCanvas
):
class
XYButtons
(
wx
.
StaticBitmap
):
keypad_positions
=
{
keypad_positions
=
{
0
:
(
102
,
109
),
0
:
(
102
,
109
),
1
:
(
78
,
86
),
1
:
(
78
,
86
),
2
:
(
49
,
58
)
2
:
(
49
,
58
)
}
}
concentric_circle_radii
=
[
19
,
4
4
,
80
,
125
]
concentric_circle_radii
=
[
19
,
4
5
,
81
,
120
]
center
=
(
14
5
,
147
)
center
=
(
14
6
,
149
)
distance
=
[
distance
=
[
# Order of Magnitude 0 (i.e. 0.1, 1, 10)
# Order of Magnitude 0 (i.e. 0.1, 1, 10)
[
[
...
@@ -37,25 +37,21 @@ class XYButtons(wx.StaticBitmap):
...
@@ -37,25 +37,21 @@ class XYButtons(wx.StaticBitmap):
]
]
]
]
def
__init__
(
self
,
parent
):
def
__init__
(
self
,
parent
,
ID
=-
1
):
self
.
bg_bmp
=
wx
.
Image
(
imagefile
(
"control_xy.png"
),
wx
.
BITMAP_TYPE_PNG
)
.
ConvertToBitmap
()
self
.
keypad_bmp
=
wx
.
Image
(
imagefile
(
"arrow_keys.png"
),
wx
.
BITMAP_TYPE_PNG
)
.
ConvertToBitmap
()
self
.
keypad_idx
=
0
self
.
keypad_idx
=
0
self
.
orderOfMagnitude
=
0
self
.
orderOfMagnitude
=
0
self
.
quadrant
=
None
self
.
concentric
=
None
# Set up background image
BufferedCanvas
.
__init__
(
self
,
parent
,
ID
)
bmp
=
wx
.
Image
(
imagefile
(
"control_xy.png"
),
wx
.
BITMAP_TYPE_PNG
)
.
ConvertToBitmap
()
self
.
bg_bmp
=
wx
.
StaticBitmap
.
__init__
(
self
,
parent
,
-
1
,
bmp
,
(
0
,
0
))
bmp
=
wx
.
Image
(
imagefile
(
"arrow_keys.png"
),
wx
.
BITMAP_TYPE_PNG
)
.
ConvertToBitmap
()
self
.
keypad_bmp
=
wx
.
StaticBitmap
(
self
,
-
1
,
bmp
,
XYButtons
.
keypad_positions
[
self
.
keypad_idx
])
# 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_MOTION
,
self
.
OnMotion
)
self
.
Bind
(
wx
.
EVT_MOTION
,
self
.
OnMotion
)
parent
.
Bind
(
wx
.
EVT_CHAR_HOOK
,
self
.
onKey
)
parent
.
Bind
(
wx
.
EVT_CHAR_HOOK
,
self
.
onKey
)
# Paint
self
.
Bind
(
wx
.
EVT_PAINT
,
self
.
OnPaint
)
def
onKey
(
self
,
evt
):
def
onKey
(
self
,
evt
):
if
evt
.
GetKeyCode
()
==
wx
.
WXK_TAB
:
if
evt
.
GetKeyCode
()
==
wx
.
WXK_TAB
:
...
@@ -86,7 +82,8 @@ class XYButtons(wx.StaticBitmap):
...
@@ -86,7 +82,8 @@ class XYButtons(wx.StaticBitmap):
def
setKeypadIndex
(
self
,
idx
):
def
setKeypadIndex
(
self
,
idx
):
self
.
keypad_idx
=
idx
self
.
keypad_idx
=
idx
self
.
keypad_bmp
.
Move
(
XYButtons
.
keypad_positions
[
self
.
keypad_idx
])
self
.
update
()
# self.keypad_bmp.Move(XYButtons.keypad_positions[self.keypad_idx])
def
getQuadrantConcentricFromPosition
(
self
,
pos
):
def
getQuadrantConcentricFromPosition
(
self
,
pos
):
rel_x
=
pos
[
0
]
-
XYButtons
.
center
[
0
]
rel_x
=
pos
[
0
]
-
XYButtons
.
center
[
0
]
...
@@ -103,33 +100,112 @@ class XYButtons(wx.StaticBitmap):
...
@@ -103,33 +100,112 @@ class XYButtons(wx.StaticBitmap):
idx
=
self
.
lookupConcentric
(
radius
)
idx
=
self
.
lookupConcentric
(
radius
)
return
(
quadrant
,
idx
)
return
(
quadrant
,
idx
)
def
mouseOverKeypad
(
self
,
mpos
):
for
idx
,
kpos
in
XYButtons
.
keypad_positions
.
items
():
rect
=
wx
.
Rect
(
kpos
[
0
],
kpos
[
1
],
44
,
32
)
if
rect
.
Contains
(
mpos
):
return
idx
return
None
def
OnMotion
(
self
,
event
):
def
OnMotion
(
self
,
event
):
mpos
=
event
.
GetPosition
()
oldq
,
oldc
=
self
.
quadrant
,
self
.
concentric
quadrant
,
concentric
=
self
.
getQuadrantConcentricFromPosition
(
mpos
)
# print 'motion:', mpos, quadrant, concentric
mpos
=
event
.
GetPosition
()
idx
=
self
.
mouseOverKeypad
(
mpos
)
if
idx
!=
None
:
self
.
quadrant
=
None
self
.
concentric
=
None
else
:
self
.
quadrant
,
self
.
concentric
=
self
.
getQuadrantConcentricFromPosition
(
mpos
)
if
oldq
!=
self
.
quadrant
or
oldc
!=
self
.
concentric
:
self
.
update
()
def
OnLeftDown
(
self
,
event
):
def
OnLeftDown
(
self
,
event
):
mpos
=
event
.
GetPosition
()
mpos
=
event
.
GetPosition
()
for
idx
,
kpos
in
XYButtons
.
keypad_positions
.
items
():
rect
=
wx
.
Rect
(
kpos
[
0
],
kpos
[
1
],
44
,
32
)
idx
=
self
.
mouseOverKeypad
(
mpos
)
if
rect
.
Contains
(
mpos
)
:
if
idx
!=
None
:
self
.
setKeypadIndex
(
idx
)
self
.
setKeypadIndex
(
idx
)
quadrant
,
concentric
=
self
.
getQuadrantConcentricFromPosition
(
mpos
)
quadrant
,
concentric
=
self
.
getQuadrantConcentricFromPosition
(
mpos
)
print
'click:'
,
mpos
,
quadrant
,
concentric
# print 'click:', mpos, quadrant, concentric
if
concentric
==
-
1
:
print
'center button'
elif
quadrant
!=
None
and
concentric
!=
None
:
dist
=
XYButtons
.
distance
[
self
.
orderOfMagnitude
][
quadrant
][
concentric
]
print
'x'
,
dist
[
0
],
'y'
,
dist
[
1
]
def
OnPaint
(
self
,
event
):
def
drawPartialPie
(
self
,
dc
,
center
,
r1
,
r2
,
angle1
,
angle2
):
# wx.StaticBitmap.OnPaint(self, event)
parts
=
64
dc
=
wx
.
PaintDC
(
self
)
angle_dist
=
angle2
-
angle1
# dc.Clear()
angle_inc
=
angle_dist
/
parts
p1
=
wx
.
Point
(
center
.
x
+
r1
*
math
.
cos
(
angle1
),
center
.
y
+
r1
*
math
.
sin
(
angle1
))
p2
=
wx
.
Point
(
center
.
x
+
r2
*
math
.
cos
(
angle1
),
center
.
y
+
r2
*
math
.
sin
(
angle1
))
p3
=
wx
.
Point
(
center
.
x
+
r2
*
math
.
cos
(
angle2
),
center
.
y
+
r2
*
math
.
sin
(
angle2
))
p4
=
wx
.
Point
(
center
.
x
+
r1
*
math
.
cos
(
angle2
),
center
.
y
+
r1
*
math
.
sin
(
angle2
))
points
=
[
p1
,
p2
]
points
.
extend
([
wx
.
Point
(
center
.
x
+
r1
*
math
.
cos
(
angle1
+
i
*
angle_inc
),
center
.
y
+
r1
*
math
.
sin
(
angle1
+
i
*
angle_inc
))
for
i
in
range
(
0
,
parts
)])
# points.extend([p3])
points
.
extend
([
wx
.
Point
(
center
.
x
+
r2
*
math
.
cos
(
angle1
+
i
*
angle_inc
),
center
.
y
+
r2
*
math
.
sin
(
angle1
+
i
*
angle_inc
))
for
i
in
range
(
parts
,
0
,
-
1
)])
dc
.
DrawPolygon
(
points
)
def
highlightQuadrant
(
self
,
dc
,
quadrant
,
concentric
):
assert
(
quadrant
>=
0
and
quadrant
<=
3
)
assert
(
concentric
>=
0
and
concentric
<=
2
)
inner_ring_radius
=
XYButtons
.
concentric_circle_radii
[
0
]
# fudge = math.pi*0.002
fudge
=
0
center
=
wx
.
Point
(
XYButtons
.
center
[
0
],
XYButtons
.
center
[
1
])
center
=
wx
.
Point
(
XYButtons
.
center
[
0
],
XYButtons
.
center
[
1
])
if
quadrant
==
0
:
a1
,
a2
=
(
-
math
.
pi
*
0.25
,
math
.
pi
*
0.25
)
center
.
x
+=
inner_ring_radius
elif
quadrant
==
1
:
a1
,
a2
=
(
math
.
pi
*
1.25
,
math
.
pi
*
1.75
)
center
.
y
-=
inner_ring_radius
elif
quadrant
==
2
:
a1
,
a2
=
(
math
.
pi
*
0.75
,
math
.
pi
*
1.25
)
center
.
x
-=
inner_ring_radius
elif
quadrant
==
3
:
a1
,
a2
=
(
math
.
pi
*
0.25
,
math
.
pi
*
0.75
)
center
.
y
+=
inner_ring_radius
r1
=
XYButtons
.
concentric_circle_radii
[
concentric
]
r2
=
XYButtons
.
concentric_circle_radii
[
concentric
+
1
]
self
.
drawPartialPie
(
dc
,
center
,
r1
-
inner_ring_radius
,
r2
-
inner_ring_radius
,
a1
+
fudge
,
a2
-
fudge
)
def
draw
(
self
,
dc
):
# print 'draw called'
dc
.
Clear
()
center
=
wx
.
Point
(
XYButtons
.
center
[
0
],
XYButtons
.
center
[
1
])
start
=
wx
.
Point
(
50
,
0
)
start
=
wx
.
Point
(
50
,
0
)
end
=
wx
.
Point
(
0
,
50
)
end
=
wx
.
Point
(
0
,
50
)
dc
.
SetPen
(
wx
.
Pen
(
wx
.
Colour
(
0
,
0
,
0
),
4
))
dc
.
SetPen
(
wx
.
Pen
(
wx
.
Colour
(
100
,
100
,
100
,
172
),
4
))
dc
.
SetBrush
(
wx
.
Brush
(
wx
.
Colour
(
255
,
0
,
0
)))
dc
.
SetBrush
(
wx
.
Brush
(
wx
.
Colour
(
0
,
0
,
0
,
128
)))
dc
.
DrawArcPoint
(
start
,
end
,
center
)
dc
.
DrawBitmap
(
self
.
bg_bmp
,
0
,
0
)
# dc.DrawArc(50, 0, 0, 50, XYButtons.center[0], XYButtons.center[1])
# self.drawPartialPie(dc, center, 19, 44, -math.pi/4, math.pi/4)
if
self
.
concentric
==
-
1
:
pass
elif
self
.
quadrant
!=
None
and
self
.
concentric
!=
None
:
self
.
highlightQuadrant
(
dc
,
self
.
quadrant
,
self
.
concentric
)
pos
=
XYButtons
.
keypad_positions
[
self
.
keypad_idx
]
dc
.
DrawBitmap
(
self
.
keypad_bmp
,
pos
[
0
],
pos
[
1
])
# dc.DrawArcPoint(start, end, center)
return
True
return
True
...
@@ -146,19 +222,5 @@ class MyApp(wx.App):
...
@@ -146,19 +222,5 @@ class MyApp(wx.App):
frame
.
Centre
()
frame
.
Centre
()
return
True
return
True
# def main():
# app = wx.App()
# frame = wx.Frame(None, title='Icon', pos=(350,300))
# # frame.SetIcon(wx.Icon('tipi.ico', wx.BITMAP_TYPE_ICO))
# frame.Center()
# frame.Show()
# panel = wx.Panel(self, -1)
# button = wx.Button(panel, -1, "Button1", (0,0))
# # wx.Image('stock_exit-16.png',wx.BITMAP_TYPE_PNG).ConvertToBitmap()
# app.MainLoop()
app
=
MyApp
(
0
)
app
=
MyApp
(
0
)
app
.
MainLoop
()
app
.
MainLoop
()
\ No newline at end of file
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