Ich habe eine Jimdo Webseite gestartet. In Zukunft werde ich mich darauf konzentrieren. Darum ist dies auch mein letzter kurzer Beitrag.
Wenn der geschätzte Leser wissen will, wie es weitergeht ..
http://www.erasand.jimdo.com/
Bis bald ..
ERASAND
Blog über die Programmentwicklung in Python unter Linux
Seiten
Mittwoch, 3. August 2011
Sonntag, 3. Juli 2011
Und wieder wxPy
Gerade habe ich das Kapitel 'widgets' des Tutorials durchgemacht. Auch hier habe ich die Beispiele in einer Anwendung zusammengefasst.
Mit nur einem Skript wurde es zu unübersichtlich. Durch das Tutorial habe ich einiges gesehen und kann es gleich anwenden.
In einem Programmfenster mit mehreren Registern sind alle 'widgets' abgebildet. Die einzelnen Bereiche sind eigene Objekte, meist in externen Skripts.
Und hier Screenshots, für jedes Register einen:
Register Page one: wx.Button, wx.ToggleButton, wx.StaticText, wx.CheckBox
Register Page two: wx.BitmapButton & wx.Slider, wx.ComboBox & wx.StaticBitmap
Register Page three: wx.RadioButton, wx.Gauge, wx.ListBox
Register Page four: wx.SpinCtrl
Register Splitter
Register Scroll
Register Sheet
Und hier die Skripte:
06_widgets.py (Das Hauptmodul)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
import wx.lib.sheet as sheet
import random
from wdgbtn import WdgButton #wx.Button: Page 1
# WdgButton(parent, frame, width, height)
from wdgtglbtn import WdgToggleButton #wx.ToggleButton: Page 1
# WdgToggleButton(parent, frame)
from wdgbmpbtn import WdgBitmapButton #wx.BitmapButton: Page 2
# WdgBitmapButton(parent, frame)
from wdgstxt import WdgStaticText #wx.StaticText: Page 1
# WdgStaticText(parent, frame)
from wdgcmbbx import WdgComboBox #wx.ComboBox: Page 2
# WdgComboBox(parent, frame)
from wdgchkbx import WdgCheckBox #wx.CheckBox: Page 1
# WdgCheckBox(parent, frame, title)
from wdgradbtn import WdgRadioButton #wx.RadioButton: Page 3
# WdgRadioButton(parent, frame)
from wdggaug import WdgGauge #wx.Gauge: Page 3
# WdgGauge(parent, frame)
from wdglstbx import WdgListBox #wx.WdgListBox: Page 3
# WdgListBox(parent, frame)
from wdgspnctr import WdgSpinCtrl #wx.SpinCtrl: Page 4
# WdgSpinCtrl(parent, frame)
from wdgsplwnd import WdgSplitterWindow #wx.SplitterWindow: Page Splitter
# WdgSplitterWindow(parent)
from wdgscrwnd import WdgScrolledWindow #wx.ScrolledWindow: Page Scroll
# WdgScrolledWindow(parent)
from wdgntbsht import WdgNotebook, WdgSheet #wx.Notebook: Page Notebook
# WdgNotebook(parent)
#parent= wx.Object (Frame, Panel, Notebook)
#frame= wx.Frame
#title= wx.Frame title
APP_WIDTH= 360
APP_HEIGHT= 660
class Widgets(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title,
size=(APP_WIDTH, APP_HEIGHT))
menubar= wx.MenuBar()
mnufile= wx.Menu()
idmnuexit= wx.ID_EXIT
mnufile.Append(idmnuexit, '&Quit\tCtrl+W',
'Quit the application')
self.Bind(wx.EVT_MENU, self.onclose, id= idmnuexit)
menubar.Append(mnufile, '&File')
mnuplay= wx.Menu()
mnuplay.Append(wx.ID_ANY, '&Video',
'Play a video')
menubar.Append(mnuplay, '&Play')
mnuview= wx.Menu()
mnuview.Append(wx.ID_ANY, 'Show &all files',
'Play all open files')
menubar.Append(mnuview, '&View')
mnutools= wx.Menu()
mnutools.Append(wx.ID_ANY, '&Convert',
'Convert in a other format')
menubar.Append(mnutools, '&Tools')
mnufavorites= wx.Menu()
mnufavorites.Append(wx.ID_ANY, '&Add to favorites',
'Add current file to favorites')
menubar.Append(mnufavorites, 'F&avorites')
mnuhelp= wx.Menu()
mnuhelp.Append(wx.ID_ANY, '&About',
'Info about Erasand.06.Widget.py')
menubar.Append(mnuhelp, '&Help')
self.SetMenuBar(menubar)
self.__stb= self.CreateStatusBar()
self.__sa= ''
self.__sb= ''
self.__sc= ''
self.__stxt= ''
# Notebook for a couple of pages
nbk= wx.Notebook(self)
nbk.AddPage(PageOne(nbk, self, title), 'Page one')
nbk.AddPage(PageTwo(nbk, self, title), 'Page two')
nbk.AddPage(PageThree(nbk, self, title), 'Page three')
nbk.AddPage(PageFour(nbk, self, title), 'Page four')
nbk.AddPage(WdgSplitterWindow(nbk), 'Splitter')
nbk.AddPage(WdgScrolledWindow(nbk), 'Scroll')
nbk.AddPage(WdgNotebook(nbk), 'Sheet')
self.SetMinSize((APP_WIDTH, APP_HEIGHT))
# self.SetMaxSize((x, y))
self.Centre()
self.Show()
def onclose(self, event):
self.Close()
def setstatusa(self, txt):
self.__sa= txt
self.setstatusbar()
def setstatusb(self, txt):
self.__sb= txt
self.setstatusbar()
def setstatusc(self, txt):
self.__sc= txt
self.setstatusbar()
def setstatustxt(self, txt):
self.__stxt= txt
self.setstatusbar()
def setstatusbar(self):
txt = ' A: '+ self.__sa+ ' | B: '+ self.__sb+ ' | C: '+ self.__sc
txt+= ' | '+ self.__stxt
self.__stb.SetStatusText(txt)
class PageOne(wx.Panel):
def __init__(self, parent, frame, title):
wx.Panel.__init__(self, parent)
vbox= wx.BoxSizer(wx.VERTICAL)
hbox= wx.BoxSizer(wx.HORIZONTAL)
# wx.StaticLine
hln1= wx.StaticLine(self, size= (300, 1), style= wx.LI_HORIZONTAL)
hln2= wx.StaticLine(self, size= (300, 1), style= wx.LI_HORIZONTAL)
hln3= wx.StaticLine(self, size= (300, 1), style= wx.LI_HORIZONTAL)
hln4= wx.StaticLine(self, size= (300, 1), style= wx.LI_HORIZONTAL)
hln5= wx.StaticLine(self, size= (300, 1), style= wx.LI_HORIZONTAL)
vln1= wx.StaticLine(self, size= (1, 440), style= wx.LI_VERTICAL)
vln2= wx.StaticLine(self, size= (1, 440), style= wx.LI_VERTICAL)
vbox.Add(hln1, 0, wx.ALL, 5)
# wx.Button
a= WdgButton(self, frame, APP_WIDTH, APP_HEIGHT)
vbox.Add(a, 0, wx.EXPAND|wx.ALL, 5)
vbox.Add(hln2, 0, wx.ALL, 5)
# wx.ToggleButton
b= WdgToggleButton(self, frame)
vbox.Add(b, 0, wx.EXPAND|wx.ALL, 5)
vbox.Add(hln3, 0, wx.ALL, 5)
# wx.StaticText
c= WdgStaticText(self, frame)
vbox.Add(c, 0, wx.EXPAND|wx.ALL, 5)
vbox.Add(hln4, 0, wx.ALL, 5)
# wx.CheckBox
d= WdgCheckBox(self, frame, title)
vbox.Add(d, 0, wx.EXPAND|wx.ALL, 5)
vbox.Add(hln5, 0, wx.ALL, 5)
hbox.Add(vln1, wx.ALL, 5)
hbox.Add(vbox, 0, wx.EXPAND, 5)
hbox.Add(vln2, wx.ALL, 5)
self.SetSizer(hbox)
class PageTwo(wx.Panel):
def __init__(self, parent, frame, title):
wx.Panel.__init__(self, parent)
vbox= wx.BoxSizer(wx.VERTICAL)
# wx.BitmapButton
a= WdgBitmapButton(self, frame)
vbox.Add(a, 0, wx.EXPAND|wx.ALL, 5)
# wx.ComboBox
b= WdgComboBox(self, frame)
vbox.Add(b, 0, wx.EXPAND|wx.ALL, 5)
self.SetSizer(vbox)
class PageThree(wx.Panel):
def __init__(self, parent, frame, title):
wx.Panel.__init__(self, parent)
vbox= wx.BoxSizer(wx.VERTICAL)
# wx.RadioButton
a= WdgRadioButton(self, frame)
vbox.Add(a, 0, wx.EXPAND|wx.ALL, 5)
# wx.Gauge
b= WdgGauge(self, frame)
vbox.Add(b, 0, wx.EXPAND|wx.ALL, 5)
# wx.ListBox
c= WdgListBox(self, frame)
vbox.Add(c, 0, wx.EXPAND|wx.ALL, 5)
self.SetSizer(vbox)
class PageFour(wx.Panel):
def __init__(self, parent, frame, title):
wx.Panel.__init__(self, parent)
vbox= wx.BoxSizer(wx.VERTICAL)
# wx.SpinCtrl
a= WdgSpinCtrl(self, frame)
vbox.Add(a, 0, wx.EXPAND|wx.ALL, 5)
self.SetSizer(vbox)
if __name__== '__main__':
app= wx.App()
Widgets(None, 'Erasand.06.Widgets')
app.MainLoop()
wdgbtn.py (Modul für wx.Button auf Page one)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
import random
class WdgButton(wx.Panel):
def __init__(self, parent, frame, width, height):
wx.Panel.__init__(self, parent)
self.__frame= frame
self.__width= width
self.__height= height
statbx= wx.StaticBox(self, label= 'wx.Button')
sbox= wx.StaticBoxSizer(statbx, wx.HORIZONTAL)
close= wx.Button(self, wx.ID_CLOSE)
sbox.Add(close, 0, wx.ALL, 10)
close.Bind(wx.EVT_BUTTON, self.onclose)
random= wx.Button(self, label= 'Random Move')
sbox.Add(random, 0, wx.ALL, 10)
random.Bind(wx.EVT_BUTTON, self.onrndmove)
close.Bind(wx.EVT_ENTER_WINDOW, self.enterbutton)
random.Bind(wx.EVT_ENTER_WINDOW, self.enterbutton)
close.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
random.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
self.SetSizer(sbox)
def onclose(self, event):
self.__frame.Close()
def onrndmove(self, event):
screensize= wx.GetDisplaySize()
randx= random.randrange(0, screensize.x- self.__width)
randy= random.randrange(0, screensize.y- self.__height)
self.__frame.Move((randx, randy))
def enterbutton(self, event):
self.__frame.setstatustxt('wx.Button')
event.Skip()
def leavewdg(self, event):
self.__frame.setstatustxt('')
event.Skip()
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
WdgButton(self, self, 300, 300)
self.Show()
def setstatustxt(self, txt):
print(txt)
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdgbtn.py')
app.MainLoop()
# wx.Button styles: wx.BU_LEFT|wx.BU_TOP|wx.BU_RIGHT|wx.BU_BOTTOM|
# wx.BU_EXACTFIT|wx.NO_BORDER
wdgtglbtn.py (Modul für wx.ToggleButton auf Page one)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class WdgToggleButton(wx.Panel):
def __init__(self, parent, frame):
wx.Panel.__init__(self, parent)
self.__frame= frame
statbx= wx.StaticBox(self, label= 'wx.Toggle-Button',
style= wx.SUNKEN_BORDER)
sbox= wx.StaticBoxSizer(statbx, wx.VERTICAL)
self.__panel= wx.Panel(self)
self.__color= wx.Colour(0, 0, 0)
self.__panel.SetBackgroundColour(self.__color)
sbox.Add(self.__panel, 0, wx.EXPAND|wx.ALL, 5)
hbox= wx.BoxSizer(wx.HORIZONTAL)
btnred= wx.ToggleButton(self, label= 'red')
hbox.Add(btnred, 0, wx.ALL, 5)
btnred.Bind(wx.EVT_TOGGLEBUTTON, self.onred)
btngreen= wx.ToggleButton(self, label= 'green')
hbox.Add(btngreen, 0, wx.ALL, 5)
btngreen.Bind(wx.EVT_TOGGLEBUTTON, self.ongreen)
btnblue= wx.ToggleButton(self, label= 'blue')
hbox.Add(btnblue, 0, wx.ALL, 5)
btnblue.Bind(wx.EVT_TOGGLEBUTTON, self.onblue)
sbox.Add(hbox, 0, wx.ALL, 5)
self.__panel.Bind(wx.EVT_ENTER_WINDOW, self.enterpanel)
self.__panel.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
for i in btnred, btngreen, btnblue:
i.Bind(wx.EVT_ENTER_WINDOW, self.entertglbutton)
i.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
self.SetSizer(sbox)
def onred(self, event):
green= self.__color.Green()
blue= self.__color.Blue()
if self.__color.Red():
self.__color.Set(0, green, blue)
else:
self.__color.Set(255, green, blue)
self.__panel.SetBackgroundColour(self.__color)
def ongreen(self, event):
red= self.__color.Red()
blue= self.__color.Blue()
if self.__color.Green():
self.__color.Set(red, 0, blue)
else:
self.__color.Set(red, 255, blue)
self.__panel.SetBackgroundColour(self.__color)
def onblue(self, event):
red= self.__color.Red()
green= self.__color.Green()
if self.__color.Blue():
self.__color.Set(red, green, 0)
else:
self.__color.Set(red, green, 255)
self.__panel.SetBackgroundColour(self.__color)
def entertglbutton(self, event):
self.__frame.setstatustxt('wx.ToggelButton')
event.Skip()
def enterpanel(self, event):
self.__frame.setstatustxt('wx.Panel')
event.Skip()
def leavewdg(self, event):
self.__frame.setstatustxt('')
event.Skip()
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
WdgToggleButton(self, self)
self.Show()
def setstatustxt(self, txt):
print(txt)
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdgtglbtn.py')
app.MainLoop()
wdgstxt.py (Modul für wx.StaticText auf Page one)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class WdgStaticText(wx.Panel):
def __init__(self, parent, frame):
wx.Panel.__init__(self, parent)
self.__frame= frame
lyrics1= '''I'm giving up the ghost of love
in the shadows cast on devotion
She is the one that I adore
creed of my silent suffocation
Break this bittersweet spell on me
lost in the arms of destiny'''
lyrics2= '''There is something in the way
You're always somewhere else
Feelings have deserted me
To a point of no return
I don't believe in God
But I pray for you'''
statbx= wx.StaticBox(self, label= 'wx.StaticText')
sbox= wx.StaticBoxSizer(statbx, wx.VERTICAL)
statxt1= wx.StaticText(self, label= lyrics1, style= wx.ALIGN_CENTRE)
sbox.Add(statxt1, 0, wx.EXPAND|wx.ALL, 10)
statxt2= wx.StaticText(self, label= lyrics2, style= wx.ALIGN_CENTRE)
sbox.Add(statxt2, 0, wx.EXPAND|wx.ALL, 10)
self.SetSizer(sbox)
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
WdgStaticText(self, self)
self.Show()
def setstatustxt(self, txt):
print(txt)
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdgstxt.py')
app.MainLoop()
# wx.StaticText styles: wx.ALIGN_RIGHT|wx.ALIGN_LEFT|
# wx.ALIGN_CENTER|wx.ALIGN_CENTRE|wx.ST_NO_AUTORESIZE
wdgchkbx.py (Modul für wx.CheckBox auf Page one)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class WdgCheckBox(wx.Panel):
def __init__(self, parent, frame, title):
wx.Panel.__init__(self, parent)
self.__frame= frame
self.__title= title
statbx= wx.StaticBox(self, label= 'wx.CheckBox')
sbox= wx.StaticBoxSizer(statbx, wx.HORIZONTAL)
self.__checkbx= wx.CheckBox(self, label= 'Show Title')
sbox.Add(self.__checkbx, 0, wx.ALL, 10)
self.__checkbx.Bind(wx.EVT_CHECKBOX, self.oncheckbx)
self.__checkbx.Bind(wx.EVT_ENTER_WINDOW, self.entercheckbx)
self.__checkbx.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
self.SetSizer(sbox)
def oncheckbx(self, event):
if self.__checkbx.GetValue():
self.__frame.SetTitle(self.__title+ ' / Checkbox aktiviert')
else:
self.__frame.SetTitle(self.__title)
def entercheckbx(self, event):
self.__frame.setstatustxt('wx.CheckBox')
event.Skip()
def leavewdg(self, event):
self.__frame.setstatustxt('')
event.Skip()
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(400, 200))
WdgCheckBox(self, self, title)
self.Show()
def setstatustxt(self, txt):
print(txt)
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdgchkbx.py')
app.MainLoop()
wdgbmpbtn.py (Modul für wx.BitmapButton und wx.Slider auf Page two)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class WdgBitmapButton(wx.Panel):
def __init__(self, parent, frame):
wx.Panel.__init__(self, parent)
self.__frame= frame
statbx= wx.StaticBox(self, label= 'wx.BitmapButton & wx.Slider')
sbox= wx.StaticBoxSizer(statbx, wx.VERTICAL)
pnlplay= wx.Panel(self, size=(200,200))
pnlplay.SetBackgroundColour(wx.BLACK)
sbox.Add(pnlplay, 0, wx.EXPAND|wx.ALL, 10)
self.__sldply= wx.Slider(self, wx.ID_ANY, 0, 0, 3600)
sbox.Add(self.__sldply, 0, wx.EXPAND | wx.BOTTOM, 10)
hbox1= wx.BoxSizer(wx.HORIZONTAL)
pause= wx.BitmapButton(self, wx.ID_ANY,
wx.Bitmap('../icons_22/media-playback-pause.png'))
hbox1.Add(pause)
play= wx.BitmapButton(self, wx.ID_ANY,
wx.Bitmap('../icons_22/media-playback-start.png'))
hbox1.Add(play, 0, wx.RIGHT, 5)
next= wx.BitmapButton(self, wx.ID_ANY,
wx.Bitmap('../icons_22/media-skip-forward.png'))
hbox1.Add(next, 0, wx.LEFT, 5)
prev= wx.BitmapButton(self, wx.ID_ANY,
wx.Bitmap('../icons_22/media-skip-backward.png'))
hbox1.Add(prev, 0, wx.RIGHT, 5)
volume= wx.BitmapButton(self, wx.ID_ANY,
wx.Bitmap('../icons_22/audio-volume-medium.png'))
hbox1.Add(volume, 0, wx.LEFT, 5)
self.__sldvol= wx.Slider(self, wx.ID_ANY, 0, 0, 100,
size=(120, -1), style= wx.SL_AUTOTICKS|wx.SL_LABELS)
hbox1.Add(self.__sldvol, 0, wx.TOP|wx.LEFT, 5)
sbox.Add(hbox1, 0, wx.EXPAND)
self.__inftxt= wx.StaticText(self, label= 'Positon: / Volume:')
sbox.Add(self.__inftxt, 0, wx.ALL, 5)
pnlplay.Bind(wx.EVT_ENTER_WINDOW, self.enterpanel)
self.__sldply.Bind(wx.EVT_ENTER_WINDOW, self.enterslider)
self.__sldvol.Bind(wx.EVT_ENTER_WINDOW, self.enterslider)
for i in pause, play, next, prev, volume:
i.Bind(wx.EVT_ENTER_WINDOW, self.enterbitmapbutton)
for i in pnlplay, pause, play, next, prev, volume:
i.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
for i in self.__sldply, self.__sldvol:
i.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
for i in self.__sldply, self.__sldvol:
i.Bind(wx.EVT_SLIDER, self.oninfo)
self.infoupdate()
self.SetSizer(sbox)
def enterpanel(self, event):
self.__frame.setstatustxt('wx.Panel')
event.Skip()
def enterslider(self, event):
self.__frame.setstatustxt('wx.Slider')
event.Skip()
def enterbitmapbutton(self, event):
self.__frame.setstatustxt('wx.BitmapButton')
event.Skip()
def enterbutton(self, event):
self.__frame.setstatustxt('wx.Button')
event.Skip()
def leavewdg(self, event):
self.__frame.setstatustxt('')
event.Skip()
def oninfo(self, event):
self.infoupdate()
def infoupdate(self):
mm= int(self.__sldply.GetValue()/ 60)
ss= self.__sldply.GetValue()- (60* mm)
vol= self.__sldvol.GetValue()
mmtxt, sstxt, voltxt= str(mm), str(ss), str(vol)
if len(mmtxt)==1:
mmtxt= '0'+ mmtxt
if len(sstxt)==1:
sstxt= '0'+ sstxt
if len(voltxt)==1:
voltxt= '0'+ voltxt
txt= 'Position: '+ mmtxt+ ':'+ sstxt+ ' / '
txt+= 'Volume: '+ voltxt
self.__inftxt.SetLabel(txt)
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 400))
WdgBitmapButton(self, self)
self.Show()
def setstatustxt(self, txt):
print(txt)
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdgbmpbtn.py')
app.MainLoop()
# wx.Slider(parent, id, startvalue, minvalue, maxvalue, style)
# wx.Slider style: wx.SL_HORIZONTAL|wx.SL_VERTICAL|
# wx.SL_AUTOTICKS| (display tick marks)
# wx.SL_LABELS| (display value labels)
# wx.SL_LEFT|wx.SL_RIGHT|wx.SL_TOP|wx.SL_BOTTOM|wx.SL_INVERSE
wdgcmbbx.py (Modul für wx.ComboBox und wx.StaticBitmap auf Page two)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class WdgComboBox(wx.Panel):
def __init__(self, parent, frame):
wx.Panel.__init__(self, parent)
self.__frame= frame
statbox= wx.StaticBox(self, label= 'wx.ComboBox & wx.StaticBitmap')
sbox= wx.StaticBoxSizer(statbox, wx.VERTICAL)
pnlpic = wx.Panel(self, style=wx.SUNKEN_BORDER)
self.__pic= wx.StaticBitmap(pnlpic)
self.__pic.SetBitmap(wx.Bitmap('pictures/leer_100-127.png'))
pnlpic.SetBackgroundColour(wx.WHITE)
sbox.Add(pnlpic, 0, wx.ALL, 10)
self.__pictures= ['pictures/tolstoy.png',
'pictures/feuchtwanger.png',
'pictures/balzac.png',
'pictures/pasternak.png',
'pictures/galsworthy.png',
'pictures/wolfe.png',
'pictures/zweig.png']
authors= ['Leo Tolstoy', 'Lion Feuchtwanger', 'Honore de Balzac',
'Boris Pasternak', 'John Galsworthy', 'Tom Wolfe', 'Stefan Zweig']
combobx= wx.ComboBox(self, size=(150, -1), choices=authors,
style=wx.CB_READONLY)
sbox.Add(combobx, 0, wx.EXPAND|wx.ALL, 10)
combobx.Bind(wx.EVT_COMBOBOX, self.oncombo)
pnlpic.Bind(wx.EVT_ENTER_WINDOW, self.enterpanel)
combobx.Bind(wx.EVT_ENTER_WINDOW, self.entercombobox)
pnlpic.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
combobx.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
self.SetSizer(sbox)
def oncombo(self, event):
item = event.GetSelection()
self.__pic.SetFocus()
self.__pic.SetBitmap(wx.Bitmap(self.__pictures[item]))
def enterpanel(self, event):
self.__frame.setstatustxt('wx.Panel')
event.Skip()
def entercombobox(self, event):
self.__frame.setstatustxt('wx.ComboBox')
event.Skip()
def leavewdg(self, event):
self.__frame.setstatustxt('')
event.Skip()
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
WdgComboBox(self, self)
self.Show()
def setstatustxt(self, txt):
print(txt)
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdgcmbbx.py')
app.MainLoop()
wdgradbtn.py (Modul für wx.RadioButton auf Page three)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class WdgRadioButton(wx.Panel):
def __init__(self, parent, frame):
wx.Panel.__init__(self, parent)
self.__frame= frame
statbx= wx.StaticBox(self, label= 'wx.RadioButton')
sbox= wx.StaticBoxSizer(statbx, wx.VERTICAL)
self.__radiobtn1 = wx.RadioButton(self, label= 'Value A',
style=wx.RB_GROUP)
sbox.Add(self.__radiobtn1, 0, wx.EXPAND|wx.ALL, 5)
self.__radiobtn1.Bind(wx.EVT_RADIOBUTTON, self.setval)
self.__radiobtn2 = wx.RadioButton(self, label= 'Value B')
sbox.Add(self.__radiobtn2, 0, wx.EXPAND|wx.ALL, 5)
self.__radiobtn2.Bind(wx.EVT_RADIOBUTTON, self.setval)
self.__radiobtn3 = wx.RadioButton(self, label= 'Value C')
sbox.Add(self.__radiobtn3, 0, wx.EXPAND|wx.ALL, 5)
self.__radiobtn3.Bind(wx.EVT_RADIOBUTTON, self.setval)
for i in self.__radiobtn1, self.__radiobtn2, self.__radiobtn3:
i.Bind(wx.EVT_ENTER_WINDOW, self.enterradiobtn)
i.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
self.setval(True)
self.SetSizer(sbox)
def setval(self, event):
self.__frame.setstatusa(str(self.__radiobtn1.GetValue()))
self.__frame.setstatusb(str(self.__radiobtn2.GetValue()))
self.__frame.setstatusc(str(self.__radiobtn3.GetValue()))
def enterradiobtn(self, event):
self.__frame.setstatustxt('wx.RadioButton')
event.Skip()
def leavewdg(self, event):
self.__frame.setstatustxt('')
event.Skip()
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
WdgRadioButton(self, self)
self.Show()
def setstatustxt(self, txt):
print(txt)
def setstatusa(self, txt):
print(txt)
def setstatusb(self, txt):
print(txt)
def setstatusc(self, txt):
print(txt)
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdgradbtn.py')
app.MainLoop()
# wx.RadioButton styles: wx.RB_GROUP|wx.RB_SINGLE|wx.CB_SORT
wdggaug.py (Modul für wx.Gauge auf Page three)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class WdgGauge(wx.Panel):
def __init__(self, parent, frame):
wx.Panel.__init__(self, parent)
self.__frame= frame
self.__timer= wx.Timer(self, 1)
self.__count= 0
self.Bind(wx.EVT_TIMER, self.ontimer, self.__timer)
statbx= wx.StaticBox(self, label= 'wx.Gauge')
sbox= wx.StaticBoxSizer(statbx, wx.VERTICAL)
hbox1= wx.BoxSizer(wx.HORIZONTAL)
self.__gag = wx.Gauge(self, wx.ID_ANY, 50, size=(250, 25))
hbox1.Add(self.__gag, 1, wx.ALIGN_CENTRE)
hbox2= wx.BoxSizer(wx.HORIZONTAL)
btnok = wx.Button(self, wx.ID_OK)
hbox2.Add(btnok, 1, wx.RIGHT, 10)
btnok.Bind(wx.EVT_BUTTON, self.onok)
btnstop = wx.Button(self, wx.ID_STOP)
hbox2.Add(btnstop, 1)
btnstop.Bind(wx.EVT_BUTTON, self.onstop)
hbox3= wx.BoxSizer(wx.HORIZONTAL)
self.__txt = wx.StaticText(self, label= 'Task to be done')
hbox3.Add(self.__txt, 1)
sbox.Add(hbox1, 0, wx.TOP|wx.ALIGN_CENTRE, 20)
sbox.Add(hbox2, 0, wx.TOP|wx.ALIGN_CENTRE, 20)
sbox.Add(hbox3, 0, wx.TOP|wx.BOTTOM|wx.ALIGN_CENTRE, 20)
self.__gag.Bind(wx.EVT_ENTER_WINDOW, self.entergauge)
btnok.Bind(wx.EVT_ENTER_WINDOW, self.enterbutton)
btnstop.Bind(wx.EVT_ENTER_WINDOW, self.enterbutton)
for i in self.__gag, btnok, btnstop:
i.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
self.SetSizer(sbox)
def enterbutton(self, event):
self.__frame.setstatustxt('wx.Button')
event.Skip()
def entergauge(self, event):
self.__frame.setstatustxt('wx.Gauge')
event.Skip()
def leavewdg(self, event):
self.__frame.setstatustxt('')
event.Skip()
def onok(self, event):
if self.__count>= 50:
self.__count= 0
self.__timer.Start(100)
self.__txt.SetLabel('Task again in progress')
else:
self.__timer.Start(100)
self.__txt.SetLabel('Task in progress')
def onstop(self, event):
if self.__count== 0 or self.__count>= 50 or not self.__timer.IsRunning():
return
self.__timer.Stop()
self.__txt.SetLabel('Task interrupted')
wx.Bell()
def ontimer(self, event):
self.__count = self.__count +1
self.__gag.SetValue(self.__count)
if self.__count== 50:
self.__timer.Stop()
self.__txt.SetLabel('Task completed')
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
WdgGauge(self, self)
self.Show()
def setstatustxt(self, txt):
print(txt)
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdggaug.py')
app.MainLoop()
# wx.Gauge styles: wx.GA_HORIZONTAL|wx.GA_VERTICAL
wdglstbx.py (Modul für wx.WdgListBox auf Page three)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
import time
class WdgListBox(wx.Panel):
def __init__(self, parent, frame):
wx.Panel.__init__(self, parent)
self.__frame= frame
statbox= wx.StaticBox(self, label= 'wx.ListBox')
sbox= wx.StaticBoxSizer(statbox, wx.VERTICAL)
zone_list= ['CET', 'GMT', 'MSK', 'EST', 'PST', 'EDT']
self.__fulllist= {'CET': 'Central European Time',
'GMT': 'Greenwich Mean Time',
'MSK': 'Moscow Time',
'EST': 'Eastern Standard Time',
'PST': 'Pacific Standard Time',
'EDT': 'Eastern Daylight Time'}
self.__timediff= {'CET': 1,
'GMT' : 0,
'MSK': 3,
'EST': -5,
'PST': -8,
'EDT': -4}
self.__timer= wx.Timer(self, 1)
self.Bind(wx.EVT_TIMER, self.ontimer, self.__timer)
self.__diff= 0
hbox= wx.BoxSizer(wx.HORIZONTAL)
self.__lbxzone = wx.ListBox(self, choices= zone_list,
style= wx.LB_SINGLE)
# wx.ListBox(self, 26, (-1, -1), (170, 130), zone_list, wx.LB_SINGLE)
self.__lbxzone.SetSelection(0)
hbox.Add(self.__lbxzone, 1, wx.EXPAND|wx.LEFT|wx.TOP|wx.BOTTOM, 10)
self.__lbxzone.Bind(wx.EVT_LISTBOX, self.onselect)
self.__txctr= wx.TextCtrl(self, value= '',
style=wx.TE_MULTILINE)
hbox.Add(self.__txctr, 1, wx.EXPAND|wx.ALL, 10)
sbox.Add(hbox, 1, wx.EXPAND)
self.__stxt= wx.StaticText(self, label= '')
sbox.Add(self.__stxt, 1, wx.ALL, 5)
self.__lbxzone.Bind(wx.EVT_ENTER_WINDOW, self.enterlstbx)
self.__lbxzone.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
self.__txctr.Bind(wx.EVT_ENTER_WINDOW, self.entertxtctrl)
self.__txctr.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
self.SetSizer(sbox)
self.__timer.Start(100)
self.selection(self.__lbxzone.GetSelection())
def onselect(self, event):
self.selection(event.GetSelection())
def selection(self, index):
zone= self.__lbxzone.GetString(index)
self.__diff= self.__timediff[zone]
self.__txctr.SetValue(self.__fulllist[zone])
def ontimer(self, event):
ct= time.gmtime()
cttuple = (ct[0], ct[1], ct[2], ct[3]+self.__diff, ct[4], ct[5], ct[6],
ct[7], -1)
txt= 'Wintertime: '+ time.strftime('%H:%M:%S', cttuple)
self.__stxt.SetLabel(txt)
def enterlstbx(self, event):
self.__frame.setstatustxt('wx.ListBox')
event.Skip()
def entertxtctrl(self, event):
self.__frame.setstatustxt('wx.TextCtrl')
event.Skip()
def leavewdg(self, event):
self.__frame.setstatustxt('')
event.Skip()
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
WdgListBox(self, self)
self.Show()
def setstatustxt(self, txt):
print(txt)
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdglstbx.py')
app.MainLoop()
wdgspnctr.py (Modul für wx.SpinCtrl auf Page four)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class WdgSpinCtrl(wx.Panel):
def __init__(self, parent, frame):
wx.Panel.__init__(self, parent)
self.__frame= frame
statbox= wx.StaticBox(self, label= 'wx.SpinCtrl')
sbox= wx.StaticBoxSizer(statbox, wx.VERTICAL)
stxtitle= wx.StaticText(self,
label= 'Convert Fahrenheit temperature to Celsius')
sbox.Add(stxtitle, 1, wx.ALL|wx.EXPAND, 5)
fxgrd= wx.FlexGridSizer(2, 2, 5, 5)
stxfahr= wx.StaticText(self, label= 'Fahrenheit:', size= (100, -1))
self.__spcfahr= wx.SpinCtrl(self, -1, '')
self.__spcfahr.SetRange(-459, 1000)
self.__spcfahr.SetValue(0)
self.__spcfahr.Bind(wx.EVT_SPINCTRL, self.onspnctr)
stxcel1= wx.StaticText(self, label= 'Celsius:')
self.__cel2= wx.StaticText(self, label= '')
fxgrd.AddMany( [(stxfahr, 1, wx.EXPAND|wx.ALL, 5),
(self.__spcfahr, 1, wx.EXPAND),
(stxcel1, 1, wx.EXPAND|wx.ALL, 5),
(self.__cel2, 1, wx.EXPAND|wx.ALL, 5)] )
sbox.Add(fxgrd, 1, wx.ALL|wx.EXPAND)
self.__spcfahr.Bind(wx.EVT_ENTER_WINDOW, self.enterspnctr)
self.__spcfahr.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
self.SetSizer(sbox)
self.fahrtocels()
def onspnctr(self, event):
self.fahrtocels()
def fahrtocels(self):
fahr= self.__spcfahr.GetValue()
cels= round((fahr- 32)* 5/ 9.0, 2)
self.__cel2.SetLabel(str(cels))
def enterspnctr(self, event):
self.__frame.setstatustxt('wx.SpinCtrl')
event.Skip()
def leavewdg(self, event):
self.__frame.setstatustxt('')
event.Skip()
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
WdgSpinCtrl(self, self)
self.Show()
def setstatustxt(self, txt):
print(txt)
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdgspnctr.py')
app.MainLoop()
# wx.SpinCtrl styles: wx.SP_ARROW_KEYS|wx.SP_WRAP
wdgsplwnd.py (Modul für wx.SplitterWindow auf Page Splitter)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class WdgSplitterWindow(wx.SplitterWindow):
def __init__(self, parent):
wx.SplitterWindow.__init__(self, parent)
pnl1= wx.Panel(self)
pic= wx.StaticBitmap(pnl1)
pic.SetBitmap(wx.Bitmap('pictures/CasparOskarLightning.jpg'))
pnl1.SetBackgroundColour(wx.LIGHT_GREY)
pnl2= wx.Panel(self)
pnl2.SetBackgroundColour(wx.WHITE)
self.SplitVertically(pnl1, pnl2)
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
WdgSplitterWindow(self)
self.Show()
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdgsplwnd.py')
app.MainLoop()
wdgscrwnd.py (Modul für wx.ScrolledWindow auf Page Scroll)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class WdgScrolledWindow(wx.ScrolledWindow):
def __init__(self, parent):
wx.ScrolledWindow.__init__(self, parent)
vbox= wx.BoxSizer(wx.VERTICAL)
pnl= wx.Panel(self)
vbox.Add(pnl)
pic= wx.Image('pictures/CasparOskarLightning.jpg',
wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
wx.StaticBitmap(pnl, wx.ID_ANY, pic)
x, y= pic.GetSize()
self.SetScrollbars(1, 1, x, y)
self.SetSizer(vbox)
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
WdgScrolledWindow(self)
self.Show()
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdgscrwnd.py')
app.MainLoop()
wdgntbsht.py (Modul für wx.Notebook auf Page Sheet)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
import wx.lib.sheet as sheet
class WdgNotebook(wx.Notebook):
def __init__(self, parent):
wx.Notebook.__init__(self, parent, wx.ID_ANY, style= wx.NB_BOTTOM)
self.__sht1= WdgSheet(self)
self.__sht2= WdgSheet(self)
self.__sht3= WdgSheet(self)
self.AddPage(self.__sht1, 'Sheet 1')
self.AddPage(self.__sht2, 'Sheet 2')
self.AddPage(self.__sht3, 'Sheet 3')
class WdgSheet(sheet.CSheet):
def __init__(self, parent):
sheet.CSheet.__init__(self, parent)
self.SetNumberRows(50)
self.SetNumberCols(50)
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
WdgNotebook(self)
self.Show()
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdgntbsht.py')
app.MainLoop()
Mit nur einem Skript wurde es zu unübersichtlich. Durch das Tutorial habe ich einiges gesehen und kann es gleich anwenden.
In einem Programmfenster mit mehreren Registern sind alle 'widgets' abgebildet. Die einzelnen Bereiche sind eigene Objekte, meist in externen Skripts.
Und hier Screenshots, für jedes Register einen:
Register Page one: wx.Button, wx.ToggleButton, wx.StaticText, wx.CheckBox
Register Page two: wx.BitmapButton & wx.Slider, wx.ComboBox & wx.StaticBitmap
Register Page three: wx.RadioButton, wx.Gauge, wx.ListBox
Register Page four: wx.SpinCtrl
Register Splitter
Register Scroll
Register Sheet
Und hier die Skripte:
06_widgets.py (Das Hauptmodul)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
import wx.lib.sheet as sheet
import random
from wdgbtn import WdgButton #wx.Button: Page 1
# WdgButton(parent, frame, width, height)
from wdgtglbtn import WdgToggleButton #wx.ToggleButton: Page 1
# WdgToggleButton(parent, frame)
from wdgbmpbtn import WdgBitmapButton #wx.BitmapButton: Page 2
# WdgBitmapButton(parent, frame)
from wdgstxt import WdgStaticText #wx.StaticText: Page 1
# WdgStaticText(parent, frame)
from wdgcmbbx import WdgComboBox #wx.ComboBox: Page 2
# WdgComboBox(parent, frame)
from wdgchkbx import WdgCheckBox #wx.CheckBox: Page 1
# WdgCheckBox(parent, frame, title)
from wdgradbtn import WdgRadioButton #wx.RadioButton: Page 3
# WdgRadioButton(parent, frame)
from wdggaug import WdgGauge #wx.Gauge: Page 3
# WdgGauge(parent, frame)
from wdglstbx import WdgListBox #wx.WdgListBox: Page 3
# WdgListBox(parent, frame)
from wdgspnctr import WdgSpinCtrl #wx.SpinCtrl: Page 4
# WdgSpinCtrl(parent, frame)
from wdgsplwnd import WdgSplitterWindow #wx.SplitterWindow: Page Splitter
# WdgSplitterWindow(parent)
from wdgscrwnd import WdgScrolledWindow #wx.ScrolledWindow: Page Scroll
# WdgScrolledWindow(parent)
from wdgntbsht import WdgNotebook, WdgSheet #wx.Notebook: Page Notebook
# WdgNotebook(parent)
#parent= wx.Object (Frame, Panel, Notebook)
#frame= wx.Frame
#title= wx.Frame title
APP_WIDTH= 360
APP_HEIGHT= 660
class Widgets(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title,
size=(APP_WIDTH, APP_HEIGHT))
menubar= wx.MenuBar()
mnufile= wx.Menu()
idmnuexit= wx.ID_EXIT
mnufile.Append(idmnuexit, '&Quit\tCtrl+W',
'Quit the application')
self.Bind(wx.EVT_MENU, self.onclose, id= idmnuexit)
menubar.Append(mnufile, '&File')
mnuplay= wx.Menu()
mnuplay.Append(wx.ID_ANY, '&Video',
'Play a video')
menubar.Append(mnuplay, '&Play')
mnuview= wx.Menu()
mnuview.Append(wx.ID_ANY, 'Show &all files',
'Play all open files')
menubar.Append(mnuview, '&View')
mnutools= wx.Menu()
mnutools.Append(wx.ID_ANY, '&Convert',
'Convert in a other format')
menubar.Append(mnutools, '&Tools')
mnufavorites= wx.Menu()
mnufavorites.Append(wx.ID_ANY, '&Add to favorites',
'Add current file to favorites')
menubar.Append(mnufavorites, 'F&avorites')
mnuhelp= wx.Menu()
mnuhelp.Append(wx.ID_ANY, '&About',
'Info about Erasand.06.Widget.py')
menubar.Append(mnuhelp, '&Help')
self.SetMenuBar(menubar)
self.__stb= self.CreateStatusBar()
self.__sa= ''
self.__sb= ''
self.__sc= ''
self.__stxt= ''
# Notebook for a couple of pages
nbk= wx.Notebook(self)
nbk.AddPage(PageOne(nbk, self, title), 'Page one')
nbk.AddPage(PageTwo(nbk, self, title), 'Page two')
nbk.AddPage(PageThree(nbk, self, title), 'Page three')
nbk.AddPage(PageFour(nbk, self, title), 'Page four')
nbk.AddPage(WdgSplitterWindow(nbk), 'Splitter')
nbk.AddPage(WdgScrolledWindow(nbk), 'Scroll')
nbk.AddPage(WdgNotebook(nbk), 'Sheet')
self.SetMinSize((APP_WIDTH, APP_HEIGHT))
# self.SetMaxSize((x, y))
self.Centre()
self.Show()
def onclose(self, event):
self.Close()
def setstatusa(self, txt):
self.__sa= txt
self.setstatusbar()
def setstatusb(self, txt):
self.__sb= txt
self.setstatusbar()
def setstatusc(self, txt):
self.__sc= txt
self.setstatusbar()
def setstatustxt(self, txt):
self.__stxt= txt
self.setstatusbar()
def setstatusbar(self):
txt = ' A: '+ self.__sa+ ' | B: '+ self.__sb+ ' | C: '+ self.__sc
txt+= ' | '+ self.__stxt
self.__stb.SetStatusText(txt)
class PageOne(wx.Panel):
def __init__(self, parent, frame, title):
wx.Panel.__init__(self, parent)
vbox= wx.BoxSizer(wx.VERTICAL)
hbox= wx.BoxSizer(wx.HORIZONTAL)
# wx.StaticLine
hln1= wx.StaticLine(self, size= (300, 1), style= wx.LI_HORIZONTAL)
hln2= wx.StaticLine(self, size= (300, 1), style= wx.LI_HORIZONTAL)
hln3= wx.StaticLine(self, size= (300, 1), style= wx.LI_HORIZONTAL)
hln4= wx.StaticLine(self, size= (300, 1), style= wx.LI_HORIZONTAL)
hln5= wx.StaticLine(self, size= (300, 1), style= wx.LI_HORIZONTAL)
vln1= wx.StaticLine(self, size= (1, 440), style= wx.LI_VERTICAL)
vln2= wx.StaticLine(self, size= (1, 440), style= wx.LI_VERTICAL)
vbox.Add(hln1, 0, wx.ALL, 5)
# wx.Button
a= WdgButton(self, frame, APP_WIDTH, APP_HEIGHT)
vbox.Add(a, 0, wx.EXPAND|wx.ALL, 5)
vbox.Add(hln2, 0, wx.ALL, 5)
# wx.ToggleButton
b= WdgToggleButton(self, frame)
vbox.Add(b, 0, wx.EXPAND|wx.ALL, 5)
vbox.Add(hln3, 0, wx.ALL, 5)
# wx.StaticText
c= WdgStaticText(self, frame)
vbox.Add(c, 0, wx.EXPAND|wx.ALL, 5)
vbox.Add(hln4, 0, wx.ALL, 5)
# wx.CheckBox
d= WdgCheckBox(self, frame, title)
vbox.Add(d, 0, wx.EXPAND|wx.ALL, 5)
vbox.Add(hln5, 0, wx.ALL, 5)
hbox.Add(vln1, wx.ALL, 5)
hbox.Add(vbox, 0, wx.EXPAND, 5)
hbox.Add(vln2, wx.ALL, 5)
self.SetSizer(hbox)
class PageTwo(wx.Panel):
def __init__(self, parent, frame, title):
wx.Panel.__init__(self, parent)
vbox= wx.BoxSizer(wx.VERTICAL)
# wx.BitmapButton
a= WdgBitmapButton(self, frame)
vbox.Add(a, 0, wx.EXPAND|wx.ALL, 5)
# wx.ComboBox
b= WdgComboBox(self, frame)
vbox.Add(b, 0, wx.EXPAND|wx.ALL, 5)
self.SetSizer(vbox)
class PageThree(wx.Panel):
def __init__(self, parent, frame, title):
wx.Panel.__init__(self, parent)
vbox= wx.BoxSizer(wx.VERTICAL)
# wx.RadioButton
a= WdgRadioButton(self, frame)
vbox.Add(a, 0, wx.EXPAND|wx.ALL, 5)
# wx.Gauge
b= WdgGauge(self, frame)
vbox.Add(b, 0, wx.EXPAND|wx.ALL, 5)
# wx.ListBox
c= WdgListBox(self, frame)
vbox.Add(c, 0, wx.EXPAND|wx.ALL, 5)
self.SetSizer(vbox)
class PageFour(wx.Panel):
def __init__(self, parent, frame, title):
wx.Panel.__init__(self, parent)
vbox= wx.BoxSizer(wx.VERTICAL)
# wx.SpinCtrl
a= WdgSpinCtrl(self, frame)
vbox.Add(a, 0, wx.EXPAND|wx.ALL, 5)
self.SetSizer(vbox)
if __name__== '__main__':
app= wx.App()
Widgets(None, 'Erasand.06.Widgets')
app.MainLoop()
wdgbtn.py (Modul für wx.Button auf Page one)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
import random
class WdgButton(wx.Panel):
def __init__(self, parent, frame, width, height):
wx.Panel.__init__(self, parent)
self.__frame= frame
self.__width= width
self.__height= height
statbx= wx.StaticBox(self, label= 'wx.Button')
sbox= wx.StaticBoxSizer(statbx, wx.HORIZONTAL)
close= wx.Button(self, wx.ID_CLOSE)
sbox.Add(close, 0, wx.ALL, 10)
close.Bind(wx.EVT_BUTTON, self.onclose)
random= wx.Button(self, label= 'Random Move')
sbox.Add(random, 0, wx.ALL, 10)
random.Bind(wx.EVT_BUTTON, self.onrndmove)
close.Bind(wx.EVT_ENTER_WINDOW, self.enterbutton)
random.Bind(wx.EVT_ENTER_WINDOW, self.enterbutton)
close.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
random.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
self.SetSizer(sbox)
def onclose(self, event):
self.__frame.Close()
def onrndmove(self, event):
screensize= wx.GetDisplaySize()
randx= random.randrange(0, screensize.x- self.__width)
randy= random.randrange(0, screensize.y- self.__height)
self.__frame.Move((randx, randy))
def enterbutton(self, event):
self.__frame.setstatustxt('wx.Button')
event.Skip()
def leavewdg(self, event):
self.__frame.setstatustxt('')
event.Skip()
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
WdgButton(self, self, 300, 300)
self.Show()
def setstatustxt(self, txt):
print(txt)
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdgbtn.py')
app.MainLoop()
# wx.Button styles: wx.BU_LEFT|wx.BU_TOP|wx.BU_RIGHT|wx.BU_BOTTOM|
# wx.BU_EXACTFIT|wx.NO_BORDER
wdgtglbtn.py (Modul für wx.ToggleButton auf Page one)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class WdgToggleButton(wx.Panel):
def __init__(self, parent, frame):
wx.Panel.__init__(self, parent)
self.__frame= frame
statbx= wx.StaticBox(self, label= 'wx.Toggle-Button',
style= wx.SUNKEN_BORDER)
sbox= wx.StaticBoxSizer(statbx, wx.VERTICAL)
self.__panel= wx.Panel(self)
self.__color= wx.Colour(0, 0, 0)
self.__panel.SetBackgroundColour(self.__color)
sbox.Add(self.__panel, 0, wx.EXPAND|wx.ALL, 5)
hbox= wx.BoxSizer(wx.HORIZONTAL)
btnred= wx.ToggleButton(self, label= 'red')
hbox.Add(btnred, 0, wx.ALL, 5)
btnred.Bind(wx.EVT_TOGGLEBUTTON, self.onred)
btngreen= wx.ToggleButton(self, label= 'green')
hbox.Add(btngreen, 0, wx.ALL, 5)
btngreen.Bind(wx.EVT_TOGGLEBUTTON, self.ongreen)
btnblue= wx.ToggleButton(self, label= 'blue')
hbox.Add(btnblue, 0, wx.ALL, 5)
btnblue.Bind(wx.EVT_TOGGLEBUTTON, self.onblue)
sbox.Add(hbox, 0, wx.ALL, 5)
self.__panel.Bind(wx.EVT_ENTER_WINDOW, self.enterpanel)
self.__panel.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
for i in btnred, btngreen, btnblue:
i.Bind(wx.EVT_ENTER_WINDOW, self.entertglbutton)
i.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
self.SetSizer(sbox)
def onred(self, event):
green= self.__color.Green()
blue= self.__color.Blue()
if self.__color.Red():
self.__color.Set(0, green, blue)
else:
self.__color.Set(255, green, blue)
self.__panel.SetBackgroundColour(self.__color)
def ongreen(self, event):
red= self.__color.Red()
blue= self.__color.Blue()
if self.__color.Green():
self.__color.Set(red, 0, blue)
else:
self.__color.Set(red, 255, blue)
self.__panel.SetBackgroundColour(self.__color)
def onblue(self, event):
red= self.__color.Red()
green= self.__color.Green()
if self.__color.Blue():
self.__color.Set(red, green, 0)
else:
self.__color.Set(red, green, 255)
self.__panel.SetBackgroundColour(self.__color)
def entertglbutton(self, event):
self.__frame.setstatustxt('wx.ToggelButton')
event.Skip()
def enterpanel(self, event):
self.__frame.setstatustxt('wx.Panel')
event.Skip()
def leavewdg(self, event):
self.__frame.setstatustxt('')
event.Skip()
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
WdgToggleButton(self, self)
self.Show()
def setstatustxt(self, txt):
print(txt)
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdgtglbtn.py')
app.MainLoop()
wdgstxt.py (Modul für wx.StaticText auf Page one)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class WdgStaticText(wx.Panel):
def __init__(self, parent, frame):
wx.Panel.__init__(self, parent)
self.__frame= frame
lyrics1= '''I'm giving up the ghost of love
in the shadows cast on devotion
She is the one that I adore
creed of my silent suffocation
Break this bittersweet spell on me
lost in the arms of destiny'''
lyrics2= '''There is something in the way
You're always somewhere else
Feelings have deserted me
To a point of no return
I don't believe in God
But I pray for you'''
statbx= wx.StaticBox(self, label= 'wx.StaticText')
sbox= wx.StaticBoxSizer(statbx, wx.VERTICAL)
statxt1= wx.StaticText(self, label= lyrics1, style= wx.ALIGN_CENTRE)
sbox.Add(statxt1, 0, wx.EXPAND|wx.ALL, 10)
statxt2= wx.StaticText(self, label= lyrics2, style= wx.ALIGN_CENTRE)
sbox.Add(statxt2, 0, wx.EXPAND|wx.ALL, 10)
self.SetSizer(sbox)
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
WdgStaticText(self, self)
self.Show()
def setstatustxt(self, txt):
print(txt)
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdgstxt.py')
app.MainLoop()
# wx.StaticText styles: wx.ALIGN_RIGHT|wx.ALIGN_LEFT|
# wx.ALIGN_CENTER|wx.ALIGN_CENTRE|wx.ST_NO_AUTORESIZE
wdgchkbx.py (Modul für wx.CheckBox auf Page one)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class WdgCheckBox(wx.Panel):
def __init__(self, parent, frame, title):
wx.Panel.__init__(self, parent)
self.__frame= frame
self.__title= title
statbx= wx.StaticBox(self, label= 'wx.CheckBox')
sbox= wx.StaticBoxSizer(statbx, wx.HORIZONTAL)
self.__checkbx= wx.CheckBox(self, label= 'Show Title')
sbox.Add(self.__checkbx, 0, wx.ALL, 10)
self.__checkbx.Bind(wx.EVT_CHECKBOX, self.oncheckbx)
self.__checkbx.Bind(wx.EVT_ENTER_WINDOW, self.entercheckbx)
self.__checkbx.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
self.SetSizer(sbox)
def oncheckbx(self, event):
if self.__checkbx.GetValue():
self.__frame.SetTitle(self.__title+ ' / Checkbox aktiviert')
else:
self.__frame.SetTitle(self.__title)
def entercheckbx(self, event):
self.__frame.setstatustxt('wx.CheckBox')
event.Skip()
def leavewdg(self, event):
self.__frame.setstatustxt('')
event.Skip()
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(400, 200))
WdgCheckBox(self, self, title)
self.Show()
def setstatustxt(self, txt):
print(txt)
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdgchkbx.py')
app.MainLoop()
wdgbmpbtn.py (Modul für wx.BitmapButton und wx.Slider auf Page two)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class WdgBitmapButton(wx.Panel):
def __init__(self, parent, frame):
wx.Panel.__init__(self, parent)
self.__frame= frame
statbx= wx.StaticBox(self, label= 'wx.BitmapButton & wx.Slider')
sbox= wx.StaticBoxSizer(statbx, wx.VERTICAL)
pnlplay= wx.Panel(self, size=(200,200))
pnlplay.SetBackgroundColour(wx.BLACK)
sbox.Add(pnlplay, 0, wx.EXPAND|wx.ALL, 10)
self.__sldply= wx.Slider(self, wx.ID_ANY, 0, 0, 3600)
sbox.Add(self.__sldply, 0, wx.EXPAND | wx.BOTTOM, 10)
hbox1= wx.BoxSizer(wx.HORIZONTAL)
pause= wx.BitmapButton(self, wx.ID_ANY,
wx.Bitmap('../icons_22/media-playback-pause.png'))
hbox1.Add(pause)
play= wx.BitmapButton(self, wx.ID_ANY,
wx.Bitmap('../icons_22/media-playback-start.png'))
hbox1.Add(play, 0, wx.RIGHT, 5)
next= wx.BitmapButton(self, wx.ID_ANY,
wx.Bitmap('../icons_22/media-skip-forward.png'))
hbox1.Add(next, 0, wx.LEFT, 5)
prev= wx.BitmapButton(self, wx.ID_ANY,
wx.Bitmap('../icons_22/media-skip-backward.png'))
hbox1.Add(prev, 0, wx.RIGHT, 5)
volume= wx.BitmapButton(self, wx.ID_ANY,
wx.Bitmap('../icons_22/audio-volume-medium.png'))
hbox1.Add(volume, 0, wx.LEFT, 5)
self.__sldvol= wx.Slider(self, wx.ID_ANY, 0, 0, 100,
size=(120, -1), style= wx.SL_AUTOTICKS|wx.SL_LABELS)
hbox1.Add(self.__sldvol, 0, wx.TOP|wx.LEFT, 5)
sbox.Add(hbox1, 0, wx.EXPAND)
self.__inftxt= wx.StaticText(self, label= 'Positon: / Volume:')
sbox.Add(self.__inftxt, 0, wx.ALL, 5)
pnlplay.Bind(wx.EVT_ENTER_WINDOW, self.enterpanel)
self.__sldply.Bind(wx.EVT_ENTER_WINDOW, self.enterslider)
self.__sldvol.Bind(wx.EVT_ENTER_WINDOW, self.enterslider)
for i in pause, play, next, prev, volume:
i.Bind(wx.EVT_ENTER_WINDOW, self.enterbitmapbutton)
for i in pnlplay, pause, play, next, prev, volume:
i.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
for i in self.__sldply, self.__sldvol:
i.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
for i in self.__sldply, self.__sldvol:
i.Bind(wx.EVT_SLIDER, self.oninfo)
self.infoupdate()
self.SetSizer(sbox)
def enterpanel(self, event):
self.__frame.setstatustxt('wx.Panel')
event.Skip()
def enterslider(self, event):
self.__frame.setstatustxt('wx.Slider')
event.Skip()
def enterbitmapbutton(self, event):
self.__frame.setstatustxt('wx.BitmapButton')
event.Skip()
def enterbutton(self, event):
self.__frame.setstatustxt('wx.Button')
event.Skip()
def leavewdg(self, event):
self.__frame.setstatustxt('')
event.Skip()
def oninfo(self, event):
self.infoupdate()
def infoupdate(self):
mm= int(self.__sldply.GetValue()/ 60)
ss= self.__sldply.GetValue()- (60* mm)
vol= self.__sldvol.GetValue()
mmtxt, sstxt, voltxt= str(mm), str(ss), str(vol)
if len(mmtxt)==1:
mmtxt= '0'+ mmtxt
if len(sstxt)==1:
sstxt= '0'+ sstxt
if len(voltxt)==1:
voltxt= '0'+ voltxt
txt= 'Position: '+ mmtxt+ ':'+ sstxt+ ' / '
txt+= 'Volume: '+ voltxt
self.__inftxt.SetLabel(txt)
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 400))
WdgBitmapButton(self, self)
self.Show()
def setstatustxt(self, txt):
print(txt)
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdgbmpbtn.py')
app.MainLoop()
# wx.Slider(parent, id, startvalue, minvalue, maxvalue, style)
# wx.Slider style: wx.SL_HORIZONTAL|wx.SL_VERTICAL|
# wx.SL_AUTOTICKS| (display tick marks)
# wx.SL_LABELS| (display value labels)
# wx.SL_LEFT|wx.SL_RIGHT|wx.SL_TOP|wx.SL_BOTTOM|wx.SL_INVERSE
wdgcmbbx.py (Modul für wx.ComboBox und wx.StaticBitmap auf Page two)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class WdgComboBox(wx.Panel):
def __init__(self, parent, frame):
wx.Panel.__init__(self, parent)
self.__frame= frame
statbox= wx.StaticBox(self, label= 'wx.ComboBox & wx.StaticBitmap')
sbox= wx.StaticBoxSizer(statbox, wx.VERTICAL)
pnlpic = wx.Panel(self, style=wx.SUNKEN_BORDER)
self.__pic= wx.StaticBitmap(pnlpic)
self.__pic.SetBitmap(wx.Bitmap('pictures/leer_100-127.png'))
pnlpic.SetBackgroundColour(wx.WHITE)
sbox.Add(pnlpic, 0, wx.ALL, 10)
self.__pictures= ['pictures/tolstoy.png',
'pictures/feuchtwanger.png',
'pictures/balzac.png',
'pictures/pasternak.png',
'pictures/galsworthy.png',
'pictures/wolfe.png',
'pictures/zweig.png']
authors= ['Leo Tolstoy', 'Lion Feuchtwanger', 'Honore de Balzac',
'Boris Pasternak', 'John Galsworthy', 'Tom Wolfe', 'Stefan Zweig']
combobx= wx.ComboBox(self, size=(150, -1), choices=authors,
style=wx.CB_READONLY)
sbox.Add(combobx, 0, wx.EXPAND|wx.ALL, 10)
combobx.Bind(wx.EVT_COMBOBOX, self.oncombo)
pnlpic.Bind(wx.EVT_ENTER_WINDOW, self.enterpanel)
combobx.Bind(wx.EVT_ENTER_WINDOW, self.entercombobox)
pnlpic.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
combobx.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
self.SetSizer(sbox)
def oncombo(self, event):
item = event.GetSelection()
self.__pic.SetFocus()
self.__pic.SetBitmap(wx.Bitmap(self.__pictures[item]))
def enterpanel(self, event):
self.__frame.setstatustxt('wx.Panel')
event.Skip()
def entercombobox(self, event):
self.__frame.setstatustxt('wx.ComboBox')
event.Skip()
def leavewdg(self, event):
self.__frame.setstatustxt('')
event.Skip()
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
WdgComboBox(self, self)
self.Show()
def setstatustxt(self, txt):
print(txt)
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdgcmbbx.py')
app.MainLoop()
wdgradbtn.py (Modul für wx.RadioButton auf Page three)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class WdgRadioButton(wx.Panel):
def __init__(self, parent, frame):
wx.Panel.__init__(self, parent)
self.__frame= frame
statbx= wx.StaticBox(self, label= 'wx.RadioButton')
sbox= wx.StaticBoxSizer(statbx, wx.VERTICAL)
self.__radiobtn1 = wx.RadioButton(self, label= 'Value A',
style=wx.RB_GROUP)
sbox.Add(self.__radiobtn1, 0, wx.EXPAND|wx.ALL, 5)
self.__radiobtn1.Bind(wx.EVT_RADIOBUTTON, self.setval)
self.__radiobtn2 = wx.RadioButton(self, label= 'Value B')
sbox.Add(self.__radiobtn2, 0, wx.EXPAND|wx.ALL, 5)
self.__radiobtn2.Bind(wx.EVT_RADIOBUTTON, self.setval)
self.__radiobtn3 = wx.RadioButton(self, label= 'Value C')
sbox.Add(self.__radiobtn3, 0, wx.EXPAND|wx.ALL, 5)
self.__radiobtn3.Bind(wx.EVT_RADIOBUTTON, self.setval)
for i in self.__radiobtn1, self.__radiobtn2, self.__radiobtn3:
i.Bind(wx.EVT_ENTER_WINDOW, self.enterradiobtn)
i.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
self.setval(True)
self.SetSizer(sbox)
def setval(self, event):
self.__frame.setstatusa(str(self.__radiobtn1.GetValue()))
self.__frame.setstatusb(str(self.__radiobtn2.GetValue()))
self.__frame.setstatusc(str(self.__radiobtn3.GetValue()))
def enterradiobtn(self, event):
self.__frame.setstatustxt('wx.RadioButton')
event.Skip()
def leavewdg(self, event):
self.__frame.setstatustxt('')
event.Skip()
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
WdgRadioButton(self, self)
self.Show()
def setstatustxt(self, txt):
print(txt)
def setstatusa(self, txt):
print(txt)
def setstatusb(self, txt):
print(txt)
def setstatusc(self, txt):
print(txt)
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdgradbtn.py')
app.MainLoop()
# wx.RadioButton styles: wx.RB_GROUP|wx.RB_SINGLE|wx.CB_SORT
wdggaug.py (Modul für wx.Gauge auf Page three)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class WdgGauge(wx.Panel):
def __init__(self, parent, frame):
wx.Panel.__init__(self, parent)
self.__frame= frame
self.__timer= wx.Timer(self, 1)
self.__count= 0
self.Bind(wx.EVT_TIMER, self.ontimer, self.__timer)
statbx= wx.StaticBox(self, label= 'wx.Gauge')
sbox= wx.StaticBoxSizer(statbx, wx.VERTICAL)
hbox1= wx.BoxSizer(wx.HORIZONTAL)
self.__gag = wx.Gauge(self, wx.ID_ANY, 50, size=(250, 25))
hbox1.Add(self.__gag, 1, wx.ALIGN_CENTRE)
hbox2= wx.BoxSizer(wx.HORIZONTAL)
btnok = wx.Button(self, wx.ID_OK)
hbox2.Add(btnok, 1, wx.RIGHT, 10)
btnok.Bind(wx.EVT_BUTTON, self.onok)
btnstop = wx.Button(self, wx.ID_STOP)
hbox2.Add(btnstop, 1)
btnstop.Bind(wx.EVT_BUTTON, self.onstop)
hbox3= wx.BoxSizer(wx.HORIZONTAL)
self.__txt = wx.StaticText(self, label= 'Task to be done')
hbox3.Add(self.__txt, 1)
sbox.Add(hbox1, 0, wx.TOP|wx.ALIGN_CENTRE, 20)
sbox.Add(hbox2, 0, wx.TOP|wx.ALIGN_CENTRE, 20)
sbox.Add(hbox3, 0, wx.TOP|wx.BOTTOM|wx.ALIGN_CENTRE, 20)
self.__gag.Bind(wx.EVT_ENTER_WINDOW, self.entergauge)
btnok.Bind(wx.EVT_ENTER_WINDOW, self.enterbutton)
btnstop.Bind(wx.EVT_ENTER_WINDOW, self.enterbutton)
for i in self.__gag, btnok, btnstop:
i.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
self.SetSizer(sbox)
def enterbutton(self, event):
self.__frame.setstatustxt('wx.Button')
event.Skip()
def entergauge(self, event):
self.__frame.setstatustxt('wx.Gauge')
event.Skip()
def leavewdg(self, event):
self.__frame.setstatustxt('')
event.Skip()
def onok(self, event):
if self.__count>= 50:
self.__count= 0
self.__timer.Start(100)
self.__txt.SetLabel('Task again in progress')
else:
self.__timer.Start(100)
self.__txt.SetLabel('Task in progress')
def onstop(self, event):
if self.__count== 0 or self.__count>= 50 or not self.__timer.IsRunning():
return
self.__timer.Stop()
self.__txt.SetLabel('Task interrupted')
wx.Bell()
def ontimer(self, event):
self.__count = self.__count +1
self.__gag.SetValue(self.__count)
if self.__count== 50:
self.__timer.Stop()
self.__txt.SetLabel('Task completed')
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
WdgGauge(self, self)
self.Show()
def setstatustxt(self, txt):
print(txt)
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdggaug.py')
app.MainLoop()
# wx.Gauge styles: wx.GA_HORIZONTAL|wx.GA_VERTICAL
wdglstbx.py (Modul für wx.WdgListBox auf Page three)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
import time
class WdgListBox(wx.Panel):
def __init__(self, parent, frame):
wx.Panel.__init__(self, parent)
self.__frame= frame
statbox= wx.StaticBox(self, label= 'wx.ListBox')
sbox= wx.StaticBoxSizer(statbox, wx.VERTICAL)
zone_list= ['CET', 'GMT', 'MSK', 'EST', 'PST', 'EDT']
self.__fulllist= {'CET': 'Central European Time',
'GMT': 'Greenwich Mean Time',
'MSK': 'Moscow Time',
'EST': 'Eastern Standard Time',
'PST': 'Pacific Standard Time',
'EDT': 'Eastern Daylight Time'}
self.__timediff= {'CET': 1,
'GMT' : 0,
'MSK': 3,
'EST': -5,
'PST': -8,
'EDT': -4}
self.__timer= wx.Timer(self, 1)
self.Bind(wx.EVT_TIMER, self.ontimer, self.__timer)
self.__diff= 0
hbox= wx.BoxSizer(wx.HORIZONTAL)
self.__lbxzone = wx.ListBox(self, choices= zone_list,
style= wx.LB_SINGLE)
# wx.ListBox(self, 26, (-1, -1), (170, 130), zone_list, wx.LB_SINGLE)
self.__lbxzone.SetSelection(0)
hbox.Add(self.__lbxzone, 1, wx.EXPAND|wx.LEFT|wx.TOP|wx.BOTTOM, 10)
self.__lbxzone.Bind(wx.EVT_LISTBOX, self.onselect)
self.__txctr= wx.TextCtrl(self, value= '',
style=wx.TE_MULTILINE)
hbox.Add(self.__txctr, 1, wx.EXPAND|wx.ALL, 10)
sbox.Add(hbox, 1, wx.EXPAND)
self.__stxt= wx.StaticText(self, label= '')
sbox.Add(self.__stxt, 1, wx.ALL, 5)
self.__lbxzone.Bind(wx.EVT_ENTER_WINDOW, self.enterlstbx)
self.__lbxzone.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
self.__txctr.Bind(wx.EVT_ENTER_WINDOW, self.entertxtctrl)
self.__txctr.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
self.SetSizer(sbox)
self.__timer.Start(100)
self.selection(self.__lbxzone.GetSelection())
def onselect(self, event):
self.selection(event.GetSelection())
def selection(self, index):
zone= self.__lbxzone.GetString(index)
self.__diff= self.__timediff[zone]
self.__txctr.SetValue(self.__fulllist[zone])
def ontimer(self, event):
ct= time.gmtime()
cttuple = (ct[0], ct[1], ct[2], ct[3]+self.__diff, ct[4], ct[5], ct[6],
ct[7], -1)
txt= 'Wintertime: '+ time.strftime('%H:%M:%S', cttuple)
self.__stxt.SetLabel(txt)
def enterlstbx(self, event):
self.__frame.setstatustxt('wx.ListBox')
event.Skip()
def entertxtctrl(self, event):
self.__frame.setstatustxt('wx.TextCtrl')
event.Skip()
def leavewdg(self, event):
self.__frame.setstatustxt('')
event.Skip()
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
WdgListBox(self, self)
self.Show()
def setstatustxt(self, txt):
print(txt)
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdglstbx.py')
app.MainLoop()
wdgspnctr.py (Modul für wx.SpinCtrl auf Page four)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class WdgSpinCtrl(wx.Panel):
def __init__(self, parent, frame):
wx.Panel.__init__(self, parent)
self.__frame= frame
statbox= wx.StaticBox(self, label= 'wx.SpinCtrl')
sbox= wx.StaticBoxSizer(statbox, wx.VERTICAL)
stxtitle= wx.StaticText(self,
label= 'Convert Fahrenheit temperature to Celsius')
sbox.Add(stxtitle, 1, wx.ALL|wx.EXPAND, 5)
fxgrd= wx.FlexGridSizer(2, 2, 5, 5)
stxfahr= wx.StaticText(self, label= 'Fahrenheit:', size= (100, -1))
self.__spcfahr= wx.SpinCtrl(self, -1, '')
self.__spcfahr.SetRange(-459, 1000)
self.__spcfahr.SetValue(0)
self.__spcfahr.Bind(wx.EVT_SPINCTRL, self.onspnctr)
stxcel1= wx.StaticText(self, label= 'Celsius:')
self.__cel2= wx.StaticText(self, label= '')
fxgrd.AddMany( [(stxfahr, 1, wx.EXPAND|wx.ALL, 5),
(self.__spcfahr, 1, wx.EXPAND),
(stxcel1, 1, wx.EXPAND|wx.ALL, 5),
(self.__cel2, 1, wx.EXPAND|wx.ALL, 5)] )
sbox.Add(fxgrd, 1, wx.ALL|wx.EXPAND)
self.__spcfahr.Bind(wx.EVT_ENTER_WINDOW, self.enterspnctr)
self.__spcfahr.Bind(wx.EVT_LEAVE_WINDOW, self.leavewdg)
self.SetSizer(sbox)
self.fahrtocels()
def onspnctr(self, event):
self.fahrtocels()
def fahrtocels(self):
fahr= self.__spcfahr.GetValue()
cels= round((fahr- 32)* 5/ 9.0, 2)
self.__cel2.SetLabel(str(cels))
def enterspnctr(self, event):
self.__frame.setstatustxt('wx.SpinCtrl')
event.Skip()
def leavewdg(self, event):
self.__frame.setstatustxt('')
event.Skip()
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
WdgSpinCtrl(self, self)
self.Show()
def setstatustxt(self, txt):
print(txt)
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdgspnctr.py')
app.MainLoop()
# wx.SpinCtrl styles: wx.SP_ARROW_KEYS|wx.SP_WRAP
wdgsplwnd.py (Modul für wx.SplitterWindow auf Page Splitter)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class WdgSplitterWindow(wx.SplitterWindow):
def __init__(self, parent):
wx.SplitterWindow.__init__(self, parent)
pnl1= wx.Panel(self)
pic= wx.StaticBitmap(pnl1)
pic.SetBitmap(wx.Bitmap('pictures/CasparOskarLightning.jpg'))
pnl1.SetBackgroundColour(wx.LIGHT_GREY)
pnl2= wx.Panel(self)
pnl2.SetBackgroundColour(wx.WHITE)
self.SplitVertically(pnl1, pnl2)
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
WdgSplitterWindow(self)
self.Show()
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdgsplwnd.py')
app.MainLoop()
wdgscrwnd.py (Modul für wx.ScrolledWindow auf Page Scroll)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class WdgScrolledWindow(wx.ScrolledWindow):
def __init__(self, parent):
wx.ScrolledWindow.__init__(self, parent)
vbox= wx.BoxSizer(wx.VERTICAL)
pnl= wx.Panel(self)
vbox.Add(pnl)
pic= wx.Image('pictures/CasparOskarLightning.jpg',
wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
wx.StaticBitmap(pnl, wx.ID_ANY, pic)
x, y= pic.GetSize()
self.SetScrollbars(1, 1, x, y)
self.SetSizer(vbox)
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
WdgScrolledWindow(self)
self.Show()
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdgscrwnd.py')
app.MainLoop()
wdgntbsht.py (Modul für wx.Notebook auf Page Sheet)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
import wx.lib.sheet as sheet
class WdgNotebook(wx.Notebook):
def __init__(self, parent):
wx.Notebook.__init__(self, parent, wx.ID_ANY, style= wx.NB_BOTTOM)
self.__sht1= WdgSheet(self)
self.__sht2= WdgSheet(self)
self.__sht3= WdgSheet(self)
self.AddPage(self.__sht1, 'Sheet 1')
self.AddPage(self.__sht2, 'Sheet 2')
self.AddPage(self.__sht3, 'Sheet 3')
class WdgSheet(sheet.CSheet):
def __init__(self, parent):
sheet.CSheet.__init__(self, parent)
self.SetNumberRows(50)
self.SetNumberCols(50)
class TestWin(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(300, 300))
WdgNotebook(self)
self.Show()
if __name__== '__main__':
app= wx.App()
TestWin(None, 'wdgntbsht.py')
app.MainLoop()
Abonnieren
Posts (Atom)