diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f5bfd51 --- /dev/null +++ b/.gitignore @@ -0,0 +1,127 @@ +.DS_Store + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don’t work, or not +# install all needed dependencies. +#Pipfile.lock + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + + diff --git a/00-README.md b/00-README.md new file mode 100644 index 0000000..778ee38 --- /dev/null +++ b/00-README.md @@ -0,0 +1,45 @@ +wxPythonDemos +============= + +wxPython Demos: Various small demos of wxPython features -- developed over years of discussion on the wxPython-users mailinglist. + +This is a collection of a bunch of mini apps, each designed to test one +small piece of wxPython. + +Some of these were done in response to things I was trying to figure out +myself, and some to help answer a question on the wxPython-users list. + +Some of the code I wrote myself, and some was written by other folks on +the list, and edited by me. + +Note that these were written over a long period of time, with a lot of +wxPython versions. They may not all run under the latest version, and +some of them are written in very outdated style. + +Please don't imitate all the style you see here. For a description of +good, modern pythonic style, see: + +http://wiki.wxpython.org/index.cgi/wxPython_Style_Guide + +Despite these flaws, I think there is a lot to be learned from this +collection. + +I suggest you search or grep for a widget you may want to learn something about, or just fire up each one and see what it does! + +To Do +---------- + +One of these days, I'd like to go through the code and clean it all up -- proper modern style, testing on recent wxPyton versions and all OSs, etc. + +It would also be great to put in more documentation -- maybe a Sphinx auto-generated doc. + +Contributing +-------------- +If you'd like to help out, please feel free to clone the repository and send me pull requests. If you think you'd like to do a fair bit over a period of time, ask me about getting commit privileges. + + +-Chris Barker + PythonCHB@gmail.com + + + diff --git a/AboutDialog.py b/AboutDialog.py index 30ae6ed..eb5e020 100755 --- a/AboutDialog.py +++ b/AboutDialog.py @@ -10,129 +10,138 @@ """ import wx -from wx.lib.hyperlink import HyperLinkCtrl +from wx.lib.agw.hyperlink import HyperLinkCtrl + class AboutDialog(wx.Dialog): """ - + A fancier About Dialog that the "usual" """ + def __init__(self, parent, icon1=None, - icon2=None, - short_name=None, - long_name=None, - version=None, - description=None, - urls=None, - licence=None, - developers = []): + icon2=None, + short_name=None, + long_name=None, + version=None, + description=None, + urls=None, + licence=None, + developers=[]): wx.Dialog.__init__(self, parent) - self.icon1 = icon1 - self.icon2 = icon2 + self.icon1 = icon1 + self.icon2 = icon2 self.short_name = short_name - self.long_name = long_name + self.long_name = long_name self.version = version self.version = version self.description = description self.urls = urls self.licence = licence self.developers = developers - + self.Build() - + def Build(self): - + # Build the header Header = wx.BoxSizer(wx.HORIZONTAL) if self.icon1: Header.Add(wx.StaticBitmap(self, bitmap=self.icon1), 0) else: - Header.Add((64,64)) - Header.Add((20,1),1) + Header.Add((64, 64)) + Header.Add((20, 1), 1) if self.short_name: Label = wx.StaticText(self, label=self.short_name) of = Label.GetFont() - Font = wx.Font(int(of.GetPointSize() * 2), of.GetFamily(), wx.NORMAL, wx.FONTWEIGHT_BOLD) + Font = wx.Font(int(of.GetPointSize() * 2), + of.GetFamily(), wx.NORMAL, wx.FONTWEIGHT_BOLD) Label.SetFont(Font) - Header.Add(Label, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5) + Header.Add(Label, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) else: - Header.Add((1,1), 1) - Header.Add((20,1),1) + Header.Add((1, 1), 1) + Header.Add((20, 1), 1) if self.icon2: Header.Add(wx.StaticBitmap(self, bitmap=self.icon2), 0) else: - Header.Add((64,64)) + Header.Add((64, 64)) width = Header.MinSize[0] # Now the rest; MainSizer = wx.BoxSizer(wx.VERTICAL) - - MainSizer.Add(Header, 0, wx.EXPAND|wx.ALIGN_CENTER|wx.ALL, 5) - + + MainSizer.Add(Header, 0, wx.EXPAND | wx.ALIGN_CENTER | wx.ALL, 5) + if self.long_name: Label = wx.StaticText(self, label=self.long_name) of = Label.GetFont() - Font = wx.Font(int(of.GetPointSize() * 1.5), of.GetFamily(), wx.NORMAL, wx.NORMAL) + Font = wx.Font(int(of.GetPointSize() * 1.5), + of.GetFamily(), wx.NORMAL, wx.NORMAL) Label.SetFont(Font) - MainSizer.Add(Label, 0, wx.TOP|wx.RIGHT|wx.LEFT|wx.ALIGN_CENTER, 5) + MainSizer.Add(Label, 0, wx.TOP | wx.RIGHT | + wx.LEFT | wx.ALIGN_CENTER, 5) width = max(width, Label.Size[0]) if self.version: Label = wx.StaticText(self, label="version: "+self.version) #of = Label.GetFont() #Font = wx.Font(int(of.GetPointSize() * 1.5), of.GetFamily(), wx.NORMAL, wx.NORMAL) - #Label.SetFont(Font) - MainSizer.Add(Label, 0, wx.BOTTOM|wx.ALIGN_CENTER, 5) + # Label.SetFont(Font) + MainSizer.Add(Label, 0, wx.BOTTOM | wx.ALIGN_CENTER, 5) if self.description: Label = wx.StaticText(self, label=self.description) - #of = Label.GetFont() - #Font = wx.Font(int(of.GetPointSize() * 1.5), of.GetFamily(), wx.NORMAL, wx.NORMAL) - #Label.SetFont(Font) - - Label.Wrap(max(250, 0.9*width)) - MainSizer.Add(Label, 0, wx.ALL|wx.ALIGN_CENTER, 5) + # of = Label.GetFont() + # Font = wx.Font(int(of.GetPointSize() * 1.5), of.GetFamily(), wx.NORMAL, wx.NORMAL) + # Label.SetFont(Font) + + Label.Wrap(max(250, int(0.9 * width))) + MainSizer.Add(Label, 0, wx.ALL | wx.ALIGN_CENTER, 5) - if self.licence: Label = wx.StaticText(self, label="License:") of = Label.GetFont() - Font = wx.Font(of.GetPointSize(), of.GetFamily(), wx.NORMAL, wx.BOLD) + Font = wx.Font(of.GetPointSize(), of.GetFamily(), + wx.NORMAL, wx.BOLD) Label.SetFont(Font) - MainSizer.Add(Label, 0, wx.ALL|wx.ALIGN_LEFT, 5) + MainSizer.Add(Label, 0, wx.ALL | wx.ALIGN_LEFT, 5) Label = wx.StaticText(self, label=self.licence) - Label.Wrap(max(250, 0.9*width)) - MainSizer.Add(Label, 0, wx.ALL|wx.ALIGN_CENTER, 2) + Label.Wrap(max(250, int(0.9 * width))) + MainSizer.Add(Label, 0, wx.ALL | wx.ALIGN_CENTER, 2) if self.developers: Label = wx.StaticText(self, label="Developed by:") of = Label.GetFont() - Font = wx.Font(of.GetPointSize(), of.GetFamily(), wx.NORMAL, wx.BOLD) + Font = wx.Font(of.GetPointSize(), of.GetFamily(), + wx.NORMAL, wx.BOLD) Label.SetFont(Font) - MainSizer.Add(Label, 0, wx.ALL|wx.ALIGN_LEFT, 5) - + MainSizer.Add(Label, 0, wx.ALL | wx.ALIGN_LEFT, 5) + for developer in self.developers: - Label = wx.StaticText(self, label=" "+developer) - MainSizer.Add(Label, 0, wx.ALL|wx.ALIGN_LEFT, 0) - - if self.urls: + Label = wx.StaticText(self, label=" " + developer) + MainSizer.Add(Label, 0, wx.ALL | wx.ALIGN_LEFT, 0) + + if self.urls: Label = wx.StaticText(self, label="For more information:") of = Label.GetFont() - Font = wx.Font(of.GetPointSize(), of.GetFamily(), wx.NORMAL, wx.BOLD) + Font = wx.Font(of.GetPointSize(), of.GetFamily(), + wx.NORMAL, wx.BOLD) Label.SetFont(Font) - MainSizer.Add(Label, 0, wx.ALL|wx.ALIGN_LEFT, 5) + MainSizer.Add(Label, 0, wx.ALL | wx.ALIGN_LEFT, 5) for url in self.urls: Link = HyperLinkCtrl(self, label=url, URL=url) - MainSizer.Add(Link, 0, wx.ALL|wx.ALIGN_CENTER, 2) - - MainSizer.Add((1,5),1) - MainSizer.Add(wx.Button(self, id=wx.ID_OK, label="Dismiss"), 0, wx.ALL|wx.ALIGN_RIGHT,5) + MainSizer.Add(Link, 0, wx.ALL | wx.ALIGN_CENTER, 2) + + MainSizer.Add((1, 5), 1) + MainSizer.Add(wx.Button(self, id=wx.ID_OK, label="Dismiss"), + 0, wx.ALL | wx.ALIGN_RIGHT, 5) SpaceSizer = wx.BoxSizer(wx.VERTICAL) SpaceSizer.Add(MainSizer, 0, wx.ALL, 10) self.SetSizerAndFit(SpaceSizer) - + + if __name__ == "__main__": a = wx.App(False) @@ -141,11 +150,14 @@ def Build(self): icon2=wx.Bitmap("Images/NOAA.png"), short_name='Acronym', long_name='A Longer Name for the Program', - version = "1.2.3", - description="A description of the program. This could be a pretty long bit of text. How shall I know how long to make it? How will it fit in?", - urls = ["http://www.some.website.org", - "mailto:someone@somwewhere.com"], + version="1.2.3", + description="A description of the program. " + "This could be a pretty long bit of text. " + "How shall I know how long to make it? " + "How will it fit in?", + urls=["http://www.some.website.org", + "mailto:someone@somwewhere.com"], licence="This is a short description of the license used for the program.", - developers = ["A Developer", "Another Developer"]) - + developers=["A Developer", "Another Developer"]) + d.ShowModal() diff --git a/Append_test.py b/Append_test.py index 0e24910..5c8b228 100755 --- a/Append_test.py +++ b/Append_test.py @@ -12,18 +12,18 @@ def __init__(self): wx.DefaultPosition, size=(800,600), style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE) - - self.objects = [] + + self.objects = [] self.dragImage = None self.DragPaper = None - self.hiliteObjects = None + self.hiliteObjects = None self.lines = [] self.maxWidth = 1000 self.maxHeight = 1000 self.x = self.y = 0 self.curLine = [] self.drawing = False - + self.Paper = wx.Bitmap("Paper.BMP", wx.BITMAP_TYPE_BMP) if self.Paper.Ok(): print "bitmap loaded OK" @@ -31,7 +31,7 @@ def __init__(self): raise Exception("bitmap DID NOT load OK") self.DrawTextOnPaper() - + #-------------------------------------------------------------------------- if BUFFERED: self.buffer = wx.EmptyBitmap(self.maxWidth, self.maxHeight) @@ -60,27 +60,27 @@ def DrawTextOnPaper(self): dc.SetFont(wx.Font(36, wx.MODERN, wx.NORMAL, wx.NORMAL, 0, "Arial")) dc.SetTextForeground(wx.BLACK) dc.DrawText(text, 155, 25) - + def DoDrawing(self, dc, printing=False): - dc.BeginDrawing() - + dc.BeginDrawing() + ## l1 = ['a','b','c','d'] ## text = " "+"".join(l1) ## bg_colour = wx.Colour(57, 115, 57) # matches the bg image ## dc.SetFont(wx.Font(36, wx.MODERN, wx.NORMAL, wx.NORMAL, 0, "Arial")) ## dc.SetTextForeground(wx.BLACK) ## te = dc.GetTextExtent(text) - - + + dc.DrawBitmap(self.Paper, 200, 20, True) - - + + #dc = wx.MemoryDC() #dc.SelectObject(self.manuscript) #self.DoDrawing(dc) - + ## dc.DrawText(text, 225, 25) - + dc.EndDrawing() #-------------------------------------------------------------------------- class MyApp(wx.App): @@ -95,4 +95,3 @@ def OnInit(self): if __name__ == "__main__": app = MyApp(0) app.MainLoop() - diff --git a/AutoSizeBitmap.py b/AutoSizeBitmap.py new file mode 100755 index 0000000..5029a3e --- /dev/null +++ b/AutoSizeBitmap.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python + +""" +AutoSizeBitmap.py + +Example for how to have a bitmap autosize itself in wxPython +""" +import math +import wx + +KEEP_ASPECT_RATIO = True + + +class AutoSizeFrame(wx.Frame): + def __init__(self, image, *args, **kwargs): + wx.Frame.__init__(self, *args, **kwargs) + + self.aspect_ratio = float(image.Width) / float(image.Height) + self.canvas = AutoSizeBitmap(image, self) + self.canvas.SetSize((300, 400)) + + self.Bind(wx.EVT_SIZE, self.OnSize) + + self.Fit() + self.Show() + + def OnSize(self, evt=None): + size = self.Size + if (size[0] > 0 and size[1] > 0): + width, height = size + if KEEP_ASPECT_RATIO: + total_size = width * height + height = int(math.sqrt(total_size / self.aspect_ratio)) + width = int(total_size / height) + # resize window on the fly to keep the aspect ratio + self.SetSize((width, height)) + self.canvas.SetSize((width, height)) + + +class AutoSizeBitmap(wx.Window): + """ + A subclass of wx.Window that will hold an image (much like a StaticBitmap), + but re-size it to fit the current size of the Window + """ + def __init__(self, image, *args, **kwargs): + """ + initialize an AutoSizeBitmap + + :param parent: parent Window for this window + :param image: a wx.Image that you want to display + """ + wx.Window.__init__(self, *args, **kwargs) + + self.orig_image = image + self.bitmap = None + self.prev_size = self.Size + + self.Bind(wx.EVT_SIZE, self.OnSize) + self.Bind(wx.EVT_PAINT, self.OnPaint) + + def OnSize(self, evt=None): + size = self.Size + if size[0] > 0 and size[1] > 0: + img = self.orig_image.Copy() + img.Rescale(*size) + self.bitmap = wx.BitmapFromImage(img) + self.Refresh() + + def OnPaint(self, evt=None): + dc = wx.PaintDC(self) + try: + dc.DrawBitmap(self.bitmap, 0, 0) + except ValueError: # in case bitmap has not yet been initialized + pass + +if __name__ == "__main__": + import sys + + try: + filename = sys.argv[1] + except: + filename = "Images/cute_close_up.jpg" + App = wx.App(False) + img = wx.Image(filename) + f = AutoSizeFrame(img, None, size=(400, 600)) + App.MainLoop() + diff --git a/BitmapFromBufferTest.py b/BitmapFromBufferTest.py index e4ae423..b326d01 100755 --- a/BitmapFromBufferTest.py +++ b/BitmapFromBufferTest.py @@ -12,10 +12,10 @@ class BitmapWindow(wx.Window): def __init__(self, parent, bytearray, *args, **kwargs): wx.Window.__init__(self, parent, *args, **kwargs) - + self.bytearray = bytearray self.Bind(wx.EVT_PAINT, self.OnPaint) - + def OnPaint(self, evt): dc = wx.PaintDC(self) bmp = wx.BitmapFromBufferRGBA(200,200, self.bytearray) diff --git a/BitmapFromPILTest.py b/BitmapFromPILTest.py index 1130640..515118e 100755 --- a/BitmapFromPILTest.py +++ b/BitmapFromPILTest.py @@ -21,7 +21,7 @@ def __init__(self, title = "Bitmap Demo"): self.bitmap = wx.BitmapFromBuffer(w, h, image.tostring() ) self.Bind(wx.EVT_PAINT, self.OnPaint) - + def OnPaint(self, evt): dc = wx.PaintDC(self) dc.DrawBitmap(self.bitmap, 10, 10 ) diff --git a/BlitTest.py b/BlitTest.py index 13d6ea1..484a346 100755 --- a/BlitTest.py +++ b/BlitTest.py @@ -1,95 +1,101 @@ #!/usr/bin/env python -import wx, random +""" +demo oif blitting from a MemoryDC to the screen using DC.DrawBitmap +""" + +from __future__ import print_function, unicode_literals + +import random +import wx + class MainWindow(wx.Frame): - """ This window displays a button """ - def __init__(self,parent,id,title): - wx.Frame.__init__(self, None, -1, "Blit Test", - wx.DefaultPosition, - size=(500,500), - style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE) - - wx.EVT_CLOSE(self,self.OnQuit) + """ This window displays some random lines """ + + def __init__(self, parent, id, title): + wx.Frame.__init__( + self, + None, + -1, + "Blit Test", + wx.DefaultPosition, + size=(500, 500), + style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE) + + wx.EVT_CLOSE(self, self.OnQuit) self.Bind(wx.EVT_TIMER, self.OnTimer) self.Bind(wx.EVT_SIZE, self.BuildImage) self.Numtimer = 0 self.NumLines = 100 - self.t=wx.Timer(self) + self.t = wx.Timer(self) self.BuildImage() self.t.Start(100) - - def OnQuit(self,Event): + + def OnQuit(self, Event): self.Destroy() - def BuildImage(self, event = None): - Size = self.GetClientSizeTuple() + def BuildImage(self, event=None): + Size = self.ClientSize # Make new offscreen bitmap: this bitmap will always have the # current drawing in it, so it can be used to save the image to # a file, or whatever. - print "making new buffer:",Size - self._Buffer = wx.EmptyBitmap(Size[0],Size[1]) + print("making new buffer:", Size) + self._Buffer = wx.EmptyBitmap(Size[0], Size[1]) dc = wx.MemoryDC() dc.SelectObject(self._Buffer) - self.Lines = [] for i in range(self.NumLines): - x1,y1,x2,y2 = (random.randint(1,max(Size)), - random.randint(1,max(Size)), - random.randint(1,max(Size)), - random.randint(1,max(Size))) - + x1, y1, x2, y2 = (random.randint(1, max(Size)), + random.randint(1, max(Size)), + random.randint(1, max(Size)), + random.randint(1, max(Size))) + color = self.random_color() - self.Lines.append( [color, (x1,y1,x2,y2)] ) - - dc.BeginDrawing() + self.Lines.append([color, (x1, y1, x2, y2)]) + dc.Clear() for line in self.Lines: dc.SetPen(wx.Pen(line[0], 2)) dc.DrawLine(*line[1]) - dc.EndDrawing() - def OnTimer(self,event): + def OnTimer(self, event): self.Numtimer += 1 - print "Timer fired: %i times"%self.Numtimer + print("Timer fired: %i times" % self.Numtimer) # change one color: self.Lines[random.randrange(self.NumLines)][0] = self.random_color() # update the screen dc = wx.MemoryDC() dc.SelectObject(self._Buffer) - dc.BeginDrawing() dc.Clear() for line in self.Lines: dc.SetPen(wx.Pen(line[0], 2)) dc.DrawLine(*line[1]) - dc.EndDrawing() - del dc - wx.ClientDC(self).DrawBitmap(self._Buffer,0,0) - + # del dc + wx.ClientDC(self).DrawBitmap(self._Buffer, 0, 0) + def random_color(self): - return apply(wx.Colour,(random.randrange(255),random.randrange(255),random.randrange(255))) + return wx.Colour(random.randrange(255), + random.randrange(255), + random.randrange(255), + ) class MyApp(wx.App): def OnInit(self): - frame = MainWindow(None, -1, "BlitTest") + frame = MainWindow(None, wx.ID_ANY, title="BlitTest") self.SetTopWindow(frame) frame.Show() - + return True - + app = MyApp(0) app.MainLoop() - - - - - diff --git a/BufferedWithControls.py b/BufferedWithControls.py index 53d0a77..56efb3b 100755 --- a/BufferedWithControls.py +++ b/BufferedWithControls.py @@ -63,7 +63,7 @@ def UpdateDrawing(self): dc.SelectObject(self._Buffer) self.Draw(dc) self.Refresh() # This forces a Paint event, so the screen gets updated. - #self.Update() # If it's not getting updated fast enough, this should force it. + #self.Update() # If it's not getting updated fast enough, this should force it. class DrawWindow(wxBufferedWindow): def __init__(self, parent, id = -1): @@ -119,7 +119,7 @@ def OnBitmapButton(self,event=None): def CheckB(self): self.ID_SOSO = wx.NewId() self.checkB = wx.CheckBox(self, self.ID_SOSO, "test", pos = (50, 50)) - + class TestFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, "Double Buffered Test", diff --git a/ButtonArray.py b/ButtonArray.py index bbe12e0..42b3e13 100755 --- a/ButtonArray.py +++ b/ButtonArray.py @@ -6,20 +6,20 @@ class ButtonArrayPanel(wx.Panel): def __init__(self, *args, **kwargs): wx.Panel.__init__(self, *args, **kwargs) Sizer = wx.GridSizer(16, 2, 0, 0) - + for i in range(32): B = wx.Button(self, label = "button %i"%i) B.Bind(wx.EVT_BUTTON, lambda evt, but_num = i: self.OnButton(evt, but_num) ) Sizer.Add(B, 0, wx.GROW|wx.ALL, 4) - + self.SetSizerAndFit(Sizer) - + def OnButton(self, evt, but_num): print "Button number: %i clicked"%but_num - - - + + + class DemoFrame(wx.Frame): @@ -39,10 +39,10 @@ def __init__(self, title = "Button Array Demo"): self.Bind(wx.EVT_CLOSE, self.OnQuit) - + def OnQuit(self,Event): self.Destroy() - + app = wx.App(False) frame = DemoFrame() diff --git a/CalculatorDemo.py b/CalculatorDemo.py index 5bc7429..a6d7fa0 100755 --- a/CalculatorDemo.py +++ b/CalculatorDemo.py @@ -1,9 +1,8 @@ #!/usr/bin/env python - """ wxPython Calculator Demo in 50 lines of code -This demo was pulled form teh wxPython Wiki: +This demo was pulled from the wxPython Wiki: http://wiki.wxpython.org/CalculatorDemo by Miki Tebeka @@ -11,45 +10,45 @@ It has been altered to allow it to be "driven" by an external script, plus a little layout improvement -See CalcualtorDemoDriver.py +See CalcualtorDemoDriver.py for an example """ - # Calculator GUI: # ___________v -# [7][8][9][/] +# [7][8][9][/] # [4][5][6][*] # [1][2][3][-] # [0][.][C][+] # [ = ] -from __future__ import division # So that 8/3 will be 2.6666 and not 2 +from __future__ import (division, unicode_literals, print_function) import wx -from math import * # So we can evaluate "sqrt(8)" +from math import * # So we can evaluate "sqrt(8)" and others -class Calculator(wx.Frame): + +class Calculator(wx.Panel): '''Main calculator dialog''' - def __init__(self, parent=None): - wx.Frame.__init__(self, parent, title="Calculator") - sizer = wx.BoxSizer(wx.VERTICAL) # Main vertical sizer - self.display = wx.ComboBox(self, -1) # Current calculation - sizer.Add(self.display, 0, wx.EXPAND) # Add to main sizer + def __init__(self, *args, **kwargs): + wx.Panel.__init__(self, *args, **kwargs) + sizer = wx.BoxSizer(wx.VERTICAL) # Main vertical sizer + + self.display = wx.ComboBox(self) # Current calculation + sizer.Add(self.display, 0, wx.EXPAND | wx.BOTTOM, + 8) # Add to main sizer - # [7][8][9][/] + # [7][8][9][/] # [4][5][6][*] # [1][2][3][-] # [0][.][C][+] gsizer = wx.GridSizer(4, 4, 8, 8) - for row in (("7", "8", "9", "/"), - ("4", "5", "6", "*"), - ("1", "2", "3", "-"), - ("0", ".", "C", "+")): + for row in (("7", "8", "9", "/"), ("4", "5", "6", "*"), + ("1", "2", "3", "-"), ("0", ".", "C", "+")): for label in row: - b = wx.Button(self, label=label, size=(40,-1)) + b = wx.Button(self, label=label, size=(40, -1)) gsizer.Add(b) b.Bind(wx.EVT_BUTTON, self.OnButton) sizer.Add(gsizer, 1, wx.EXPAND) @@ -57,33 +56,32 @@ def __init__(self, parent=None): # [ = ] b = wx.Button(self, label="=") b.Bind(wx.EVT_BUTTON, self.OnButton) - sizer.Add(b, 0, wx.EXPAND|wx.ALL, 8) + sizer.Add(b, 0, wx.EXPAND | wx.ALL, 8) self.equal = b # Set sizer and center - self.SetSizer(sizer) - sizer.Fit(self) - self.CenterOnScreen() + self.SetSizerAndFit(sizer) def OnButton(self, evt): '''Handle button click event''' - + # Get title of clicked button label = evt.GetEventObject().GetLabel() - if label == "=": # Calculate + if label == "=": # Calculate self.Calculate() - elif label == "C": # Clear + elif label == "C": # Clear self.display.SetValue("") - else: # Just add button text to current calculation + else: # Just add button text to current calculation self.display.SetValue(self.display.GetValue() + label) - self.equal.SetFocus() # Set the [=] button in focus + self.display.SetInsertionPointEnd() + self.equal.SetFocus() # Set the [=] button in focus def Calculate(self): """ do the calculation itself - + in a separate method, so it can be called outside of a button event handler """ try: @@ -100,22 +98,38 @@ def Calculate(self): # Show result self.display.SetValue(str(result)) - except Exception, e: + except Exception as e: wx.LogError(str(e)) return def ComputeExpression(self, expression): """ Compute the expression passed in. - + This can be called from another class, module, etc. """ + print("ComputeExpression called with:", expression) self.display.SetValue(expression) self.Calculate() + +class MainFrame(wx.Frame): + def __init__(self, *args, **kwargs): + kwargs.setdefault('title', "Calculator") + wx.Frame.__init__(self, *args, **kwargs) + + self.calcPanel = Calculator(self) + + # put the panel on -- in a sizer to give it some space + S = wx.BoxSizer(wx.VERTICAL) + S.Add(self.calcPanel, 1, wx.GROW | wx.ALL, 10) + self.SetSizerAndFit(S) + self.CenterOnScreen() + + if __name__ == "__main__": # Run the application app = wx.App(False) - frame = Calculator(None) + frame = MainFrame(None) frame.Show() - app.MainLoop() \ No newline at end of file + app.MainLoop() diff --git a/CalculatorDemoDriver.py b/CalculatorDemoDriver.py index 2e886b5..08e5cf8 100755 --- a/CalculatorDemoDriver.py +++ b/CalculatorDemoDriver.py @@ -1,17 +1,24 @@ #!/usr/bin/env python - + """ -demo of how to drive a wxPython app from another script: +NOTE: This worked when it was written, but not with recent + versions of wxPython (at least on a Mac) + I suspect that it would have to be re-factored + to put the GUI in the main thread, and star a secondary thread to + interact with the user. + +Demo of how to drive a wxPython app from another script: one thread to do the driving, one thread to run the Calculator: the primary thread runs the GUI - - it gets "locked up" with the mainloop. -the secondary thread i used to do things in a way outside the GUI. In this +the secondary thread is used to do things outside the GUI. In this case, a simple pause and sending commands now and then. The commands are put on the event loop with a wx.CallAfter() call. """ +from __future__ import (division, unicode_literals, print_function) import threading @@ -19,13 +26,14 @@ import CalculatorDemo + class GUI_Thread(threading.Thread): """ - class to create a thread to run the GUI in - + class to create a thread to run the GUI in + this should allow the command line to stay active in the main thread, while the mainloop is running in this thread. - + """ def run(self): """ @@ -33,21 +41,22 @@ def run(self): """ #Create the application self.app = wx.App(False) - self.calculator = CalculatorDemo.Calculator() + self.calculator = CalculatorDemo.MainFrame(None) self.calculator.Show() self.app.MainLoop() - + # create and start the thread for the GUI gui_thread = GUI_Thread() gui_thread.start() +# the computer object: +#computer = gui_thread.calculator.calcPanel.ComputeExpression + # now we have control back -- start a loop for user input -print "enter expressions to calcualte: enter to evaluate" -print "hit ctrl+C to exit" +print("enter expressions to calculate: enter to evaluate") +print("hit ctrl+C to exit") while True: - expr = raw_input() - # send the input to the calculator to calculate + expr = input() gui_thread.calculator.ComputeExpression(expr) - diff --git a/CenterTest.py b/CenterTest.py index a477fe5..fedb55f 100755 --- a/CenterTest.py +++ b/CenterTest.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.4 +#!/usr/bin/env python import wx diff --git a/ChangePanel.py b/ChangePanel.py index 85dc14c..bccbc0c 100755 --- a/ChangePanel.py +++ b/ChangePanel.py @@ -1,98 +1,98 @@ -#!/usr/bin/env python2.5 +#!/usr/bin/env python import wx class Panel1(wx.Panel): - def __init__(self, parent, id): - print "Panel1 being initialized" - - wx.Panel.__init__(self, parent, id) + def __init__(self, parent, id): + print "Panel1 being initialized" - topSizer = wx.BoxSizer(wx.VERTICAL) + wx.Panel.__init__(self, parent, id) - header = wx.StaticText(self, -1, 'First Panel') - topSizer.Add(header, 0, wx.ALIGN_CENTER|wx.ALL, 3) + topSizer = wx.BoxSizer(wx.VERTICAL) - button = wx.Button(self, -1, ' Next Panel ', wx.DefaultPosition, wx.Size(-1, 32)) - self.Bind(wx.EVT_BUTTON, self.Click, button) + header = wx.StaticText(self, -1, 'First Panel') + topSizer.Add(header, 0, wx.ALIGN_CENTER|wx.ALL, 3) - topSizer.Add((1, 13), 0, wx.ALIGN_CENTER) - topSizer.Add(button, 0, wx.ALIGN_CENTER|wx.RIGHT|wx.LEFT, 60) - topSizer.Add((1, 13), 0, wx.ALIGN_CENTER) + button = wx.Button(self, -1, ' Next Panel ', wx.DefaultPosition, wx.Size(-1, 32)) + self.Bind(wx.EVT_BUTTON, self.Click, button) - footer = wx.StaticText(self, -1, 'First Panel') - topSizer.Add(footer, 0, wx.ALIGN_CENTER|wx.ALL, 3) + topSizer.Add((1, 13), 0, wx.ALIGN_CENTER) + topSizer.Add(button, 0, wx.ALIGN_CENTER|wx.RIGHT|wx.LEFT, 60) + topSizer.Add((1, 13), 0, wx.ALIGN_CENTER) - self.SetSizer(topSizer) - self.Fit() + footer = wx.StaticText(self, -1, 'First Panel') + topSizer.Add(footer, 0, wx.ALIGN_CENTER|wx.ALL, 3) - def Click(self, event): - self.GetParent().ChangePanel() + self.SetSizer(topSizer) + self.Fit() + + def Click(self, event): + self.GetParent().ChangePanel() class Panel2(wx.Panel): - def __init__(self, parent, id): - print "Panel2 being initialized" - wx.Panel.__init__(self, parent, id) + def __init__(self, parent, id): + print "Panel2 being initialized" + wx.Panel.__init__(self, parent, id) + + topSizer = wx.BoxSizer(wx.HORIZONTAL) + topSizer.Add((20, 20), 0, wx.ALIGN_CENTER|wx.ALL, 3) - topSizer = wx.BoxSizer(wx.HORIZONTAL) - topSizer.Add((20, 20), 0, wx.ALIGN_CENTER|wx.ALL, 3) + leftText = wx.StaticText(self, -1, 'Second\n Panel') + topSizer.Add(leftText, 0, wx.ALIGN_CENTER|wx.ALL, 3) - leftText = wx.StaticText(self, -1, 'Second\n Panel') - topSizer.Add(leftText, 0, wx.ALIGN_CENTER|wx.ALL, 3) + button = wx.Button(self, -1, ' Next Panel ', wx.DefaultPosition, wx.Size(-1, 32)) + self.Bind(wx.EVT_BUTTON, self.Click, button) - button = wx.Button(self, -1, ' Next Panel ', wx.DefaultPosition, wx.Size(-1, 32)) - self.Bind(wx.EVT_BUTTON, self.Click, button) + topSizer.Add((20, 20), 0, wx.ALIGN_CENTER|wx.ALL, 3) + topSizer.Add(button, 0, wx.ALIGN_CENTER|wx.TOP|wx.BOTTOM, 33) + topSizer.Add((20, 20), 0, wx.ALIGN_CENTER|wx.ALL, 3) - topSizer.Add((20, 20), 0, wx.ALIGN_CENTER|wx.ALL, 3) - topSizer.Add(button, 0, wx.ALIGN_CENTER|wx.TOP|wx.BOTTOM, 33) - topSizer.Add((20, 20), 0, wx.ALIGN_CENTER|wx.ALL, 3) - - rightText = wx.StaticText(self, -1, 'Second\n Panel') - topSizer.Add(rightText, 0, wx.ALIGN_CENTER|wx.ALL, 3) + rightText = wx.StaticText(self, -1, 'Second\n Panel') + topSizer.Add(rightText, 0, wx.ALIGN_CENTER|wx.ALL, 3) - topSizer.Add((20, 20), 0, wx.ALIGN_CENTER|wx.ALL, 3) + topSizer.Add((20, 20), 0, wx.ALIGN_CENTER|wx.ALL, 3) - self.SetSizer(topSizer) - self.Fit() + self.SetSizer(topSizer) + self.Fit() - def Click(self, event): - self.GetParent().ChangePanel() + def Click(self, event): + self.GetParent().ChangePanel() class MyFrame(wx.Frame): - def __init__(self, parent, id): - wx.Frame.__init__(self, parent, id, 'My App') + def __init__(self, parent, id): + wx.Frame.__init__(self, parent, id, 'My App') - self.panel1 = Panel1(self, -1) - self.panel2 = Panel2(self, -1) - self.currentPanel = 2 + self.panel1 = Panel1(self, -1) + self.panel2 = Panel2(self, -1) + self.currentPanel = 2 - self.ChangePanel() + self.ChangePanel() - self.Fit() - self.Show(True) + self.Fit() + self.Show(True) - def ChangePanel(self): - if self.currentPanel == 1: - self.currentPanel = 2 - self.panel1.Hide() - self.panel2.Show() - else: - self.currentPanel = 1 - self.panel2.Hide() - self.panel1.Show() - self.Fit() + def ChangePanel(self): + if self.currentPanel == 1: + self.currentPanel = 2 + self.panel1.Hide() + self.panel2.Show() + else: + self.currentPanel = 1 + self.panel2.Hide() + self.panel1.Show() + self.Fit() class MyApp(wx.App): - def OnInit(self): - self.frame = MyFrame(None, -1) - self.SetTopWindow(self.frame) - return True + def OnInit(self): + self.frame = MyFrame(None, -1) + self.SetTopWindow(self.frame) + return True def main(): - app = MyApp(0) - app.MainLoop() + app = MyApp(0) + app.MainLoop() if __name__ == '__main__': - main() + main() diff --git a/ChoiceTest.py b/ChoiceTest.py index 785cdf2..15d2dfe 100755 --- a/ChoiceTest.py +++ b/ChoiceTest.py @@ -1,24 +1,20 @@ -#!/usr/bin/env python2.4 +#!/usr/bin/env python import wx + class DemoFrame(wx.Frame): """ This window displays a wx.Choice """ def __init__(self, title = "Micro App"): wx.Frame.__init__(self, None , -1, title) - Choice = wx.Choice(self, choices = [str(x) for x in range(20)] ) - self.Fit() - -app = wx.App() -frame = DemoFrame() -frame.Show() -app.MainLoop() - - - +if __name__ == "__main__": + app = wx.App(0) + frame = DemoFrame() + frame.Show() + app.MainLoop() diff --git a/ClickBitmap.py b/ClickBitmap.py index 67e138e..e41fc9d 100755 --- a/ClickBitmap.py +++ b/ClickBitmap.py @@ -1,31 +1,35 @@ #!/usr/bin/env python + import wx import wx.lib.statbmp as statbmp + class MainFrame(wx.Frame): def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) - bmp = wx.Bitmap("Images/medtest.jpg") - self.Image = statbmp.GenStaticBitmap(self, wx.ID_ANY, bmp) + bmp = wx.Bitmap("Images/medtest.jpg") + self.Image = statbmp.GenStaticBitmap(self, wx.ID_ANY, bmp) self.Image.Bind(wx.EVT_LEFT_DOWN, self.OnClick) S = wx.BoxSizer(wx.VERTICAL) S.Add(self.Image, 0) self.SetSizerAndFit(S) - + def OnClick(self, event): - print "Image: was clicked at: %i, %i "%(event.GetX(), event.GetY()) - + print("Image: was clicked at: %i, %i "%(event.GetX(), event.GetY())) + + class App(wx.App): def OnInit(self): - frame = MainFrame(None, title= "wxWindowBitmap Test") + frame = MainFrame(None, title="wxWindowBitmap Test") self.SetTopWindow(frame) frame.Show(True) return True -app = App(0) -app.MainLoop() +if __name__ == "__main__": + app = App(0) + app.MainLoop() diff --git a/ClientDCTest.py b/ClientDCTest.py index ed825c2..43a5be0 100755 --- a/ClientDCTest.py +++ b/ClientDCTest.py @@ -5,11 +5,11 @@ """ import wx -print wx.__version__ +print(wx.version()) import random -class BufferedWindow(wx.Window): +class BufferedWindow(wx.Window): """ A Buffered window class. @@ -22,11 +22,9 @@ class BufferedWindow(wx.Window): When the drawing needs to change, you app needs to call the UpdateDrawing() method. Since the drawing is stored in a bitmap, you can also save the drawing to file by calling the - SaveToFile(self,file_name,file_type) method. + SaveToFile(self, file_name, file_type) method. """ - - def __init__(self, parent, id, pos = wx.DefaultPosition, size = wx.DefaultSize, @@ -41,7 +39,7 @@ def __init__(self, parent, id, # platforms at initialization, but little harm done. self.OnSize(None) - def Draw(self,dc): + def Draw(self, dc): ## just here as a place holder. ## This method should be over-ridden when subclassed pass @@ -49,7 +47,7 @@ def Draw(self,dc): def OnPaint(self, event): # All that is needed here is to draw the buffer to screen dc = wx.PaintDC(self) - dc.DrawBitmap(self._Buffer,0,0) + dc.DrawBitmap(self._Buffer, 0, 0) def OnSize(self,event): # The Buffer init is done here, to make sure the buffer is always @@ -58,14 +56,14 @@ def OnSize(self,event): # Make sure we don't try to create a 0 size bitmap Size = (max(Size[0], 1), max(Size[1], 1)) - self._Buffer = wx.EmptyBitmap(Size[0],Size[1]) + self._Buffer = wx.EmptyBitmap(Size[0], Size[1]) self.UpdateDrawing() - def SaveToFile(self,FileName,FileType): + def SaveToFile(self, FileName, FileType): ## This will save the contents of the buffer - ## to the specified file. See the wxWindows docs for + ## to the specified file. See the wxWindows docs for ## wx.Bitmap::SaveFile for the details - self._Buffer.SaveFile(FileName,FileType) + self._Buffer.SaveFile(FileName, FileType) def UpdateDrawing(self): """ @@ -84,13 +82,14 @@ def UpdateDrawing(self): # update the screen wx.ClientDC(self).DrawBitmap(self._Buffer,0,0) + class DrawWindow(BufferedWindow): def __init__(self, parent, id = -1): ## Any data the Draw() function needs must be initialized before ## calling BufferedWindow.__init__, as it will call the Draw ## function. BufferedWindow.__init__(self, parent, id) - + self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) self.Bind(wx.EVT_MOTION, self.OnMove) @@ -108,7 +107,7 @@ def OnLeftUp(self, event): self.DrawLine(event, New=False) self.StartMove = None self.PrevMove = None - + def OnMove(self, event): if event.Dragging() and event.LeftIsDown() and self.StartMove is not None: self.DrawLine(event) @@ -119,14 +118,12 @@ def DrawLine(self, event, New=True): dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.SetLogicalFunction(wx.INVERT) if self.PrevMove is not None: - print "Drawing Over old line:", self.StartMove, self.PrevMove + print("Drawing Over old line:", self.StartMove, self.PrevMove) dc.DrawLinePoint(self.StartMove, self.PrevMove) self.PrevMove = event.GetPosition() - print "Drawing new line:", self.StartMove, self.PrevMove + print("Drawing new line:", self.StartMove, self.PrevMove) if New: dc.DrawLinePoint( self.StartMove, self.PrevMove ) - - def Draw(self, dc): coords = ((40,40),(200,220),(210,120),(120,300)) @@ -144,14 +141,23 @@ class TestFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, "ClientDC Test", wx.DefaultPosition, - size=(500,500), + size=(500, 500), style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE) self.Window = DrawWindow(self) + self.Window.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) + self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) + + self.Centre() + + def OnKeyDown(self, event): + if event.GetKeyCode() == wx.WXK_ESCAPE: + self.Close() + class DemoApp(wx.App): def OnInit(self): - wx.InitAllImageHandlers() # called so a PNG can be saved + wx.InitAllImageHandlers() # called so a PNG can be saved frame = TestFrame() frame.Show(True) @@ -166,26 +172,7 @@ def OnInit(self): return True + if __name__ == "__main__": app = DemoApp(0) app.MainLoop() - - - - - - - - - - - - - - - - - - - - diff --git a/Clock.py b/Clock.py index 0ea9191..7d2b51b 100755 --- a/Clock.py +++ b/Clock.py @@ -1,13 +1,16 @@ -#!/usr/bin/env python2.4 +#!/usr/bin/env python import wx from wx.lib.analogclock import * + class MainWindow(wx.Dialog): """ This window displays a clock and a button """ - def __init__(self,parent,id,title): - wx.Dialog.__init__(self, parent, id, title, size = (800,600), style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE) + def __init__(self, parent, id, title): + wx.Dialog.__init__(self, parent, id, title, size=(800,600), + style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE) self.SetBackgroundColour(wx.WHITE) + self.SetDoubleBuffered(True) clock = AnalogClockWindow(self) clock.SetBackgroundColour("RED") @@ -17,12 +20,12 @@ def __init__(self,parent,id,title): box = wx.BoxSizer(wx.VERTICAL) box.Add(clock,1, wx.EXPAND | wx.ALIGN_CENTER | wx.ALL | wx.SHAPED, 10) - box.Add(btn,0 , wx.ALIGN_CENTER | wx.ALL, 10) + box.Add(btn, 0, wx.ALIGN_CENTER | wx.ALL, 10) self.SetAutoLayout(True) self.SetSizer(box) self.Layout() - + self.ShowModal() self.Destroy() @@ -36,18 +39,17 @@ def OnInit(self): Dw_i = Dw_mm / 25.4 Dh_i = Dh_mm / 25.4 - print "The display is %i by %i pixels"%(Dw, Dh) - print "The display is %i by %i inches"%(Dw_i, Dh_i) - print "resulting in %i by %i ppi"%(Dw / Dw_i, Dh / Dh_i) - - + print("The display is %i by %i pixels" %(Dw, Dh)) + print("The display is %i by %i inches" %(Dw_i, Dh_i)) + print("resulting in %i by %i ppi" %(Dw / Dw_i, Dh / Dh_i)) + + frame = MainWindow(None, -1, "Clock") self.SetTopWindow(frame) - - return True - -app = MyApp(0) -app.MainLoop() + return True +if __name__ == "__main__": + app = MyApp(0) + app.MainLoop() diff --git a/DisplayRes.py b/DisplayRes.py index e1f7759..1d61324 100755 --- a/DisplayRes.py +++ b/DisplayRes.py @@ -1,7 +1,7 @@ -#!/usr/bin/env python2.4 +#!/usr/bin/env python import wx - + class MyApp(wx.App): def OnInit(self): @@ -11,20 +11,15 @@ def OnInit(self): Dw_i = Dw_mm / 25.4 Dh_i = Dh_mm / 25.4 - print "The display is %i by %i pixels"%(Dw, Dh) - print "The display is %i by %i inches"%(Dw_i, Dh_i) - print "resulting in %i by %i ppi"%(Dw / Dw_i, Dh / Dh_i) + print("The display is %i by %i pixels" %(Dw, Dh)) + print("The display is %i by %i inches" %(Dw_i, Dh_i)) + print("resulting in %i by %i ppi" %(Dw / Dw_i, Dh / Dh_i)) dc = wx.ScreenDC() - print " The system reports : %s PPI"%dc.GetPPI() + print(" The system reports : %s PPI" %dc.GetPPI()) return True - - -app = MyApp(0) -app.MainLoop() - - - - +if __name__ == '__main__': + app = MyApp(1) + app.MainLoop() diff --git a/DoubleBufferDemo.py b/DoubleBufferDemo.py index 2a5be2c..84f395a 100755 --- a/DoubleBufferDemo.py +++ b/DoubleBufferDemo.py @@ -10,6 +10,7 @@ USE_BUFFERED_DC = False #USE_BUFFERED_DC = True + class BufferedWindow(wx.Window): """ @@ -53,7 +54,7 @@ def OnPaint(self, event): dc = wx.PaintDC(self) dc.DrawBitmap(self._Buffer, 0, 0) - def OnSize(self,event): + def OnSize(self, event): # The Buffer init is done here, to make sure the buffer is always # the same size as the Window Size = self.ClientSize @@ -66,7 +67,7 @@ def OnSize(self,event): def SaveToFile(self, FileName, FileType=wx.BITMAP_TYPE_PNG): ## This will save the contents of the buffer - ## to the specified file. See the wxWindows docs for + ## to the specified file. See the wxWindows docs for ## wx.Bitmap::SaveFile for the details self._Buffer.SaveFile(FileName, FileType) @@ -86,7 +87,8 @@ def UpdateDrawing(self): del dc # need to get rid of the MemoryDC before Update() is called. self.Refresh(eraseBackground=False) self.Update() - + + class DrawWindow(BufferedWindow): def __init__(self, *args, **kwargs): ## Any data the Draw() function needs must be initialized before @@ -121,23 +123,23 @@ def Draw(self, dc): class TestFrame(wx.Frame): def __init__(self, parent=None): wx.Frame.__init__(self, parent, - size = (500,500), + size = (500, 500), title="Double Buffered Test", style=wx.DEFAULT_FRAME_STYLE) ## Set up the MenuBar MenuBar = wx.MenuBar() - + file_menu = wx.Menu() - + item = file_menu.Append(wx.ID_EXIT, text="&Exit") self.Bind(wx.EVT_MENU, self.OnQuit, item) MenuBar.Append(file_menu, "&File") - + draw_menu = wx.Menu() - item = draw_menu.Append(wx.ID_ANY, "&New Drawing","Update the Drawing Data") + item = draw_menu.Append(wx.ID_ANY, "&New Drawing", "Update the Drawing Data") self.Bind(wx.EVT_MENU, self.NewDrawing, item) - item = draw_menu.Append(wx.ID_ANY,'&Save Drawing\tAlt-I','') + item = draw_menu.Append(wx.ID_ANY, '&Save Drawing\tAlt-I', '') self.Bind(wx.EVT_MENU, self.SaveToFile, item) MenuBar.Append(draw_menu, "&Draw") @@ -150,7 +152,7 @@ def __init__(self, parent=None): def OnQuit(self,event): self.Close(True) - + def NewDrawing(self, event=None): self.Window.DrawData = self.MakeNewData() self.Window.UpdateDrawing() @@ -160,7 +162,7 @@ def SaveToFile(self,event): defaultDir = "", defaultFile = "", wildcard = "*.png", - style = wx.SAVE) + style = wx.FD_SAVE) if dlg.ShowModal() == wx.ID_OK: self.Window.SaveToFile(dlg.GetPath(), wx.BITMAP_TYPE_PNG) dlg.Destroy() @@ -173,35 +175,36 @@ def MakeNewData(self): # make some random rectangles l = [] for i in range(5): - w = random.randint(1,MaxX/2) - h = random.randint(1,MaxY/2) - x = random.randint(1,MaxX-w) - y = random.randint(1,MaxY-h) - l.append( (x,y,w,h) ) + w = random.randint(1, MaxX / 2) + h = random.randint(1, MaxY / 2) + x = random.randint(1, MaxX - w) + y = random.randint(1, MaxY - h) + l.append((x, y, w, h)) DrawData["Rectangles"] = l # make some random ellipses l = [] for i in range(5): - w = random.randint(1,MaxX/2) - h = random.randint(1,MaxY/2) - x = random.randint(1,MaxX-w) - y = random.randint(1,MaxY-h) - l.append( (x,y,w,h) ) + w = random.randint(1, MaxX / 2) + h = random.randint(1, MaxY / 2) + x = random.randint(1, MaxX - w) + y = random.randint(1, MaxY - h) + l.append((x, y, w, h)) DrawData["Ellipses"] = l # Polygons l = [] for i in range(3): points = [] - for j in range(random.randint(3,8)): - point = (random.randint(1,MaxX),random.randint(1,MaxY)) + for j in range(random.randint(3, 8)): + point = (random.randint(1, MaxX), random.randint(1, MaxY)) points.append(point) l.append(points) DrawData["Polygons"] = l return DrawData + class DemoApp(wx.App): def OnInit(self): self.frame = TestFrame() @@ -209,25 +212,7 @@ def OnInit(self): return True + if __name__ == "__main__": app = DemoApp(0) app.MainLoop() - - - - - - - - - - - - - - - - - - - diff --git a/DoubleBufferTest.py b/DoubleBufferTest.py index ce80552..fadb942 100755 --- a/DoubleBufferTest.py +++ b/DoubleBufferTest.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.4 +#!/usr/bin/env python import wx import random @@ -9,6 +9,7 @@ USE_BUFFERED_DC = 1 + class BufferedWindow(wx.Window): """ @@ -27,7 +28,7 @@ class BufferedWindow(wx.Window): """ - + def __init__(self, parent, id, pos = wx.DefaultPosition, size = wx.DefaultSize, @@ -37,13 +38,12 @@ def __init__(self, parent, id, wx.EVT_PAINT(self, self.OnPaint) wx.EVT_SIZE(self, self.OnSize) - # OnSize called to make sure the buffer is initialized. # This might result in OnSize getting called twice on some # platforms at initialization, but little harm done. self.OnSize(None) - def Draw(self,dc): + def Draw(self, dc): ## just here as a place holder. ## This method should be over-ridden when subclassed pass @@ -56,7 +56,7 @@ def OnPaint(self, event): dc = wx.PaintDC(self) dc.DrawBitmap(self._Buffer,0,0) - def OnSize(self,event): + def OnSize(self, event): # The Buffer init is done here, to make sure the buffer is always # the same size as the Window Size = self.GetClientSizeTuple() @@ -64,12 +64,12 @@ def OnSize(self,event): # Make new offscreen bitmap: this bitmap will always have the # current drawing in it, so it can be used to save the image to # a file, or whatever. - self._Buffer = wx.EmptyBitmap(Size[0],Size[1]) + self._Buffer = wx.EmptyBitmap(Size[0], Size[1]) self.UpdateDrawing() - def SaveToFile(self,FileName,FileType): + def SaveToFile(self, FileName, FileType): ## This will save the contents of the buffer - ## to the specified file. See the wxWindows docs for + ## to the specified file. See the wxWindows docs for ## wx.Bitmap::SaveFile for the details self._Buffer.SaveFile(FileName,FileType) @@ -92,10 +92,10 @@ def UpdateDrawing(self): dc.SelectObject(self._Buffer) self.Draw(dc) # update the screen - wx.ClientDC(self).DrawBitmap(self._Buffer,0,0) + wx.ClientDC(self).DrawBitmap(self._Buffer, 0, 0) class DrawWindow(BufferedWindow): - def __init__(self, parent, id = -1): + def __init__(self, parent, id=-1): ## Any data the Draw() function needs must be initialized before ## calling BufferedWindow.__init__, as it will call the Draw ## function. @@ -103,11 +103,11 @@ def __init__(self, parent, id = -1): self.DrawData = {} ## create a marker bitmap - print "initing the marker" + print("initing the marker") + + MaskColor = wx.Colour(254, 255, 255) - MaskColor = wx.Colour(254,255,255) - - self.Marker = wx.EmptyBitmap(40,40) + self.Marker = wx.EmptyBitmap(40, 40) dc = wx.MemoryDC() dc.SelectObject(self.Marker) @@ -117,27 +117,27 @@ def __init__(self, parent, id = -1): dc.Clear() dc.SetPen(wx.RED_PEN) dc.SetBrush(wx.GREEN_BRUSH) - dc.DrawPolygon(((20,0),(30,10),(24,24),(40,40),(0,20))) + dc.DrawPolygon(((20, 0), (30, 10), (24, 24), (40, 40), (0, 20))) dc.EndDrawing() - Mask = wx.MaskColour(self.Marker,MaskColor) - self.Marker.SetMask(Mask) - + ###FIXME### Mask = wx.Mask(self.Marker, MaskColor) + ###FIXME### self.Marker.SetMask(Mask) + BufferedWindow.__init__(self, parent, id) - + def Draw(self, dc): - coords = ((40,40),(100,120),(110,20),(20,200)) + coords = ((40, 40), (100, 120), (110, 20), (20, 200)) dc.BeginDrawing() dc.SetBackground( wx.Brush("Blue") ) dc.Clear() # make sure you clear the bitmap! try: dc.DrawBitmapList(self.Marker, coords, True) - print "using DrawBitmapList" + print("using DrawBitmapList") except AttributeError: - print "not using DrawBitmapList" - for (x,y) in coords: - dc.DrawBitmap(self.Marker,x, y, True) + print("not using DrawBitmapList") + for (x, y) in coords: + dc.DrawBitmap(self.Marker, x, y, True) dc.EndDrawing() @@ -145,33 +145,33 @@ class TestFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, "Double Buffered Test", wx.DefaultPosition, - size=(500,500), + size=(500, 500), style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE) ## Set up the MenuBar MenuBar = wx.MenuBar() - + file_menu = wx.Menu() ID_EXIT_MENU = wx.NewId() file_menu.Append(ID_EXIT_MENU, "E&xit","Terminate the program") - wx.EVT_MENU(self, ID_EXIT_MENU, self.OnQuit) + self.Bind(wx.EVT_MENU, self.OnQuit, id=ID_EXIT_MENU) MenuBar.Append(file_menu, "&File") - + draw_menu = wx.Menu() ID_DRAW_MENU = wx.NewId() BMP_ID = wx.NewId() - draw_menu.Append(BMP_ID,'&Save Drawing\tAlt-I','') - wx.EVT_MENU(self,BMP_ID, self.SaveToFile) + draw_menu.Append(BMP_ID, '&Save Drawing\tAlt-I','') + self.Bind(wx.EVT_MENU, self.SaveToFile, id=BMP_ID) MenuBar.Append(draw_menu, "&Draw") self.SetMenuBar(MenuBar) - self.Window = DrawWindow(self) + def OnQuit(self,event): self.Close(True) - + def SaveToFile(self,event): dlg = wx.FileDialog(self, "Choose a file name to save the image as a PNG to", defaultDir = "", @@ -182,9 +182,10 @@ def SaveToFile(self,event): self.Window.SaveToFile(dlg.GetPath(),wx.BITMAP_TYPE_PNG) dlg.Destroy() + class DemoApp(wx.App): def OnInit(self): - wx.InitAllImageHandlers() # called so a PNG can be saved + # wx.InitAllImageHandlers() # called so a PNG can be saved frame = TestFrame() frame.Show(True) @@ -199,25 +200,7 @@ def OnInit(self): return True + if __name__ == "__main__": app = DemoApp(0) app.MainLoop() - - - - - - - - - - - - - - - - - - - diff --git a/DrawLinesTest.py b/DrawLinesTest.py index b5a9bd4..1ed7711 100755 --- a/DrawLinesTest.py +++ b/DrawLinesTest.py @@ -1,83 +1,93 @@ -#!/usr/bin/env python2.4 +#!/usr/bin/env pythonw -import wx -import numarray -from numarray import random_array -import RandomArray # the Numeric version -import time +""" +Timing test of the DrawLineList DC methods +It is NOT fast! +""" + +import time +import wx +from numpy import random -NumLinePoints = 5000 -NumPointPoints = 5000 +NumLinePoints = 500 +NumPointPoints = 500 -## Make some random data to draw things with. -MaxX = 500 -LinesPoints = random_array.randint(1, MaxX, (NumLinePoints,2) ) -#PointsPoints = random_array.randint(1, MaxX, (NumPointPoints,2) ) -PointsPoints = RandomArray.randint(1, MaxX, (NumPointPoints,2) ) # Numeric +# Make some random data to draw things with. +MaxX = 500 +LinesPoints = random.randint(1, MaxX, (NumLinePoints, 2)) +PointsPoints = random.randint(1, MaxX, (NumPointPoints, 2)) class TestFrame(wx.Frame): def __init__(self): - wx.Frame.__init__(self, None, -1, "DrawLines Test", - wx.DefaultPosition, - size=(500,500), - style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE) - - ## Set up the MenuBar + wx.Frame.__init__( + self, + None, + -1, + "DrawLines Test", + wx.DefaultPosition, + size=(MaxX, MaxX), + style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE) + + # Set up the MenuBar. MenuBar = wx.MenuBar() - + file_menu = wx.Menu() - ID_EXIT_MENU = wx.NewId() - file_menu.Append(ID_EXIT_MENU, "E&xit","Terminate the program") - wx.EVT_MENU(self, ID_EXIT_MENU, self.OnQuit) + item = file_menu.Append(wx.ID_EXIT, "E&xit", "Terminate the program") + self.Bind(wx.EVT_MENU, self.OnQuit, item) MenuBar.Append(file_menu, "&File") - + draw_menu = wx.Menu() - ID_DRAW_MENU = wx.NewId() - draw_menu.Append(ID_DRAW_MENU, "&ReDraw","DrawAgain") - wx.EVT_MENU(self, ID_DRAW_MENU,self.ReDraw) + item = draw_menu.Append(wx.ID_ANY, "&ReDraw", "DrawAgain") + self.Bind(wx.EVT_MENU, self.ReDraw, item) MenuBar.Append(draw_menu, "&Draw") self.SetMenuBar(MenuBar) - wx.EVT_PAINT(self, self.OnPaint) + self.Bind(wx.EVT_PAINT, self.OnPaint) - def OnPaint(self,event): + def OnPaint(self, event): + print("in OnPaint...") dc = wx.PaintDC(self) - dc.SetBackground( wx.Brush("White") ) + dc.SetBackground(wx.Brush("White")) dc.Clear() self.DrawLines(dc) self.DrawPoints(dc) - def ReDraw(self, event = None): + def ReDraw(self, event=None): dc = wx.ClientDC(self) - dc.SetBackground( wx.Brush("White") ) + dc.SetBackground(wx.Brush("White")) dc.Clear() self.DrawLines(dc) self.DrawPoints(dc) def DrawLines(self, dc): - dc.BeginDrawing() dc.SetPen(wx.Pen('Black', 2)) - start = time.clock() - #dc.DrawLines(LinesPoints.tolist()) + start = time.time() dc.DrawLines(LinesPoints) - print "DrawLines Call took %f seconds"%(time.clock() - start) - dc.EndDrawing() + print("DrawLines Call took %f seconds" % (time.time() - start)) + start = time.time() + for i in range(len(LinesPoints) - 1): + dc.DrawLine( + LinesPoints[i, 0], + LinesPoints[i, 1], + LinesPoints[i + 1, 0], + LinesPoints[i + 1, 1], + ) + print("DrawLine loop took %f seconds" % (time.time() - start)) def DrawPoints(self, dc): - dc.BeginDrawing() dc.SetPen(wx.Pen('Red', 2)) - start = time.clock() + start = time.time() dc.DrawPointList(PointsPoints) - print "DrawPointList Call took %f seconds"%(time.clock() - start) - dc.EndDrawing() + print("DrawPointList Call took %f seconds" % (time.time() - start)) - def OnQuit(self,event): + def OnQuit(self, event): self.Close(True) + class DemoApp(wx.App): def OnInit(self): frame = TestFrame() @@ -86,25 +96,7 @@ def OnInit(self): return True + if __name__ == "__main__": - app = DemoApp(0) + app = DemoApp(False) app.MainLoop() - - - - - - - - - - - - - - - - - - - diff --git a/DrawOnControl.py b/DrawOnControl.py index 7f6c73c..581fa1d 100755 --- a/DrawOnControl.py +++ b/DrawOnControl.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.4 +#!/usr/bin/env python """ Note that this doesn't work right! @@ -8,29 +8,36 @@ import wx + class MyFrame(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, size=wx.Size(360, 240)) self.panel = MyPanel(self) - wx.EVT_CLOSE(self,self.OnCloseWindow) - + self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) + def OnCloseWindow(self, event): self.Destroy() + class MyPanel(wx.Panel): - def __init__(self,window): - wx.Panel.__init__(self, window, wx.NewId(), wx.DefaultPosition, wx.DefaultSize, wx.CLIP_CHILDREN) - self.b = wx.Button(self, -1, "Start Flashing", (50,50) ) - s = wx.StaticText(self, -1, "A Static Text", (50,100) ) + def __init__(self, window): + wx.Panel.__init__(self, window, wx.NewId(), style=wx.CLIP_CHILDREN) + self.b = wx.Button(self, -1, "Start Flashing", (50, 50)) + self.st = wx.StaticText(self, -1, "A Static Text", (50, 100), style=wx.BORDER_SUNKEN) wx.EVT_BUTTON(self,self.b.GetId(), self.OnButton) wx.EVT_PAINT(self, self.OnPaint) self.BorderColor = wx.RED - self.timer = wx.Timer(self, 999 ) + self.timer = wx.Timer(self, 999) #self.timer.Start(300) - wx.EVT_TIMER(self, 999, self.OnTimer) + self.Bind(wx.EVT_TIMER, self.OnTimer) + + self.Bind(wx.EVT_SIZE, self.OnSize) + + def OnSize(self, event): + self.Refresh() def OnTimer(self, event): if self.BorderColor == wx.RED: @@ -38,38 +45,39 @@ def OnTimer(self, event): else: self.BorderColor = wx.RED self.ResetBorder() - - def OnPaint(self,Event): + + def OnPaint(self, event): dc = wx.PaintDC(self) self.DrawBorder(dc) - Event.Skip() + event.Skip() - def OnSize(self,Event): + def OnSize(self, event): dc = wx.ClientDC(self) self.DrawBorder(dc) - + def DrawBorder(self, dc): size = self.GetSize() - dc.SetPen( wx.Pen(self.BorderColor,4) ) - dc.DrawRectangle(2,2,size[0]-3,size[1]-3) + dc.SetPen(wx.Pen(self.BorderColor, 4)) + dc.DrawRectangle(2, 2, size[0] - 3, size[1] - 3) - def ResetBorder(self, Color = wx.RED): + def ResetBorder(self, Color=wx.RED): dc = wx.ClientDC(self) self.DrawBorder(dc) for c in self.GetChildren(): c.Refresh() def OnButton(self,Event): - print "Button Clicked" + print("Button Clicked") if self.timer.IsRunning(): - print "Stopping Timer" + self.st.SetLabel("Stopping Timer") self.timer.Stop() self.b.SetLabel("Start Flashing") else: - print "starting timer" + self.st.SetLabel("Starting timer") self.timer.Start(200) self.b.SetLabel("Stop Flashing") + class MyApp(wx.App): def OnInit(self): frame = MyFrame(None, -1, "This is a test") @@ -77,11 +85,7 @@ def OnInit(self): self.SetTopWindow(frame) return True -app = MyApp(0) # Create an instance of the application class -app.MainLoop() # Tell it to start processing events - - - - - +if __name__ == "__main__": + app = MyApp(0) # Create an instance of the application class + app.MainLoop() # Tell it to start processing events diff --git a/DrawingWhileMouseMoves.py b/DrawingWhileMouseMoves.py new file mode 100755 index 0000000..eeb3b1a --- /dev/null +++ b/DrawingWhileMouseMoves.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python + +""" +A test of drawing while the mouse is moving. + +The old way of doing this is with a wxClientDC, but that does +not work right, or at least not well on OS-X. So this shows how +to do it with Refresh();Update(). +""" + +import wx + +print "running with version:", wx.__version__ +import random + + +class DrawWindow(wx.Window): + def __init__(self, parent, id = -1): + ## Any data the Draw() function needs must be initialized before + ## calling BufferedWindow.__init__, as it will call the Draw + ## function. + wx.Window.__init__(self, parent, id) + + self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) + self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) + self.Bind(wx.EVT_MOTION, self.OnMove) + + wx.EVT_PAINT(self, self.OnPaint) + wx.EVT_SIZE(self, self.OnSize) + + # OnSize called to make sure the buffer is initialized. + # This might result in OnSize getting called twice on some + # platforms at initialization, but little harm done. + + self.mouse_line = None + self.OnSize(None) + + def OnPaint(self, event): + # This draws the buffer to the screen, then optionally the mouse_line + dc = wx.PaintDC(self) + dc.DrawBitmap(self._Buffer,0,0) + if self.mouse_line is not None: + dc.SetPen(wx.Pen('WHITE', 2, wx.SHORT_DASH)) + dc.DrawLinePoint( *self.mouse_line ) + + def OnSize(self,event): + # The Buffer init is done here, to make sure the buffer is always + # the same size as the Window + Size = self.GetClientSizeTuple() + + # Make sure we don't try to create a 0 size bitmap + Size = (max(Size[0], 1), max(Size[1], 1)) + self._Buffer = wx.EmptyBitmap(Size[0],Size[1]) + self.Draw() + + def Draw(self): + """ + This draws the backgound image on the buffer + + """ + # update the buffer + dc = wx.MemoryDC() + dc.SelectObject(self._Buffer) + + coords = ((40,40),(200,220),(210,120),(120,300)) + dc.BeginDrawing() + dc.SetBackground( wx.Brush("Blue") ) + dc.Clear() # make sure you clear the bitmap! + + dc.SetPen(wx.RED_PEN) + dc.SetBrush(wx.CYAN_BRUSH) + + dc.DrawPolygon(coords) + + + def OnLeftDown(self, event): + self.CaptureMouse() + self.mouse_line = [ event.GetPosition(), None] + + def OnLeftUp(self, event): + self.mouse_line = None + if self.HasCapture(): + self.ReleaseMouse() + self.Refresh() + self.Update() + + def OnMove(self, event): + if event.Dragging() and event.LeftIsDown() and (self.mouse_line is not None): + self.mouse_line[1] = event.GetPosition() + self.Refresh() + ## note: "Update() is not recommended on wxMac -- but response is slower without it... " + #self.Update() + + +if __name__ == "__main__": + app = wx.App(False) + frame = wx.Frame(None, size = (400,500), title="Mouse Move Drawing Test") + draw_window = DrawWindow(frame) + frame.Show(True) + app.MainLoop() + + + + + + + + + + + + + + + + + + + + diff --git a/EllipticArcTest.py b/EllipticArcTest.py index 32ff0c8..ae69410 100755 --- a/EllipticArcTest.py +++ b/EllipticArcTest.py @@ -2,6 +2,7 @@ import wx + class MyPanel(wx.Panel): def __init__(self, *args, **kwargs): wx.Panel.__init__(self, *args, **kwargs) @@ -13,14 +14,15 @@ def OnPaint(self, event): dc.Clear() dc.SetPen(wx.BLACK_PEN) dc.SetBrush(wx.RED_BRUSH) - x = 100 - y = 100 + x = 50 + y = 50 w = 50 h = 50 for angle in [0, 90, 180, 270, -90, -180, -270]: dc.DrawEllipticArc(x, y, w, h, 0, angle) - dc.DrawText(`angle`, x+w+10, y+h/2) - y+=100 + dc.DrawText(repr(angle), x + w + 10, y + h / 2) + y += 100 + class MyFrame(wx.Frame): def __init__(self, *args, **kwargs): @@ -29,10 +31,10 @@ def __init__(self, *args, **kwargs): #self.Fit() + if __name__ == '__main__': app = wx.App(0) - frame = MyFrame(None, title="Test", size=(300, 800) ) + frame = MyFrame(None, title="Test", size=(300, 800)) frame.Show() frame.Fit() app.MainLoop() - diff --git a/FontSizeTest.py b/FontSizeTest.py index 9b4d462..7b3ff58 100755 --- a/FontSizeTest.py +++ b/FontSizeTest.py @@ -1,11 +1,14 @@ #!/usr/bin/env python """ -Simple demo/sample for testing Font Size with a DC -- using wx.FontFromPixel Size - +Simple demo/sample for testing Font Size with a DC -- +using wx.FontFromPixel Size """ +from __future__ import division, unicode_literals, print_function + import wx + class MyPanel(wx.Panel): def __init__(self, *args, **kwargs): wx.Panel.__init__(self, *args, **kwargs) @@ -15,44 +18,41 @@ def __init__(self, *args, **kwargs): def OnPaint(self, event): dc = wx.PaintDC(self) self.Draw(dc) - + def Draw(self, dc): dc.Clear() - x,y = 20, 0 + x, y = 20, 0 for fs in [8, 10, 12, 14, 18, 20, 30, 60]: - y += 1.2*fs + y += 1.2 * fs w = fs * 11 - S = (0.45*fs, fs) # this hieght/width ratio seems to match what I get on OS-X and GTK - text = "%i pixel Font and Box"%fs - Font = wx.FontFromPixelSize(S, wx.SWISS, wx.NORMAL, wx.NORMAL, underlined=True) + S = wx.Size((0, fs)) + # S = wx.Size((fs, fs)) + text = "%i pixel Font and Box" % fs + Font = wx.Font(S, wx.SWISS, wx.NORMAL, wx.NORMAL, underline=True) dc.SetFont(Font) E = dc.GetTextExtent(text) dc.SetFont(Font) E = dc.GetTextExtent(text) - print "Font size: %s, Extent ratio: %s"%(S, E[0] / E[1]) - print "font point size::", Font.GetPointSize() + print("Font size: %s, Extent ratio: %s" % (S, E[0] / E[1])) + print("font point size::", Font.GetPointSize()) dc.DrawText(text, x, y) dc.DrawRectangle(x, y, w, fs) dc.DrawText(text, x, y) + class MyFrame(wx.Frame): def __init__(self, parent): - wx.Frame.__init__(self, parent, title="test", size = (500, 500)) + wx.Frame.__init__(self, parent, title="test", size=(500, 500)) self.Panel = MyPanel(self) sizer = wx.BoxSizer(wx.VERTICAL) - sizer.Add(self.Panel,1,wx.EXPAND) + sizer.Add(self.Panel, 1, wx.EXPAND) self.SetSizer(sizer) - - def UpdatePanel(self,event): - #self.Panel.DrawRect() - pass - + if __name__ == '__main__': app = wx.App(0) frame = MyFrame(None) frame.Show() app.MainLoop() - diff --git a/FrameFlags.py b/FrameFlags.py index 618715b..616e82b 100755 --- a/FrameFlags.py +++ b/FrameFlags.py @@ -1,15 +1,13 @@ #!/usr/bin/env python -import wx - -app = wx.App(False) -frame = wx.Frame(None, - title = "Frame Style Test" - style=wx.DEFAULT_FRAME_STYLE & ~wx.CLOSE_BOX) -frame.Show() -app.MainLoop() - - - - - +if __name__ == '__main__': + import wx + app = wx.App(False) + def OnClose(event): + frame.Close() + frame = wx.Frame(None, + title = "Frame Style Test", + style=wx.DEFAULT_FRAME_STYLE & ~wx.CLOSE_BOX) + frame.Bind(wx.EVT_RIGHT_UP, OnClose) + frame.Show() + app.MainLoop() diff --git a/GenStaticBitmap.py b/GenStaticBitmap.py index 6ef282c..087c50a 100755 --- a/GenStaticBitmap.py +++ b/GenStaticBitmap.py @@ -3,6 +3,7 @@ import wx.lib.statbmp + class cWindowBitmap(wx.lib.statbmp.GenStaticBitmap): """ @@ -17,15 +18,15 @@ def __init__(self, parent, bitmapfilename, ImageNumber, **kwargs): self.filename = bitmapfilename self.ImageNumber = ImageNumber - self.Bind(wx.EVT_LEFT_DOWN,self.OnLeftDown) - self.Bind(wx.EVT_LEFT_UP,self.OnLeftUp) + self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) + self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) def OnLeftDown(self, event): - print "In Left Down of:", self.filename + print("In Left Down of:", self.filename) self.parent.OnBitmapClicked(self.ImageNumber) def OnLeftUp(self, event): - print "In Left Up of:", self.filename + print("In Left Up of:", self.filename) class MainFrame(wx.Frame): @@ -33,28 +34,29 @@ def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) Sizer = wx.BoxSizer(wx.VERTICAL) - #These represent "many" bitmaps. - for i in range(3): - pic = cWindowBitmap(self, "Images/smalltest.jpg", i) - Sizer.Add(pic, 0, wx.ALL, 10) + # These represent "many" bitmaps. + [Sizer.Add(cWindowBitmap(self, "Images/smalltest.jpg", i), 0, wx.ALL, 10) + for i in range(3)] self.SetSizerAndFit(Sizer) - wx.EVT_CLOSE(self, self.OnCloseWindow) - + self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) + def OnBitmapClicked(self, ImageNumber): - print "Image: %i was clicked"%ImageNumber - + print("Image: %i was clicked" %ImageNumber) + def OnCloseWindow(self, event): self.Destroy() + class App(wx.App): def OnInit(self): - frame = MainFrame(None, -1, "wxWindowBitmap Test", wx.DefaultPosition,(550,600)) + frame = MainFrame(None, -1, "wxWindowBitmap Test", wx.DefaultPosition, (550, 600)) self.SetTopWindow(frame) frame.Show(True) return True -app = App(0) -app.MainLoop() +if __name__ == '__main__': + app = App(0) + app.MainLoop() diff --git a/GridBagSizer.1.py b/GridBagSizer.1.py index 43ed8ff..21181ce 100755 --- a/GridBagSizer.1.py +++ b/GridBagSizer.1.py @@ -9,13 +9,12 @@ import wx + class MyFrame(wx.Frame): def __init__(self, parent, ID, title): - wx.Frame.__init__(self, parent, ID, title, wx.DefaultPosition) + wx.Frame.__init__(self, parent, ID, title) - Buttons = [] - for i in range(6): - Buttons.append(wx.Button(self,-1, "Button %i"%(i))) + Buttons = [wx.Button(self, -1, "Button %i"%(i)) for i in range(6)] sizer = wx.GridBagSizer(9, 9) sizer.Add(Buttons[0], (0, 0), wx.DefaultSpan, wx.ALL, 5) @@ -34,23 +33,12 @@ def __init__(self, parent, ID, title): class MyApp(wx.App): def OnInit(self): - frame = MyFrame(None, -1, "wx.gridbagsizer.py") + frame = MyFrame(None, -1, "wx.GridBagSizer Test 1") frame.Show(True) self.SetTopWindow(frame) return True + if __name__ == "__main__": app = MyApp(0) app.MainLoop() - - - - - - - - - - - - diff --git a/GridBagSizer.2.py b/GridBagSizer.2.py index a2150c7..6746e2c 100755 --- a/GridBagSizer.2.py +++ b/GridBagSizer.2.py @@ -2,6 +2,7 @@ import wx + class TestFrame(wx.Frame): def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) @@ -15,7 +16,7 @@ def __init__(self, *args, **kwargs): exitBut.Bind(wx.EVT_BUTTON, self.OnCloseWindow) sizer = wx.GridBagSizer(10, 10) - sizer.Add(t, (0,0), span=(2,1), flag=wx.ALIGN_CENTER_VERTICAL ) + sizer.Add(t, (0,0), span=(2,1), flag=wx.ALIGN_CENTER_VERTICAL) sizer.Add(b1, (0,1), span=(2,1), flag=wx.ALIGN_CENTER) sizer.Add(b2, (0,2), flag=wx.ALIGN_CENTER) @@ -28,6 +29,7 @@ def __init__(self, *args, **kwargs): def OnCloseWindow(self, event): self.Destroy() + class App(wx.App): def OnInit(self): frame = TestFrame(None, title="GridBagSizer Test") @@ -35,18 +37,7 @@ def OnInit(self): frame.Show(True) return True + if __name__ == "__main__": app = App(0) app.MainLoop() - - - - - - - - - - - - diff --git a/HTML_tester.py b/HTML_tester.py index 68bae19..9f33edc 100755 --- a/HTML_tester.py +++ b/HTML_tester.py @@ -43,6 +43,7 @@ #------------------------------------------------------------------- + class MyHTMLWindow(wx.html.HtmlWindow): """ Not much need for a class here -- but maybe they'll be moreto add later @@ -50,11 +51,12 @@ class MyHTMLWindow(wx.html.HtmlWindow): def __init__(self, parent): wx.html.HtmlWindow.__init__(self, parent, style=wx.VSCROLL|wx.ALWAYS_SHOW_SB) - + if "gtk2" in wx.PlatformInfo: self.SetStandardFonts() self.Show() + class MyFrame(wx.Frame): def __init__(self, *args, **kwargs): @@ -74,9 +76,9 @@ def __init__(self, *args, **kwargs): S = wx.BoxSizer(wx.HORIZONTAL) S.Add(self.InputWindow, 3, wx.EXPAND) S.Add(self.htwindow, 4, wx.EXPAND) - + self.Printer = wx.html.HtmlEasyPrinting() - + MenuBar = wx.MenuBar() FileMenu = wx.Menu() @@ -95,9 +97,9 @@ def __init__(self, *args, **kwargs): def OnTextChanged(self, evt=None): """ - Updates the HTML: called whenever there is a change in the input + Updates the HTML: called whenever there is a change in the input text field. - + Keeps the HtmlWindow scrolled to the same position as it was """ pos = self.htwindow.GetViewStart() @@ -115,12 +117,12 @@ def OnPreview(self, evt=None): def OnQuit(self,Event): self.Destroy() -class MyApp(wx.App): +class MyApp(wx.App): def OnInit(self): - frame = MyFrame(None, title="HTML Tester Window", size = (600,500)) + frame = MyFrame(None, title="HTML Tester Window", size=(600, 500)) self.SetTopWindow(frame) - frame.Size = (900,500) + frame.Size = (900, 500) frame.Centre() frame.Show(True) return True @@ -129,4 +131,3 @@ def OnInit(self): if __name__ == "__main__" : app = MyApp(0) app.MainLoop() - diff --git a/ImageInHtml.py b/ImageInHtml.py index 4d23621..413c39a 100755 --- a/ImageInHtml.py +++ b/ImageInHtml.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import wx -import wx.lib.wxpTag +import wx.lib.wxpTag # The html page as a python string literal page = r""" @@ -29,7 +29,7 @@ class Bitmap1(wx.StaticBitmap): """ - A custom StaticBitmap class that holds your image. + A custom StaticBitmap class that holds your image. """ def __init__(self, *args, **kwargs): """ @@ -41,6 +41,7 @@ def __init__(self, *args, **kwargs): kwargs['bitmap'] = bmp wx.StaticBitmap.__init__(self, *args, **kwargs) + class DemoFrame(wx.Frame): """ This window displays a HtmlWindow """ def __init__(self, *args, **kwargs): @@ -49,7 +50,7 @@ def __init__(self, *args, **kwargs): htmlwin = wx.html.HtmlWindow(self) htmlwin.SetPage(page) - + class MyApp(wx.App): """ A little test wx.App @@ -60,14 +61,14 @@ def OnInit(self): wx.FileSystem_AddHandler(mfs) mfs.AddFile("smalltest.png", smalltest.GetImage(), wx.BITMAP_TYPE_PNG) - # Initializing the Frame frame = DemoFrame(None, title="HTML Tester Window", size = (500,500)) self.SetTopWindow(frame) - + frame.Show(True) return True + ## This is the image data itself, created with the img2py utility that ## ships with wxPython from wx.lib.embeddedimage import PyEmbeddedImage @@ -184,4 +185,3 @@ def OnInit(self): if __name__ == "__main__" : app = MyApp(0) app.MainLoop() - diff --git a/ImageNumpy.py b/ImageNumpy.py index 6dcfec7..92579ce 100755 --- a/ImageNumpy.py +++ b/ImageNumpy.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.5 +#!/usr/bin/env python """ a small test of initializing a wxImage from a numpy array @@ -9,20 +9,21 @@ import numpy as N import numpy.random as rand + class ImagePanel(wx.Panel): - """ + """ A very simple panel for displaying a wx.Image """ def __init__(self, image, *args, **kwargs): wx.Panel.__init__(self, *args, **kwargs) - + self.image = image self.Bind(wx.EVT_PAINT, self.OnPaint) - + def OnPaint(self, event): dc = wx.PaintDC(self) dc.DrawBitmap(wx.BitmapFromImage(self.image), 0, 0) - + class DemoFrame(wx.Frame): """ This window displays a button """ @@ -32,48 +33,48 @@ def __init__(self, title = "Micro App"): MenuBar = wx.MenuBar() FileMenu = wx.Menu() - item = FileMenu.Append(wx.ID_ANY, text = "&Open") + item = FileMenu.Append(wx.ID_ANY, text="&Open") self.Bind(wx.EVT_MENU, self.OnOpen, item) - item = FileMenu.Append(wx.ID_PREFERENCES, text = "&Preferences") + item = FileMenu.Append(wx.ID_PREFERENCES, text="&Preferences") self.Bind(wx.EVT_MENU, self.OnPrefs, item) - item = FileMenu.Append(wx.ID_EXIT, text = "&Exit") + item = FileMenu.Append(wx.ID_EXIT, text="&Exit") self.Bind(wx.EVT_MENU, self.OnQuit, item) MenuBar.Append(FileMenu, "&File") - + HelpMenu = wx.Menu() item = HelpMenu.Append(wx.ID_HELP, "Test &Help", - "Help for this simple test") + "Help for this simple test") self.Bind(wx.EVT_MENU, self.OnHelp, item) ## this gets put in the App menu on OS-X item = HelpMenu.Append(wx.ID_ABOUT, "&About", - "More information About this program") + "More information About this program") self.Bind(wx.EVT_MENU, self.OnAbout, item) MenuBar.Append(HelpMenu, "&Help") self.SetMenuBar(MenuBar) - btn = wx.Button(self, label = "NewImage") - btn.Bind(wx.EVT_BUTTON, self.OnNewImage ) + btn = wx.Button(self, label="NewImage") + btn.Bind(wx.EVT_BUTTON, self.OnNewImage) self.Bind(wx.EVT_CLOSE, self.OnQuit) ##Create numpy array, and image from it w = h = 200 self.array = rand.randint(0, 255, (3, w, h)).astype('uint8') - print self.array + print(self.array) image = wx.ImageFromBuffer(w, h, self.array) #image = wx.Image("Images/cute_close_up.jpg") self.Panel = ImagePanel(image, self) - + sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(btn, 0, wx.ALIGN_CENTER|wx.ALL, 5) sizer.Add(self.Panel, 1, wx.GROW) - + self.SetSizer(sizer) def OnNewImage(self, event=None): @@ -82,11 +83,10 @@ def OnNewImage(self, event=None): """ self.array *= 1.2 self.Panel.Refresh() - - + def OnQuit(self,Event): self.Destroy() - + def OnAbout(self, event): dlg = wx.MessageDialog(self, "This is a small program to test\n" "the use of menus on Mac, etc.\n", @@ -115,12 +115,9 @@ def OnPrefs(self, event): dlg.ShowModal() dlg.Destroy() -app = wx.App(False) -frame = DemoFrame() -frame.Show() -app.MainLoop() - - - - +if __name__ == "__main__" : + app = wx.App(False) + frame = DemoFrame() + frame.Show() + app.MainLoop() diff --git a/ImageWindow.py b/ImageWindow.py index 0c11a4a..3dba542 100755 --- a/ImageWindow.py +++ b/ImageWindow.py @@ -9,14 +9,15 @@ import wx + class ImageWindow(wx.Window): """ ImageWindow(Image, *args, **kwargs) - + Image: A wx.Image *args and **kwargs are passed in to wx.Window """ - + def __init__(self, Image, *args, **kwargs): wx.Window.__init__(self, *args, **kwargs) @@ -33,7 +34,7 @@ def __init__(self, Image, *args, **kwargs): def OnPaint(self, event): dc = wx.PaintDC(self) dc.DrawBitmap(self._buffer, 0, 0) - + def OnSize(self, event): w, h = self.GetSize() if not self.Proportional: @@ -58,12 +59,15 @@ def OnSize(self, event): dc.SetBackground(wx.Brush(self.BackgroundColor)) dc.Clear() x = (w - NewW) / 2 - y = (h - NewH) / 2 + y = (h - NewH) / 2 dc.DrawBitmap(wx.BitmapFromImage(Img), x, y) self.Refresh(False) + if __name__ == "__main__": import TestImage + + class TestFrame(wx.Frame): def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) @@ -84,7 +88,8 @@ def __init__(self, *args, **kwargs): box.Add(IW, 1, wx.ALL | wx.EXPAND, 10) self.SetSizer(box) - + + class App(wx.App): def OnInit(self): frame = TestFrame(None, title="ImageWindow Test", size=(300, 300)) @@ -94,5 +99,3 @@ def OnInit(self): app = App(False) app.MainLoop() - - diff --git a/Jeopardy.py b/Jeopardy.py index e5541eb..a21aaeb 100755 --- a/Jeopardy.py +++ b/Jeopardy.py @@ -7,19 +7,22 @@ lets you run a simple game yourself, with questions and answers provided by you. +NOTE: very much a work in progress! + This code is in the public domain -Chris.Barker@noaa.gov """ - import wx + class Question(object): """ A class to hold each question, and data about it. """ + def __init__(self, question, answer, value): self.question = question self.answer = answer @@ -34,7 +37,7 @@ def __init__(self, catagories, questions): self.questions = questions self.num_cat = len(catagories) self.num_ques = len(questions[0]) - + def all_answered(self): """ returns True if all the questions are answered @@ -51,27 +54,29 @@ def all_answered(self): class GridGeom: def __init__(self, w, h, num_catagories=6, num_questions=5): - self.box_w = w / num_catagories - self.box_h = h / (num_questions + 1) + self.box_w = int(w / num_catagories) + self.box_h = int(h / (num_questions + 1)) self.num_cat = num_catagories self.num_ques = num_questions - - self.font_size = min( int(self.box_w / 2), int(self.box_h / 2) ) + + self.font_size = min(int(self.box_w / 2), int(self.box_h / 2)) ##figure out the text offset dc = wx.ScreenDC() - dc.SetFont(wx.FontFromPixelSize((self.font_size, self.font_size), - wx.FONTFAMILY_SWISS, - wx.FONTSTYLE_NORMAL, - wx.FONTWEIGHT_BOLD, - ), - ) + dc.SetFont( + wx.Font( + (self.font_size, self.font_size), + wx.FONTFAMILY_SWISS, + wx.FONTSTYLE_NORMAL, + wx.FONTWEIGHT_BOLD, + ), ) w, h = dc.GetTextExtent("500") - self.text_off_x = ( self.box_w - w ) / 2 - self.text_off_y = ( self.box_h - h ) / 2 + self.text_off_x = int((self.box_w - w) / 2) + self.text_off_y = int((self.box_h - h) / 2) -class GridWindow(wx.Window): - def __init__(self, parent, game): + +class GridWindow(wx.Window): + def __init__(self, parent, game): wx.Window.__init__(self, parent) self.SetBackgroundColour("White") @@ -79,34 +84,36 @@ def __init__(self, parent, game): ## a few initalzers self.Selected = None - + self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) self.Bind(wx.EVT_MOTION, self.OnMotion) self.OnSize() - + def InitBuffer(self): - w, h = self.GetClientSize() - self.buffer = wx.EmptyBitmap(w, h) + w, h = self.GetClientSize() + self.buffer = wx.Bitmap(w, h) self.DrawNow() - + def OnSize(self, event=None): size = self.GetClientSize() if size[0] > 0 and size[1] > 1: self.grid = GridGeom(*size) self.InitBuffer() - + def DrawNow(self): dc = wx.MemoryDC() dc.SelectObject(self.buffer) self.Draw(dc) self.Refresh() self.Update() + + # dc = wx.BufferedDC(wx.ClientDC(self), self.buffer) # self.Draw(dc) - + def Draw(self, dc): # Make grid local: grid = self.grid @@ -115,47 +122,43 @@ def Draw(self, dc): # draw the background: dc.SetBackground(wx.Brush(self.GetBackgroundColour())) dc.Clear() - dc.SetBrush(wx.Brush(wx.Color(128,128,255))) + dc.SetBrush(wx.Brush(wx.Colour(128, 128, 255))) dc.SetPen(wx.TRANSPARENT_PEN) dc.DrawRectangle(0, 0, w * grid.num_cat, h * grid.num_ques) # draw catagory headings - dc.SetFont(wx.FontFromPixelSize((grid.font_size, grid.font_size), - wx.FONTFAMILY_SWISS, - wx.FONTSTYLE_NORMAL, - wx.FONTWEIGHT_BOLD)) - + dc.SetFont( + wx.Font((grid.font_size, grid.font_size), wx.FONTFAMILY_SWISS, + wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)) + for i, cat in enumerate(self.game.catagories): - dc.SetBrush( wx.Brush("Blue", wx.SOLID) ) - dc.SetPen( wx.Pen("White", width=4) ) - dc.DrawRectangle(i*w + 3, h + 3, w - 6, h - 6 ) - dc.DrawText(cat, i*w + grid.text_off_x, h + grid.text_off_y) + dc.SetBrush(wx.Brush("Blue", wx.BRUSHSTYLE_SOLID)) + dc.SetPen(wx.Pen("White", width=4)) + dc.DrawRectangle(i * w + 3, h + 3, w - 6, h - 6) + dc.DrawText(cat, i * w + grid.text_off_x, h + grid.text_off_y) - #draw cells - dc.SetFont(wx.FontFromPixelSize((grid.font_size, grid.font_size), - wx.FONTFAMILY_SWISS, - wx.FONTSTYLE_NORMAL, - wx.FONTWEIGHT_BOLD)) + dc.SetFont( + wx.Font((grid.font_size, grid.font_size), wx.FONTFAMILY_SWISS, + wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)) for i, cat in enumerate(self.game.questions): for j, q in enumerate(cat): - j+=1 + j += 1 if q.answered: - dc.SetBrush( wx.Brush("Blue", wx.SOLID) ) - dc.SetPen( wx.Pen("Black", width=4) ) - dc.DrawRectangle(i*w + 3, j*h + 3, w - 6, h - 6 ) + dc.SetBrush(wx.Brush("Blue", wx.BRUSHSTYLE_SOLID)) + dc.SetPen(wx.Pen("Black", width=4)) + dc.DrawRectangle(i * w + 3, j * h + 3, w - 6, h - 6) else: - dc.SetBrush( wx.Brush("Blue", wx.SOLID) ) - dc.SetPen( wx.Pen("White", width=4) ) - dc.DrawRectangle(i*w + 3, j*h + 3, w - 6, h - 6 ) - dc.DrawText('%i'%q.value, i*w + grid.text_off_x, j*h + grid.text_off_y) - - + dc.SetBrush(wx.Brush("Blue", wx.BRUSHSTYLE_SOLID)) + dc.SetPen(wx.Pen("White", width=4)) + dc.DrawRectangle(i * w + 3, j * h + 3, w - 6, h - 6) + dc.DrawText('%i' % q.value, i * w + grid.text_off_x, + j * h + grid.text_off_y) # # draw the selected cells: # dc.SetBrush(wx.Brush("Red", wx.SOLID)) # dc.DrawRectangle(x0 + d*self.Selected[1], y0 + d*self.Selected[0], d, d) - + # # draw the white lines: # dc.SetPen(wx.Pen("White", 2, wx.SOLID) ) # for i in range(10): @@ -163,7 +166,7 @@ def Draw(self, dc): # dc.DrawLine(x0 + d*i, y0, x0 + d*i, y0 + d*9) # # draw the numbers: - # dc.SetFont(wx.FontFromPixelSize((font_size,font_size), + # dc.SetFont(wx.Font((font_size,font_size), # wx.FONTFAMILY_SWISS, # wx.FONTSTYLE_NORMAL, # wx.FONTWEIGHT_BOLD)) @@ -181,23 +184,23 @@ def Draw(self, dc): # for i in range(4): # dc.DrawLine(x0, y0 + d*i, x0 + d*3, y0 + d*i) # dc.DrawLine(x0 + d*i, y0, x0 + d*i, y0 + d*3) - - + def OnPaint(self, event): dc = wx.BufferedPaintDC(self, self.buffer) def OnLeftDown(self, e): """called when the left mouse button is pressed""" grid = self.grid - x, y = e.GetPositionTuple() - i = x / grid.box_w - j = y / grid.box_h + x, y = e.GetPosition() + i = int(x // grid.box_w) + j = int(y // grid.box_h - 1) # compensate for header if i >= 0 and i < grid.num_cat and j >= 0 and j < grid.num_ques: self.game.questions[i][j].answered = not self.game.questions[i][j].answered self.DrawNow() def OnMotion(self, evt): pass + # def OnKeyDown(self, e): # keycode = e.GetKeyCode() # i, j = self.Selected @@ -229,20 +232,22 @@ def OnMotion(self, evt): # i = 0 # if i < 0: # i = 8 - + # self.Selected = (i,j) # self.DrawNow() - + # def SetValue(self, value): # self.Puzzle.Grid[self.Selected] = value - + + class MainFrame(wx.Frame): def __init__(self, parent, game): wx.Frame.__init__(self, parent, title="Jeopardy", size=(600, 500)) self.game = game self.grid = GridWindow(self, game) #self.ToolBar() - + + # def ToolBar(self): # statusBar = self.CreateStatusBar() # menuBar = wx.MenuBar() @@ -257,6 +262,7 @@ def __init__(self, parent, game): # menuBar.Append(menu2, "&Edit") # self.SetMenuBar(menuBar) + class Header(object): """ class to handle drawing of question header @@ -269,18 +275,21 @@ class to handle drawing of question header FaceName = '' def __init__(self, text): - + self.width = 100 self.font_size = 12 self.text = text - + self.wrap_to_width() self.PadSize = 2 def wrap_to_width(self): dc = wx.MemoryDC() bitmap = wx.EmptyBitmap(1, 1) - dc.SelectObject(bitmap) #wxMac needs a Bitmap selected for GetTextExtent to work. + dc.SelectObject( + bitmap) #wxMac needs a Bitmap selected for GetTextExtent to work. + + # Size = self.font_size # Width = (self.Width - 2*self.PadSize) # self.SetFont(DrawingSize, self.Family, self.Style, self.Weight, self.Underlined, self.FaceName) @@ -378,94 +387,98 @@ def wrap_to_width(self): # self.BoxHeight = BoxHeight # self.CalcBoundingBox() - def draw(self, DC): for word in question: pass - + class TestFrame(wx.Frame): def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) - + self.Bind(wx.EVT_PAINT, self.OnPaint) #self.header = Header("This is a pretty long question that will need to wrap") #header.wrap_to_width #print header.question_lines - + def OnPaint(self, evt): dc = wx.PaintDC(self) #if self.header is not None: # self.header.draw(dc) - + if __name__ == '__main__': - A = wx.App() - F = TestFrame(None, title="test frame") - A.mainloop() -if False: + # A = wx.App() + # F = TestFrame(None, title="test frame") + # F.Show(True) + # A.MainLoop() catagories = [None for i in range(6)] - questions = [ [None for i in range(5)] for j in range(6) ] - ## test data: + questions = [[None for i in range(5)] for j in range(6)] + + # test data: catagories[0] = "Household Pets" - questions[0][0] = Question("slobbery","what is a dog?", 100) - questions[0][1] = Question("cute an fuzzy","what is a cat?", 200) - questions[0][2] = Question("long and slithery","what is a snake?", 300) - questions[0][3] = Question("sometimes lives in a sewer","what is a rat?", 400) - questions[0][4] = Question("a reptile often mistaken for an amphibian","what is a turtle?", 500) + questions[0][0] = Question("slobbery", "what is a dog?", 100) + questions[0][1] = Question("cute and fuzzy", "what is a cat?", 200) + questions[0][2] = Question("long and slithery", "what is a snake?", 300) + questions[0][3] = Question("sometimes lives in a sewer", "what is a rat?", + 400) + questions[0][4] = Question("a reptile often mistaken for an amphibian", + "what is a turtle?", 500) - ## test data: catagories[1] = "Household Pets" - questions[1][0] = Question("slobbery","what is a dog?", 100) - questions[1][1] = Question("cute an fuzzy","what is a cat?", 200) - questions[1][2] = Question("long and slithery","what is a snake?", 300) - questions[1][3] = Question("sometimes lives in a sewer","what is a rat?", 400) - questions[1][4] = Question("a reptile often mistaken for an amphibian","what is a turtle?", 500) + questions[1][0] = Question("slobbery", "what is a dog?", 100) + questions[1][1] = Question("cute an fuzzy", "what is a cat?", 200) + questions[1][2] = Question("long and slithery", "what is a snake?", 300) + questions[1][3] = Question("sometimes lives in a sewer", "what is a rat?", + 400) + questions[1][4] = Question("a reptile often mistaken for an amphibian", + "what is a turtle?", 500) - ## test data: catagories[2] = "Household Pets" - questions[2][0] = Question("slobbery","what is a dog?", 100) - questions[2][1] = Question("cute an fuzzy","what is a cat?", 200) - questions[2][2] = Question("long and slithery","what is a snake?", 300) - questions[2][3] = Question("sometimes lives in a sewer","what is a rat?", 400) - questions[2][4] = Question("a reptile often mistaken for an amphibian","what is a turtle?", 500) + questions[2][0] = Question("slobbery", "what is a dog?", 100) + questions[2][1] = Question("cute an fuzzy", "what is a cat?", 200) + questions[2][2] = Question("long and slithery", "what is a snake?", 300) + questions[2][3] = Question("sometimes lives in a sewer", "what is a rat?", + 400) + questions[2][4] = Question("a reptile often mistaken for an amphibian", + "what is a turtle?", 500) - ## test data: catagories[3] = "Household Pets" - questions[3][0] = Question("slobbery","what is a dog?", 100) - questions[3][1] = Question("cute an fuzzy","what is a cat?", 200) - questions[3][2] = Question("long and slithery","what is a snake?", 300) - questions[3][3] = Question("sometimes lives in a sewer","what is a rat?", 400) - questions[3][4] = Question("a reptile often mistaken for an amphibian","what is a turtle?", 500) - ## test data: + questions[3][0] = Question("slobbery", "what is a dog?", 100) + questions[3][1] = Question("cute an fuzzy", "what is a cat?", 200) + questions[3][2] = Question("long and slithery", "what is a snake?", 300) + questions[3][3] = Question("sometimes lives in a sewer", "what is a rat?", + 400) + questions[3][4] = Question("a reptile often mistaken for an amphibian", + "what is a turtle?", 500) catagories[4] = "Household Pets" - questions[4][0] = Question("slobbery","what is a dog?", 100) - questions[4][1] = Question("cute an fuzzy","what is a cat?", 200) - questions[4][2] = Question("long and slithery","what is a snake?", 300) - questions[4][3] = Question("sometimes lives in a sewer","what is a rat?", 400) - questions[4][4] = Question("a reptile often mistaken for an amphibian","what is a turtle?", 500) + questions[4][0] = Question("slobbery", "what is a dog?", 100) + questions[4][1] = Question("cute an fuzzy", "what is a cat?", 200) + questions[4][2] = Question("long and slithery", "what is a snake?", 300) + questions[4][3] = Question("sometimes lives in a sewer", "what is a rat?", + 400) + questions[4][4] = Question("a reptile often mistaken for an amphibian", + "what is a turtle?", 500) - ## test data: catagories[5] = "Household Pets" - questions[5][0] = Question("slobbery","what is a dog?", 100) - questions[5][1] = Question("cute an fuzzy","what is a cat?", 200) - questions[5][2] = Question("long and slithery","what is a snake?", 300) - questions[5][3] = Question("sometimes lives in a sewer","what is a rat?", 400) - questions[5][4] = Question("a reptile often mistaken for an amphibian","what is a turtle?", 500) - - - #set a few as answered + questions[5][0] = Question("slobbery", "what is a dog?", 100) + questions[5][1] = Question("cute an fuzzy", "what is a cat?", 200) + questions[5][2] = Question("long and slithery", "what is a snake?", 300) + questions[5][3] = Question("sometimes lives in a sewer", "what is a rat?", + 400) + questions[5][4] = Question("a reptile often mistaken for an amphibian", + "what is a turtle?", 500) + + # set a few as answered questions[3][3].answered = True questions[2][4].answered = True - app = wx.App(0) game = Game(catagories, questions) frame = MainFrame(None, game) frame.Show(True) app.MainLoop() - diff --git a/JustButton.py b/JustButton.py new file mode 100644 index 0000000..45fa5ae --- /dev/null +++ b/JustButton.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python + +import wx +import wx.lib.buttons + +class ButtonPanel(wx.Panel): + def __init__(self, *args, **kwargs): + wx.Panel.__init__(self, *args, **kwargs) + + btn = wx.Button(self, label = "Push Me", pos=(40,60), size=(120,-1)) + btn = wx.Button(self, label = "Push Me Also", pos=(80,30), size=(200, 60)) + btn = wx.Button(self, label = "No, push me!", pos=(90,110), size=(65, 80)) + btn = wx.lib.buttons.GenButton(self, label = "better?", pos=(40,150), size=(60, 60)) + + btn.Bind(wx.EVT_BUTTON, self.OnButton ) + + def OnButton(self, evt): + print "Button Clicked" + + +class DemoFrame(wx.Frame): + """ This frame displays a panel with a button] """ + def __init__(self, title = "Micro App"): + wx.Frame.__init__(self, None , -1, title) + + pnl = ButtonPanel(self) + + self.Bind(wx.EVT_CLOSE, self.OnQuit) + + + def OnQuit(self,Event): + self.Destroy() + + +app = wx.App(False) +frame = DemoFrame() +frame.Show() +app.MainLoop() + + + + + diff --git a/KeyPressDraw.py b/KeyPressDraw.py index 75d7d78..04fa15f 100755 --- a/KeyPressDraw.py +++ b/KeyPressDraw.py @@ -1,7 +1,8 @@ -#!/usr/bin/env python2.4 - +#!/usr/bin/env python + import wx + class DrawPanel(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent, -1, style=0) @@ -10,20 +11,19 @@ def __init__(self, parent): def OnPaint(self, event=None): - print "In Paint Event" - print PressedKey_instance.a_key_is_pressed - + print("In Paint Event") + print(PressedKey_instance.a_key_is_pressed) + dc = wx.PaintDC(self) dc.Clear() dc.SetPen(wx.Pen("RED", 4)) - + if PressedKey_instance.a_key_is_pressed == 'TRUE': dc.DrawLine(0, 0, 1000, 0) - + PressedKey_instance.a_key_is_pressed = 'FALSE' - print PressedKey_instance.a_key_is_pressed - - + print(PressedKey_instance.a_key_is_pressed) + class PressedKey(wx.Panel): def __init__(self, parent): @@ -32,25 +32,27 @@ def __init__(self, parent): self.SetFocus() self.a_key_is_pressed = 'FALSE' + def LogKeyEvent(self, evt): self.a_key_is_pressed = 'TRUE' - print self.a_key_is_pressed + print(self.a_key_is_pressed) class MyApp(wx.App): def OnInit(self): - frame1 = wx.Frame(None, -1, "Draw A Line", pos=(0,0), size=(400,300)) - frame2 = wx.Frame(None, -1, "Keep Focus!", pos=(400,300), size=(410,310)) - + frame1 = wx.Frame(None, -1, "Draw A Line", pos=(0, 0), size=(400, 300)) + frame2 = wx.Frame(None, -1, "Keep Focus!", pos=(400, 300), size=(410, 310)) + global PressedKey_instance PressedKey_instance = PressedKey(frame2) - + DrawPanel(frame1) - + frame1.Show(True) frame2.Show(True) return True -app = MyApp(0) -app.MainLoop() +if __name__ == "__main__": + app = MyApp(0) + app.MainLoop() diff --git a/LamdaTrick.py b/LamdaTrick.py index 8677926..0c1ff4c 100755 --- a/LamdaTrick.py +++ b/LamdaTrick.py @@ -12,34 +12,33 @@ import wx + class TestFrame(wx.Frame): def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) - MenuBar = wx.MenuBar() TestMenu = wx.Menu() - + # build menu from data: menu_names = ['item 1', 'item 2', 'item 3'] - + for name in menu_names: - item = TestMenu.Append(wx.ID_ANY, text = name) + item = TestMenu.Append(wx.ID_ANY, text=name) self.Bind(wx.EVT_MENU, - (lambda evt, name = name: - self.onMenuSelect(evt, name) ), + (lambda evt, name = name: + self.onMenuSelect(evt, name)), item) MenuBar.Append(TestMenu , "&Test") self.SetMenuBar(MenuBar) def onMenuSelect(self, evt, menu_name): - print "Menu: %s was selected"%menu_name - -A = wx.App(False) -F = TestFrame(None) -F.Show() -A.MainLoop() - + print("Menu: %s was selected" %menu_name) +if __name__ == "__main__": + A = wx.App(False) + F = TestFrame(None) + F.Show() + A.MainLoop() diff --git a/MPLmath.py b/MPLmath.py index 4f58f66..74b9a9c 100755 --- a/MPLmath.py +++ b/MPLmath.py @@ -7,7 +7,7 @@ """ import matplotlib -matplotlib.use( 'WXAgg' ) +matplotlib.use('WXAgg') import matplotlib.figure import matplotlib.backends.backend_wxagg @@ -18,25 +18,25 @@ class MathPanel (wx.Panel): The MathPanel is a very simple panel with just and MPL figure on it, it will automatically render text in the middle of the figure """ - def __init__( self, *args, **kwargs ): + def __init__(self, *args, **kwargs): kwargs['style'] = wx.NO_FULL_REPAINT_ON_RESIZE - wx.Panel.__init__( self, *args, **kwargs ) + wx.Panel.__init__(self, *args, **kwargs) # initialize matplotlib stuff - self.figure = matplotlib.figure.Figure( None ) - self.canvas = matplotlib.backends.backend_wxagg.FigureCanvasWxAgg( self, -1, self.figure ) + self.figure = matplotlib.figure.Figure(None) + self.canvas = matplotlib.backends.backend_wxagg.FigureCanvasWxAgg( self, -1, self.figure) self._SetSize() self.Bind(wx.EVT_SIZE, self._SetSize) - + self.TeX = "" self.font_size = 32 self.draw() def SetTeX(self, str): - self.TeX = "$%s$"%str + self.TeX = "$%s$" %str self.draw() def draw(self): @@ -48,41 +48,41 @@ def draw(self): self.figure.clear() self.figure.text(0.05, 0.5, "Parsing Error in MathTeX", size=self.font_size) self.canvas.draw() - - def _SetSize( self, evt=None ): + + def _SetSize(self, evt=None): pixels = self.GetSize() - self.SetSize( pixels ) - self.canvas.SetSize( pixels ) - self.figure.set_size_inches( float( pixels[0] )/self.figure.get_dpi(), - float( pixels[1] )/self.figure.get_dpi() ) + self.SetSize(pixels) + self.canvas.SetSize(pixels) + self.figure.set_size_inches(float(pixels[0]) / self.figure.get_dpi(), + float(pixels[1]) / self.figure.get_dpi()) class MathFrame(wx.Frame): def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) - - self.input_box = wx.TextCtrl(self, size=(500,80), ) + + self.input_box = wx.TextCtrl(self, size=(500, 80)) self.input_box.Font = wx.Font(16, wx.FONTFAMILY_TELETYPE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL) self.Bind(wx.EVT_TEXT, self.OnText) - self.math_panel = MathPanel(self, size = (500, 200)) - + self.math_panel = MathPanel(self, size=(500, 200)) + S = wx.BoxSizer(wx.VERTICAL) - S.Add(wx.StaticText(self, label="Type some TeX here:"), 0, wx.TOP|wx.LEFT, 5) + S.Add(wx.StaticText(self, label="Type some TeX here:"), 0, wx.TOP | wx.LEFT, 5) S.Add(self.input_box, 0, wx.GROW|wx.ALL, 5) S.Add(self.math_panel, 1, wx.GROW) self.SetSizerAndFit(S) - + self.Show() self.input_box.Value = r'\frac{(a+fffb)}{(c-d)}' - + def OnText(self, evt): self.math_panel.SetTeX(self.input_box.Value) - -if __name__ == '__main__': - app = wx.App( False ) - frame = MathFrame( None, title='Test Matplotlib Math Renderer') + +if __name__ == '__main__': + app = wx.App(False) + frame = MathFrame(None, title='Test Matplotlib Math Renderer') app.MainLoop() diff --git a/MacApp.py b/MacApp.py index f631cf5..41ce2fd 100755 --- a/MacApp.py +++ b/MacApp.py @@ -1,8 +1,7 @@ -#!/usr/bin/env python +#!/usr/bin/env pythonw """ - MacApp.py This is a small, simple app that tried to do all the right things on @@ -12,26 +11,27 @@ import wx + class DemoFrame(wx.Frame): """ This window displays a button """ - def __init__(self, title = "Micro App"): + def __init__(self, title="Micro App"): wx.Frame.__init__(self, None , -1, title) MenuBar = wx.MenuBar() FileMenu = wx.Menu() - - item = FileMenu.Append(wx.ID_EXIT, text = "&Exit") + + item = FileMenu.Append(wx.ID_EXIT, item="&Exit") self.Bind(wx.EVT_MENU, self.OnQuit, item) - item = FileMenu.Append(wx.ID_ANY, text = "&Open") + item = FileMenu.Append(wx.ID_ANY, item="&Open") self.Bind(wx.EVT_MENU, self.OnOpen, item) - item = FileMenu.Append(wx.ID_PREFERENCES, text = "&Preferences") + item = FileMenu.Append(wx.ID_PREFERENCES, item="&Preferences") self.Bind(wx.EVT_MENU, self.OnPrefs, item) MenuBar.Append(FileMenu, "&File") - + HelpMenu = wx.Menu() item = HelpMenu.Append(wx.ID_HELP, "Test &Help", @@ -46,22 +46,22 @@ def __init__(self, title = "Micro App"): self.SetMenuBar(MenuBar) - btn = wx.Button(self, label = "Quit") + btn = wx.Button(self, label="Quit") btn.Bind(wx.EVT_BUTTON, self.OnQuit ) self.Bind(wx.EVT_CLOSE, self.OnQuit) s = wx.BoxSizer(wx.VERTICAL) - s.Add((200,50)) + s.Add((200, 50)) s.Add(btn, 0, wx.CENTER, wx.ALL, 20) - s.Add((200,50)) + s.Add((200, 50)) self.SetSizerAndFit(s) - + def OnQuit(self,Event): self.Destroy() - + def OnAbout(self, event): dlg = wx.MessageDialog(self, "This is a small program to test\n" "the use of menus on Mac, etc.\n", @@ -89,11 +89,12 @@ def OnPrefs(self, event): "Preferences", wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy() - + + class MyApp(wx.App): def __init__(self, *args, **kwargs): wx.App.__init__(self, *args, **kwargs) - + # This catches events when the app is asked to activate by some other # process self.Bind(wx.EVT_ACTIVATE_APP, self.OnActivate) @@ -114,43 +115,38 @@ def BringWindowToFront(self): self.GetTopWindow().Raise() except: pass - + def OnActivate(self, event): # if this is an activate event, rather than something else, like iconize. if event.GetActive(): self.BringWindowToFront() event.Skip() - + def OpenFileMessage(self, filename): dlg = wx.MessageDialog(None, "This app was just asked to open:\n%s\n"%filename, "File Dropped", - wx.OK|wx.ICON_INFORMATION) + wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy() def MacOpenFile(self, filename): """Called for files droped on dock icon, or opened via finders context menu""" - print filename - print "%s dropped on app"%(filename) #code to load filename goes here. + print(filename) + print("%s dropped on app" %(filename)) #code to load filename goes here. self.OpenFileMessage(filename) - + def MacReopenApp(self): """Called when the doc icon is clicked, and ???""" self.BringWindowToFront() def MacNewFile(self): pass - + def MacPrintFile(self, file_path): pass - - - -app = MyApp(False) -app.MainLoop() - - - +if __name__ == "__main__": + app = MyApp(False) + app.MainLoop() diff --git a/MacAppsetup.py b/MacAppsetup.py index 9881041..ab6e8b5 100755 --- a/MacAppsetup.py +++ b/MacAppsetup.py @@ -17,9 +17,9 @@ APP = ['MacApp.py'] DATA_FILES = [] -OPTIONS = {'argv_emulation': True, # this puts the names of dropped files into sys.argv when starting the app. +OPTIONS = {'argv_emulation': True, # this puts the names of dropped files into sys.argv when starting the app. 'iconfile': 'MacAppIcon.icns', - 'plist': Plist, + 'plist': Plist, } diff --git a/MicroApp.py b/MicroApp.py index 086bf7c..9ccf5c5 100755 --- a/MicroApp.py +++ b/MicroApp.py @@ -2,6 +2,7 @@ import wx + class DemoFrame(wx.Frame): """ This window displays a button """ def __init__(self, title = "Micro App"): @@ -10,21 +11,21 @@ def __init__(self, title = "Micro App"): MenuBar = wx.MenuBar() FileMenu = wx.Menu() - - item = FileMenu.Append(wx.ID_ANY, text = "&Open") + + item = FileMenu.Append(wx.ID_ANY, item="&Open") self.Bind(wx.EVT_MENU, self.OnOpen, item) - item = FileMenu.Append(wx.ID_PREFERENCES, text = "&Preferences") + item = FileMenu.Append(wx.ID_PREFERENCES, item="&Preferences") self.Bind(wx.EVT_MENU, self.OnPrefs, item) - item = FileMenu.Append(wx.ID_EXIT, text = "&Exit") + item = FileMenu.Append(wx.ID_EXIT, item="&Exit") self.Bind(wx.EVT_MENU, self.OnQuit, item) MenuBar.Append(FileMenu, "&File") - + HelpMenu = wx.Menu() item = HelpMenu.Append(wx.ID_HELP, "Test &Help", @@ -39,16 +40,16 @@ def __init__(self, title = "Micro App"): self.SetMenuBar(MenuBar) - btn = wx.Button(self, label = "Quit") + btn = wx.Button(self, label = "Quit", pos=(40,60)) btn.Bind(wx.EVT_BUTTON, self.OnQuit ) self.Bind(wx.EVT_CLOSE, self.OnQuit) - + def OnQuit(self,Event): self.Destroy() - + def OnAbout(self, event): dlg = wx.MessageDialog(self, "This is a small program to test\n" "the use of menus on Mac, etc.\n", @@ -77,12 +78,9 @@ def OnPrefs(self, event): dlg.ShowModal() dlg.Destroy() -app = wx.App(False) -frame = DemoFrame() -frame.Show() -app.MainLoop() - - - - +if __name__ == "__main__": + app = wx.App(False) + frame = DemoFrame() + frame.Show() + app.MainLoop() diff --git a/MoveText.py b/MoveText.py index ac57dc0..ec1f9ba 100755 --- a/MoveText.py +++ b/MoveText.py @@ -1,8 +1,10 @@ #!/usr/bin/env python -import os, sys +import os +import sys import wx + class MyPanel(wx.Panel): def __init__(self, frame, id): wx.Panel.__init__(self, frame, id) @@ -24,7 +26,6 @@ def OnPaint(self, event): dc.SetBackground(wx.Brush("white")) dc.Clear() self.drawText(dc) - def OnMouseMove(self, event): if event.Dragging(): @@ -52,6 +53,7 @@ def drawText(self, dc=None): return None + class MyFrame(wx.Frame): def __init__(self, parent, ID, title): wx.Frame.__init__(self, parent, ID, title, pos=(150, 150), size=(500, 400)) @@ -70,6 +72,7 @@ def OnInit(self): frame.Show(True) return True + if __name__ == '__main__': app = MyApp(0) app.MainLoop() diff --git a/MultiFrame.py b/MultiFrame.py index 22d8f59..172f5c1 100755 --- a/MultiFrame.py +++ b/MultiFrame.py @@ -7,20 +7,21 @@ import wx import random + class MsgFrame(wx.Frame): """ This window displays a simple message """ def __init__(self, frame_num): - wx.Frame.__init__(self, None, -1, title="Frame # %i"%frame_num, size=(400,100)) + wx.Frame.__init__(self, None, -1, title="Frame # %i" %frame_num, size=(400, 100)) self.frame_num = frame_num self.message = wx.StaticText(self, label = "A non-message") s = wx.BoxSizer(wx.VERTICAL) - s.Add((1,1), 1) + s.Add((1, 1), 1) s.Add(self.message, 0, wx.ALIGN_CENTER) - s.Add((1,1), 1) - + s.Add((1, 1), 1) + self.SetSizer(s) - + self.Bind(wx.EVT_LEFT_DOWN, self.OnClick) def SetMessage(self, message): @@ -32,22 +33,24 @@ def SetMessage(self, message): def OnClick(self, evt): pos = evt.Position App = wx.GetApp() - App.SetMessage("Mouse clicked in frame: %i at position: (%i, %i)"%(self.frame_num, pos[0], pos[1]), self.frame_num+1) + App.SetMessage("Mouse clicked in frame: %i at position: (%i, %i)" %( + self.frame_num, pos[0], pos[1]), self.frame_num + 1) + class DemoApp(wx.App): def OnInit(self): - + # build the frames: self.frames = [] for i in range(5): frame = MsgFrame(frame_num=i) - frame.Move((30+i*100, 30+i*100)) + frame.Move((30 + i * 100, 30 + i * 100)) frame.Show() self.frames.append(frame) - + return True - + def SetMessage(self, message, frame_num): """ set a message on the given frame_number """ try: @@ -56,10 +59,6 @@ def SetMessage(self, message, frame_num): self.frames[0].SetMessage(message) -app = DemoApp(False) -app.MainLoop() - - - - - +if __name__ == "__main__": + app = DemoApp(False) + app.MainLoop() diff --git a/NewSizertest.py b/NewSizertest.py index a7a2080..900d5f0 100755 --- a/NewSizertest.py +++ b/NewSizertest.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.4 +#!/usr/bin/env python """ @@ -9,6 +9,7 @@ import wx + class PyBoxSizer(wx.BoxSizer): """ PyBoxSizer class, that is more pythonic than the raw wxWidgets @@ -70,28 +71,29 @@ def PyAdd(self, flags |= wx.ALIGN_RIGHT flags |= Borders - flags |= ExtraFlags + flags |= ExtraFlags - print "Calling old Add:", (proportion, flags, BorderSize) + print("Calling old Add:", (proportion, flags, BorderSize)) self.OldAdd(Widget, proportion, flags, BorderSize) - + + class MyDialog(wx.Dialog): """ A simple app to test the new sizer API - + """ - + def __init__(self, *args, **kwargs): wx.Dialog.__init__(self, *args, **kwargs) - + # Create a vertical BoxSizer for the Main Sizer - topsizer = PyBoxSizer( wx.VERTICAL ) + topsizer = PyBoxSizer(wx.VERTICAL) # Create text ctrl with minimum size 100x60 textBox = wx.TextCtrl(self, value="My text.", - size=(300,100), + size=(300, 100), style=wx.TE_MULTILINE) # Add the text control @@ -103,7 +105,7 @@ def __init__(self, *args, **kwargs): Borders = wx.ALL, BorderSize = 10, ExtraFlags = wx.ADJUST_MINSIZE) - + # Create a Horizontal Sizer for the Buttons button_sizer = PyBoxSizer(wx.HORIZONTAL) button_sizer.Add(wx.Button(self, wx.ID_OK), @@ -112,16 +114,15 @@ def __init__(self, *args, **kwargs): button_sizer.Add(wx.Button(self, wx.ID_CANCEL), Borders=wx.ALL, BorderSize=10 ) - - topsizer.Add(button_sizer, AlignmentHorizontal = wx.RIGHT) - + + topsizer.Add(button_sizer, AlignmentHorizontal=wx.RIGHT) + self.SetSizerAndFit(topsizer) + if __name__=='__main__': App = wx.App() - #AppFrame().Show() - dlg = MyDialog(None, title="Test Dialog", style=wx.RESIZE_BORDER ) + dlg = MyDialog(None, title="Test Dialog", style=wx.RESIZE_BORDER) dlg.ShowModal() dlg.Destroy() App.MainLoop() - diff --git a/OffScreenHTML.py b/OffScreenHTML.py index 72c03ff..8415ccb 100755 --- a/OffScreenHTML.py +++ b/OffScreenHTML.py @@ -2,94 +2,99 @@ """ test of rendering HTML to an off-screen bitmap + +This version uses a wx.GCDC, so you can have an alpha background. + +Works on OS-X, may need an explicit alpha bitmap on other platforms """ import wx import wx.html + class OffScreenHTML: def __init__(self, width, height): - + self.width = width self.height = height - self.Buffer = wx.EmptyBitmap(width, height) - + self.Buffer = wx.Bitmap(width, height) + self.HR = wx.html.HtmlDCRenderer() - + # a bunch of defaults... - self.BackgroundColor = "White" + self.BackgroundColor = "white" + self.BackgroundColor = (255, 255, 255, 50) self.Padding = 10 - - + def Render(self, source): """ Render the html source to the bitmap """ DC = wx.MemoryDC() DC.SelectObject(self.Buffer) + DC = wx.GCDC(DC) DC.SetBackground(wx.Brush(self.BackgroundColor)) DC.Clear() - + self.HR.SetDC(DC, 1.0) - self.HR.SetSize(self.width-2*self.Padding, self.height) - + self.HR.SetSize(self.width - 2 * self.Padding, self.height) + self.HR.SetHtmlText(source) self.HR.Render(self.Padding, self.Padding, []) - self.RenderedSize = (self.width, self.HR.GetTotalHeight()+2*self.Padding) + self.RenderedSize = (self.width, self.HR.GetTotalHeight() + 2 * self.Padding) def SaveAsPNG(self, filename): sub = self.Buffer.GetSubBitmap(wx.Rect(0, 0, *self.RenderedSize) ) + print("saving as: ", filename) sub.SaveFile(filename, wx.BITMAP_TYPE_PNG) + class Text2html: """ A simple class for converting plain text to basic HTML - + This is an alternative to using
-- I want it to wrap, but otherwise preserve newlines, etc.
"""
def __init__(self):
pass
-
+
def Convert(self, text):
"""
Takes raw text, and returns html with newlines converted, etc.
"""
- print "raw text:", text
+ print("raw text:", text)
# double returns are a new paragraph
text = text.split("\n\n")
- print "split by paragraphs:", text
+ print("split by paragraphs:", text)
text = [p.strip().replace("\n","
") for p in text]
- print text
+ print(text)
text = "\n" + "\n
\n\n".join(text) + "\n
"
-
- return text
-
+ return text
if __name__ == "__main__":
HTML = """ A Title
-
+
This is a simple test of rendering a little text with an html renderer
-
+
Now another paragraph, with a bunch more text in it. This is a test
that will show if it can take care of the basic rendering for us, and
auto-wrap, and all sorts of nifty stuff like that
-
- It does seem to work OK
+
+
+ and here is some Bold Text
+
It does seem to work OK
"""
-
+
App = wx.App(False)
OSR = OffScreenHTML(500, 500)
- OSR.width = 200
+ OSR.width = 200
OSR.Render(HTML)
OSR.SaveAsPNG('junk.png')
- OSR.width = 300
+ OSR.width = 300
OSR.Render(HTML)
OSR.SaveAsPNG('junk2.png')
-
-
-
diff --git a/Overlaytest.py b/Overlaytest.py
index e0be138..17373d0 100755
--- a/Overlaytest.py
+++ b/Overlaytest.py
@@ -1,16 +1,16 @@
#!/usr/bin/env python
-
"""
-A test of temporatry drawing using a method called from OnPaint
+A test of temporary drawing using a method called from OnPaint
+
+NOTE: this is broken -- needs debugging!
"""
import wx
-print wx.__version__
import random
-class BufferedWindow(wx.Window):
+class BufferedWindow(wx.Window):
"""
A Buffered window class.
@@ -27,24 +27,25 @@ class BufferedWindow(wx.Window):
"""
-
- def __init__(self, parent, id,
- pos = wx.DefaultPosition,
- size = wx.DefaultSize,
- style = wx.NO_FULL_REPAINT_ON_RESIZE):
+ def __init__(self,
+ parent,
+ id,
+ pos=wx.DefaultPosition,
+ size=wx.DefaultSize,
+ style=wx.NO_FULL_REPAINT_ON_RESIZE):
wx.Window.__init__(self, parent, id, pos, size, style)
- wx.EVT_PAINT(self, self.OnPaint)
- wx.EVT_SIZE(self, self.OnSize)
+ self.Bind(wx.EVT_PAINT, self.OnPaint)
+ self.Bind(wx.EVT_SIZE, self.OnSize)
# OnSize called to make sure the buffer is initialized.
# This might result in OnSize getting called twice on some
# platforms at initialization, but little harm done.
self.OnSize(None)
- def Draw(self,dc):
- ## just here as a place holder.
- ## This method should be over-ridden when subclassed
+ def Draw(self, dc):
+ # just here as a place holder.
+ # This method should be over-ridden when subclassed
pass
def TempDraw(self, dc):
@@ -53,29 +54,29 @@ def TempDraw(self, dc):
of the buffer, like during Mouse actions, etc.
"""
pass
-
+
def OnPaint(self, event):
- print "In OnPaint"
+ print("In OnPaint")
# All that is needed here is to draw the buffer to screen
dc = wx.PaintDC(self)
- dc.DrawBitmap(self._Buffer,0,0)
+ dc.DrawBitmap(self._Buffer, 0, 0)
self.TempDraw(dc)
- def OnSize(self,event):
+ def OnSize(self, event):
# The Buffer init is done here, to make sure the buffer is always
# the same size as the Window
- Size = self.GetClientSizeTuple()
+ Size = self.GetClientSize()
# Make sure we don't try to create a 0 size bitmap
Size = (max(Size[0], 1), max(Size[1], 1))
- self._Buffer = wx.EmptyBitmap(Size[0],Size[1])
+ self._Buffer = wx.Bitmap(Size[0], Size[1])
self.UpdateDrawing()
- def SaveToFile(self,FileName,FileType):
- ## This will save the contents of the buffer
- ## to the specified file. See the wxWindows docs for
- ## wx.Bitmap::SaveFile for the details
- self._Buffer.SaveFile(FileName,FileType)
+ def SaveToFile(self, FileName, FileType):
+ # This will save the contents of the buffer
+ # to the specified file. See the wxWindows docs for
+ # wx.Bitmap::SaveFile for the details
+ self._Buffer.SaveFile(FileName, FileType)
def UpdateDrawing(self):
"""
@@ -84,7 +85,6 @@ def UpdateDrawing(self):
The idea here is that the drawing is based on some data generated
elsewhere in the system. IF that data changes, the drawing needs to
be updated.
-
"""
# update the buffer
@@ -92,22 +92,22 @@ def UpdateDrawing(self):
dc.SelectObject(self._Buffer)
self.Draw(dc)
# update the screen
- wx.ClientDC(self).DrawBitmap(self._Buffer,0,0)
+ wx.ClientDC(self).DrawBitmap(self._Buffer, 0, 0)
+
class DrawWindow(BufferedWindow):
- def __init__(self, parent, id = -1):
- ## Any data the Draw() function needs must be initialized before
- ## calling BufferedWindow.__init__, as it will call the Draw
- ## function.
+ def __init__(self, parent, id=-1):
+ # Any data the Draw() function needs must be initialized before
+ # calling BufferedWindow.__init__, as it will call the Draw
+ # function.
BufferedWindow.__init__(self, parent, id)
-
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
self.Bind(wx.EVT_MOTION, self.OnMove)
self.StartMove = None
-
+
self.overlay = wx.Overlay()
def OnLeftDown(self, event):
@@ -118,37 +118,36 @@ def OnLeftUp(self, event):
if self.HasCapture():
self.ReleaseMouse()
self.StartMove = None
- #self.Refresh()
- # When the mouse is released we reset the overlay and it
- # restores the former content to the window.
- #dc = wx.ClientDC(self)
- #odc = wx.DCOverlay(self.overlay, dc)
- #odc.Clear()
- #del odc
+ # self.Refresh()
+ # # When the mouse is released we reset the overlay and it
+ # # restores the former content to the window.
+ # dc = wx.ClientDC(self)
+ # odc = wx.DCOverlay(self.overlay, dc)
+ # odc.Clear()
+ # del odc
self.overlay.Reset()
-
def OnMove(self, event):
- if event.Dragging() and event.LeftIsDown() and self.StartMove is not None:
+ if (event.Dragging() and event.LeftIsDown()
+ and self.StartMove is not None):
pos = event.GetPosition()
- #self.Refresh()
+ # self.Refresh()
dc = wx.ClientDC(self)
- odc = wx.DCOverlay( self.overlay, dc)
+ odc = wx.DCOverlay(self.overlay, dc)
odc.Clear()
- ## a black and white line so you can see it over any color.
+ # a black and white line so you can see it over any color.
dc.SetPen(wx.Pen('WHITE', 2))
dc.SetBrush(wx.TRANSPARENT_BRUSH)
- dc.DrawLinePoint(self.StartMove, pos)
+ dc.DrawLine(self.StartMove, pos)
dc.SetPen(wx.Pen('BLACK', 2, wx.SHORT_DASH))
- dc.DrawLinePoint(self.StartMove, pos)
+ dc.DrawLine(self.StartMove, pos)
+
+ del odc # to ensure it gets delted before the Client
- del odc # to ensure it gets delted before the Client
-
def Draw(self, dc):
- coords = ((40,40),(200,220),(210,120),(120,300))
- dc.BeginDrawing()
- dc.SetBackground( wx.Brush("Blue") )
- dc.Clear() # make sure you clear the bitmap!
+ coords = ((40, 40), (200, 220), (210, 120), (120, 300))
+ dc.SetBackground(wx.Brush("Blue"))
+ dc.Clear() # make sure you clear the bitmap!
dc.SetPen(wx.RED_PEN)
dc.SetBrush(wx.CYAN_BRUSH)
@@ -161,35 +160,17 @@ def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.Window = DrawWindow(self)
+
class DemoApp(wx.App):
def OnInit(self):
- wx.InitAllImageHandlers() # called so a PNG can be saved
- frame = TestFrame(None, title="OverlayTest", size=(500,500))
+ frame = TestFrame(None, title="OverlayTest", size=(500, 500))
frame.Show(True)
self.SetTopWindow(frame)
return True
+
if __name__ == "__main__":
app = DemoApp(0)
app.MainLoop()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Overlaytest2.py b/Overlaytest2.py
index f3fab8a..9dad557 100755
--- a/Overlaytest2.py
+++ b/Overlaytest2.py
@@ -1,5 +1,4 @@
#!/usr/bin/env python
-
"""
A simple sample of using a wx.Overlay to draw a rubberband effect
@@ -7,10 +6,13 @@
I've added stuff for non-mac platfroms based on code posted by Chris Mellon
+NOTE: something is wrong with the zooming, but the overlay works.
+
"""
import wx
-print wx.version()
+print(wx.version())
+
class TestPanel(wx.Panel):
def __init__(self, *args, **kw):
@@ -27,17 +29,16 @@ def __init__(self, *args, **kw):
def OnPaint(self, evt):
# Just some simple stuff to paint in the window for an example
dc = wx.PaintDC(self)
- coords = ((40,40),(200,220),(210,120),(120,300))
+ coords = ((40, 40), (200, 220), (210, 120), (120, 300))
dc.SetBackground(wx.Brush("sky blue"))
dc.Clear()
dc.SetPen(wx.Pen("red", 2))
dc.SetBrush(wx.CYAN_BRUSH)
dc.DrawPolygon(coords)
- dc.DrawLabel("Draw the mouse across this window to see \n"
- "a rubber-band effect using wx.Overlay",
- (140, 50, -1, -1))
-
+ dc.DrawLabel(
+ "Draw the mouse across this window to see \n"
+ "a rubber-band effect using wx.Overlay", (140, 50, -1, -1))
def OnLeftDown(self, evt):
# Capture the mouse and save the starting posiiton for the
@@ -45,35 +46,34 @@ def OnLeftDown(self, evt):
self.CaptureMouse()
self.startPos = evt.GetPosition()
-
def OnMouseMove(self, evt):
if not self.HasCapture():
- return
- rect = wx.RectPP(self.startPos, evt.GetPosition())
+ return
+ rect = wx.Rect(self.startPos, evt.GetPosition())
# Draw the rubber-band rectangle using an overlay so it
# will manage keeping the rectangle and the former window
# contents separate.
dc = wx.ClientDC(self)
odc = wx.DCOverlay(self.overlay, dc)
odc.Clear()
-
+
pen = wx.Pen("black", 2)
- brush = wx.Brush(wx.Color(192,192,192,128))
+ brush = wx.Brush(wx.Colour(192, 192, 192, 128))
if "wxMac" in wx.PlatformInfo:
dc.SetPen(pen)
dc.SetBrush(brush)
- dc.DrawRectangleRect(rect)
+ dc.DrawRectangle(rect)
else:
# use a GC on Windows (and GTK?)
- # this crashed on the Mac
- ctx = wx.GraphicsContext_Create(dc)
+ # this doesn't work on the Mac
+ ctx = wx.GraphicsContext.Create(dc)
ctx.SetPen(pen)
ctx.SetBrush(brush)
+ print("drawing:", rect)
ctx.DrawRectangle(*rect)
- del odc # work around a bug in the Python wrappers to make
- # sure the odc is destroyed before the dc is.
-
+ del odc # work around a bug in the Python wrappers to make
+ # sure the odc is destroyed before the dc is.
def OnLeftUp(self, evt):
if self.HasCapture():
@@ -88,13 +88,15 @@ def OnLeftUp(self, evt):
del odc
self.overlay.Reset()
-app = wx.App(redirect=False)
-frm = wx.Frame(None, title="wx.Overlay Test", size=(450,450))
-#work around flicker on MSW - setting transparency
-#turns on window compositing, which allows for buffering
-#of clientDC drawing
-if "wxMSW" in wx.PlatformInfo:
- frm.SetTransparent(254)
-pnl = TestPanel(frm)
-frm.Show()
-app.MainLoop()
+
+if __name__ == "__main__":
+ app = wx.App(redirect=False)
+ frm = wx.Frame(None, title="wx.Overlay Test", size=(450, 450))
+ #work around flicker on MSW - setting transparency
+ #turns on window compositing, which allows for buffering
+ #of clientDC drawing
+ if "wxMSW" in wx.PlatformInfo:
+ frm.SetTransparent(254)
+ pnl = TestPanel(frm)
+ frm.Show()
+ app.MainLoop()
diff --git a/PaintDemo.py b/PaintDemo.py
index d2916d2..02d43aa 100755
--- a/PaintDemo.py
+++ b/PaintDemo.py
@@ -1,28 +1,60 @@
-#!/usr/bin/python
+#!/usr/bin/env python
import wx
-from random import *
+from random import randint
+
class MyPanel(wx.Panel):
def __init__(self, parent, size, position):
wx.Panel.__init__(self, parent, -1, size=size, pos=position)
- self.NewRect()
+ self.NewShape()
self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnPaint(self, event):
dc = wx.PaintDC(self)
dc.Clear()
- dc.DrawRectangle(*self.rect)
-
- def NewRect(self):
- self.rect = (randint(0, 300), randint(0, 300), 50, 50)
+ dc.DrawRectangle(*self.shape)
+
+ def NewShape(self):
+ shapeSz = randint(50, 100)
+ sz = self.GetSize()
+ self.shape = (randint(0, sz[0] - shapeSz),
+ randint(0, sz[1] - shapeSz),
+ shapeSz, shapeSz)
- def DrawRect(self):
- self.NewRect()
+ def DrawShape(self):
dc = wx.ClientDC(self)
dc.Clear()
- dc.DrawRectangle(*self.rect)
+
+ for i in range(randint(0, 6)):
+ self.NewShape()
+ dc.SetBrush(wx.Brush(wx.Colour(randint(0, 255),
+ randint(0, 255),
+ randint(0, 255),
+ 255)))
+ r = randint(0, 5)
+ if r == 0:
+ dc.DrawCircle(self.shape[0], self.shape[1], self.shape[2])
+ elif r == 1:
+ dc.DrawRectangle(*self.shape)
+ elif r == 2:
+ dc.SetFont(wx.Font(24, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
+ dc.DrawRotatedText('(%s, %s)' %(self.shape[0], self.shape[1]),
+ self.shape[0], self.shape[1],
+ float(randint(0, 360)))
+ elif r == 3:
+ dc.DrawRoundedRectangle(*self.shape, radius=float(randint(0, 20)))
+ elif r == 4:
+ dc.GradientFillLinear(wx.Rect(*self.shape),
+ initialColour=wx.Colour(randint(0, 255), randint(0, 255), randint(0, 255), 255),
+ destColour=wx.Colour(randint(0, 255), randint(0, 255), randint(0, 255), 255))
+ elif r == 5:
+ dc.GradientFillConcentric(wx.Rect(*self.shape),
+ initialColour=wx.Colour(randint(0, 255), randint(0, 255), randint(0, 255), 255),
+ destColour=wx.Colour(randint(0, 255), randint(0, 255), randint(0, 255), 255),
+ circleCenter=(self.shape[0], self.shape[1]))
+
class MyFrame(wx.Frame):
def __init__(self, *args, **kwargs):
@@ -30,20 +62,20 @@ def __init__(self, *args, **kwargs):
button = wx.Button(self, -1, label="Add New")
button.Bind(wx.EVT_BUTTON, self.UpdatePanel)
- self.Panel = MyPanel(self, (200,200), (100,250))
+ self.Panel = MyPanel(self, (200, 200), (100, 250))
sizer = wx.BoxSizer(wx.VERTICAL)
- sizer.Add(button,0,wx.ALIGN_CENTER | wx.ALL, 10)
- sizer.Add(self.Panel,1,wx.EXPAND)
+ sizer.Add(button, 0, wx.ALIGN_CENTER | wx.ALL, 10)
+ sizer.Add(self.Panel, 1, wx.EXPAND)
self.SetSizer(sizer)
-
+
def UpdatePanel(self,event):
- self.Panel.DrawRect()
+ self.Panel.DrawShape()
+
if __name__ == '__main__':
app = wx.App(0)
- frame = MyFrame(None, title="Test", size=(500,500) )
+ frame = MyFrame(None, title="Test", size=(500, 500))
frame.Show()
app.MainLoop()
-
diff --git a/PassArgsToCallback.py b/PassArgsToCallback.py
index 1ceea35..e0e74ea 100755
--- a/PassArgsToCallback.py
+++ b/PassArgsToCallback.py
@@ -6,6 +6,7 @@
class MyFrame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
+ self.SetBackgroundColour(wx.WHITE)
NumButtons = 6
@@ -14,67 +15,66 @@ def __init__(self, *args, **kwargs):
## The lambda trick:
ButtonSizer = wx.StaticBoxSizer(wx.StaticBox(self,label="lambda trick"),
wx.VERTICAL)
+ bdr = 10
for i in range(NumButtons):
- b = wx.Button(self, label= str(i))
+ b = wx.Button(self, label=str(i))
b.Bind(wx.EVT_BUTTON, lambda evt, num=i: self.OnClick(evt, num))
- ButtonSizer.Add(b, 0, wx.EXPAND|wx.ALL, 10)
- MainSizer.Add(ButtonSizer)
-
+ ButtonSizer.Add(b, 0, wx.EXPAND | wx.ALL, bdr)
+ MainSizer.Add(ButtonSizer, 0, wx.ALL, bdr)
+
## Using the label:
ButtonSizer = wx.StaticBoxSizer(wx.StaticBox(self,label="Using the label"),
wx.VERTICAL)
for i in range(NumButtons):
- b = wx.Button(self, label= str(i))
+ b = wx.Button(self, label=str(i))
b.Bind(wx.EVT_BUTTON, self.OnClick2)
- ButtonSizer.Add(b, 0, wx.EXPAND|wx.ALL, 10)
- MainSizer.Add(ButtonSizer)
+ ButtonSizer.Add(b, 0, wx.EXPAND | wx.ALL, bdr)
+ MainSizer.Add(ButtonSizer, 0, wx.ALL, bdr)
## Storing the ID:
ButtonSizer = wx.StaticBoxSizer(wx.StaticBox(self,label="Storing the ID"),
wx.VERTICAL)
self.ButtonIDs = {}
for i in range(NumButtons):
- b = wx.Button(self, label= str(i))
+ b = wx.Button(self, label=str(i))
self.ButtonIDs[b.Id] = i
b.Bind(wx.EVT_BUTTON, self.OnClick3)
- ButtonSizer.Add(b, 0, wx.EXPAND|wx.ALL, 10)
- MainSizer.Add(ButtonSizer)
+ ButtonSizer.Add(b, 0, wx.EXPAND | wx.ALL, bdr)
+ MainSizer.Add(ButtonSizer, 0, wx.ALL, bdr)
## Using FindWinowById():
ButtonSizer = wx.StaticBoxSizer(wx.StaticBox(self,label="FindWinowById()"),
wx.VERTICAL)
for i in range(NumButtons):
- b = wx.Button(self, label= str(i))
+ b = wx.Button(self, label=str(i))
b.Bind(wx.EVT_BUTTON, self.OnClick4)
# add an arbitrary attribute
- b.myData = "This is button %i"%i
- ButtonSizer.Add(b, 0, wx.EXPAND|wx.ALL, 10)
- MainSizer.Add(ButtonSizer)
+ b.myData = "This is button %i" %i
+ ButtonSizer.Add(b, 0, wx.EXPAND | wx.ALL, bdr)
+ MainSizer.Add(ButtonSizer, 0, wx.ALL, bdr)
self.SetSizerAndFit(MainSizer)
-
+ sz = self.GetSize()
+ self.SetSizeHints(sz[0], sz[1], sz[0], sz[1])
+
def OnClick(self, evt, num):
- print "Button %i Clicked"%num
+ print("Button %i Clicked" %num)
def OnClick2(self, evt):
but = evt.GetEventObject()
- print "Button %s Clicked"%but.Label
+ print("Button %s Clicked" %but.Label)
def OnClick3(self, evt):
but = self.ButtonIDs[evt.Id]
- print "Button %s Clicked"%but
+ print("Button %s Clicked" %but)
def OnClick4(self, evt):
but = wx.FindWindowById(evt.Id)
- print "Button %s Clicked"%but.myData
-
-
-
-App = wx.App(False)
-F = MyFrame(None, title="Test Frame")
-F.Show()
-App.MainLoop()
+ print("Button %s Clicked" %but.myData)
-
-
+if __name__ == '__main__':
+ App = wx.App(False)
+ F = MyFrame(None, title="Test Frame")
+ F.Show()
+ App.MainLoop()
diff --git a/Popup.py b/Popup.py
index 98bfdf3..63bab5b 100755
--- a/Popup.py
+++ b/Popup.py
@@ -1,11 +1,11 @@
-#!/usr/bin/env python2.5
+#!/usr/bin/env python
"""
A demo and test of how to make a poopup menu that is customized to when
it is called
"""
-
+
import wx
@@ -14,7 +14,7 @@ def __init__(self, WinName):
wx.Menu.__init__(self)
self.WinName = WinName
-
+
# Binding the conventional way:
item = wx.MenuItem(self, wx.NewId(),"Item One")
self.AppendItem(item)
@@ -31,25 +31,24 @@ def __init__(self, WinName):
self.Bind(wx.EVT_MENU, lambda event, name=name: self.OnItems(event, name), item)
def OnItem1(self, event):
- print "Item One selected in the %s window"%self.WinName
+ print("Item One selected in the %s window" %self.WinName)
def OnItem2(self, event):
- print "Item Two selected in the %s window"%self.WinName
+ print("Item Two selected in the %s window" %self.WinName)
def OnItems(self, event, name):
- print "%s selected in the %s window"%(name, self.WinName)
+ print("%s selected in the %s window" %(name, self.WinName))
class MyWindow(wx.Window):
def __init__(self, parent, color):
wx.Window.__init__(self, parent, -1)
-
self.color = color
self.SetBackgroundColour(color)
self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
-
+
def OnRightDown(self,event):
menu = MyPopupMenu(self.color)
self.PopupMenu(menu, event.GetPosition())
@@ -57,24 +56,26 @@ def OnRightDown(self,event):
# hang around forever, and you'll create a new one each time this is called!
menu.Destroy()
+
class MyFrame(wx.Frame):
def __init__(self):
- wx.Frame.__init__(self,None, -1, "Test", size=(300, 200))
+ wx.Frame.__init__(self, None, -1, "Test", size=(300, 200))
sizer = wx.GridSizer(2,2,5,5)
- sizer.Add(MyWindow(self,"blue"),1,wx.GROW)
- sizer.Add(MyWindow(self,"yellow"),1,wx.GROW)
- sizer.Add(MyWindow(self,"red"),1,wx.GROW)
- sizer.Add(MyWindow(self,"green"),1,wx.GROW)
+ sizer.Add(MyWindow(self,"blue"), 1, wx.GROW)
+ sizer.Add(MyWindow(self,"yellow"), 1, wx.GROW)
+ sizer.Add(MyWindow(self,"red"), 1, wx.GROW)
+ sizer.Add(MyWindow(self,"green"), 1, wx.GROW)
self.SetSizer(sizer)
self.Show()
-app = wx.App(False)
-frame = MyFrame()
-app.SetTopWindow(frame)
-app.MainLoop()
+if __name__ == '__main__':
+ app = wx.App(False)
+ frame = MyFrame()
+ app.SetTopWindow(frame)
+ app.MainLoop()
diff --git a/ProceduralTest.py b/ProceduralTest.py
index cf1eee1..85e2556 100755
--- a/ProceduralTest.py
+++ b/ProceduralTest.py
@@ -14,21 +14,22 @@
from sys import exit
+
## Here's an example of a custom dialog with no parent
class MyCheckDialog(wx.Dialog):
def __init__(self, Choices):
wx.Dialog.__init__(self, None, -1, 'wxDialog')
- self.Choices = Choices
+ self.Choices = Choices
self.clb = wx.CheckListBox(self, -1, wx.DefaultPosition, wx.DefaultSize, self.Choices)
ok = wx.Button(self, wx.ID_OK, 'Ok')
-
+
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.clb, 1, wx.EXPAND|wx.ALL, 5)
sizer.Add(ok, 0, wx.ALIGN_RIGHT|wx.ALL^wx.TOP, 5)
self.SetSizer(sizer)
-
+
self.Center() # make it come up on the center of the screen
def GetChecked(self):
@@ -38,42 +39,42 @@ def GetChecked(self):
Checked.append(item)
return Checked
-# You could put some code here, to run before initializing wx.
+# You could put some code here, to run before initializing wx.
# you need to start by initializing a wxApp
-app = wx.App(False)
-
-
-## now you can run your script, bringing up various dialogs.
-
-fd = wx.FileDialog(None,"Pick a File")
-if fd.ShowModal() != wx.ID_OK:
- exit(1)
-else:
- print "You choose the file: ", fd.GetFilename()
-
-md = wx.MessageDialog(None, 'Continue?')
-if md.ShowModal() != wx.ID_OK:
- exit(1)
-else:
- print "You chose to continue"
-
-scd = wx.SingleChoiceDialog(None, 'Pick One',
- 'A Single Choice Dialog',
- ['single', 'choice', 'dialog','with','some','choices'])
-if scd.ShowModal() != wx.ID_OK:
- exit(1)
-else:
- print "You chose:", scd.GetStringSelection()
-
-# now lets get some input on the command line:
-I = raw_input("type something here >>")
-print "You typed:", I
-
-
-myd = MyCheckDialog(['check', 'list', 'box', 'another'])
-if myd.ShowModal() != wx.ID_OK:
- exit(1)
-else:
- print "You checked:", myd.GetChecked()
+if __name__ == '__main__':
+ app = wx.App(False)
+
+ ## now you can run your script, bringing up various dialogs.
+
+ fd = wx.FileDialog(None,"Pick a File")
+ if fd.ShowModal() != wx.ID_OK:
+ exit(1)
+ else:
+ print("You choose the file: ", fd.GetFilename())
+
+ md = wx.MessageDialog(None, 'Continue?')
+ if md.ShowModal() != wx.ID_OK:
+ exit(1)
+ else:
+ print("You chose to continue")
+
+ scd = wx.SingleChoiceDialog(None, 'Pick One',
+ 'A Single Choice Dialog',
+ ['single', 'choice', 'dialog','with','some','choices'])
+ if scd.ShowModal() != wx.ID_OK:
+ exit(1)
+ else:
+ print("You chose:", scd.GetStringSelection())
+
+ # now lets get some input on the command line:
+ I = raw_input("type something here >>")
+ print("You typed:", I)
+
+
+ myd = MyCheckDialog(['check', 'list', 'box', 'another'])
+ if myd.ShowModal() != wx.ID_OK:
+ exit(1)
+ else:
+ print("You checked:", myd.GetChecked())
diff --git a/README.md b/README.md
index 0605186..0f06825 100644
--- a/README.md
+++ b/README.md
@@ -1,45 +1,12 @@
-wxPythonDemos
-=============
+# wxPythonDemos
+wxPython Demos: Various small demos of wxPython features -- dveloped over years of discussion on the wxPython-users mailinglist
-wxPython Demos: Various small demos of wxPython features -- developed over years of discussion on the wxPython-users mailinglist.
+These were put together over many years, and test / demostrate a wide variety or wxPython features.
-This is a collection of a bunch of mini apps, each designed to test one
-small piece of wxPython.
-
-Some of these were done in response to things I was trying to figure out
-myself, and some to help answer a question on the wxPython-users list.
-
-Some of the code I wrote myself, and some was written by other folks on
-the list, and edited by me.
-
-Note that these were written over a long period of time, with a lot of
-wxPython versions. They may not all run under the latest version, and
-some of them are written in very outdated style.
-
-Please don't imitate all the style you see here. For a description of
-good, modern pythonic style, see:
-
-http://wiki.wxpython.org/index.cgi/wxPython_Style_Guide
-
-Despite these flaws, I think there is a lot to be learned from this
-collection.
-
-I suggest you search or grep for a widget you may want to learn somethign about, or just fire up each one and see what it does!
-
-To Do
-----------
-
-One of these days, I'd like to go through the code and clean it all up -- proper modern style, testing on recent wxPyton versions and all OSs, etc.
-
-It would also be great to put in more documentation -- maybe a Sphinx auto-generated doc.
-
-Contributing
---------------
-If you'd like to help out, please feel free to clone the repository and send me pull requests. If you think you'd like to do a fair bit over a period of time, ask me about getting commit privileges.
-
-
--Chris Barker
- PythonCHB@gmail.com
+Since they are so old, many have outdated style, and may not work with py3 and/or wxPython4
+If you find a problem, please post an issue, or even better, a PR with a fix.
+I hope they are useful to you.
+-Chris
diff --git a/RadioBox.py b/RadioBox.py
index a6a9356..bdb6b73 100755
--- a/RadioBox.py
+++ b/RadioBox.py
@@ -1,48 +1,45 @@
-#!/usr/bin/env python2.4
+#!/usr/bin/env python
import wx
+
class DemoFrame(wx.Frame):
""" This window displays a button """
- def __init__(self, title = "Micro App"):
- wx.Frame.__init__(self, None , -1, title)#, size = (800,600), style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
+
+ def __init__(self, title="Micro App"):
+ wx.Frame.__init__(self, None, -1, title)
MenuBar = wx.MenuBar()
FileMenu = wx.Menu()
-
- item = wx.MenuItem(FileMenu, wx.ID_ANY, "&Quit")
- FileMenu.AppendItem(item)
+ item = wx.MenuItem(FileMenu, wx.ID_EXIT, "&Quit")
+ FileMenu.Append(item)
self.Bind(wx.EVT_MENU, self.OnQuit, item)
MenuBar.Append(FileMenu, "&File")
self.SetMenuBar(MenuBar)
+ panel = wx.Panel(self, -1)
- RB = wx.RadioBox(self,
- -1,
- "Hedges",
- wx.DefaultPosition,
- wx.DefaultSize,
- ["ABOUT", "AROUND", "ABOVE", "POSITIVE", "BELOW",
- "VICINITY", "GENERALLY", "CLOSE", "NOT", "SOMEWHAT", "VERY", "EXTREMELY",
- "SLIGHTLY", "AFTER", "BEFORE"],
- 2,
- wx.RA_SPECIFY_COLS)
+ RB = wx.RadioBox(
+ self,
+ label="Hedges",
+ choices=[
+ "ABOUT", "AROUND", "ABOVE", "POSITIVE", "BELOW", "VICINITY",
+ "GENERALLY", "CLOSE", "NOT", "SOMEWHAT", "VERY", "EXTREMELY",
+ "SLIGHTLY", "AFTER", "BEFORE"
+ ],
+ majorDimension=2,
+ style=wx.RA_SPECIFY_COLS)
- wx.EVT_CLOSE(self,self.OnQuit)
+ self.Bind(wx.EVT_CLOSE, self.OnQuit)
- self.Fit()
-
- def OnQuit(self,Event):
+ def OnQuit(self, Event):
self.Destroy()
-app = wx.PySimpleApp(0)
-frame = DemoFrame()
-frame.Show()
-app.MainLoop()
-
-
-
-
+if __name__ == '__main__':
+ app = wx.App(False)
+ frame = DemoFrame()
+ frame.Show()
+ app.MainLoop()
diff --git a/RotatedText.py b/RotatedText.py
index 9fcb0a8..7822b15 100755
--- a/RotatedText.py
+++ b/RotatedText.py
@@ -45,35 +45,35 @@ class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "Double Buffered Test",
wx.DefaultPosition,
- size=(500,500),
+ size=(500, 500),
style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE)
## Set up the MenuBar
MenuBar = wx.MenuBar()
-
+
file_menu = wx.Menu()
ID_EXIT_MENU = wx.NewId()
file_menu.Append(ID_EXIT_MENU, "E&xit","Terminate the program")
- wx.EVT_MENU(self, ID_EXIT_MENU, self.OnQuit)
+ self.Bind(wx.EVT_MENU, self.OnQuit, id=ID_EXIT_MENU)
MenuBar.Append(file_menu, "&File")
-
+
draw_menu = wx.Menu()
ID_DRAW_MENU = wx.NewId()
draw_menu.Append(ID_DRAW_MENU, "&New Drawing","Update the Drawing Data")
- wx.EVT_MENU(self, ID_DRAW_MENU,self.NewDrawing)
+ self.Bind(wx.EVT_MENU, self.NewDrawing, id=ID_DRAW_MENU)
+
BMP_ID = wx.NewId()
- draw_menu.Append(BMP_ID,'&Save Drawing\tAlt-I','')
- wx.EVT_MENU(self,BMP_ID, self.SaveToFile)
+ draw_menu.Append(BMP_ID, '&Save Drawing\tAlt-I', '')
+ self.Bind(wx.EVT_MENU, self.SaveToFile, id=BMP_ID)
MenuBar.Append(draw_menu, "&Draw")
self.SetMenuBar(MenuBar)
-
self.Window = DrawWindow(self)
def OnQuit(self,event):
self.Close(True)
-
+
def NewDrawing(self,event):
self.Window.DrawData = self.MakeNewData()
self.Window.UpdateDrawing()
@@ -85,15 +85,15 @@ def SaveToFile(self,event):
wildcard = "*.png",
style = wx.SAVE)
if dlg.ShowModal() == wx.ID_OK:
- self.Window.SaveToFile(dlg.GetPath(),wx.BITMAP_TYPE_PNG)
+ self.Window.SaveToFile(dlg.GetPath(), wx.BITMAP_TYPE_PNG)
dlg.Destroy()
def MakeNewData(self):
return None
+
class DemoApp(wx.App):
def OnInit(self):
- wx.InitAllImageHandlers() # called so a PNG can be saved
frame = TestFrame()
frame.Show(True)
@@ -107,26 +107,8 @@ def OnInit(self):
return True
+
if __name__ == "__main__":
- print "about to initialize the app"
+ print("about to initialize the app")
app = DemoApp(0)
app.MainLoop()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/ScrolledBitmap.py b/ScrolledBitmap.py
index 50fdbee..d5c5b61 100755
--- a/ScrolledBitmap.py
+++ b/ScrolledBitmap.py
@@ -1,76 +1,63 @@
-#!/usr/bin/env python2.4
+#!/usr/bin/env python
-from wxPython.wx import *
+"""
+Putting an image in a Scrolled Window
+And drawing something over it.
+"""
-class MyCanvas(wxScrolledWindow):
- def __init__(self, parent, id = -1, size = wxDefaultSize):
- wxScrolledWindow.__init__(self, parent, id , wxPoint(0, 0), size, wxSUNKEN_BORDER)
- ##wxScrolledWindow.__init__(self, parent)
- ## read the image in (this is not a good place to do this in a real app)
+import wx
- print "about to Init"
+# set an image file here
+img_filename = 'Images/white_tank.jpg'
- wxInitAllImageHandlers()
- print "done initing"
+class MyCanvas(wx.ScrolledWindow):
+ def __init__(self, *args, **kwargs):
+ wx.ScrolledWindow.__init__(self, *args, **kwargs)
- #img = wxImage("white_tank.jpg",wxBITMAP_TYPE_JPEG )
- #img = wxImage("white_tank.jpg")
- #bmp = img.ConvertToBitmap()
- #jpg = wxImage(opj('bitmaps/image.jpg'), wxBITMAP_TYPE_JPEG).ConvertToBitmap()
+ self.bmp = wx.Image(img_filename).ConvertToBitmap()
- self.bmp = wxImage('Images/white_tank.jpg', wxBITMAP_TYPE_JPEG ).ConvertToBitmap()
+ self.maxWidth, self.maxHeight = self.bmp.GetWidth(), self.bmp.GetHeight()
- print "done loading image"
+ self.SetScrollbars(20, 20, self.maxWidth / 20, self.maxHeight / 20)
- self.maxWidth, self.maxHeight = self.bmp.GetWidth(), self.bmp.GetHeight()
+ self.Bind(wx.EVT_PAINT, self.OnPaint)
- self.SetScrollbars(20, 20, self.maxWidth/20, self.maxHeight/20)
-
- EVT_PAINT(self, self.OnPaint)
+ # an arbitrary rect to draw -- in pixel coords of the image
+ self.rect = (200, 200, 300, 200) # x, y, width, height
def OnPaint(self, event):
- dc = wxPaintDC(self)
+ dc = wx.PaintDC(self)
self.PrepareDC(dc)
- dc.DrawBitmap(self.bmp, 0, 0)
+ dc.SetPen(wx.Pen(wx.RED, 2))
+ dc.SetBrush(wx.Brush((255, 255, 255, 85)))
-class TestFrame(wxFrame):
- def __init__(self,parent, id,title,position,size):
- wxFrame.__init__(self,parent, id,title,position, size)
+ dc.DrawBitmap(self.bmp, 0, 0)
+ dc.DrawRectangle(*self.rect)
- EVT_CLOSE(self, self.OnCloseWindow)
+class TestFrame(wx.Frame):
+ def __init__(self, *args, **kwargs):
+ wx.Frame.__init__(self, *args, **kwargs)
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
- self.Canvas1 = MyCanvas(self, wxNewId() )
+ self.Canvas = MyCanvas(self)
def OnCloseWindow(self, event):
self.Destroy()
-class App(wxApp):
+
+class App(wx.App):
def OnInit(self):
- frame = TestFrame(NULL, -1, "Scroll Test", wxDefaultPosition,(550,200))
+ frame = TestFrame(None, title="Scroll Test", size=(800, 700))
self.SetTopWindow(frame)
frame.Show(True)
- return true
+ return True
-if __name__ == "__main__":
-
- app = App(0)
- print "about to start Mainloop"
+if __name__ == "__main__":
+ app = App(False)
app.MainLoop()
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/SelectText.py b/SelectText.py
index 9cdc754..fb7a9d9 100755
--- a/SelectText.py
+++ b/SelectText.py
@@ -1,14 +1,11 @@
-#!/usr/bin/env python2.3
-
-import wxversion
-wxversion.select("2.5")
+#!/usr/bin/env python
import wx
BUFFERED = 1
-class Shape:
+class Shape:
def HitTest(self, pt):
rect = self.GetRect()
return rect.InsideXY(pt.x, pt.y)
@@ -55,29 +52,30 @@ def HitTest(self, pt):
return rect.InsideXY(pt.x, pt.y)
- def Draw(self, dc, op = wx.COPY):
- font = wx.Font(36, wx.MODERN, wx.NORMAL, wx.NORMAL, 0, "Arial")
+ def Draw(self, dc, op=wx.COPY):
+ font = wx.Font(36, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, "Arial")
#text1 = "Hi there, this is some text"
- #textExtent = self.GetFullTextExtent(text1, font)
+ #textExtent = self.GetFullTextExtent(text1, font)
dc.SetTextForeground(wx.BLACK)
dc.SetFont(font)
- if self.Size is None:
+ if self.Size is None:
self.Size = dc.GetTextExtent(self.string)
dc.DrawText(self.string, self.pos[0], self.pos[1])
+
#----------------------------------------------------------------------
class MyCanvas(wx.ScrolledWindow):
def __init__(self, parent, id = -1, size = wx.DefaultSize):
wx.ScrolledWindow.__init__(self, parent, id, (0, 0), size=size, style=wx.SUNKEN_BORDER | wx.NO_FULL_REPAINT_ON_RESIZE)
-
+
self.shapes = []
self.shape1 = []
self.shape2 = []
-
+
self.dragImage = None
self.dragShape = None
self.hiliteShape = None
-
+
self.lines = []
self.maxWidth = 1000
self.maxHeight = 1000
@@ -85,12 +83,12 @@ def __init__(self, parent, id = -1, size = wx.DefaultSize):
self.curLine = []
self.drawing = False
- self.bg_bmp = wx.Bitmap("BG.jpg", wx.BITMAP_TYPE_ANY)
+ self.bg_bmp = wx.Bitmap("Images/BG.jpg", wx.BITMAP_TYPE_ANY)
self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
- self.SetScrollbars(80, 25, self.maxWidth/20, self.maxHeight/20)
+ self.SetScrollbars(80, 25, self.maxWidth / 20, self.maxHeight / 20)
-#-----------------------------------------------------------------------------------
+#-----------------------------------------------------------------------------------
if BUFFERED:
# Initialize the buffer bitmap. No real DC is needed at this point.
@@ -106,7 +104,6 @@ def __init__(self, parent, id = -1, size = wx.DefaultSize):
self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
self.Bind(wx.EVT_MOTION, self.OnMotion)
self.Bind(wx.EVT_PAINT, self.OnPaint)
-
def getWidth(self):
return self.maxWidth
@@ -122,7 +119,6 @@ def OnPaint(self, event):
self.PrepareDC(dc)
self.DoDrawing(dc)
-
def DoDrawing(self, dc, printing=False):
dc.BeginDrawing()
@@ -130,16 +126,16 @@ def DoDrawing(self, dc, printing=False):
text1 = TextShape("Hi there, this is some text")
text1.pos = (25, 25)
self.shapes.append(text1)
-
+
bmp = wx.EmptyBitmap(845, 1079)
shape1 = DragShape(bmp)
shape1.pos = (125, 55)
- shape1.fullscreen = False
+ shape1.fullscreen = False
self.shapes.append(shape1)
-
+
dc = wx.MemoryDC()
dc.SelectObject(bmp)
-
+
bmp2 = wx.Bitmap("Paper.jpg", wx.BITMAP_TYPE_ANY)
dc.DrawBitmap(bmp2, -14, -15)
@@ -154,7 +150,6 @@ def ConvertEventCoords(self, event):
return (event.GetX() + (xView * xDelta),
event.GetY() + (yView * yDelta))
-
# tile the background bitmap
def TileBackground(self, dc):
sz = self.GetClientSize()
@@ -172,7 +167,6 @@ def TileBackground(self, dc):
x = x + w
-
# Go through our list of shapes and draw them in whatever place they are.
def DrawShapes(self, dc):
for shape in self.shapes:
@@ -245,12 +239,12 @@ def OnLeftUp(self, evt):
self.hiliteShape = None
-
+
self.dragShape.pos = (
self.dragShape.pos[0] + evt.GetPosition()[0] - self.dragStartPos[0],
self.dragShape.pos[1] + evt.GetPosition()[1] - self.dragStartPos[1]
)
-
+
self.dragShape.shown = True
self.dragShape.Draw(dc)
self.dragShape = None
@@ -320,11 +314,12 @@ def OnMotion(self, evt):
# now move it and show it again if needed
self.dragImage.Move(evt.GetPosition())
if unhiliteOld or hiliteNew:
- self.dragImage.Show()
+ self.dragImage.Show()
+
if __name__ == '__main__':
- app = wx.PySimpleApp(0)
- frame = wx.Frame(None,-1,"A Test Frame")
+ app = wx.App(0)
+ frame = wx.Frame(None, -1, "A Test Frame")
win = MyCanvas(frame)
frame.Show()
app.MainLoop()
diff --git a/SeparateThread.py b/SeparateThread.py
index 8e5310c..afae68f 100755
--- a/SeparateThread.py
+++ b/SeparateThread.py
@@ -14,37 +14,40 @@
import DoubleBufferDemo
+
class MicroFrame(wx.Frame):
pass
+
class MicroApp(wx.App):
def OnInit(self):
f = MicroFrame(None, title="threading demo")
f.Show()
-
+
self.startup_event
return True
-
-
+
+
class wxThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
-
+
self.startup_event = startup_event = threading.Event()
-
+
def run(self):
- print "starting up the wx app"
+ print("starting up the wx app")
self.app = DoubleBufferDemo.DemoApp(False)
- print "app started --- starting the mainloop"
+ print("app started --- starting the mainloop")
self.startup_event.set()
self.app.MainLoop()
+
if __name__ == "__main__":
wxt = wxThread()
startup_event = wxt.startup_event
wxt.start()
- print "thread started..."
+ print("thread started...")
# wait for the wx.Frame to be created
startup_event.wait()
@@ -52,6 +55,5 @@ def run(self):
# run an endless loop to do re-draw...
while True:
time.sleep(0.5)
- print "another moment passed..."
+ print("another moment passed...")
frame.NewDrawing()
-
diff --git a/SimpleSizer.py b/SimpleSizer.py
index 582151e..0b1de52 100755
--- a/SimpleSizer.py
+++ b/SimpleSizer.py
@@ -1,44 +1,35 @@
-#!/usr/bin/env python2.3
+#!/usr/bin/env python
import wx
+
class TestFrame(wx.Frame):
- def __init__(self,parent, id,title,position,size):
+ def __init__(self, parent, id, title, position, size):
- wx.Frame.__init__(self, parent, -1, title, style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
+ wx.Frame.__init__(self, parent, -1, title, style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE)
self.panel1 = wx.Panel(self, -1, wx.DefaultPosition, wx.DefaultSize, wx.SUNKEN_BORDER)
self.exit = wx.Button(self, -1, "Exit")
- wx.EVT_BUTTON(self, self.exit.GetId(), self.OnCloseWindow)
+ self.exit.Bind(wx.EVT_BUTTON, self.OnCloseWindow)
box = wx.BoxSizer(wx.VERTICAL)
- box.Add(self.panel1,1, wx.EXPAND|wx.ALL,10)
- box.Add(self.exit,0, wx.ALIGN_BOTTOM|wx.ALIGN_RIGHT|wx.ALL, 4)
+ box.Add(self.panel1, 1, wx.EXPAND | wx.ALL, 10)
+ box.Add(self.exit, 0, wx.ALIGN_BOTTOM | wx.ALIGN_RIGHT | wx.ALL, 4)
self.SetSizer(box)
- wx.EVT_CLOSE(self, self.OnCloseWindow)
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def OnCloseWindow(self, event):
self.Destroy()
+
class App(wx.App):
def OnInit(self):
- frame = TestFrame(wx.NULL, -1, "Sizer Test", wx.DefaultPosition,(400,400))
+ frame = TestFrame(None, -1, "Sizer Test", wx.DefaultPosition, (400, 400))
self.SetTopWindow(frame)
frame.Show(True)
return True
+
if __name__ == "__main__":
app = App(0)
app.MainLoop()
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/SimpleSizer2.py b/SimpleSizer2.py
index 6245991..0dfb473 100755
--- a/SimpleSizer2.py
+++ b/SimpleSizer2.py
@@ -1,13 +1,14 @@
-#!/usr/bin/env python2.3
+#!/usr/bin/env python
# I Always specify the python version in the #! line, it makes it much
# easier to have multiple versions on your system
import wx
+
class ColoredPanel(wx.Panel):
def __init__(self, parent, color):
- wx.Panel.__init__(self, parent, -1, style = wx.SIMPLE_BORDER)
+ wx.Panel.__init__(self, parent, -1, style=wx.SIMPLE_BORDER)
self.SetBackgroundColour(color)
self.exit = wx.Button(self, -1, "Exit")
@@ -17,54 +18,44 @@ def __init__(self, parent, color):
# and here it is if you want to add more controls.
box = wx.BoxSizer(wx.VERTICAL)
- box.Add(self.exit,0, wx.ALL, 4)
+ box.Add(self.exit, 0, wx.ALL, 4)
self.SetSizer(box)
self.Fit()
- def OnExit(self,Event):
+ def OnExit(self, event):
# Note: this is an ugly way to do this...
self.GetParent().OnCloseWindow(None)
-
-
+
+
class TestFrame(wx.Frame):
- def __init__(self,parent, id,title,position,size):
+ def __init__(self, parent, id, title, position, size):
- wx.Frame.__init__(self, parent, -1, title, style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
+ wx.Frame.__init__(self, parent, -1, title, style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE)
self.panel1 = wx.Panel(self, -1, wx.DefaultPosition, wx.DefaultSize, wx.SUNKEN_BORDER)
self.panel2 = ColoredPanel(self, wx.RED)
box = wx.BoxSizer(wx.VERTICAL)
- box.Add(self.panel1,1, wx.EXPAND|wx.ALL)
- box.Add(self.panel2,0, wx.ALIGN_BOTTOM|wx.ALIGN_RIGHT)
+ box.Add(self.panel1, 1, wx.EXPAND | wx.ALL)
+ box.Add(self.panel2, 0, wx.ALIGN_BOTTOM | wx.ALIGN_RIGHT)
self.SetSizer(box)
- self.Show(1)
+ self.Show(1)
- wx.EVT_CLOSE(self, self.OnCloseWindow)
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def OnCloseWindow(self, event):
self.Destroy()
+
class App(wx.App):
def OnInit(self):
- frame = TestFrame(wx.NULL, -1, "Sizer Test", wx.DefaultPosition,(400,400))
+ frame = TestFrame(None, -1, "Sizer Test", wx.DefaultPosition, (400, 400))
self.SetTopWindow(frame)
frame.Show(True)
return True
+
if __name__ == "__main__":
app = App(0)
app.MainLoop()
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/SimpleSizer3.py b/SimpleSizer3.py
index f3b84b8..c18d019 100755
--- a/SimpleSizer3.py
+++ b/SimpleSizer3.py
@@ -1,20 +1,20 @@
-#!/usr/bin/env python2.3
+#!/usr/bin/env python
import wx
class TestFrame(wx.Frame):
- def __init__(self, parent, ID, title = ""):
+ def __init__(self, parent, ID, title=""):
wx.Frame.__init__(self, parent, -1, title, style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
ID_CODE = wx.NewId()
# Set Controls
label_name = wx.StaticText(self, -1, "Name: ")
- self.name = wx.TextCtrl(self, -1, "A name", wx.DefaultPosition, (200,20))
+ self.name = wx.TextCtrl(self, -1, "A name", wx.DefaultPosition, (200, 20))
label_sysfile = wx.StaticText(self, -1, "System file: ")
- self.sysfile = wx.TextCtrl(self, -1, " A file", wx.DefaultPosition, (200,20))
+ self.sysfile = wx.TextCtrl(self, -1, " A file", wx.DefaultPosition, (200, 20))
button_sysfile = wx.Button(self, ID_CODE, "View Code")
label_sysname = wx.StaticText(self, -1, "System name: ")
- self.sysname = wx.TextCtrl(self, -1, " A sysname", wx.DefaultPosition, (200,20))
+ self.sysname = wx.TextCtrl(self, -1, " A sysname", wx.DefaultPosition, (200, 20))
line = wx.StaticLine(self, -1)
buttonOK = wx.Button(self, wx.ID_OK, "OK")
buttonOK.SetDefault()
@@ -23,42 +23,42 @@ def __init__(self, parent, ID, title = ""):
# Do Layout
sizer = wx.BoxSizer(wx.VERTICAL)
-
box1 = wx.BoxSizer(wx.HORIZONTAL)
box1.Add(label_name, 0, wx.LEFT, 5)
- box1.Add((1,1), 1)
+ box1.Add((1, 1), 1)
box1.Add(self.name, 0, wx.ALIGN_RIGHT, 5)
- sizer.Add(box1, 0, wx.EXPAND|wx.ALL, 5)
+ sizer.Add(box1, 0, wx.EXPAND | wx.ALL, 5)
box5 = wx.BoxSizer(wx.HORIZONTAL)
box5.Add(label_sysfile, 0, wx.LEFT, 5)
- box5.Add((1,1), 1)
- box5.Add(self.sysfile, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER, 5)
- sizer.Add(box5, 0, wx.EXPAND|wx.ALL, 5)
- sizer.Add(button_sysfile, 0, wx.ALIGN_TOP|wx.ALIGN_RIGHT, 5)
+ box5.Add((1, 1), 1)
+ box5.Add(self.sysfile, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER, 5)
+ sizer.Add(box5, 0, wx.EXPAND | wx.ALL, 5)
+ sizer.Add(button_sysfile, 0, wx.ALIGN_TOP | wx.ALIGN_RIGHT, 5)
sizer.Add((1,10), 0, wx.EXPAND)
box6 = wx.BoxSizer(wx.HORIZONTAL)
box6.Add(label_sysname, 0, wx.LEFT, 5)
- box6.Add((1,1), 1, wx.GROW)
+ box6.Add((1, 1), 1, wx.GROW)
box6.Add(self.sysname, 0, wx.ALIGN_RIGHT, 5)
- sizer.Add(box6, 0, wx.EXPAND|wx.ALL, 5)
+ sizer.Add(box6, 0, wx.EXPAND | wx.ALL, 5)
- sizer.Add(line, 0, wx.EXPAND|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
- sizer.Add((1,1), 1, wx.EXPAND)
+ sizer.Add(line, 0, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
+ sizer.Add((1, 1), 1, wx.EXPAND)
box7 = wx.BoxSizer(wx.HORIZONTAL)
- box7.Add(buttonOK, 0, wx.ALIGN_CENTER|wx.ALL, 5)
- box7.Add(buttonCancel, 0, wx.ALIGN_CENTER|wx.ALL, 5)
- sizer.Add(box7, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, 5)
+ box7.Add(buttonOK, 0, wx.ALIGN_CENTER | wx.ALL, 5)
+ box7.Add(buttonCancel, 0, wx.ALIGN_CENTER | wx.ALL, 5)
+ sizer.Add(box7, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5)
self.SetSizer(sizer)
self.SetAutoLayout(True)
sizer.Fit(self)
-
+
def OnCloseWindow(self, event):
self.Destroy()
+
class App(wx.App):
def OnInit(self):
frame = TestFrame(None, -1, "Sizer Test")
@@ -66,18 +66,7 @@ def OnInit(self):
frame.Show(True)
return True
+
if __name__ == "__main__":
app = App(0)
app.MainLoop()
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/SimpleSizer4.py b/SimpleSizer4.py
index 082cf46..a5871b4 100755
--- a/SimpleSizer4.py
+++ b/SimpleSizer4.py
@@ -1,36 +1,36 @@
-#!/usr/bin/env python2.3
+#!/usr/bin/env python
import wx
+
class TestFrame(wx.Frame):
def __init__(self, parent, ID, title = ""):
wx.Frame.__init__(self, parent, -1, title, style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
self.vbox = wx.BoxSizer(wx.VERTICAL)
-
# Amount/Cleared Row
Space = 4
self.amountrow = wx.BoxSizer(wx.HORIZONTAL)
- self.amountrow.Add(wx.StaticText(self,-1,"Amount"), 0, wx.ALL, Space)
+ self.amountrow.Add(wx.StaticText(self, -1, "Amount"), 0, wx.ALL, Space)
- self.amount = wx.TextCtrl(self,-1,"",size=wx.Size(80,-1))
+ self.amount = wx.TextCtrl(self,-1, "", size=wx.Size(80,-1))
self.amountrow.Add(self.amount, 1, wx.ALL, Space)
self.cleared = wx.CheckBox(self,-1,"Cleared")
self.amountrow.Add(self.cleared, 0, wx.ALIGN_RIGHT | wx.ALL, Space)
self.vbox.Add(self.amountrow, 0, wx.EXPAND | wx.ALL, Space)
-
+
# Memo/Button box
self.buttonrow = wx.BoxSizer(wx.HORIZONTAL)
- self.buttonrow.Add(wx.StaticText(self,-1,"Memo"), 0, wx.ALL, Space)
- self.memo = wx.TextCtrl(self,-1,"",size=wx.Size(80,-1))
+ self.buttonrow.Add(wx.StaticText(self, -1, "Memo"), 0, wx.ALL, Space)
+ self.memo = wx.TextCtrl(self, -1, "",size=wx.Size(80,-1))
self.buttonrow.Add(self.memo, 0, wx.ALL, Space)
- self.ok_button = wx.Button(self,wx.ID_OK,"OK")
+ self.ok_button = wx.Button(self, wx.ID_OK, "OK")
self.ok_button.SetDefault()
- self.cancel_button = wx.Button(self,wx.ID_CANCEL,"Cancel")
+ self.cancel_button = wx.Button(self, wx.ID_CANCEL, "Cancel")
self.buttonrow.Add(self.ok_button, 0, wx.ALL, Space)
self.buttonrow.Add(self.cancel_button, 0, wx.ALL, Space)
self.vbox.Add(self.buttonrow, 0, wx.ALL, Space)
@@ -38,11 +38,12 @@ def __init__(self, parent, ID, title = ""):
self.vbox.Layout()
self.SetSizerAndFit(self.vbox)
- return True
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def OnCloseWindow(self, event):
self.Destroy()
+
class App(wx.App):
def OnInit(self):
frame = TestFrame(None, -1, "Sizer Test")
@@ -50,18 +51,7 @@ def OnInit(self):
frame.Show(True)
return True
+
if __name__ == "__main__":
app = App(0)
app.MainLoop()
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/SizerTest.py b/SizerTest.py
index 8855b04..26f354d 100755
--- a/SizerTest.py
+++ b/SizerTest.py
@@ -1,13 +1,14 @@
-#!/usr/bin/env python2.3
+#!/usr/bin/env python
import wx
+
class MainWindow(wx.Frame):
""" This window displays a button """
- def __init__(self,parent,id,title):
+ def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent , -1, title)
- self.List = map(str, range(10) ) # just to get a list of text items
+ self.List = map(str, range(10)) # just to get a list of text items
#Create a box inside to contain everything except the outputbox
@@ -21,7 +22,7 @@ def __init__(self,parent,id,title):
#Create a flexsizer to contain other widgets (everything except the
#outputbox) need 2 rows and 9 columns
# 18 widgets?, I count ten. and you had rows and columns backward.
- flexsizer= wx.FlexGridSizer(5,2,0,0)
+ flexsizer= wx.FlexGridSizer(5, 2, 0, 0)
#Create a box to which to write output
self.outputbox = wx.TextCtrl(self, -1, "",size=wx.DefaultSize,
@@ -29,17 +30,17 @@ def __init__(self,parent,id,title):
self.file_input = wx.RadioButton(self, 31, label='Read input from file',
- pos=(-1,-1))
+ pos=(-1, -1))
self.gui_input = wx.RadioButton(self, 36, label='Select command below',
- pos=(1,-1))
+ pos=(1, -1))
#wx.EVT_RADIOBUTTON(self, 31, self.SetMode)
#wx.EVT_RADIOBUTTON(self, 36, self.SetMode)
#was this ever used?
#radiosizer = wx.BoxSizer(wx.HORIZONTAL)
- flexsizer.Add(self.file_input,1,wx.ALL, 10)
- flexsizer.Add(self.gui_input,1, wx.EXPAND|wx.ALL, 15)
+ flexsizer.Add(self.file_input, 1, wx.ALL, 10)
+ flexsizer.Add(self.gui_input, 1, wx.EXPAND | wx.ALL, 15)
#Create combosizer which will contain the combobox and its label
combosizer = wx.BoxSizer(wx.HORIZONTAL)
@@ -52,8 +53,8 @@ def __init__(self,parent,id,title):
self.List, wx.CB_DROPDOWN)
#wx.EVT_COMBOBOX(self, 30, self.CommandCallback)
- combosizer.Add(self.combolabel, 1, wx.EXPAND|wx.ALL, 10)
- combosizer.Add(self.combo, 2, wx.EXPAND|wx.ALL, 10)
+ combosizer.Add(self.combolabel, 1, wx.EXPAND | wx.ALL, 10)
+ combosizer.Add(self.combo, 2, wx.EXPAND | wx.ALL, 10)
flexsizer.Add(combosizer, 2, wx.EXPAND, 10)
#Create a box to accept parameters
@@ -61,54 +62,62 @@ def __init__(self,parent,id,title):
self.parameters=wx.TextCtrl(self,-1,"", size=wx.DefaultSize)
parametersizer = wx.BoxSizer(wx.HORIZONTAL)
- parametersizer.Add(self.parameterslabel,0,wx.ALL, 10)
- parametersizer.Add(self.parameters,1, wx.ALL, 15)
+ parametersizer.Add(self.parameterslabel, 0, wx.ALL, 10)
+ parametersizer.Add(self.parameters, 1, wx.ALL, 15)
flexsizer.Add(parametersizer,1,3,wx.ALL,10)
#Create button 1
- self.buttonone = wx.Button(self, 32, label= "ONE",
- style = wx.BU_BOTTOM ,size=(150,20),
- name = "one")
- #wx.EVT_BUTTON(self, 32, self.One_Func)
+ self.buttonone = wx.Button(self, 32, label="ONE", style = wx.BU_BOTTOM,
+ size=(150, 20), name = "one")
+ self.buttonone.Bind(wx.EVT_BUTTON, self.OnButton)
#Create button 2
- self.buttontwo = wx.Button(self, 33, label= "TWO",
- style = wx.BU_BOTTOM ,size=(150,20),
- name = "two")
- #wx.EVT_BUTTON(self, 33, self.Two_Func)
+ self.buttontwo = wx.Button(self, 33, label="TWO", style=wx.BU_BOTTOM,
+ size=(150, 20), name="two")
+ self.buttontwo.Bind(wx.EVT_BUTTON, self.OnButton)
+
#Create button 3
- self.buttonthree = wx.Button(self, 34, label= "THREE",
- style = wx.BU_BOTTOM ,size=(150,20),
- name = "three")
- #wx.EVT_BUTTON(self, 34, self.Three_Func)
+ self.buttonthree = wx.Button(self, 34, label="THREE", style=wx.BU_BOTTOM,
+ size=(150, 20), name="three")
+ self.buttonthree.Bind(wx.EVT_BUTTON, self.OnButton)
+
#Create button 4
- self.buttonfour = wx.Button(self, 35, label= "FOUR",
- style = wx.BU_BOTTOM ,size=(150,20),
- name = "four")
- #wx.EVT_BUTTON(self, 35, self.Four_Func)
+ self.buttonfour = wx.Button(self, 35, label="FOUR", style=wx.BU_BOTTOM,
+ size=(150, 20), name="four")
+ self.buttonfour.Bind(wx.EVT_BUTTON, self.OnButton)
+
timeoutwarning=wx.StaticText(self, -1, 'Disable Timeouts Prior to Use')
- flexsizer.Add(self.buttonone,4, wx.ALL|wx.ALIGN_RIGHT, 10)
- flexsizer.Add(self.buttontwo, 5, wx.ALL|wx.ALIGN_RIGHT, 10)
- flexsizer.Add(self.buttonthree, 6, wx.ALL|wx.ALIGN_RIGHT, 10)
- flexsizer.Add(self.buttonfour, 8, wx.ALL|wx.ALIGN_RIGHT, 10)
- flexsizer.Add(timeoutwarning, 9, wx.ALL|wx.ALIGN_BOTTOM, 10)
+ flexsizer.Add(self.buttonone,4, wx.ALL | wx.ALIGN_RIGHT, 10)
+ flexsizer.Add(self.buttontwo, 5, wx.ALL | wx.ALIGN_RIGHT, 10)
+ flexsizer.Add(self.buttonthree, 6, wx.ALL | wx.ALIGN_RIGHT, 10)
+ flexsizer.Add(self.buttonfour, 8, wx.ALL | wx.ALIGN_RIGHT, 10)
+ flexsizer.Add(timeoutwarning, 9, wx.ALL | wx.ALIGN_BOTTOM, 10)
#Now add the output box and the flexgridsizer to the outerboxsize
#Create the outer sizer which is essentially the main window
# no, it's not a Window...it does do the layout for the main window.
# I like to build fromt eh inside out, so I put this here. It's really a matter of taste.
outerboxsizer = wx.BoxSizer(wx.VERTICAL)
- outerboxsizer.Add(self.outputbox, 1, wx.EXPAND|wx.ALL, 10)
+ outerboxsizer.Add(self.outputbox, 1, wx.EXPAND | wx.ALL, 10)
outerboxsizer.Add(flexsizer)
#Connect the outerboxsizer to the window (self)
self.SetSizer(outerboxsizer)
self.Fit()
-
+
+ self.Bind(wx.EVT_CLOSE, self.OnQuit)
+
+ def OnButton(self, event):
+ print(event.GetEventObject().GetLabel())
+ evtId = event.GetId()
+ if evtId == 32: print('1')
+ elif evtId == 33: print('2')
+ elif evtId == 34: print('3')
+ elif evtId == 35: print('4')
def SetMode(self):
pass
@@ -116,21 +125,17 @@ def SetMode(self):
def OnQuit(self,Event):
self.Destroy()
-
+
class MyApp(wx.App):
def OnInit(self):
frame = MainWindow(None, -1, "Micro App")
self.SetTopWindow(frame)
frame.Show()
-
- return True
-
-
-app = MyApp(0)
-app.MainLoop()
-
-
+ return True
+if __name__ == "__main__":
+ app = MyApp(0)
+ app.MainLoop()
diff --git a/SizerTest2.py b/SizerTest2.py
index 7db9776..53132de 100755
--- a/SizerTest2.py
+++ b/SizerTest2.py
@@ -1,82 +1,83 @@
-#!/usr/bin/env python2.3
+#!/usr/bin/env python
+"""
+A semi-complicated example of sizer use
+"""
import wx
+
class MyFrame(wx.Frame):
- def __init__(self, parent, id, name):
- wx.Frame.__init__ (self,
- parent,
- id,
- name,
- size = wx.DefaultSize,
- style = (wx.DEFAULT_DIALOG_STYLE |
- wx.MAXIMIZE_BOX |
- wx.THICK_FRAME |
- wx.RESIZE_BORDER)
- )
- self.status = self.CreateStatusBar()
-
- btn1above = wx.Button(self, -1, "Create")
- btn2above = wx.Button(self, -1, "Ok")
- btn1right = wx.Button(self, -1, "Cancel")
- btnbrowser = wx.Button(self, -1, "Browse")
- btnmenu = wx.Button(self, -1, "Menu")
- lst = wx.ListCtrl(self, -1)
- self.chkMatchCase = wx.CheckBox(self, -1, "Match Case")
- self.chkRegularExpression = wx.CheckBox(self, -1,"RegularExpression")
- self.chkSubDirectories = wx.CheckBox(self, -1, "Subdirectories")
+ def __init__(self, parent, id, title):
+ wx.Frame.__init__(
+ self,
+ parent,
+ id,
+ title,
+ size=wx.DefaultSize,
+ style=wx.DEFAULT_DIALOG_STYLE | wx.MAXIMIZE_BOX |
+ # wx.THICK_FRAME |
+ wx.RESIZE_BORDER)
+ self.status = self.CreateStatusBar()
+
+ btn1above = wx.Button(self, -1, "Create")
+ btn2above = wx.Button(self, -1, "Ok")
+ btn1right = wx.Button(self, -1, "Cancel")
+ btnbrowser = wx.Button(self, -1, "Browse")
+ btnmenu = wx.Button(self, -1, "Menu")
+ lst = wx.ListCtrl(self, -1)
+ self.chkMatchCase = wx.CheckBox(self, -1, "Match Case")
+ self.chkRegularExpression = wx.CheckBox(self, -1, "RegularExpression")
+ self.chkSubDirectories = wx.CheckBox(self, -1, "Subdirectories")
+
+ helpsizer = wx.BoxSizer(wx.VERTICAL)
+ helpsizer.Add((0, 5), 0, wx.ALL, 0)
+ helpsizer.Add(btnbrowser, 0, wx.ALL, 0)
+ helpsizer.Add((0, 30), 0, wx.ALL, 0)
+ helpsizer.Add(btnmenu, 0, wx.ALL, 0)
+ helpsizer.Add((0, 40), 0, wx.ALL, 0)
+ helpsizer.Add(btn1above, 0, wx.ALL, 0)
+ helpsizer.Add((0, 5), 0, wx.ALL, 0)
+ helpsizer.Add(self.chkRegularExpression, 0, wx.ALL, 0)
+ helpsizer.Add((0, 25), 0, wx.ALL, 0)
+ helpsizer.Add(self.chkMatchCase, 0, wx.ALL, 0)
+ helpsizer.Add((0, 5), 0, wx.ALL, 0)
+ helpsizer.Add(self.chkSubDirectories, 0, wx.ALL, 0)
+ helpsizer.Add((0, 30), 0, wx.ALL, 0)
+ helpsizer.Add(btn2above, 0, wx.ALL, 0)
+ helpsizer.Add((0, 10), 0, wx.ALL, 0)
+ helpsizer.Add(btn1right, 0, wx.ALL, 0)
-# status = wx.StatusBar(self, -1)
-
- helpsizer = wx.BoxSizer(wx.VERTICAL)
- helpsizer.Add((0, 5), 0, wx.ALL, 0)
- helpsizer.Add(btnbrowser, 0, wx.ALL, 0)
- helpsizer.Add((0, 30), 0, wx.ALL, 0)
- helpsizer.Add(btnmenu, 0, wx.ALL, 0)
- helpsizer.Add((0, 40), 0, wx.ALL, 0)
- helpsizer.Add(btn1above, 0, wx.ALL, 0)
- helpsizer.Add((0, 5), 0, wx.ALL, 0)
- helpsizer.Add(self.chkRegularExpression, 0, wx.ALL, 0)
- helpsizer.Add((0, 25), 0, wx.ALL, 0)
- helpsizer.Add(self.chkMatchCase, 0, wx.ALL, 0)
- helpsizer.Add((0, 5), 0, wx.ALL, 0)
- helpsizer.Add(self.chkSubDirectories, 0, wx.ALL, 0)
- helpsizer.Add((0, 30), 0, wx.ALL, 0)
- helpsizer.Add(btn2above, 0, wx.ALL, 0)
- helpsizer.Add((0, 10), 0, wx.ALL, 0)
- helpsizer.Add(btn1right, 0, wx.ALL, 0)
+ stat1 = wx.StaticText(self, -1, "Directory:")
+ stat2 = wx.StaticText(self, -1, "File Pattern:")
+ stat3 = wx.StaticText(self, -1, "Search For:")
+ text1 = wx.ComboBox(self, -1, "", wx.DefaultPosition, (300, -1))
+ text2 = wx.ComboBox(self, -1, "")
+ text3 = wx.ComboBox(self, -1, "")
- stat1 = wx.StaticText(self, -1, "Directory:")
- stat2 = wx.StaticText(self, -1, "File Pattern:")
- stat3 = wx.StaticText(self, -1, "Search For:")
- text1 = wx.ComboBox(self, -1, "", wx.DefaultPosition, (300,-1))
- text2 = wx.ComboBox(self, -1, "")
- text3 = wx.ComboBox(self, -1, "")
+ topsizer = wx.FlexGridSizer(3, 2, 5, 5)
+ topsizer.AddGrowableCol(1)
+ topsizer.Add(stat1, 0)
+ topsizer.Add(text1, 1, wx.GROW)
+ topsizer.Add(stat2, 0)
+ topsizer.Add(text2, 1, wx.GROW)
+ topsizer.Add(stat3, 0)
+ topsizer.Add(text3, 1, wx.GROW)
- topsizer = wx.FlexGridSizer(2,2,5,5)
- topsizer.AddGrowableCol(1)
- topsizer.Add(stat1,0)
- topsizer.Add(text1,1,wx.GROW)
- topsizer.Add(stat2,0)
- topsizer.Add(text2,1,wx.GROW)
- topsizer.Add(stat3,0)
- topsizer.Add(text3,1,wx.GROW)
+ leftSizer = wx.BoxSizer(wx.VERTICAL)
+ leftSizer.Add(topsizer, 0, wx.EXPAND | wx.ALL, 5)
+ leftSizer.Add(lst, 1, wx.EXPAND | wx.ALL, 5)
- leftSizer = wx.BoxSizer(wx.VERTICAL)
- leftSizer.Add(topsizer,0, wx.EXPAND | wx.ALL, 5)
- leftSizer.Add(lst,1, wx.EXPAND | wx.ALL, 5)
-
- newSizer = wx.BoxSizer(wx.HORIZONTAL)
- newSizer.Add(leftSizer,1, wx.EXPAND | wx.ALL, 10)
- newSizer.Add(helpsizer,0, wx.ALIGN_TOP | wx.ALL, 10)
- lastSizer = wx.BoxSizer(wx.VERTICAL)
- self.SetSizer(newSizer)
+ newSizer = wx.BoxSizer(wx.HORIZONTAL)
+ newSizer.Add(leftSizer, 1, wx.EXPAND | wx.ALL, 10)
+ newSizer.Add(helpsizer, 0, wx.ALIGN_TOP | wx.ALL, 10)
+ lastSizer = wx.BoxSizer(wx.VERTICAL)
+ self.SetSizer(newSizer)
- self.Fit()
- self.Show()
-
-app = wx.PySimpleApp()
-Panel = MyFrame(None, -1, "Find Files")
+ self.Fit()
+ self.Show()
-app.MainLoop()
+if __name__ == "__main__":
+ app = wx.App(False)
+ Panel = MyFrame(None, wx.ID_ANY, title="Find Files")
+ app.MainLoop()
diff --git a/SizerTest3.py b/SizerTest3.py
index 2267138..861d133 100755
--- a/SizerTest3.py
+++ b/SizerTest3.py
@@ -1,35 +1,32 @@
-#!/usr/bin/env python2.3
+#!/usr/bin/env python
import wx
+
class MyFrame(wx.Frame):
- def __init__(self, parent, id, name):
- wx.Frame.__init__ (self,
- parent,
- id,
- name,
- size = (300,300)
- )
+ def __init__(self, parent, id, title):
+ wx.Frame.__init__ (self, parent, id, title, size = (300, 300))
globalSizer=wx.BoxSizer(wx.VERTICAL)
-
+
title=wx.StaticText(self, -1, "Title")
nameText = wx.StaticText(self, -1, "Name")
- self.NameTextCtrl = wx.TextCtrl(self,wx.NewId(), "", size = (500,25))
-
+ self.NameTextCtrl = wx.TextCtrl(self,wx.NewId(), "", size=(500, 25))
+
self.ListCtrl = wx.ListCtrl(self, wx.NewId())
-
+
globalSizer.Add(title , 0, wx.ALIGN_LEFT | wx.BOTTOM, 5)
globalSizer.Add(nameText, 0, wx.ALIGN_LEFT)
globalSizer.Add(self.NameTextCtrl ,0,wx.EXPAND | wx.BOTTOM, 5)
globalSizer.Add(self.ListCtrl, 1, wx.EXPAND)
-
+
self.SetSizer(globalSizer)
self.Show()
-
-app = wx.PySimpleApp()
-Panel = MyFrame(None, -1, "Sizer Test 3")
-app.MainLoop()
+if __name__ == "__main__":
+ app = wx.App(0)
+ Panel = MyFrame(None, -1, "Sizer Test 3")
+
+ app.MainLoop()
diff --git a/SplashScreen.py b/SplashScreen.py
index b9c5337..5fbb1e3 100755
--- a/SplashScreen.py
+++ b/SplashScreen.py
@@ -1,46 +1,34 @@
-#!/usr/bin/env python2.4
+#!/usr/bin/env python
-# I Always specify the python version in the #! line, it makes it much
-# easier to have multiple versions on your system
-import wxversion
-wxversion.select("2.6")
-## Note: it may well work with other versions, but it's been tested on 2.6.
import wx
-import os, time
+import os
+import time
+
class MySplashScreen(wx.SplashScreen):
- def __init__(self,imageFileName):
- bmp = wx.Bitmap(imageFileName)
- wx.SplashScreen.__init__(self,
- bitmap = bmp,
- splashStyle = wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT,
- milliseconds = 5000,
- parent = None)
- #self.Bind(wx.EVT_CLOSE, self.OnClose)
- #self.fc = wx.FutureCall(2000, self.ShowMain)
-
- def OnClose(self, evt):
- print "OnClose Called"
- # Make sure the default handler runs too so this window gets
- # destroyed
- #evt.Skip()
- #self.Hide()
-
- # if the timer is still running then go ahead and show the
- # main frame now
- #if self.fc.IsRunning():
- # self.fc.Stop()
+ def __init__(self, imageFileName):
+ bmp = wx.Bitmap(imageFileName)
+ wx.SplashScreen.__init__(self, bitmap=bmp,
+ splashStyle=wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT,
+ milliseconds=5000, parent=None)
+
+ self.Bind(wx.EVT_CLOSE, self.OnExit)
+ wx.Yield()
+
+ def OnExit(self, event):
+ """"""
+ self.Hide()
+ event.Skip() # Make sure the default handler runs too...
self.ShowMain()
-
def ShowMain(self):
print "ShowMain called"
frame = MainFrame(None, title="An Empty Frame")
frame.CenterOnScreen()
frame.Show()
- #if self.fc.IsRunning():
- # self.Raise()
+
+
class MainFrame(wx.Frame):
"""
@@ -48,6 +36,7 @@ class MainFrame(wx.Frame):
"""
pass
+
class App(wx.App):
def OnInit(self):
"""
@@ -55,24 +44,13 @@ def OnInit(self):
"""
Splash = MySplashScreen(SplashImageFile)
- frame = MainFrame(None, title = "Main Frame")
+ frame = MainFrame(None, title="Main Frame")
frame.Show()
- #Splash.Show(True)
+
return True
+
if __name__ == "__main__":
SplashImageFile = "Images/cute_close_up.jpg"
app = App(0)
app.MainLoop()
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/StaticBitmap.py b/StaticBitmap.py
index a9c5709..26e7016 100755
--- a/StaticBitmap.py
+++ b/StaticBitmap.py
@@ -4,55 +4,64 @@
Simple app that demonstrates how to use a wx.StaticBitmap, specifically
replacing bitmap dynamically.
-Note: there needs to be an "Images" directory with one or more jpegs in it in the
- current working directory for this to work
+Note: There needs to be an "Images" directory with one or more jpegs in it in the
+ current working directory for this to work.
Test most recently on OS-X wxPython 2.9.3.1
+MCow: Also On WinXP Pro SP3 32bit at least
+classic wx2.8.12.1 - wx.2.9.5.0 & phoenix wx.2.9.5.81 +
-But it been reported to work on lots of other platforms/versions
+But it been reported to work on lots of other platforms/versions.
"""
-import wx, os
-print "running wx version:", wx.__version__
+import os
+
+import wx
+print("running wx version:", wx.version())
+
class TestFrame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
- # there needs to be an "Images" directory with one or more jpegs in it in the
- # current working directory for this to work
- self.jpgs = GetJpgList("./Images") # get all the jpegs in the Images directory
+ # There needs to be an "Images" directory with one or more jpegs in it in the
+ # current working directory for this to work.
+ self.jpgs = GetJpgList("./Images") # Get all the jpegs in the Images directory.
self.CurrentJpg = 0
self.MaxImageSize = 200
-
+
b = wx.Button(self, -1, "Display next")
b.Bind(wx.EVT_BUTTON, self.DisplayNext)
- # starting with an EmptyBitmap, the real one will get put there
- # by the call to .DisplayNext()
- self.Image = wx.StaticBitmap(self, bitmap=wx.EmptyBitmap(self.MaxImageSize, self.MaxImageSize))
+ # Starting with an EmptyBitmap, the real one will get put there
+ # by the call to .DisplayNext().
+ if 'phoenix' in wx.version():
+ bmp = wx.Bitmap(self.MaxImageSize, self.MaxImageSize)
+ else:
+ bmp = wx.EmptyBitmap(self.MaxImageSize, self.MaxImageSize)
+ self.Image = wx.StaticBitmap(self, -1, bmp)
self.DisplayNext()
- # Using a Sizer to handle the layout: I never use absolute positioning
+ # Using a Sizer to handle the layout: I never use absolute positioning.
box = wx.BoxSizer(wx.VERTICAL)
- box.Add(b, 0, wx.CENTER | wx.ALL,10)
+ box.Add(b, 0, wx.CENTER | wx.ALL, 10)
- # adding stretchable space before and after centers the image.
- box.Add((1,1),1)
+ # Adding stretchable space before and after centers the image.
+ box.Add((1, 1), 1)
box.Add(self.Image, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL | wx.ADJUST_MINSIZE, 10)
- box.Add((1,1),1)
+ box.Add((1, 1), 1)
self.SetSizerAndFit(box)
-
- wx.EVT_CLOSE(self, self.OnCloseWindow)
+
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def DisplayNext(self, event=None):
- # load the image
+ # Load the image.
Img = wx.Image(self.jpgs[self.CurrentJpg], wx.BITMAP_TYPE_JPEG)
- # scale the image, preserving the aspect ratio
+ # Scale the image, preserving the aspect ratio.
W = Img.GetWidth()
H = Img.GetHeight()
if W > H:
@@ -61,18 +70,18 @@ def DisplayNext(self, event=None):
else:
NewH = self.MaxImageSize
NewW = self.MaxImageSize * W / H
- Img = Img.Scale(NewW,NewH)
-
- # convert it to a wx.Bitmap, and put it on the wx.StaticBitmap
- self.Image.SetBitmap(wx.BitmapFromImage(Img))
+ Img = Img.Scale(NewW, NewH)
+
+ # Convert it to a wx.Bitmap, and put it on the wx.StaticBitmap.
+ self.Image.SetBitmap(Img.ConvertToBitmap())
# You can fit the frame to the image, if you want.
- #self.Fit()
- #self.Layout()
+ ## self.Fit()
+ ## self.Layout()
self.Refresh()
self.CurrentJpg += 1
- if self.CurrentJpg > len(self.jpgs) -1:
+ if self.CurrentJpg > len(self.jpgs) - 1:
self.CurrentJpg = 0
def OnCloseWindow(self, event):
@@ -81,29 +90,19 @@ def OnCloseWindow(self, event):
def GetJpgList(dir):
jpgs = [f for f in os.listdir(dir) if f[-4:] == ".jpg"]
- # print "JPGS are:", jpgs
+ ## print("JPGS are:", jpgs)
return [os.path.join(dir, f) for f in jpgs]
+
class App(wx.App):
def OnInit(self):
- frame = TestFrame(None, -1, "wxBitmap Test", wx.DefaultPosition,(550,200))
+ frame = TestFrame(None, -1, "wxBitmap Test", wx.DefaultPosition, (550, 200))
self.SetTopWindow(frame)
frame.Show(True)
return True
+
if __name__ == "__main__":
app = App(0)
app.MainLoop()
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/StaticTextSizer.py b/StaticTextSizer.py
index 58954b9..47e0fe5 100755
--- a/StaticTextSizer.py
+++ b/StaticTextSizer.py
@@ -1,12 +1,8 @@
-#!/usr/bin/env python2.3
-
-import wxversion
-wxversion.select("2.5.3")
-#wxversion.select("2.5.1")
-#wxversion.select("2.4")
+#!/usr/bin/env python
import wx
-#print "Using version:", wx.__version__
+print("running wx version:", wx.version())
+
class DemoFrame(wx.Frame):
""" This window displays a button """
@@ -20,7 +16,7 @@ def __init__(self, title = "Micro App"):
text = wx.TextCtrl(self, wx.NewId())
btn = wx.Button(self, wx.NewId(), "Resize")
- wx.EVT_BUTTON(self, btn.GetId(), self.OnChange )
+ btn.Bind(wx.EVT_BUTTON, self.OnChange)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(title, 0, wx.ALL | wx.ALIGN_CENTER, 4)
@@ -35,26 +31,23 @@ def __init__(self, title = "Micro App"):
self.Labels = ["One label",
"Another Label",
"Yet Another Label",
- "A now a really really long one",
+ "A now a really%s long one" %(' really' * 10),
"A short one",
"short"]
self.Curlabel = 0
-
+
def OnChange(self,Event):
self.Curlabel += 1
if self.Curlabel > len(self.Labels)-1:
self.Curlabel = 0
self.Static.SetLabel(self.Labels[self.Curlabel])
self.sizer.SetItemMinSize(self.Static, self.Static.GetBestSize() )
- #self.sizer.Layout()
+ self.sizer.Layout()
self.Fit()
-app = wx.PySimpleApp(0)
-frame = DemoFrame()
-frame.Show()
-app.MainLoop()
-
-
-
-
+if __name__ == "__main__":
+ app = wx.App(0)
+ frame = DemoFrame()
+ frame.Show()
+ app.MainLoop()
diff --git a/StyleApp.py b/StyleApp.py
index ebeabd4..ff1f200 100755
--- a/StyleApp.py
+++ b/StyleApp.py
@@ -1,7 +1,4 @@
-#!/usr/bin/env python2.4
-
-# I like to put the python version on the #! line,
-# so that I can have multiple versions installed.
+#!/usr/bin/env python
"""
@@ -12,14 +9,15 @@
import wx
+
class DemoPanel(wx.Panel):
- def __init__(self, Parent, *args, **kwargs):
- wx.Panel.__init__(self, Parent, *args, **kwargs)
+ def __init__(self, parent, *args, **kwargs):
+ wx.Panel.__init__(self, parent, *args, **kwargs)
- self.Parent = Parent
+ self.parent = parent
NothingBtn = wx.Button(self, label="Do Nothing with a long label")
- NothingBtn.Bind(wx.EVT_BUTTON, self.DoNothing )
+ NothingBtn.Bind(wx.EVT_BUTTON, self.DoNothing)
MsgBtn = wx.Button(self, label="Send Message")
MsgBtn.Bind(wx.EVT_BUTTON, self.OnMsgBtn )
@@ -32,7 +30,7 @@ def __init__(self, Parent, *args, **kwargs):
def DoNothing(self, event=None):
pass
-
+
def OnMsgBtn(self, event=None):
dlg = wx.MessageDialog(self,
message='A completely useless message',
@@ -42,6 +40,7 @@ def OnMsgBtn(self, event=None):
dlg.ShowModal()
dlg.Destroy()
+
class DemoFrame(wx.Frame):
""" This window displays a button """
def __init__(self, *args, **kwargs):
@@ -51,7 +50,7 @@ def __init__(self, *args, **kwargs):
MenuBar = wx.MenuBar()
FileMenu = wx.Menu()
-
+
item = FileMenu.Append(wx.ID_EXIT, text="&Quit")
self.Bind(wx.EVT_MENU, self.OnQuit, item)
@@ -66,7 +65,9 @@ def __init__(self, *args, **kwargs):
def OnQuit(self, event=None):
self.Close()
-app = wx.App()
-frame = DemoFrame(None, title="Micro App")
-frame.Show()
-app.MainLoop()
+
+if __name__ == "__main__":
+ app = wx.App(0)
+ frame = DemoFrame(None, title="Micro App")
+ frame.Show()
+ app.MainLoop()
diff --git a/TestEvents.py b/TestEvents.py
index 280f19d..02ae551 100755
--- a/TestEvents.py
+++ b/TestEvents.py
@@ -8,18 +8,18 @@
import wx
+
class TestPanel(wx.Panel):
def __init__(self, *args, **kwargs):
- wx.Panel.__init__(self, *args, **kwargs)
-
-
- wx.EVT_PAINT(self, self.OnPaint)
+ wx.Panel.__init__(self, *args, **kwargs)
+
+ self.Bind(wx.EVT_PAINT , self.OnPaint)
self.Bind(wx.EVT_LEFT_DOWN , self.LeftDown)
self.Bind(wx.EVT_LEFT_UP , self.LeftUp)
self.Bind(wx.EVT_MOTION, self.Move)
- ##This would capture all events in the same handler
- #wx.EVT_MOUSE_EVENTS(self, self.OnMouseEvents)
+ # This would capture all events in the same handler
+ ## self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouseEvents)
def OnPaint(self, event):
@@ -32,50 +32,30 @@ def OnPaint(self, event):
def OnMouseEvents(self,event):
if event.IsButton():
- print event.GetButton()
+ print(event.GetButton())
def LeftDown(self, event):
- print "In LeftDown, at:", event.Position
-
+ print("In LeftDown, at:", event.Position)
+
def LeftUp(self, event):
- print "In LeftUp at:", event.Position
-
+ print("In LeftUp at:", event.Position)
+
def Move(self, event):
- print "In Motion event at:", event.Position
-
+ print("In Motion event at:", event.Position)
+
+
class DemoApp(wx.App):
def OnInit(self):
- frame = wx.Frame(None,
- title="Mouse Event Test",
- size=(200,200),
- style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE,
- )
- print type(frame)
+ frame = wx.Frame(None, title="Mouse Event Test", size=(200,200),
+ style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE)
+ print(type(frame))
panel = TestPanel(frame)
frame.Show(True)
return True
+
if __name__ == "__main__":
app = DemoApp(False)
app.MainLoop()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/TestHTML.py b/TestHTML.py
index dcf626a..74348ef 100755
--- a/TestHTML.py
+++ b/TestHTML.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
import wx
+from wx.html import HtmlEasyPrinting
#import wx.lib.wxpTag
#-------------------------------------------------------------------
@@ -14,15 +15,15 @@ class ExpandButton(wx.BitmapButton):
"""
#DownBmp = wx.Bitmap("Images/ArrowDown.png")
#RightBmp = wx.Bitmap("Images/ArrowRight.png")
-
+
def __init__(self, *args, **kwargs):
self.__class__.DownBmp= wx.Bitmap("Images/ArrowDown.png")
self.__class__.RightBmp = wx.Bitmap("Images/ArrowRight.png")
self.Section = Sections[kwargs.pop("section")]
-
- print "Section is:", self.Section
+
+ print("Section is:", self.Section)
kwargs["bitmap"] = self.RightBmp
wx.BitmapButton.__init__(self, *args, **kwargs)
@@ -30,7 +31,7 @@ def __init__(self, *args, **kwargs):
self.Bind(wx.EVT_BUTTON, self.Clicked)
def Clicked(self, event):
- print "ExpandButton was clicked!"
+ print("ExpandButton was clicked!")
if self.Section.Expanded:
self.Section.Expanded = False
self.SetBitmapLabel(self.RightBmp)
@@ -38,6 +39,7 @@ def Clicked(self, event):
self.Section.Expanded = True
self.SetBitmapLabel(self.DownBmp)
+
class HTMLSection:
def __init__(self, header="", text=""):
self.header = header
@@ -51,7 +53,7 @@ def OnClick(self):
self.Expanded = False
else:
self.Expanded = True
-
+
def GetHtml(self):
html = []
@@ -109,7 +111,7 @@ def GetHtml(self):
is set, then it it shows the html for the whole thing. If
not, then it only shows the littel arrrow and the header
text.
-
+
"""),
HTMLSection("Still To Do:", """
@@ -121,7 +123,7 @@ def GetHtml(self):
ALIGN=TEXTTOPflag, but that may not be the best @@ -132,7 +134,7 @@ def GetHtml(self): tricky if we bundle the whole thing up in to a single .exe file. Maybe you can load a binary bitmap straight into the wx.HtmlWindow, but I don't know how. - +