Skip to content

Instantly share code, notes, and snippets.

@carandraug
Last active June 15, 2016 18:28
Show Gist options
  • Save carandraug/253a6a0134633d54da2255ea28d5fe0b to your computer and use it in GitHub Desktop.
Save carandraug/253a6a0134633d54da2255ea28d5fe0b to your computer and use it in GitHub Desktop.
Ilan's favour - quick example of sizer
# shapedBtnDemo.py Ilan Davis June 2016, based on tutorial on the web.
# Icons made on iDraw (Graphic.app) on mac (in VSG format), saves as .png approx. 10%, 100pixes high.
########################################################################
import wx
from wx.lib.agw.shapedbutton import SButton, SBitmapButton
from wx.lib.agw.shapedbutton import SBitmapToggleButton, SBitmapTextToggleButton
class MyForm(wx.Frame):
#----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Cockpit V2.0", (0,25), wx.Size(800, 1200))
self.alphaValue = 255
self.SetTransparent(self.alphaValue)
panel = wx.Panel(self, wx.ID_ANY)
lb = lambda f, c : self._make_button(panel, f, "laser_" + c + "_icon.png",
size=(100,100))
laser_buttons = [
lb(self.ToggleGreenLaser, "green"),
lb(self.ToggleRedLaser, "red"),
lb(self.ToggleFarredLaser, "farred"),
lb(self.ToggleWhiteLaser, "white"),
]
cb = lambda f, c: self._make_button(panel, f, "camera_" + c + "_icon.png")
camera_buttons = [
cb(self.ToggleCamera1, "blue"),
cb(self.ToggleCamera2, "green"),
cb(self.ToggleCamera3, "red"),
cb(self.ToggleCamera4, "farred"),
]
cb = lambda f, a: self._make_button(panel, f, a + "_icon.png")
action_buttons = [
cb(self.ToggleAbort, "abort"),
cb(self.ToggleCapture, "capture"),
cb(self.ToggleRecord, "record"),
cb(self.TogglePreview, "preview"),
cb(self.ToggleSnap, "snap"),
]
mbox = wx.BoxSizer(wx.VERTICAL)
for s in [laser_buttons, camera_buttons, action_buttons]:
hbox = wx.BoxSizer(wx.HORIZONTAL)
for b in s:
hbox.Add(b)
mbox.Add(hbox)
panel.SetSizer(mbox)
def _make_button(self, panel, action, icon_path, label="", size=(75, 75)):
bmp = wx.Bitmap("icons/" + icon_path, wx.BITMAP_TYPE_ANY)
button = SBitmapTextToggleButton(panel, wx.ID_ANY, bitmap=bmp,
label="", size=size)
button.Bind(wx.EVT_BUTTON, action)
return button
#----------------------------------------------------------------------
def ToggleBlueLaser(self, event):
if event.GetIsDown():
print "Blue Laser is ON"
else:
print "Blue Laser is OFF"
event.Skip()
#----------------------------------------------------------------------
def ToggleGreenLaser(self, event):
if event.GetIsDown():
print "Green Laser is ON"
else:
print "Green Laser is OFF"
event.Skip()
#----------------------------------------------------------------------
def ToggleRedLaser(self, event):
if event.GetIsDown():
print "Red Laser is ON"
else:
print "Red Laser is OFF"
event.Skip()
#----------------------------------------------------------------------
def ToggleFarredLaser(self, event):
if event.GetIsDown():
print "Far Red Laser is ON"
else:
print "Far Red Laser is OFF"
event.Skip()
#----------------------------------------------------------------------
def ToggleWhiteLaser(self, event):
if event.GetIsDown():
print "White Laser is ON"
else:
print "Far Red Laser is OFF"
event.Skip()
#----------------------------------------------------------------------
def ToggleCamera1(self, event):
if event.GetIsDown():
print "Camera1 is ON"
else:
print "Camera1 is OFF"
event.Skip()
#----------------------------------------------------------------------
def ToggleCamera2(self, event):
if event.GetIsDown():
print "Camera2 is ON"
else:
print "Camera2 is OFF"
event.Skip()
#----------------------------------------------------------------------
def ToggleCamera3(self, event):
if event.GetIsDown():
print "Camera3 is ON"
else:
print "Camera3 is OFF"
event.Skip()
#----------------------------------------------------------------------
def ToggleCamera4(self, event):
if event.GetIsDown():
print "Camera4 is ON"
else:
print "Camera4 is OFF"
event.Skip()
#----------------------------------------------------------------------
def ToggleAbort(self, event):
if event.GetIsDown():
print "Abort Requested"
else:
print "Abort button is reset to OFF"
event.Skip()
#----------------------------------------------------------------------
def ToggleCapture(self, event):
if event.GetIsDown():
print "Capture experiment started"
else:
print "Capture experiment stopped"
event.Skip()
#----------------------------------------------------------------------
def ToggleRecord(self, event):
if event.GetIsDown():
print "Capture experiment started"
else:
print "Capture experiment stopped"
event.Skip()
#----------------------------------------------------------------------
def TogglePreview(self, event):
if event.GetIsDown():
print "Capture experiment started"
else:
print "Capture experiment stopped"
event.Skip()
#----------------------------------------------------------------------
def ToggleSnap(self, event):
if event.GetIsDown():
print "Capture experiment started"
else:
print "Capture experiment stopped"
event.Skip()
#----------------------------------------------------------------------
# def onShapedBtn(self, event):
# self.showDialog("You Pressed the Normal ShapedButton!")
#----------------------------------------------------------------------
# def showDialog(self, message): #Displays a custom message
# dlg = wx.MessageDialog(None, message, 'Message', wx.OK|wx.ICON_EXCLAMATION)
# dlg.ShowModal()
# dlg.Destroy()
# Run the program
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment