Integrate new UI with pronterface
parent
8986a90c76
commit
8b56bbe548
|
@ -0,0 +1,141 @@
|
|||
"""
|
||||
BufferedCanvas -- Double-buffered, flicker-free canvas widget
|
||||
Copyright (C) 2005, 2006 Daniel Keep
|
||||
|
||||
To use this widget, just override or replace the draw method.
|
||||
This will be called whenever the widget size changes, or when
|
||||
the update method is explicitly called.
|
||||
|
||||
Please submit any improvements/bugfixes/ideas to the following
|
||||
url:
|
||||
|
||||
http://wiki.wxpython.org/index.cgi/BufferedCanvas
|
||||
|
||||
2006-04-29: Added bugfix for a crash on Mac provided by Marc Jans.
|
||||
"""
|
||||
|
||||
# Hint: try removing '.sp4msux0rz'
|
||||
__author__ = 'Daniel Keep <daniel.keep.sp4msux0rz@gmail.com>'
|
||||
|
||||
__license__ = """
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
As a special exception, the copyright holders of this library
|
||||
hereby recind Section 3 of the GNU Lesser General Public License. This
|
||||
means that you MAY NOT apply the terms of the ordinary GNU General
|
||||
Public License instead of this License to any given copy of the
|
||||
Library. This has been done to prevent users of the Library from being
|
||||
denied access or the ability to use future improvements.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
"""
|
||||
|
||||
__all__ = ['BufferedCanvas']
|
||||
|
||||
import wx
|
||||
|
||||
class BufferedCanvas(wx.Panel):
|
||||
"""
|
||||
Implements a double-buffered, flicker-free canvas widget.
|
||||
|
||||
Standard usage is to subclass this class, and override the
|
||||
draw method. The draw method is passed a device context, which
|
||||
should be used to do your drawing.
|
||||
|
||||
Also, you should NOT call dc.BeginDrawing() and dc.EndDrawing() --
|
||||
these methods are automatically called for you, although you still
|
||||
need to manually clear the device context.
|
||||
|
||||
If you want to force a redraw (for whatever reason), you should
|
||||
call the update method. This is because the draw method is never
|
||||
called as a result of an EVT_PAINT event.
|
||||
"""
|
||||
|
||||
# These are our two buffers. Just be aware that when the buffers
|
||||
# are flipped, the REFERENCES are swapped. So I wouldn't want to
|
||||
# try holding onto explicit references to one or the other ;)
|
||||
buffer = None
|
||||
backbuffer = None
|
||||
|
||||
def __init__(self,
|
||||
parent,
|
||||
ID=-1,
|
||||
pos=wx.DefaultPosition,
|
||||
size=wx.DefaultSize,
|
||||
style=wx.NO_FULL_REPAINT_ON_RESIZE):
|
||||
wx.Panel.__init__(self,parent,ID,pos,size,style)
|
||||
|
||||
# Bind events
|
||||
self.Bind(wx.EVT_PAINT, self.onPaint)
|
||||
self.Bind(wx.EVT_SIZE, self.onSize)
|
||||
|
||||
# Disable background erasing (flicker-licious)
|
||||
def disable_event(*pargs,**kwargs):
|
||||
pass # the sauce, please
|
||||
self.Bind(wx.EVT_ERASE_BACKGROUND, disable_event)
|
||||
|
||||
# Ensure that the buffers are setup correctly
|
||||
self.onSize(None)
|
||||
|
||||
##
|
||||
## General methods
|
||||
##
|
||||
|
||||
def draw(self,dc):
|
||||
"""
|
||||
Stub: called when the canvas needs to be re-drawn.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def flip(self):
|
||||
"""
|
||||
Flips the front and back buffers.
|
||||
"""
|
||||
self.buffer,self.backbuffer = self.backbuffer,self.buffer
|
||||
self.Refresh()
|
||||
|
||||
|
||||
def update(self):
|
||||
"""
|
||||
Causes the canvas to be updated.
|
||||
"""
|
||||
dc = wx.MemoryDC()
|
||||
dc.SelectObject(self.backbuffer)
|
||||
dc.BeginDrawing()
|
||||
self.draw(dc)
|
||||
dc.EndDrawing()
|
||||
self.flip()
|
||||
|
||||
##
|
||||
## Event handlers
|
||||
##
|
||||
|
||||
def onPaint(self, event):
|
||||
# Blit the front buffer to the screen
|
||||
dc = wx.BufferedPaintDC(self, self.buffer)
|
||||
|
||||
|
||||
def onSize(self, event):
|
||||
# Here we need to create a new off-screen buffer to hold
|
||||
# the in-progress drawings on.
|
||||
width,height = self.GetClientSizeTuple()
|
||||
if width == 0:
|
||||
width = 1
|
||||
if height == 0:
|
||||
height = 1
|
||||
self.buffer = wx.EmptyBitmap(width,height)
|
||||
self.backbuffer = wx.EmptyBitmap(width,height)
|
||||
|
||||
# Now update the screen
|
||||
self.update()
|
|
@ -30,6 +30,8 @@ if os.name=="nt":
|
|||
pass
|
||||
|
||||
|
||||
from xybuttons import XYButtons
|
||||
from zbuttons import ZButtons
|
||||
import pronsole
|
||||
|
||||
def dosify(name):
|
||||
|
@ -74,33 +76,33 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
|
|||
ycol=(180,180,255)
|
||||
zcol=(180,255,180)
|
||||
self.cpbuttons=[
|
||||
[_("X+100"),("move X 100"),(2,0),xcol,(1,3)],
|
||||
[_("X+10"),("move X 10"),(3,0),xcol,(1,3)],
|
||||
[_("X+1"),("move X 1"),(4,0),xcol,(1,3)],
|
||||
[_("X+0.1"),("move X 0.1"),(5,0),xcol,(1,3)],
|
||||
[_("HomeX"),("home X"),(6,0),(205,205,78),(1,3)],
|
||||
[_("X-0.1"),("move X -0.1"),(7,0),xcol,(1,3)],
|
||||
[_("X-1"),("move X -1"),(8,0),xcol,(1,3)],
|
||||
[_("X-10"),("move X -10"),(9,0),xcol,(1,3)],
|
||||
[_("X-100"),("move X -100"),(10,0),xcol,(1,3)],
|
||||
[_("Y+100"),("move Y 100"),(2,3),ycol,(1,3)],
|
||||
[_("Y+10"),("move Y 10"),(3,3),ycol,(1,3)],
|
||||
[_("Y+1"),("move Y 1"),(4,3),ycol,(1,3)],
|
||||
[_("Y+0.1"),("move Y 0.1"),(5,3),ycol,(1,3)],
|
||||
[_("HomeY"),("home Y"),(6,3),(150,150,205),(1,3)],
|
||||
[_("Y-0.1"),("move Y -0.1"),(7,3),ycol,(1,3)],
|
||||
[_("Y-1"),("move Y -1"),(8,3),ycol,(1,3)],
|
||||
[_("Y-10"),("move Y -10"),(9,3),ycol,(1,3)],
|
||||
[_("Y-100"),("move Y -100"),(10,3),ycol,(1,3)],
|
||||
[_("Motors off"),("M84"),(2,6),(250,250,250),(1,3)],
|
||||
[_("Z+10"),("move Z 10"),(3,6),zcol,(1,3)],
|
||||
[_("Z+1"),("move Z 1"),(4,6),zcol,(1,3)],
|
||||
[_("Z+0.1"),("move Z 0.1"),(5,6),zcol,(1,3)],
|
||||
[_("HomeZ"),("home Z"),(6,6),(150,205,150),(1,3)],
|
||||
[_("Z-0.1"),("move Z -0.1"),(7,6),zcol,(1,3)],
|
||||
[_("Z-1"),("move Z -1"),(8,6),zcol,(1,3)],
|
||||
[_("Z-10"),("move Z -10"),(9,6),zcol,(1,3)],
|
||||
[_("Home"),("home"),(10,6),(250,250,250),(1,3)],
|
||||
# [_("X+100"),("move X 100"),(2,0),xcol,(1,3)],
|
||||
# [_("X+10"),("move X 10"),(3,0),xcol,(1,3)],
|
||||
# [_("X+1"),("move X 1"),(4,0),xcol,(1,3)],
|
||||
# [_("X+0.1"),("move X 0.1"),(5,0),xcol,(1,3)],
|
||||
# [_("HomeX"),("home X"),(6,0),(205,205,78),(1,3)],
|
||||
# [_("X-0.1"),("move X -0.1"),(7,0),xcol,(1,3)],
|
||||
# [_("X-1"),("move X -1"),(8,0),xcol,(1,3)],
|
||||
# [_("X-10"),("move X -10"),(9,0),xcol,(1,3)],
|
||||
# [_("X-100"),("move X -100"),(10,0),xcol,(1,3)],
|
||||
# [_("Y+100"),("move Y 100"),(2,3),ycol,(1,3)],
|
||||
# [_("Y+10"),("move Y 10"),(3,3),ycol,(1,3)],
|
||||
# [_("Y+1"),("move Y 1"),(4,3),ycol,(1,3)],
|
||||
# [_("Y+0.1"),("move Y 0.1"),(5,3),ycol,(1,3)],
|
||||
# [_("HomeY"),("home Y"),(6,3),(150,150,205),(1,3)],
|
||||
# [_("Y-0.1"),("move Y -0.1"),(7,3),ycol,(1,3)],
|
||||
# [_("Y-1"),("move Y -1"),(8,3),ycol,(1,3)],
|
||||
# [_("Y-10"),("move Y -10"),(9,3),ycol,(1,3)],
|
||||
# [_("Y-100"),("move Y -100"),(10,3),ycol,(1,3)],
|
||||
# [_("Motors off"),("M84"),(2,6),(250,250,250),(1,3)],
|
||||
# [_("Z+10"),("move Z 10"),(3,6),zcol,(1,3)],
|
||||
# [_("Z+1"),("move Z 1"),(4,6),zcol,(1,3)],
|
||||
# [_("Z+0.1"),("move Z 0.1"),(5,6),zcol,(1,3)],
|
||||
# [_("HomeZ"),("home Z"),(6,6),(150,205,150),(1,3)],
|
||||
# [_("Z-0.1"),("move Z -0.1"),(7,6),zcol,(1,3)],
|
||||
# [_("Z-1"),("move Z -1"),(8,6),zcol,(1,3)],
|
||||
# [_("Z-10"),("move Z -10"),(9,6),zcol,(1,3)],
|
||||
# [_("Home"),("home"),(10,6),(250,250,250),(1,3)],
|
||||
[_("Check temp"),("M105"),(11,6),(225,200,200),(1,3)],
|
||||
[_("Extrude"),("extrude"),(13,0),(225,200,200),(1,2)],
|
||||
[_("Reverse"),("reverse"),(14,0),(225,200,200),(1,2)],
|
||||
|
@ -478,6 +480,9 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
|
|||
|
||||
#lls.Add((200,375))
|
||||
|
||||
lls.Add(XYButtons(self.panel, self.moveXY, self.home), pos=(2,0), span=(9,6))
|
||||
lls.Add(ZButtons(self.panel, self.moveZ, self.home), pos=(2,7), span=(9,2))
|
||||
|
||||
for i in self.cpbuttons:
|
||||
btn=wx.Button(self.panel,-1,i[0])#,size=(60,-1))
|
||||
btn.SetBackgroundColour(i[3])
|
||||
|
@ -895,6 +900,19 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
|
|||
else:
|
||||
e.Skip()
|
||||
|
||||
def moveXY(self, x, y):
|
||||
if x != 0:
|
||||
self.onecmd('move X %s' % x)
|
||||
if y != 0:
|
||||
self.onecmd('move Y %s' % y)
|
||||
|
||||
def moveZ(self, z):
|
||||
if z != 0:
|
||||
self.onecmd('move Z %s' % z)
|
||||
|
||||
def home(self):
|
||||
self.onecmd('home')
|
||||
|
||||
def procbutton(self,e):
|
||||
try:
|
||||
if hasattr(e.GetEventObject(),"custombutton"):
|
||||
|
|
Loading…
Reference in New Issue