Various demo updates

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@18566 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2003-01-04 04:16:51 +00:00
parent c2b281c55b
commit 3af61dfc11
5 changed files with 163 additions and 70 deletions

View File

@@ -1,6 +1,7 @@
*.pyc *.pyc
.DS_Store .DS_Store
.emacs.desktop .emacs.desktop
.setup.sh
b.bat b.bat
hangman_dict.txt hangman_dict.txt
mimetypes_wdr mimetypes_wdr

View File

@@ -3,44 +3,40 @@ from wxPython.wx import *
#---------------------------------------------------------------------- #----------------------------------------------------------------------
## class MyFontEnumerator(wxFontEnumerator):
## def __init__(self, list):
## wxFontEnumerator.__init__(self)
## self.list = list
## def OnFacename(self, face):
## self.list.append(face)
## return true
class TestPanel(wxPanel): class TestPanel(wxPanel):
def __init__(self, parent, log): def __init__(self, parent, log):
wxPanel.__init__(self, parent, -1) wxPanel.__init__(self, parent, -1)
## list = []
## e = MyFontEnumerator(list)
## e.EnumerateFacenames()
e = wxFontEnumerator() e = wxFontEnumerator()
e.EnumerateFacenames() e.EnumerateFacenames()
list = e.GetFacenames() list = e.GetFacenames()
list.sort() list.sort()
wxStaticText(self, -1, "Face names:", (15, 50), (65, 18)) s1 = wxStaticText(self, -1, "Face names:")
self.lb1 = wxListBox(self, -1, (80, 50), (200, 250), self.lb1 = wxListBox(self, -1, wxDefaultPosition, (200, 250),
list, wxLB_SINGLE) list, wxLB_SINGLE)
EVT_LISTBOX(self, self.lb1.GetId(), self.OnSelect) EVT_LISTBOX(self, self.lb1.GetId(), self.OnSelect)
self.txt = wxStaticText(self, -1, "Sample text...", (285, 50)) self.txt = wxStaticText(self, -1, "Sample text...", (285, 50))
row = wxBoxSizer(wxHORIZONTAL)
row.Add(s1, 0, wxALL, 5)
row.Add(self.lb1, 0, wxALL, 5)
row.Add(self.txt, 0, wxALL, 5)
sizer = wxBoxSizer(wxVERTICAL)
sizer.Add(row, 0, wxALL, 30)
self.SetSizer(sizer)
self.Layout()
self.lb1.SetSelection(0) self.lb1.SetSelection(0)
def OnSelect(self, evt): def OnSelect(self, evt):
face = self.lb1.GetStringSelection() face = self.lb1.GetStringSelection()
font = wxFont(28, wxDEFAULT, wxNORMAL, wxNORMAL, false, face) font = wxFont(28, wxDEFAULT, wxDEFAULT, wxDEFAULT, false, face)
self.txt.SetFont(font) self.txt.SetFont(font)
self.txt.SetSize(self.txt.GetBestSize()) self.txt.SetSize(self.txt.GetBestSize())
@@ -64,9 +60,12 @@ def runTest(frame, nb, log):
overview = """\ overview = """<html><body>
wxFontEnumerator enumerates either all available fonts on the system or only the ones with given attributes - either only fixed-width (suited for use in programs such as terminal emulators and the like) or the fonts available in the given encoding. wxFontEnumerator enumerates either all available fonts on the system or only
the ones with given attributes - either only fixed-width (suited for use in
programs such as terminal emulators and the like) or the fonts available in
the given encoding.
</body></html>
""" """

View File

@@ -382,12 +382,10 @@ class wxPythonDemo(wxFrame):
# add the windows to the splitter and split it. # add the windows to the splitter and split it.
splitter2.SplitHorizontally(self.nb, self.log) splitter2.SplitHorizontally(self.nb, self.log, 450)
splitter.SplitVertically(self.tree, splitter2) splitter.SplitVertically(self.tree, splitter2, 180)
splitter.SetSashPosition(180, true)
splitter.SetMinimumPaneSize(20) splitter.SetMinimumPaneSize(20)
splitter2.SetSashPosition(450, true)
splitter2.SetMinimumPaneSize(20) splitter2.SetMinimumPaneSize(20)

View File

