Added buttons to clear window and exit
* Clear button functional * Exit button has a bug (not really exiting) * Exit button is not at the right place To be tested with a Wacom tablet...
This commit is contained in:
parent
4c87dbe5d4
commit
27d100708d
78
piboard.py
78
piboard.py
@ -17,7 +17,7 @@ import wx
|
|||||||
|
|
||||||
class PaintWindow(wx.Window):
|
class PaintWindow(wx.Window):
|
||||||
# array of colors available to draw
|
# array of colors available to draw
|
||||||
colours = ['Black', 'Yellow', 'Red', 'Green', 'Blue', 'Purple',
|
colours = ['Black', 'White', 'Yellow', 'Red', 'Green', 'Blue', 'Purple',
|
||||||
'Brown', 'Aquamarine', 'Forest Green', 'Light Blue', 'Goldenrod',
|
'Brown', 'Aquamarine', 'Forest Green', 'Light Blue', 'Goldenrod',
|
||||||
'Cyan', 'Orange', 'Navy', 'Light Grey', 'ClearScreen']
|
'Cyan', 'Orange', 'Navy', 'Light Grey', 'ClearScreen']
|
||||||
# color quantity
|
# color quantity
|
||||||
@ -33,6 +33,19 @@ class PaintWindow(wx.Window):
|
|||||||
self.bindEvents()
|
self.bindEvents()
|
||||||
self.initBuffer()
|
self.initBuffer()
|
||||||
|
|
||||||
|
size = parent.GetSize()
|
||||||
|
self.button_exit = wx.Button(self, id=-1, label='Exit',
|
||||||
|
pos=(size[0]-125, size[1]-125),
|
||||||
|
size=(100, 50))
|
||||||
|
self.button_exit.Bind(wx.EVT_BUTTON, self.button_exit_handle)
|
||||||
|
self.button_exit.SetToolTip(wx.ToolTip("Click to exit"))
|
||||||
|
|
||||||
|
self.button_clear = wx.Button(self, id=-1, label='Clear',
|
||||||
|
pos=(size[0]-125, 25),
|
||||||
|
size=(100, 50))
|
||||||
|
self.button_clear.Bind(wx.EVT_BUTTON, self.button_clear_handle)
|
||||||
|
self.button_clear.SetToolTip(wx.ToolTip("Click to clear"))
|
||||||
|
|
||||||
def initDrawing(self):
|
def initDrawing(self):
|
||||||
self.SetBackgroundColour('WHITE')
|
self.SetBackgroundColour('WHITE')
|
||||||
self.currentThickness = self.thicknesses[0]
|
self.currentThickness = self.thicknesses[0]
|
||||||
@ -41,6 +54,10 @@ class PaintWindow(wx.Window):
|
|||||||
self.previousPosition = (0, 0)
|
self.previousPosition = (0, 0)
|
||||||
|
|
||||||
def bindEvents(self):
|
def bindEvents(self):
|
||||||
|
pnl = wx.Panel(self)
|
||||||
|
pnl.Bind(wx.EVT_KEY_DOWN, self.onKeyPress)
|
||||||
|
pnl.SetSize((0, 0))
|
||||||
|
pnl.SetFocus()
|
||||||
for event, handler in [
|
for event, handler in [
|
||||||
# creates bind event for left button down
|
# creates bind event for left button down
|
||||||
(wx.EVT_LEFT_DOWN, self.onLeftDown),
|
(wx.EVT_LEFT_DOWN, self.onLeftDown),
|
||||||
@ -88,7 +105,6 @@ class PaintWindow(wx.Window):
|
|||||||
# adds a static surpressor to conditions
|
# adds a static surpressor to conditions
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def addCheckableMenuItems(menu, items):
|
def addCheckableMenuItems(menu, items):
|
||||||
|
|
||||||
idToItemMapping = {}
|
idToItemMapping = {}
|
||||||
for item in items:
|
for item in items:
|
||||||
menuId = wx.NewId()
|
menuId = wx.NewId()
|
||||||
@ -97,7 +113,6 @@ class PaintWindow(wx.Window):
|
|||||||
return idToItemMapping
|
return idToItemMapping
|
||||||
|
|
||||||
def bindMenuEvents(self, menuHandler, updateUIHandler, ids):
|
def bindMenuEvents(self, menuHandler, updateUIHandler, ids):
|
||||||
|
|
||||||
sortedIds = sorted(ids)
|
sortedIds = sorted(ids)
|
||||||
firstId, lastId = sortedIds[0], sortedIds[-1]
|
firstId, lastId = sortedIds[0], sortedIds[-1]
|
||||||
for event, handler in \
|
for event, handler in \
|
||||||
@ -105,12 +120,37 @@ class PaintWindow(wx.Window):
|
|||||||
(wx.EVT_UPDATE_UI_RANGE, updateUIHandler)]:
|
(wx.EVT_UPDATE_UI_RANGE, updateUIHandler)]:
|
||||||
self.Bind(event, handler, id=firstId, id2=lastId)
|
self.Bind(event, handler, id=firstId, id2=lastId)
|
||||||
|
|
||||||
|
def button_exit_handle(self, event):
|
||||||
|
self.Destroy()
|
||||||
|
|
||||||
|
def button_clear_handle(self, event):
|
||||||
|
self.button_exit.Destroy()
|
||||||
|
self.button_clear.Destroy()
|
||||||
|
dc = wx.BufferedDC(wx.ClientDC(self), self.buffer)
|
||||||
|
dc.Clear()
|
||||||
|
|
||||||
|
size = self.GetSize()
|
||||||
|
self.button_exit = wx.Button(self, id=-1, label='Exit',
|
||||||
|
pos=(size[0]-125, size[1]-125),
|
||||||
|
size=(100, 50))
|
||||||
|
self.button_exit.Bind(wx.EVT_BUTTON, self.button_exit_handle)
|
||||||
|
self.button_exit.SetToolTip(wx.ToolTip("Click to exit"))
|
||||||
|
|
||||||
|
self.button_clear = wx.Button(self, id=-1, label='Clear',
|
||||||
|
pos=(size[0]-125, 25),
|
||||||
|
size=(100, 50))
|
||||||
|
self.button_clear.Bind(wx.EVT_BUTTON, self.button_clear_handle)
|
||||||
|
self.button_clear.SetToolTip(wx.ToolTip("Click to clear"))
|
||||||
|
|
||||||
def onLeftDown(self, event):
|
def onLeftDown(self, event):
|
||||||
# draw line
|
# draw line
|
||||||
self.currentLine = []
|
self.currentLine = []
|
||||||
self.previousPosition = event.GetPositionTuple()
|
self.previousPosition = event.GetPositionTuple()
|
||||||
self.CaptureMouse()
|
self.CaptureMouse()
|
||||||
|
|
||||||
|
self.button_exit.Destroy()
|
||||||
|
self.button_clear.Destroy()
|
||||||
|
|
||||||
def onLeftUp(self, event):
|
def onLeftUp(self, event):
|
||||||
# close motion, stop drawing, wait for event
|
# close motion, stop drawing, wait for event
|
||||||
if self.HasCapture():
|
if self.HasCapture():
|
||||||
@ -119,12 +159,35 @@ class PaintWindow(wx.Window):
|
|||||||
self.currentLine = []
|
self.currentLine = []
|
||||||
self.ReleaseMouse()
|
self.ReleaseMouse()
|
||||||
|
|
||||||
|
size = self.GetSize()
|
||||||
|
self.button_exit = wx.Button(self, id=-1, label='Exit',
|
||||||
|
pos=(size[0]-125, size[1]-125),
|
||||||
|
size=(100, 50))
|
||||||
|
self.button_exit.Bind(wx.EVT_BUTTON, self.button_exit_handle)
|
||||||
|
self.button_exit.SetToolTip(wx.ToolTip("Click to exit"))
|
||||||
|
|
||||||
|
self.button_clear = wx.Button(self, id=-1, label='Clear',
|
||||||
|
pos=(size[0]-125, 25),
|
||||||
|
size=(100, 50))
|
||||||
|
self.button_clear.Bind(wx.EVT_BUTTON, self.button_clear_handle)
|
||||||
|
self.button_clear.SetToolTip(wx.ToolTip("Click to clear"))
|
||||||
|
|
||||||
|
def onKeyPress(self, event):
|
||||||
|
# If q key is pressed, exit
|
||||||
|
keycode = event.GetKeyCode()
|
||||||
|
if event.GetKeyCode() == wx.WXK_ESCAPE:
|
||||||
|
ret = wx.MessageBox('Are you sure to quit?', 'Question',
|
||||||
|
wx.YES_NO | wx.NO_DEFAULT, self)
|
||||||
|
if ret == wx.YES:
|
||||||
|
self.Destroy()
|
||||||
|
else:
|
||||||
|
event.Skip()
|
||||||
|
|
||||||
def onRightUp(self, event):
|
def onRightUp(self, event):
|
||||||
# if right button is clicked then make wx.menu to select colors
|
# if right button is clicked then make wx.menu to select colors
|
||||||
self.PopupMenu(self.menu)
|
self.PopupMenu(self.menu)
|
||||||
|
|
||||||
def onMotion(self, event):
|
def onMotion(self, event):
|
||||||
|
|
||||||
if event.Dragging() and event.LeftIsDown():
|
if event.Dragging() and event.LeftIsDown():
|
||||||
dc = wx.BufferedDC(wx.ClientDC(self), self.buffer)
|
dc = wx.BufferedDC(wx.ClientDC(self), self.buffer)
|
||||||
currentPosition = event.GetPositionTuple()
|
currentPosition = event.GetPositionTuple()
|
||||||
@ -134,19 +197,16 @@ class PaintWindow(wx.Window):
|
|||||||
self.currentLine.append(lineSegment)
|
self.currentLine.append(lineSegment)
|
||||||
self.previousPosition = currentPosition
|
self.previousPosition = currentPosition
|
||||||
|
|
||||||
def onSize(self, event):
|
|
||||||
|
|
||||||
|
def onSize(self, event):
|
||||||
self.reInitBuffer = True
|
self.reInitBuffer = True
|
||||||
|
|
||||||
def onIdle(self, event):
|
def onIdle(self, event):
|
||||||
|
|
||||||
if self.reInitBuffer:
|
if self.reInitBuffer:
|
||||||
self.initBuffer()
|
self.initBuffer()
|
||||||
self.Refresh(False)
|
self.Refresh(False)
|
||||||
|
|
||||||
def onPaint(self, event):
|
def onPaint(self, event):
|
||||||
|
|
||||||
|
|
||||||
dc = wx.BufferedPaintDC(self, self.buffer)
|
dc = wx.BufferedPaintDC(self, self.buffer)
|
||||||
|
|
||||||
def cleanup(self, event):
|
def cleanup(self, event):
|
||||||
@ -191,5 +251,5 @@ class PaintFrame(wx.Frame):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app = wx.App()
|
app = wx.App()
|
||||||
frame = PaintFrame()
|
frame = PaintFrame()
|
||||||
frame.ShowFullScreen(True, wx.FULLSCREEN_ALL)
|
frame.Show() #FullScreen(True, wx.FULLSCREEN_ALL)
|
||||||
app.MainLoop()
|
app.MainLoop()
|
||||||
|
Loading…
Reference in New Issue
Block a user