@@ -3,41 +3,127 @@ from wxPython.wx import *
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
def runTest(frame, nb, log): class TestPanel(wxPanel):
def __init__(self, parent, log):
wxPanel.__init__(self, parent, -1)
self.log = log
btn = wxButton(self, -1, "Select Font")
EVT_BUTTON(self, btn.GetId(), self.OnSelectFont)
self.sampleText = wxTextCtrl(self, -1, "Sample Text")
#from wxPython.lib.stattext import wxGenStaticText
#self.sampleText = wxGenStaticText(self, -1, "Sample Text")
self.curFont = self.sampleText.GetFont()
self.curClr = wxBLACK
fgs = wxFlexGridSizer(cols=2, vgap=5, hgap=5)
fgs.AddGrowableCol(1)
fgs.AddGrowableRow(0)
fgs.Add(btn)
fgs.Add(self.sampleText, 0, wxADJUST_MINSIZE|wxGROW)
fgs.Add(15,15); fgs.Add(15,15) # an empty row
fgs.Add(wxStaticText(self, -1, "PointSize:"))
self.ps = wxStaticText(self, -1, "")
font = self.ps.GetFont()
font.SetWeight(wxBOLD)
self.ps.SetFont(font)
fgs.Add(self.ps, 0, wxADJUST_MINSIZE)
fgs.Add(wxStaticText(self, -1, "Family:"))
self.family = wxStaticText(self, -1, "")
self.family.SetFont(font)
fgs.Add(self.family, 0, wxADJUST_MINSIZE)
fgs.Add(wxStaticText(self, -1, "Style:"))
self.style = wxStaticText(self, -1, "")
self.style.SetFont(font)
fgs.Add(self.style, 0, wxADJUST_MINSIZE)
fgs.Add(wxStaticText(self, -1, "Weight:"))
self.weight = wxStaticText(self, -1, "")
self.weight.SetFont(font)
fgs.Add(self.weight, 0, wxADJUST_MINSIZE)
fgs.Add(wxStaticText(self, -1, "Face:"))
self.face = wxStaticText(self, -1, "")
self.face.SetFont(font)
fgs.Add(self.face, 0, wxADJUST_MINSIZE)
fgs.Add(15,15); fgs.Add(15,15) # an empty row
fgs.Add(wxStaticText(self, -1, "wxNativeFontInfo:"))
self.nfi = wxStaticText(self, -1, "")
self.nfi.SetFont(font)
fgs.Add(self.nfi, 0, wxADJUST_MINSIZE)
# give it some border space
sizer = wxBoxSizer(wxVERTICAL)
sizer.Add(fgs, 0, wxGROW|wxADJUST_MINSIZE|wxALL, 25)
self.SetSizer(sizer)
self.UpdateUI()
def UpdateUI(self):
self.sampleText.SetFont(self.curFont)
self.ps.SetLabel(str(self.curFont.GetPointSize()))
self.family.SetLabel(self.curFont.GetFamilyString())
self.style.SetLabel(self.curFont.GetStyleString())
self.weight.SetLabel(self.curFont.GetWeightString())
self.face.SetLabel(self.curFont.GetFaceName())
self.nfi.SetLabel(self.curFont.GetNativeFontInfo().ToString())
self.Layout()
def OnSelectFont(self, evt):
data = wxFontData() data = wxFontData()
data.EnableEffects(true) data.EnableEffects(true)
font_colour = wxColour(255, 0, 0) # colour of font (red) data.SetColour(self.curClr) # set colour
data.SetColour(font_colour) # set colour data.SetInitialFont(self.curFont)
dlg = wxFontDialog(frame, data)
dlg = wxFontDialog(self, data)
if dlg.ShowModal() == wxID_OK: if dlg.ShowModal() == wxID_OK:
data = dlg.GetFontData() data = dlg.GetFontData()
font = data.GetChosenFont() font = data.GetChosenFont()
log.WriteText('You selected: "%s", %d points, color %s\n' % colour = data.GetColour()
self.log.WriteText('You selected: "%s", %d points, color %s\n' %
(font.GetFaceName(), font.GetPointSize(), (font.GetFaceName(), font.GetPointSize(),
data.GetColour().Get())) colour.Get()))
self.curFont = font
self.curClr = colour
self.UpdateUI()
dlg.Destroy() dlg.Destroy()
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
win = TestPanel(nb, log)
return win
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
overview = """\ overview = """\
This class represents the font chooser dialog. This class allows you to use the system font chooser dialog.
wxFontDialog()
----------------------------
wxFontDialog(wxWindow* parent, wxFontData* data)
Constructor. Pass a parent window and a font data object, which will be copied to the font dialog's font data.
""" """
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])])

View File

@@ -5,6 +5,7 @@ import ColorPanel
import GridSimple import GridSimple
import wxListCtrl import wxListCtrl
import wxScrolledWindow import wxScrolledWindow
import images
import sys import sys
@@ -15,7 +16,6 @@ class TestNB(wxNotebook):
wxNotebook.__init__(self, parent, id, style=wxNB_BOTTOM) wxNotebook.__init__(self, parent, id, style=wxNB_BOTTOM)
self.log = log self.log = log
win = self.makeColorPanel(wxBLUE) win = self.makeColorPanel(wxBLUE)
self.AddPage(win, "Blue") self.AddPage(win, "Blue")
st = wxStaticText(win.win, -1, st = wxStaticText(win.win, -1,
@@ -26,6 +26,16 @@ class TestNB(wxNotebook):
st.SetForegroundColour(wxWHITE) st.SetForegroundColour(wxWHITE)
st.SetBackgroundColour(wxBLUE) st.SetBackgroundColour(wxBLUE)
# Show how to put an image on one of the notebook tabs,
# first make the image list:
il = wxImageList(16, 16)
idx1 = il.Add(images.getSmilesBitmap())
self.AssignImageList(il)
# now put an image on the first tab we just created:
self.SetPageImage(0, idx1)
win = self.makeColorPanel(wxRED) win = self.makeColorPanel(wxRED)
self.AddPage(win, "Red") self.AddPage(win, "Red")
@@ -94,28 +104,27 @@ def runTest(frame, nb, log):
overview = """\ overview = """\
This class represents a notebook control, which manages multiple windows with associated tabs. <html><body>
<h2>wxNotebook</h2>
To use the class, create a wxNotebook object and call AddPage or InsertPage, passing a window to be used as the page. Do not explicitly delete the window for a page that is currently managed by wxNotebook. <p>
This class represents a notebook control, which manages multiple
windows with associated tabs.
<p>
To use the class, create a wxNotebook object and call AddPage or
InsertPage, passing a window to be used as the page. Do not explicitly
delete the window for a page that is currently managed by wxNotebook.
""" """
if __name__ == "__main__":
app = wxPySimpleApp() if __name__ == '__main__':
frame = wxFrame(None, -1, "Test Notebook", size=(600, 400)) import sys,os
win = TestNB(frame, -1, sys.stdout) import run
frame.Show(true) run.main(['', os.path.basename(sys.argv[0])])
app.MainLoop()