Removed the old tests that I havn't looked at or used for years
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@20105 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
@@ -1,13 +0,0 @@
|
||||
hh_test.py
|
||||
hook.pyc
|
||||
listGetItem.pyc
|
||||
setup.bat
|
||||
ste.pyc
|
||||
test.out
|
||||
test1.pyc
|
||||
test4.pyc
|
||||
test6.pyc
|
||||
test8.pyc
|
||||
testDlg.pyc
|
||||
th_test.py
|
||||
val.pyc
|
@@ -1,12 +0,0 @@
|
||||
29-Apr-1999
|
||||
|
||||
The tests in this directory are being depreciated in favor of the demo
|
||||
program found in ../demo.
|
||||
|
||||
They are still used from time to time for my development efforts, but
|
||||
they should not be included with any distributions.
|
||||
|
||||
Robin
|
||||
|
||||
|
||||
|
@@ -1,108 +0,0 @@
|
||||
#!/bin/env python
|
||||
#----------------------------------------------------------------------------
|
||||
# Name: TstLstIcon.py
|
||||
# Purpose: Lest Icon List
|
||||
#
|
||||
# Author: Lorne White
|
||||
#
|
||||
# Version: 0.8
|
||||
# Licence: wxWindows, wxPython license
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
import sys, os
|
||||
from wxPython.wx import *
|
||||
|
||||
class AppFrame(wxFrame):
|
||||
def __init__(self, parent, id=-1, title="New"):
|
||||
wxFrame.__init__(self, parent, id, title, wxPyDefaultPosition, wxSize(420, 320))
|
||||
if wxPlatform == '__WXMSW__':
|
||||
self.icon = wxIcon('bitmaps/mondrian.ico', wxBITMAP_TYPE_ICO)
|
||||
self.SetIcon(self.icon)
|
||||
|
||||
self.CreateStatusBar()
|
||||
|
||||
self.mainmenu = wxMenuBar()
|
||||
menu = wxMenu()
|
||||
|
||||
menu = self.MakeFileMenu()
|
||||
self.mainmenu.Append(menu, '&File')
|
||||
|
||||
self.SetMenuBar(self.mainmenu)
|
||||
|
||||
self.il = wxImageList(32, 32)
|
||||
self.idx1 = idx1 = self.il.Add(wxNoRefBitmap('table.bmp', wxBITMAP_TYPE_BMP))
|
||||
self.idx2 = idx2 = self.il.Add(wxNoRefBitmap('query.bmp', wxBITMAP_TYPE_BMP))
|
||||
|
||||
self.nb = nb = wxNotebook(self, -1)
|
||||
|
||||
self.list = wxListCtrl(nb, 1100, wxDefaultPosition, wxDefaultSize)
|
||||
|
||||
nb.AddPage(self.list, "Tables")
|
||||
|
||||
self.list.SetSingleStyle(wxLC_ICON)
|
||||
self.list.SetWindowStyleFlag(wxSTATIC_BORDER|wxVSCROLL)
|
||||
self.list.SetImageList(self.il, wxIMAGE_LIST_NORMAL)
|
||||
|
||||
self.qlist = wxListCtrl(nb, 1200, wxDefaultPosition, wxDefaultSize)
|
||||
nb.AddPage(self.qlist, "Queries")
|
||||
|
||||
self.qlist.SetSingleStyle(wxLC_ICON)
|
||||
self.qlist.SetWindowStyleFlag(wxSTATIC_BORDER|wxVSCROLL)
|
||||
self.qlist.SetImageList(self.il, wxIMAGE_LIST_NORMAL)
|
||||
|
||||
self.UpdateView2()
|
||||
self.UpdateView1()
|
||||
|
||||
self.nb.SetSelection(1)
|
||||
self.nb.SetSelection(0)
|
||||
#self.nb.Refresh()
|
||||
#self.nb.ResizeChildren()
|
||||
|
||||
def MakeFileMenu(self):
|
||||
self.fl_mn = menu = wxMenu()
|
||||
|
||||
mID = NewId()
|
||||
menu.Append(mID, 'E&xit', 'Exit')
|
||||
EVT_MENU(self, mID, self.OnFileExit)
|
||||
|
||||
return menu
|
||||
|
||||
|
||||
def UpdateView1(self):
|
||||
vset = "ViewA "
|
||||
for i in range(20):
|
||||
self.list.InsertImageStringItem(i, vset + str(i), self.idx1)
|
||||
|
||||
def UpdateView2(self):
|
||||
vset = "ViewB "
|
||||
for i in range(5):
|
||||
self.qlist.InsertImageStringItem(i, vset + str(i), self.idx2)
|
||||
|
||||
def OnFileExit(self, event):
|
||||
self.Close()
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
frame = AppFrame(NULL, -1, "Demo")
|
||||
frame.Show(true)
|
||||
self.SetTopWindow(frame)
|
||||
return true
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def main():
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
def t():
|
||||
import pdb
|
||||
pdb.run('main()')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@@ -1,52 +0,0 @@
|
||||
from time import sleep
|
||||
from threading import Thread
|
||||
|
||||
def test_a_window():
|
||||
print "starting window thread"
|
||||
|
||||
from wxPython.wx import * # <-- the wxWin DLL is not loaded until here
|
||||
|
||||
app = wxPySimpleApp(1)
|
||||
frame = wxFrame(None, -1, "Hello", size=(400,200))
|
||||
frame.Show(true)
|
||||
EVT_SIZE(frame, OnFrameSize)
|
||||
app.MainLoop()
|
||||
print "finishing window thread"
|
||||
|
||||
def OnFrameSize(evt):
|
||||
print evt.GetSize()
|
||||
|
||||
|
||||
|
||||
keep_going = 1
|
||||
def counter():
|
||||
print "starting counter thread"
|
||||
count = 0
|
||||
while keep_going:
|
||||
sleep(1)
|
||||
count += 1
|
||||
print count
|
||||
print "finishing counter thread"
|
||||
|
||||
def main():
|
||||
print "main startup"
|
||||
|
||||
ct = Thread(target=counter)
|
||||
wt = Thread(target=test_a_window)
|
||||
|
||||
ct.start()
|
||||
wt.start()
|
||||
wt.join()
|
||||
|
||||
global keep_going
|
||||
keep_going = 0
|
||||
|
||||
ct.join()
|
||||
|
||||
print "main finished"
|
||||
|
||||
main()
|
||||
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 630 B |
Before Width: | Height: | Size: 238 B |
Before Width: | Height: | Size: 766 B |
Before Width: | Height: | Size: 238 B |
Before Width: | Height: | Size: 238 B |
Before Width: | Height: | Size: 238 B |
Before Width: | Height: | Size: 246 B |
Before Width: | Height: | Size: 766 B |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 238 B |
Before Width: | Height: | Size: 238 B |
@@ -1,54 +0,0 @@
|
||||
#-------------------------------------------------
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
|
||||
class MyFrame(wxFrame):
|
||||
def __init__(self,parent,title,id):
|
||||
wxFrame.__init__(self,parent,title,id,
|
||||
wxPoint(100,100),wxSize(300,300))
|
||||
|
||||
|
||||
self.SetBackgroundColour(wxWHITE)
|
||||
self.windowx,self.windowy=self.GetClientSizeTuple()
|
||||
|
||||
# make a memory DC to draw into...
|
||||
self.mask=wxMemoryDC()
|
||||
|
||||
self.maskbitmap=wxEmptyBitmap(self.windowx,self.windowy)
|
||||
self.mask.SelectObject(self.maskbitmap)
|
||||
self.mask.SetBackgroundMode(wxTRANSPARENT)
|
||||
|
||||
self.mask.SetDeviceOrigin(0,0)
|
||||
|
||||
self.mask.SetBrush(wxBrush(wxColour(150,160,0),wxSOLID))
|
||||
self.mask.SetPen(wxPen(wxColour(1,2,3),1,wxSOLID))
|
||||
self.mask.DrawRectangle(0,0,self.windowx,self.windowy)
|
||||
|
||||
img = wxImageFromBitmap(self.maskbitmap)
|
||||
print (img.GetRed(0,0), img.GetGreen(0,0), img.GetBlue(0,0))
|
||||
|
||||
|
||||
def OnPaint(self,evt):
|
||||
""" overriding OnPaint to give handler. """
|
||||
dc = wxPaintDC(self)
|
||||
|
||||
dc.Blit(0,0,self.windowx,self.windowy,self.mask,0,0,wxCOPY)
|
||||
|
||||
#-----------------------------------------------------------
|
||||
|
||||
if __name__ == "__main__":
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
|
||||
self.frame = MyFrame(NULL, -1, "Blit Test")
|
||||
self.frame.Show(true)
|
||||
|
||||
self.exiting = FALSE;
|
||||
return true
|
||||
|
||||
app = MyApp(0) # Create an instance of the application
|
||||
app.MainLoop() # Tell it to start processing events
|
||||
|
||||
|
||||
|
@@ -1,62 +0,0 @@
|
||||
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
class FieldData:
|
||||
def __init__(self, name, label, shortHelp="", defValue="",
|
||||
size=(-1, -1), style=0, ID=-1):
|
||||
self.name = name
|
||||
self.label = label
|
||||
self.shortHelp = shortHelp
|
||||
self.defValue = defValue
|
||||
self.size = size
|
||||
self.style = style
|
||||
self.ID = ID
|
||||
|
||||
|
||||
class DynamicForm(wxPanel):
|
||||
def __init__(self, parent, ID, fieldData):
|
||||
wxPanel.__init__(self, parent, ID)
|
||||
|
||||
sizer = wxFlexGridSizer(cols=2, vgap=5, hgap=5)
|
||||
for field in fieldData:
|
||||
label = wxStaticText(self, -1, field.label)
|
||||
sizer.Add(label, 0, wxALIGN_RIGHT)
|
||||
text = wxTextCtrl(self, field.ID, field.defValue,
|
||||
size=field.size, style=field.style)
|
||||
if field.shortHelp:
|
||||
text.SetToolTip(wxToolTip(field.shortHelp))
|
||||
self.__dict__["get_"+field.name] = text.GetValue
|
||||
self.__dict__["set_"+field.name] = text.SetValue
|
||||
sizer.Add(text, 0, wxEXPAND)
|
||||
|
||||
sizer.Fit(self)
|
||||
self.SetAutoLayout(true)
|
||||
self.SetSizer(sizer)
|
||||
|
||||
|
||||
class TestFrame(wxFrame):
|
||||
testFields = [
|
||||
FieldData("fname", "First name:", "Enter someone's first name"),
|
||||
FieldData("lname", "Last name:", "Enter someone's last name"),
|
||||
FieldData("email", "Email address:", "just figure it out..."),
|
||||
]
|
||||
def __init__(self):
|
||||
wxFrame.__init__(self, None, -1, "This is a test")
|
||||
form = DynamicForm(self, -1, self.testFields)
|
||||
form.set_fname("Robin")
|
||||
form.set_lname("Dunn")
|
||||
self.form = form
|
||||
self.Fit()
|
||||
EVT_CLOSE(self, self.OnCloseWindow)
|
||||
|
||||
def OnCloseWindow(self, evt):
|
||||
print self.form.get_email()
|
||||
self.Destroy()
|
||||
|
||||
|
||||
app = wxPySimpleApp()
|
||||
frame = TestFrame()
|
||||
frame.Show(true)
|
||||
app.MainLoop()
|
||||
|
@@ -1,41 +0,0 @@
|
||||
|
||||
|
||||
from wxPython.wx import *
|
||||
import glob
|
||||
|
||||
class File2(wxFileSystemHandler):
|
||||
|
||||
def CanOpen(self,location):
|
||||
return self.GetProtocol(location) == "file2"
|
||||
|
||||
def OpenFile(self,fs,location):
|
||||
return wxFSFile(wxInputStream(open(self.GetRightLocation(location),"rb")),
|
||||
location,"text/plain","",wxDateTime())
|
||||
|
||||
def FindFirst(self,location,flags):
|
||||
# the flags are ignored
|
||||
self.files = glob.glob(self.GetRightLocation(location))
|
||||
if len(self.files) == 0:
|
||||
return ""
|
||||
else:
|
||||
return self.files[0]
|
||||
|
||||
def FindNext(self):
|
||||
self.files = self.files[1:]
|
||||
if len(self.files) == 0:
|
||||
return ""
|
||||
else:
|
||||
return self.files[0]
|
||||
|
||||
# register new handler
|
||||
wxFileSystem_AddHandler(File2())
|
||||
fs = wxFileSystem()
|
||||
|
||||
# cat /etc/passwd
|
||||
print fs.OpenFile("file2:/projects/files.lst").GetStream().read()
|
||||
|
||||
# ls /etc/*
|
||||
fn = fs.FindFirst("file2:/projects/*")
|
||||
while fn:
|
||||
print fn
|
||||
fn = fs.FindNext()
|
@@ -1,48 +0,0 @@
|
||||
from wxPython.wx import *
|
||||
|
||||
class MyDlg(wxDialog):
|
||||
def __init__(self, parent):
|
||||
wxDialog.__init__(self, parent, -1, "This is a test",
|
||||
wxDefaultPosition, wxSize(150, 150))
|
||||
|
||||
self.text1 = wxTextCtrl(self, -1, "", wxPoint(10, 10), wxSize(120, -1))
|
||||
self.text2 = wxTextCtrl(self, -1, "", wxPoint(10, 40), wxSize(120, -1))
|
||||
|
||||
wxButton(self, wxID_OK, "Okay", wxPoint(10,70)).SetDefault()
|
||||
wxButton(self, wxID_CANCEL, "Cancel", wxPoint(60, 70))
|
||||
|
||||
|
||||
def GetValues(self):
|
||||
val1 = self.text1.GetValue()
|
||||
val2 = self.text2.GetValue()
|
||||
return (val1, val2)
|
||||
|
||||
|
||||
|
||||
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
|
||||
frame = wxFrame(NULL, -1, "")
|
||||
wxButton(frame, 101, "test it", wxDefaultPosition, wxSize(50, 25))
|
||||
EVT_BUTTON(frame, 101, self.OnClick)
|
||||
frame.Fit()
|
||||
frame.Show(true)
|
||||
|
||||
self.SetTopWindow(frame)
|
||||
return true
|
||||
|
||||
def OnClick(self, event):
|
||||
dlg = MyDlg(NULL)
|
||||
if dlg.ShowModal() == wxID_OK:
|
||||
values = dlg.GetValues()
|
||||
print "Your values are: %s" % str(values)
|
||||
else:
|
||||
print "You canceled!"
|
||||
|
||||
dlg.Destroy()
|
||||
|
||||
|
||||
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
@@ -1,24 +0,0 @@
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.grids import wxFlexGridSizer
|
||||
|
||||
class aFrame(wxFrame):
|
||||
def __init__(self, parent=NULL, id=-1, title="test"):
|
||||
wxFrame.__init__(self, parent, id, title)
|
||||
s =wxBoxSizer(wxVERTICAL)
|
||||
gs =wxFlexGridSizer(2, 2, 2, 2)
|
||||
for label in ('one', 'two', 'tree', 'four'):
|
||||
gs.Add(wxButton(self, -1, label, size=(100,100)), 1, wxEXPAND)
|
||||
s.Add(gs, 1, wxEXPAND|wxALL, 50)
|
||||
self.SetSizer(s)
|
||||
self.SetAutoLayout(TRUE)
|
||||
s.Fit(self)
|
||||
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
frame =aFrame()
|
||||
self.SetTopWindow(frame)
|
||||
frame.Show(TRUE)
|
||||
return TRUE
|
||||
|
||||
app=MyApp(0)
|
||||
app.MainLoop()
|
@@ -1,219 +0,0 @@
|
||||
# wxGrid workout
|
||||
|
||||
import sys
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
from wxPython.wx import *
|
||||
from wxPython.grid import *
|
||||
|
||||
class MyCellEditor(wxPyGridCellEditor):
|
||||
"""
|
||||
A custom GridCellEditor that only accepts numbers.
|
||||
Also tries to work around wxGTK anomaly that key cannot start edit.
|
||||
"""
|
||||
|
||||
def Create(self, parent, id, evtHandler):
|
||||
"""
|
||||
Called to create the control, which must derive from wxControl.
|
||||
*Must Override*
|
||||
"""
|
||||
print "Create"
|
||||
theStyle = 0
|
||||
if wxPlatform == '__WXMSW__':
|
||||
theStyle = wxTE_PROCESS_TAB | wxTE_MULTILINE | wxTE_NO_VSCROLL | wxTE_AUTO_SCROLL
|
||||
#theStyle = wxTE_PROCESS_TAB | wxTE_PROCESS_ENTER
|
||||
|
||||
self._tc = wxTextCtrl(parent, id, "", style=theStyle)
|
||||
self._tc.SetInsertionPoint(0)
|
||||
self.SetControl(self._tc)
|
||||
if evtHandler:
|
||||
print evtHandler
|
||||
self._tc.PushEventHandler(evtHandler)
|
||||
|
||||
|
||||
def SetSize(self, rect):
|
||||
"""
|
||||
Called to position/size the edit control within the cell rectangle.
|
||||
If you don't fill the cell (the rect) then be sure to override
|
||||
PaintBackground and do something meaningful there.
|
||||
"""
|
||||
self._tc.SetDimensions(rect.x-1, rect.y-1, rect.width+4, rect.height+4)
|
||||
|
||||
def BeginEdit(self, row, col, grid):
|
||||
"""
|
||||
Fetch the value from the table and prepare the edit control
|
||||
to begin editing. Set the focus to the edit control.
|
||||
*Must Override*
|
||||
"""
|
||||
print "BeginEdit"
|
||||
self.startValue = grid.GetTable().GetValue(row, col)
|
||||
self._tc.SetValue(self.startValue)
|
||||
self._tc.SetFocus()
|
||||
|
||||
def EndEdit(self, row, col, grid):
|
||||
"""
|
||||
Complete the editing of the current cell. Returns true if the value
|
||||
has changed. If necessary, the control may be destroyed.
|
||||
*Must Override*
|
||||
"""
|
||||
changed = false
|
||||
val = self._tc.GetValue()
|
||||
if val != self.startValue:
|
||||
changed = true
|
||||
grid.GetTable().SetValue(row, col, val) # update the table
|
||||
|
||||
self.startValue = ''
|
||||
self._tc.SetValue('')
|
||||
return changed
|
||||
|
||||
|
||||
def Reset(self):
|
||||
"""
|
||||
Reset the value in the control back to its starting value.
|
||||
*Must Override*
|
||||
"""
|
||||
self._tc.SetValue(self.startValue)
|
||||
self._tc.SetInsertionPointEnd()
|
||||
|
||||
|
||||
def IsAcceptedKey(self, evt):
|
||||
"""
|
||||
Return TRUE to allow the given key to start editing: the base class
|
||||
version only checks that the event has no modifiers.
|
||||
"""
|
||||
key = evt.GetKeyCode()
|
||||
print "KeyCode:", key
|
||||
if (key in range(ord('0'),ord('9')+1) or
|
||||
key in range(WXK_NUMPAD0, WXK_NUMPAD9+1)):
|
||||
return true
|
||||
else:
|
||||
return false
|
||||
|
||||
|
||||
def StartingKey(self, evt):
|
||||
"""
|
||||
If the editor is enabled by pressing keys on the grid, this will be
|
||||
called to let the editor do something about that first key if desired.
|
||||
"""
|
||||
key = evt.GetKeyCode()
|
||||
print "StartingKey", key
|
||||
ch = None
|
||||
if key in range(WXK_NUMPAD0, WXK_NUMPAD9+1):
|
||||
ch = ch = chr(ord('0') + key - WXK_NUMPAD0)
|
||||
|
||||
elif key < 256 and key >= 0 and chr(key) in string.printable:
|
||||
ch = chr(key)
|
||||
if not evt.ShiftDown():
|
||||
ch = ch.lower()
|
||||
|
||||
if ch is not None:
|
||||
# Replace the text. Other option would be to append it.
|
||||
# self._tc.AppendText(ch)
|
||||
self._tc.SetValue(ch)
|
||||
self._tc.SetInsertionPointEnd()
|
||||
else:
|
||||
evt.Skip()
|
||||
|
||||
|
||||
def Destroy(self):
|
||||
"""final cleanup"""
|
||||
self.base_Destroy()
|
||||
|
||||
|
||||
def Clone(self):
|
||||
"""
|
||||
Create a new object which is the copy of this one
|
||||
*Must Override*
|
||||
"""
|
||||
print "clone"
|
||||
return MyCellEditor()
|
||||
|
||||
|
||||
class MyGrid(wxGrid):
|
||||
def __init__(self, parent, cust):
|
||||
wxGrid.__init__(self, parent, -1)
|
||||
self.CreateGrid(10, 10)
|
||||
for column in xrange(10):
|
||||
self.SetColSize(column, 40)
|
||||
|
||||
self.SetDefaultCellAlignment(wxCENTRE, wxCENTRE)
|
||||
|
||||
import os
|
||||
if cust:
|
||||
for column in xrange(10):
|
||||
# Note, we create attr and cell editor for each column
|
||||
# otherwise segfault at exit, probably tries to free those
|
||||
# multiple times from each column.
|
||||
attr = wxGridCellAttr()
|
||||
attr.SetEditor(MyCellEditor())
|
||||
self.SetColAttr(column, attr)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
class CardNoteBook(wxNotebook):
|
||||
def __init__(self, parent, id):
|
||||
wxNotebook.__init__(self, parent, id)
|
||||
|
||||
for title, cust in [("Default", 0), ("Custom Cell Editor", 1)]:
|
||||
win = MyGrid(self, cust)
|
||||
self.AddPage(win, title)
|
||||
|
||||
EVT_NOTEBOOK_PAGE_CHANGED(self, self.GetId(), self.OnPageChanged)
|
||||
EVT_KEY_DOWN(self, self.OnKeyDown)
|
||||
EVT_NAVIGATION_KEY(self, self.OnNavKey)
|
||||
|
||||
|
||||
def OnKeyDown(self, evt):
|
||||
print 'CardNoteBook.OnKeyDown: ', evt.GetKeyCode()
|
||||
evt.Skip()
|
||||
|
||||
|
||||
def OnNavKey(self, evt):
|
||||
print 'CardNoteBook.OnNavKey:', evt
|
||||
evt.Skip()
|
||||
|
||||
def OnPageChanged(self, event):
|
||||
event.Skip()
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
class ScoreKeeper(wxFrame):
|
||||
def __init__(self, parent, id, title):
|
||||
wxFrame.__init__(self, parent, -1, title, size = (500, 400),
|
||||
style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
|
||||
EVT_CLOSE(self, self.OnCloseWindow)
|
||||
self.Centre(wxBOTH)
|
||||
|
||||
self.nb = CardNoteBook(self, -1)
|
||||
#win=MyGrid(self, "GTK")
|
||||
self.Show(true)
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.dying = true
|
||||
self.window = None
|
||||
self.mainmenu = None
|
||||
self.Destroy()
|
||||
|
||||
def OnFileExit(self, event):
|
||||
self.Close()
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
frame = ScoreKeeper(None, -1, "ScoreKeeper: (A Demonstration)")
|
||||
frame.Show(true)
|
||||
self.SetTopWindow(frame)
|
||||
return true
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
def main():
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
||||
|
||||
main()
|
@@ -1,390 +0,0 @@
|
||||
"""Hangman.py, a simple wxPython game, inspired by the
|
||||
old bsd game by Ken Arnold.
|
||||
From the original man page:
|
||||
|
||||
In hangman, the computer picks a word from the on-line
|
||||
word list and you must try to guess it. The computer
|
||||
keeps track of which letters have been guessed and how
|
||||
many wrong guesses you have made on the screen in a
|
||||
graphic fashion.
|
||||
|
||||
That says it all, doesn't it?
|
||||
|
||||
Have fun with it,
|
||||
|
||||
Harm van der Heijden (H.v.d.Heijden@phys.tue.nl)"""
|
||||
|
||||
import random,re
|
||||
from wxPython.wx import *
|
||||
|
||||
class WordFetcher:
|
||||
def __init__(self, filename, min_length = 5):
|
||||
self.min_length = min_length
|
||||
print "Trying to open file %s" % (filename,)
|
||||
try:
|
||||
f = open(filename, "r")
|
||||
except:
|
||||
print "Couldn't open dictionary file %s, using build-ins" % (filename,)
|
||||
self.words = self.builtin_words
|
||||
self.filename = None
|
||||
return
|
||||
self.words = f.read()
|
||||
self.filename = filename
|
||||
print "Got %d bytes." % (len(self.words),)
|
||||
def SetMinLength(min_length):
|
||||
self.min_length = min_length
|
||||
def Get(self):
|
||||
reg = re.compile('\s+([a-zA-Z]+)\s+')
|
||||
n = 50 # safety valve; maximum number of tries to find a suitable word
|
||||
while n:
|
||||
index = int(random.random()*len(self.words))
|
||||
m = reg.search(self.words[index:])
|
||||
if m and len(m.groups()[0]) >= self.min_length: break
|
||||
n = n - 1
|
||||
if n: return string.lower(m.groups()[0])
|
||||
return "error"
|
||||
builtin_words = ' albatros banana electrometer eggshell'
|
||||
|
||||
def stdprint(x):
|
||||
print x
|
||||
|
||||
class URLWordFetcher(WordFetcher):
|
||||
def __init__(self, url):
|
||||
self.OpenURL(url)
|
||||
WordFetcher.__init__(self, "hangman_dict.txt")
|
||||
def logprint(self,x):
|
||||
print x
|
||||
def RetrieveAsFile(self, host, path=''):
|
||||
from httplib import HTTP
|
||||
try:
|
||||
h = HTTP(host)
|
||||
except:
|
||||
self.logprint("Failed to create HTTP connection to %s... is the network available?" % (host))
|
||||
return None
|
||||
h.putrequest('GET',path)
|
||||
h.putheader('Accept','text/html')
|
||||
h.putheader('Accept','text/plain')
|
||||
h.endheaders()
|
||||
errcode, errmsg, headers = h.getreply()
|
||||
if errcode != 200:
|
||||
self.logprint("HTTP error code %d: %s" % (errcode, errmsg))
|
||||
return None
|
||||
f = h.getfile()
|
||||
return f
|
||||
def OpenURL(self,url):
|
||||
from htmllib import HTMLParser
|
||||
import formatter
|
||||
self.url = url
|
||||
m = re.match('http://([^/]+)(/\S*)\s*', url)
|
||||
if m:
|
||||
host = m.groups()[0]
|
||||
path = m.groups()[1]
|
||||
else:
|
||||
m = re.match('http://(\S+)\s*', url)
|
||||
if not m:
|
||||
# Invalid URL
|
||||
self.logprint("Invalid or unsupported URL: %s" % (url))
|
||||
return
|
||||
host = m.groups()[0]
|
||||
path = ''
|
||||
f = self.RetrieveAsFile(host,path)
|
||||
if not f:
|
||||
self.logprint("Could not open %s" % (url))
|
||||
return
|
||||
self.logprint("Receiving data...")
|
||||
data = f.read()
|
||||
tmp = open('hangman_dict.txt','w')
|
||||
fmt = formatter.AbstractFormatter(formatter.DumbWriter(tmp))
|
||||
p = HTMLParser(fmt)
|
||||
self.logprint("Parsing data...")
|
||||
p.feed(data)
|
||||
p.close()
|
||||
tmp.close()
|
||||
|
||||
class HangmanWnd(wxWindow):
|
||||
def __init__(self, parent, id, pos=wxDefaultPosition, size=wxDefaultSize):
|
||||
wxWindow.__init__(self, parent, id, pos, size)
|
||||
self.SetBackgroundColour(wxNamedColour('white'))
|
||||
if wxPlatform == '__WXGTK__':
|
||||
self.font = wxFont(12, wxMODERN, wxNORMAL, wxNORMAL)
|
||||
else:
|
||||
self.font = wxFont(10, wxMODERN, wxNORMAL, wxNORMAL)
|
||||
self.SetFocus()
|
||||
def StartGame(self, word):
|
||||
self.word = word
|
||||
self.guess = []
|
||||
self.tries = 0
|
||||
self.misses = 0
|
||||
self.Draw()
|
||||
def EndGame(self):
|
||||
self.misses = 7;
|
||||
self.guess = map(chr, range(ord('a'),ord('z')+1))
|
||||
self.Draw()
|
||||
def HandleKey(self, key):
|
||||
self.message = ""
|
||||
if self.guess.count(key):
|
||||
self.message = 'Already guessed %s' % (key,)
|
||||
return 0
|
||||
self.guess.append(key)
|
||||
self.guess.sort()
|
||||
self.tries = self.tries+1
|
||||
if not key in self.word:
|
||||
self.misses = self.misses+1
|
||||
if self.misses == 7:
|
||||
self.EndGame()
|
||||
return 1
|
||||
has_won = 1
|
||||
for letter in self.word:
|
||||
if not self.guess.count(letter):
|
||||
has_won = 0
|
||||
break
|
||||
if has_won:
|
||||
self.Draw()
|
||||
return 2
|
||||
self.Draw()
|
||||
return 0
|
||||
def Draw(self, dc = None):
|
||||
if not dc:
|
||||
dc = wxClientDC(self)
|
||||
dc.SetFont(self.font)
|
||||
dc.Clear()
|
||||
(x,y) = self.GetSizeTuple()
|
||||
x1 = x-200; y1 = 20
|
||||
for letter in self.word:
|
||||
if self.guess.count(letter):
|
||||
dc.DrawText(letter, x1, y1)
|
||||
else:
|
||||
dc.DrawText('.', x1, y1)
|
||||
x1 = x1 + 10
|
||||
x1 = x-200
|
||||
dc.DrawText("tries %d misses %d" % (self.tries,self.misses),x1,50)
|
||||
guesses = ""
|
||||
for letter in self.guess:
|
||||
guesses = guesses + letter
|
||||
dc.DrawText("guessed:", x1, 70)
|
||||
dc.DrawText(guesses[:13], x1+80, 70)
|
||||
dc.DrawText(guesses[13:], x1+80, 90)
|
||||
dc.SetUserScale(x/1000., y/1000.)
|
||||
self.DrawVictim(dc)
|
||||
def DrawVictim(self, dc):
|
||||
dc.SetPen(wxPen(wxNamedColour('black'), 20))
|
||||
dc.DrawLines([(10, 980), (10,900), (700,900), (700,940), (720,940),
|
||||
(720,980), (900,980)])
|
||||
dc.DrawLines([(100,900), (100, 100), (300,100)])
|
||||
dc.DrawLine(100,200,200,100)
|
||||
if ( self.misses == 0 ): return
|
||||
dc.SetPen(wxPen(wxNamedColour('blue'), 10))
|
||||
dc.DrawLine(300,100,300,200)
|
||||
if ( self.misses == 1 ): return
|
||||
dc.DrawEllipse(250,200,100,100)
|
||||
if ( self.misses == 2 ): return
|
||||
dc.DrawLine(300,300,300,600)
|
||||
if ( self.misses == 3) : return
|
||||
dc.DrawLine(300,300,250,550)
|
||||
if ( self.misses == 4) : return
|
||||
dc.DrawLine(300,300,350,550)
|
||||
if ( self.misses == 5) : return
|
||||
dc.DrawLine(300,600,350,850)
|
||||
if ( self.misses == 6) : return
|
||||
dc.DrawLine(300,600,250,850)
|
||||
def OnPaint(self, event):
|
||||
dc = wxPaintDC(self)
|
||||
self.Draw(dc)
|
||||
|
||||
class HangmanDemo(HangmanWnd):
|
||||
def __init__(self, wf, parent, id, pos, size):
|
||||
HangmanWnd.__init__(self, parent, id, pos, size)
|
||||
self.StartGame("dummy")
|
||||
self.start_new = 1
|
||||
self.wf = wf
|
||||
self.delay = 500
|
||||
self.timer = self.PlayTimer(self.MakeMove)
|
||||
def MakeMove(self):
|
||||
self.timer.Stop()
|
||||
if self.start_new:
|
||||
self.StartGame(self.wf.Get())
|
||||
self.start_new = 0
|
||||
self.left = list('aaaabcdeeeeefghiiiiijklmnnnoooopqrssssttttuuuuvwxyz')
|
||||
else:
|
||||
key = self.left[int(random.random()*len(self.left))]
|
||||
while self.left.count(key): self.left.remove(key)
|
||||
self.start_new = self.HandleKey(key)
|
||||
self.timer.Start(self.delay)
|
||||
def Stop(self):
|
||||
self.timer.Stop()
|
||||
class PlayTimer(wxTimer):
|
||||
def __init__(self,func):
|
||||
wxTimer.__init__(self)
|
||||
self.func = func
|
||||
self.Start(1000)
|
||||
def Notify(self):
|
||||
apply(self.func, ())
|
||||
|
||||
class HangmanDemoFrame(wxFrame):
|
||||
def __init__(self, wf, parent, id, pos, size):
|
||||
wxFrame.__init__(self, parent, id, "Hangman demo", pos, size)
|
||||
self.demo = HangmanDemo(wf, self, -1, wxDefaultPosition, wxDefaultSize)
|
||||
def OnCloseWindow(self, event):
|
||||
self.demo.timer.Stop()
|
||||
self.Destroy()
|
||||
|
||||
class AboutBox(wxDialog):
|
||||
def __init__(self, parent,wf):
|
||||
wxDialog.__init__(self, parent, -1, "About Hangman", wxDefaultPosition, wxSize(350,450))
|
||||
self.wnd = HangmanDemo(wf, self, -1, wxPoint(1,1), wxSize(350,150))
|
||||
self.static = wxStaticText(self, -1, __doc__, wxPoint(1,160), wxSize(350, 250))
|
||||
self.button = wxButton(self, 2001, "OK", wxPoint(150,420), wxSize(50,-1))
|
||||
EVT_BUTTON(self, 2001, self.OnOK)
|
||||
def OnOK(self, event):
|
||||
self.wnd.Stop()
|
||||
self.EndModal(wxID_OK)
|
||||
|
||||
class MyFrame(wxFrame):
|
||||
def __init__(self, wf):
|
||||
self.wf = wf
|
||||
wxFrame.__init__(self, NULL, -1, "hangman", wxDefaultPosition, wxSize(400,300))
|
||||
self.wnd = HangmanWnd(self, -1)
|
||||
menu = wxMenu()
|
||||
menu.Append(1001, "New")
|
||||
menu.Append(1002, "End")
|
||||
menu.AppendSeparator()
|
||||
menu.Append(1003, "Reset")
|
||||
menu.Append(1004, "Demo...")
|
||||
menu.AppendSeparator()
|
||||
menu.Append(1005, "Exit")
|
||||
menubar = wxMenuBar()
|
||||
menubar.Append(menu, "Game")
|
||||
menu = wxMenu()
|
||||
#menu.Append(1010, "Internal", "Use internal dictionary", TRUE)
|
||||
menu.Append(1011, "ASCII File...")
|
||||
urls = [ 'wxPython home', 'http://208.240.253.245/wxPython/main.html',
|
||||
'slashdot.org', 'http://slashdot.org/',
|
||||
'cnn.com', 'http://cnn.com',
|
||||
'The New York Times', 'http://www.nytimes.com',
|
||||
'De Volkskrant', 'http://www.volkskrant.nl/frameless/25000006.html',
|
||||
'Gnu GPL', 'http://www.fsf.org/copyleft/gpl.html',
|
||||
'Bijbel: Genesis', 'http://www.coas.com/bijbel/gn1.htm']
|
||||
urlmenu = wxMenu()
|
||||
for item in range(0,len(urls),2):
|
||||
urlmenu.Append(1020+item/2, urls[item], urls[item+1])
|
||||
urlmenu.Append(1080, 'Other...', 'Enter an URL')
|
||||
menu.AppendMenu(1012, 'URL', urlmenu, 'Use a webpage')
|
||||
menu.Append(1013, 'Dump', 'Write contents to stdout')
|
||||
menubar.Append(menu, "Dictionary")
|
||||
self.urls = urls
|
||||
self.urloffset = 1020
|
||||
menu = wxMenu()
|
||||
menu.Append(1090, "About...")
|
||||
menubar.Append(menu, "Help")
|
||||
self.SetMenuBar(menubar)
|
||||
self.CreateStatusBar(2)
|
||||
EVT_MENU(self, 1001, self.OnGameNew)
|
||||
EVT_MENU(self, 1002, self.OnGameEnd)
|
||||
EVT_MENU(self, 1003, self.OnGameReset)
|
||||
EVT_MENU(self, 1004, self.OnGameDemo)
|
||||
EVT_MENU(self, 1005, self.OnWindowClose)
|
||||
EVT_MENU(self, 1011, self.OnDictFile)
|
||||
EVT_MENU_RANGE(self, 1020, 1020+len(urls)/2, self.OnDictURL)
|
||||
EVT_MENU(self, 1080, self.OnDictURLSel)
|
||||
EVT_MENU(self, 1013, self.OnDictDump)
|
||||
EVT_MENU(self, 1090, self.OnHelpAbout)
|
||||
EVT_CHAR(self.wnd, self.OnChar)
|
||||
self.OnGameReset()
|
||||
def OnGameNew(self, event):
|
||||
word = self.wf.Get()
|
||||
self.in_progress = 1
|
||||
self.SetStatusText("",0)
|
||||
self.wnd.StartGame(word)
|
||||
def OnGameEnd(self, event):
|
||||
self.UpdateAverages(0)
|
||||
self.in_progress = 0
|
||||
self.SetStatusText("",0)
|
||||
self.wnd.EndGame()
|
||||
def OnGameReset(self, event=None):
|
||||
self.played = 0
|
||||
self.won = 0
|
||||
self.history = []
|
||||
self.average = 0.0
|
||||
self.OnGameNew(None)
|
||||
def OnGameDemo(self, event):
|
||||
frame = HangmanDemoFrame(self.wf, self, -1, wxDefaultPosition, self.GetSize())
|
||||
frame.Show(TRUE)
|
||||
def OnDictFile(self, event):
|
||||
fd = wxFileDialog(self)
|
||||
if (self.wf.filename):
|
||||
fd.SetFilename(self.wf.filename)
|
||||
if fd.ShowModal() == wxID_OK:
|
||||
file = fd.GetPath()
|
||||
self.wf = WordFetcher(file)
|
||||
def OnDictURL(self, event):
|
||||
item = (event.GetId() - self.urloffset)*2
|
||||
print "Trying to open %s at %s" % (self.urls[item], self.urls[item+1])
|
||||
self.wf = URLWordFetcher(self.urls[item+1])
|
||||
def OnDictURLSel(self, event):
|
||||
msg = wxTextEntryDialog(self, "Enter the URL of the dictionary document", "Enter URL")
|
||||
if msg.ShowModal() == wxID_OK:
|
||||
url = msg.GetValue()
|
||||
self.wf = URLWordFetcher(url)
|
||||
def OnDictDump(self, event):
|
||||
print self.wf.words
|
||||
def OnHelpAbout(self, event):
|
||||
about = AboutBox(self, self.wf)
|
||||
about.ShowModal()
|
||||
about.wnd.Stop() # that damn timer won't stop!
|
||||
def UpdateAverages(self, has_won):
|
||||
if has_won:
|
||||
self.won = self.won + 1
|
||||
self.played = self.played+1
|
||||
self.history.append(self.wnd.misses) # ugly
|
||||
total = 0.0
|
||||
for m in self.history:
|
||||
total = total + m
|
||||
self.average = float(total/len(self.history))
|
||||
def OnChar(self, event):
|
||||
if not self.in_progress:
|
||||
self.OnGameNew(None)
|
||||
return
|
||||
key = event.KeyCode();
|
||||
if key >= ord('A') and key <= ord('Z'):
|
||||
key = key + ord('a') - ord('A')
|
||||
key = chr(key)
|
||||
if key < 'a' or key > 'z':
|
||||
event.Skip()
|
||||
return
|
||||
res = self.wnd.HandleKey(key)
|
||||
if res == 0:
|
||||
self.SetStatusText(self.wnd.message)
|
||||
elif res == 1:
|
||||
self.UpdateAverages(0)
|
||||
self.SetStatusText("Too bad, you're dead!",0)
|
||||
self.in_progress = 0
|
||||
elif res == 2:
|
||||
self.in_progress = 0
|
||||
self.UpdateAverages(1)
|
||||
self.SetStatusText("Congratulations!",0)
|
||||
if self.played:
|
||||
percent = (100.*self.won)/self.played
|
||||
else:
|
||||
percent = 0.0
|
||||
self.SetStatusText("p %d, w %d (%g %%), av %g" % (self.played,self.won, percent, self.average),1)
|
||||
|
||||
def OnWindowClose(self, event):
|
||||
self.Destroy()
|
||||
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
if wxPlatform == '__WXGTK__':
|
||||
defaultfile = "/usr/share/games/hangman-words"
|
||||
elif wxPlatform == '__WXMSW__':
|
||||
defaultfile = "c:\\windows\\hardware.txt"
|
||||
else:
|
||||
defaultfile = ""
|
||||
wf = WordFetcher(defaultfile)
|
||||
frame = MyFrame(wf)
|
||||
self.SetTopWindow(frame)
|
||||
frame.Show(TRUE)
|
||||
return TRUE
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
@@ -1,45 +0,0 @@
|
||||
from wxPython.wx import *
|
||||
|
||||
class MyFrame(wxFrame):
|
||||
def __init__(self, parent, id, title):
|
||||
wxFrame.__init__(self, parent, id, title,
|
||||
wxDefaultPosition, wxSize(400, 400))
|
||||
self.panel = wxPanel(self, -1)
|
||||
wxStaticText(self.panel, -1, "wxTextCtrl", wxPoint(5, 25),
|
||||
wxSize(75, 20))
|
||||
self.tc = wxTextCtrl(self.panel, 10, "", wxPoint(80, 25),
|
||||
wxSize(200, 30))
|
||||
EVT_CHAR_HOOK(self, self.OnCharHook)
|
||||
#EVT_CHAR_HOOK(self.tc, self.OnCharHook)
|
||||
EVT_CHAR(self, self.OnChar)
|
||||
self.panel.Layout()
|
||||
return
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.Destroy()
|
||||
return
|
||||
|
||||
def OnChar(self, event):
|
||||
print "OnChar: %d '%c'" % (event.KeyCode(), chr(event.KeyCode()))
|
||||
event.Skip()
|
||||
return
|
||||
|
||||
def OnCharHook(self, event):
|
||||
print "OnCharHook: %d" % event.KeyCode()
|
||||
event.Skip()
|
||||
return
|
||||
|
||||
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
frame = MyFrame(None, -1, 'CharHook Test')
|
||||
frame.Show(1)
|
||||
self.SetTopWindow(frame)
|
||||
return 1
|
||||
|
||||
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 370 B |
@@ -1,26 +0,0 @@
|
||||
from wxPython.wx import *
|
||||
|
||||
class TestFrame(wxFrame):
|
||||
|
||||
def __init__(self):
|
||||
wxFrame.__init__(self,NULL,-1,"Test Frame",wxPoint(200,200))
|
||||
win = wxWindow(self, -1)
|
||||
self.Show(true)
|
||||
EVT_LEAVE_WINDOW(win, self.onLeave)
|
||||
EVT_ENTER_WINDOW(win, self.onEnter)
|
||||
|
||||
def onLeave(self, event):
|
||||
print("out")
|
||||
|
||||
def onEnter(self, event):
|
||||
print('in')
|
||||
|
||||
class MyApp(wxApp):
|
||||
|
||||
def OnInit(self):
|
||||
self.mainFrame = TestFrame()
|
||||
return true
|
||||
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
||||
|
@@ -1,61 +0,0 @@
|
||||
from wxPython.wx import *
|
||||
|
||||
LIST_ID = 101
|
||||
|
||||
class MyFrame(wxFrame):
|
||||
def __init__(self, parent, id, title):
|
||||
wxFrame.__init__(self, parent, id, title,
|
||||
wxDefaultPosition, wxSize(400, 400))
|
||||
self.panel = wxPanel(self, -1)
|
||||
self.list = wxListCtrl(self.panel, LIST_ID,
|
||||
wxPoint(10, 10), wxSize(370, 330),
|
||||
wxLC_REPORT|wxSUNKEN_BORDER)
|
||||
self.list.InsertColumn(0, "Id")
|
||||
self.list.InsertColumn(1, "Type")
|
||||
self.list.InsertColumn(2, "Description")
|
||||
|
||||
self.insertRow(self.list, 0, 'CD', 'Dark Side of the Moon')
|
||||
self.insertRow(self.list, 1, 'DVD', 'The Matrix')
|
||||
self.insertRow(self.list, 2, 'Book', 'Crime and Punishment')
|
||||
|
||||
self.list.SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER)
|
||||
self.list.SetColumnWidth(1, wxLIST_AUTOSIZE)
|
||||
self.list.SetColumnWidth(2, wxLIST_AUTOSIZE_USEHEADER)
|
||||
|
||||
EVT_LIST_ITEM_SELECTED(self.panel, LIST_ID, self.OnListSelect)
|
||||
|
||||
self.panel.Layout()
|
||||
return
|
||||
|
||||
def OnListSelect(self, event):
|
||||
item = self.list.GetItem(event.m_itemIndex, 1)
|
||||
print item.m_itemId, item.m_col, item.m_state
|
||||
type = self.list.GetItem(event.m_itemIndex, col=1).m_text
|
||||
desc = self.list.GetItem(event.m_itemIndex, col=2).m_text
|
||||
print ('Row Selected: Id: %d, Type: %s, Desc: %s' %
|
||||
(event.m_itemIndex, `type`, `desc`))
|
||||
return
|
||||
|
||||
def insertRow(self, list, row, type, desc):
|
||||
list.InsertStringItem(row, 'label' + `row`)
|
||||
list.SetStringItem(row, 0, `row`)
|
||||
list.SetStringItem(row, 1, type)
|
||||
list.SetStringItem(row, 2, desc)
|
||||
return
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.Destroy()
|
||||
return
|
||||
|
||||
|
||||
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
frame = MyFrame(None, -1, 'ListCtrl Test')
|
||||
frame.Show(1)
|
||||
self.SetTopWindow(frame)
|
||||
return 1
|
||||
|
||||
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
@@ -1,157 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# class MyWindow(wxScrolledWindow):
|
||||
#----------------------------------
|
||||
# Copes with the drawing of the main scrolled window.
|
||||
#
|
||||
# Data members:
|
||||
# num - <int> number of list entries
|
||||
# ostart - <int> line number of the top line of the previous redraw
|
||||
# vw - <int> width of the viewing window
|
||||
# vh - <int> height of the viewing window
|
||||
# smalltext - <int> 0 = size 12pt, 1 = size 9pt text
|
||||
#
|
||||
# Method members:
|
||||
# OnPaint(evt) - basic draw handler
|
||||
# OnDraw(dc) - called by OnPaint, redraws the screen if required
|
||||
# update(updatelist) - called every 3 seconds if updates are needed.
|
||||
|
||||
class MyWindow(wxScrolledWindow):
|
||||
def __init__(self,num,parent,id,pos,size,style):
|
||||
wxScrolledWindow.__init__(self,parent,id,pos,size,style)
|
||||
self.SetBackgroundColour(wxWHITE)
|
||||
|
||||
self.num=num
|
||||
self.ostart=0
|
||||
self.smalltext = 0
|
||||
self.vw,self.vh=self.GetClientSizeTuple()
|
||||
|
||||
# calculate font pt size needed: a bit of a kludge to get round
|
||||
# font compatibility problems of X and Windows.
|
||||
dc=wxClientDC(self)
|
||||
|
||||
dc.SetFont(wxFont(12,wxDEFAULT,wxNORMAL,wxNORMAL,FALSE))
|
||||
if dc.GetTextExtent("XXXXXXXXXX")[0] > 100:
|
||||
self.smalltext = 1
|
||||
|
||||
def OnPaint(self,evt):
|
||||
""" overriding OnPaint to give handler. """
|
||||
dc = wxPaintDC(self)
|
||||
self.PrepareDC(dc)
|
||||
self.OnDraw(dc)
|
||||
|
||||
def update(self,updlist):
|
||||
""" handles line by line updating of list entries. """
|
||||
dc = wxClientDC(self)
|
||||
self.PrepareDC(dc)
|
||||
dc.SetBrush(wxWHITE_BRUSH)
|
||||
dc.SetPen(wxWHITE_PEN)
|
||||
|
||||
if self.smalltext == 1:
|
||||
dc.SetFont(wxFont(9,wxDEFAULT,wxNORMAL,wxNORMAL,FALSE))
|
||||
else:
|
||||
dc.SetFont(wxFont(12,wxDEFAULT,wxNORMAL,wxNORMAL,FALSE))
|
||||
|
||||
dc.BeginDrawing()
|
||||
|
||||
for i in updlist:
|
||||
if i >= self.ostart and i < self.ostart+self.vh/17+1:
|
||||
dc.DrawRectangle(0,i*17,self.vw,17)
|
||||
dc.DrawText("This is a simple test.Line "+str(i)+".",
|
||||
10,i*17+2)
|
||||
dc.EndDrawing()
|
||||
|
||||
def OnDraw(self,dc):
|
||||
""" Main redraw function. """
|
||||
|
||||
if self.smalltext == 1:
|
||||
dc.SetFont(wxFont(9,wxDEFAULT,wxNORMAL,wxNORMAL,FALSE))
|
||||
else:
|
||||
dc.SetFont(wxFont(12,wxDEFAULT,wxNORMAL,wxNORMAL,FALSE))
|
||||
|
||||
vx,vstart=self.ViewStart()
|
||||
self.vw,self.vh=self.GetClientSizeTuple()
|
||||
vend=vstart+(self.vh/17) + 1
|
||||
if vend > self.num: vend = self.num
|
||||
|
||||
dc.BeginDrawing()
|
||||
if vstart > self.ostart: # if moving downwards...
|
||||
for i in range(vend-(vstart-self.ostart+1),vend):
|
||||
dc.DrawText("This is a simple test. Line "+str(i)+".",
|
||||
10,i*17+2)
|
||||
|
||||
elif vstart < self.ostart: # if moving upwards...
|
||||
for i in range(vstart,self.ostart):
|
||||
dc.DrawText("This is a simple test. Line "+str(i)+".",
|
||||
10,i*17+2)
|
||||
|
||||
elif vstart == self.ostart: # if not moving (redraw)...
|
||||
#dc.Clear()
|
||||
for i in range(vstart,vend):
|
||||
dc.DrawText("This is a simple test. Line "+str(i)+".",
|
||||
10,i*17+2)
|
||||
|
||||
dc.EndDrawing()
|
||||
self.ostart=vstart
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
class MyTimer(wxTimer):
|
||||
def __init__(self,frame):
|
||||
wxTimer.__init__(self)
|
||||
self.frame_ = frame
|
||||
|
||||
def Notify(self):
|
||||
self.frame_.idle()
|
||||
|
||||
|
||||
class MyFrame(wxFrame):
|
||||
def __init__(self, parent, id, title):
|
||||
wxFrame.__init__(self, parent, id, title,
|
||||
wxPoint(100, 100), wxSize(500, 300))
|
||||
|
||||
# number of entries
|
||||
self.num = 30
|
||||
|
||||
# set up the scrolling window...
|
||||
self.sw = MyWindow(self.num,self, -1,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
wxVSCROLL|wxSUNKEN_BORDER)
|
||||
|
||||
self.sw.SetScrollbars(1,17,0,self.num+1)
|
||||
|
||||
lc = wxLayoutConstraints()
|
||||
lc.top.SameAs(self, wxTop, 5)
|
||||
lc.left.SameAs(self, wxLeft, 5)
|
||||
lc.bottom.SameAs(self, wxBottom, 5)
|
||||
lc.right.SameAs(self, wxRight,5)
|
||||
self.sw.SetConstraints(lc)
|
||||
|
||||
self.timer=MyTimer(self)
|
||||
# stupidly short interval time to accelerate memory leak problem:
|
||||
self.timer.Start(80)
|
||||
|
||||
def idle(self):
|
||||
#usually just update one or two lines; to accelerate problem,
|
||||
#every line is updated here.
|
||||
self.sw.update(range(self.num))
|
||||
|
||||
|
||||
######################################################################
|
||||
# Main procedure....
|
||||
|
||||
if __name__ == "__main__":
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
|
||||
self.frame = MyFrame(NULL, -1, "Memory Leak Tester")
|
||||
self.frame.Show(true)
|
||||
|
||||
self.exiting = FALSE;
|
||||
return true
|
||||
|
||||
app = MyApp(0) # Create an instance of the application class
|
||||
app.MainLoop() # Tell it to start processing events
|
||||
|
@@ -1,43 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
class MainWindowFrame(wxFrame):
|
||||
|
||||
def __init__(self, parentframe, title):
|
||||
|
||||
wxFrame.__init__(self, parentframe, -1,
|
||||
title, size=wxSize(500, 200))
|
||||
|
||||
self.mb = wxMenuBar()
|
||||
self.SetMenuBar(self.mb)
|
||||
self.sbut = wxButton(self, -1,
|
||||
'switch menu (push twice and then use menu)')
|
||||
EVT_BUTTON(self, self.sbut.GetId(), self.switch)
|
||||
|
||||
#help menu
|
||||
self.helpmenu = wxMenu()
|
||||
self.othermenu = wxMenu()
|
||||
|
||||
self.mb.Append(self.helpmenu, '&Help')
|
||||
|
||||
|
||||
def switch(self, event):
|
||||
|
||||
lastmenu = self.mb.GetMenuCount() - 1
|
||||
self.mb.Replace(lastmenu, self.othermenu, 'Other')
|
||||
|
||||
|
||||
|
||||
class TheApp(wxApp):
|
||||
|
||||
def OnInit(self):
|
||||
|
||||
mainwin = MainWindowFrame(NULL, 'menutest')
|
||||
mainwin.Show(true)
|
||||
self.SetTopWindow(mainwin)
|
||||
return true
|
||||
|
||||
app = TheApp(0)
|
||||
app.MainLoop()
|
||||
|
||||
|
@@ -1,69 +0,0 @@
|
||||
from wxPython.wx import *
|
||||
#from Lib.Gui.PlainWidgets import *
|
||||
|
||||
class TestLayoutConstraints(wxPanel):
|
||||
def __init__(self, parent):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
#
|
||||
nb = wxNotebook(self, -1)
|
||||
page = wxPanel(nb, -1)
|
||||
page.SetBackgroundColour(wxBLUE)
|
||||
button = wxButton(page, -1, 'press me')
|
||||
#
|
||||
nb.AddPage(page, 'testpage')
|
||||
#
|
||||
lc = wxLayoutConstraints()
|
||||
lc.top.PercentOf(parent, wxBottom, 0)
|
||||
lc.bottom.PercentOf(parent, wxBottom, 100)
|
||||
lc.left.PercentOf(parent, wxRight, 0)
|
||||
lc.right.PercentOf(parent, wxRight, 100)
|
||||
self.SetConstraints(lc)
|
||||
self.SetAutoLayout(true)
|
||||
#
|
||||
lc = wxLayoutConstraints()
|
||||
lc.top.PercentOf(self, wxBottom, 0)
|
||||
lc.bottom.PercentOf(self, wxBottom, 100)
|
||||
lc.left.PercentOf(self, wxRight, 0)
|
||||
lc.right.PercentOf(self, wxRight, 100)
|
||||
nb.SetConstraints(lc)
|
||||
# nb.SetAutoLayout(true)
|
||||
#
|
||||
# lc = wxLayoutConstraints()
|
||||
# lc.top.PercentOf(nb, wxBottom, 0)
|
||||
# lc.bottom.PercentOf(nb, wxBottom, 100)
|
||||
# lc.left.PercentOf(nb, wxRight, 0)
|
||||
# lc.right.PercentOf(nb, wxRight, 100)
|
||||
# page.SetConstraints(lc)
|
||||
page.SetAutoLayout(true)
|
||||
|
||||
# this should center "button" on "page":
|
||||
lc = wxLayoutConstraints()
|
||||
lc.centreY.PercentOf(page, wxBottom, 50)
|
||||
lc.centreX.PercentOf(page, wxRight, 50)
|
||||
lc.width.AsIs()
|
||||
lc.height.AsIs()
|
||||
button.SetConstraints(lc)
|
||||
# button.SetAutoLayout(true)
|
||||
#
|
||||
button.Layout()
|
||||
page.Layout()
|
||||
nb.Layout()
|
||||
self.Layout()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
class MyFrame(wxFrame):
|
||||
def __init__(self, *argT, **optionD):
|
||||
apply(wxFrame.__init__, (self,) + argT, optionD)
|
||||
self.SetAutoLayout(true)
|
||||
TestLayoutConstraints(self)
|
||||
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
frame = MyFrame(None, -1, "TestLayoutConstraints",
|
||||
size=wxSize(400,300))
|
||||
frame.Show(true)
|
||||
return true
|
||||
|
||||
app = MyApp()
|
||||
app.MainLoop()
|
@@ -1,28 +0,0 @@
|
||||
from wxPython.wx import *
|
||||
|
||||
|
||||
class MyFrame(wxFrame):
|
||||
def __init__(self, parent, id, title='A pxFrame!'):
|
||||
wxFrame.__init__(self, parent, id, title,
|
||||
wxPyDefaultPosition, wxSize(50, 50))
|
||||
|
||||
def get_filename(self):
|
||||
dlg = wxFileDialog(self, "Choose a file", ".", "", "*.*", wxOPEN)
|
||||
dlg.ShowModal()
|
||||
self.file = dlg.GetPath()
|
||||
dlg.Destroy()
|
||||
self.Iconize(true)
|
||||
return self.file
|
||||
|
||||
|
||||
class FilePicker(wxApp):
|
||||
def OnInit(self):
|
||||
return true
|
||||
|
||||
def get_filename(self):
|
||||
dlg = wxFileDialog(NULL, "Choose a file", ".", "", "*.*", wxOPEN)
|
||||
dlg.ShowModal()
|
||||
self.file = dlg.GetPath()
|
||||
dlg.Destroy()
|
||||
return self.file
|
||||
|
@@ -1,123 +0,0 @@
|
||||
# popup.py:
|
||||
# Illustrates how to create a wxListCtrl with an associated pop-up menu, which is
|
||||
# activated when the right mouse button is clicked.
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
|
||||
class cPopupHandler(wxEvtHandler):
|
||||
|
||||
def __init__(self, this):
|
||||
wxEvtHandler.__init__(self, this)
|
||||
|
||||
|
||||
def ProcessEvent(self, event):
|
||||
print "G"
|
||||
#wxEvtHandler.ProcessEvent(self, event)
|
||||
|
||||
if event.GetEventClass() != wxTYPE_MOUSE_EVENT:
|
||||
return
|
||||
|
||||
if not event.ButtonUp(3):
|
||||
return
|
||||
|
||||
if event.ButtonDown(1):
|
||||
print "left down"
|
||||
elif event.ButtonUp(1):
|
||||
print "left up"
|
||||
elif event.ButtonDown(3):
|
||||
print "right down"
|
||||
elif event.ButtonUp(3):
|
||||
print "right up"
|
||||
|
||||
|
||||
def xProcessEvent(self, event):
|
||||
# I tried to pass this one in as the Connect() handler,
|
||||
# but all I got from that was that the icons disappeared
|
||||
# from the wxListCtrl.
|
||||
print "H"
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class cMyFrame(wxFrame):
|
||||
|
||||
def __init__(self, parent, id, title):
|
||||
wxFrame.__init__(self, parent, -1, title, wxDefaultPosition, wxSize(800, 600))
|
||||
|
||||
self.Centre(wxBOTH)
|
||||
|
||||
# create a dummy icon; can't seem to get the wxListCtrl to work without an icon
|
||||
#self.imagelist = wxImageList(16, 16)
|
||||
#self.image = self.imagelist.Add(wxNoRefBitmap('smile.bmp', wxBITMAP_TYPE_BMP))
|
||||
|
||||
# create a ListCtrl
|
||||
id = NewId()
|
||||
self.listctrl = wxListCtrl(self, id, wxDefaultPosition, wxDefaultSize, wxLC_REPORT)
|
||||
#self.listctrl.SetImageList(self.imagelist, wxIMAGE_LIST_SMALL)
|
||||
|
||||
if 1:
|
||||
# install a handler for mouse right button up events
|
||||
#EVT_RIGHT_DOWN(self.listctrl, self.OnListMouseEvent)
|
||||
#EVT_RIGHT_UP(self.listctrl, self.OnListMouseEvent)
|
||||
|
||||
#EVT_RIGHT_DOWN(self.listctrl, self.OnSaveMousePos)
|
||||
|
||||
EVT_LIST_ITEM_SELECTED(self, id, self.OnSaveSelection)
|
||||
EVT_COMMAND_RIGHT_CLICK(self, id, self.OnListRightClick)
|
||||
else:
|
||||
# create an wxEvtHandler and connect it to the wxListCtrl
|
||||
print "A"
|
||||
self.listctrl.handler = cPopupHandler(self.listctrl)
|
||||
print "B"
|
||||
id = NewId()
|
||||
self.listctrl.Connect(id, id, wxEVT_RIGHT_DOWN, self.OnListMouseEvent)
|
||||
print "C"
|
||||
|
||||
# define the ListCtrl column
|
||||
self.listctrl.InsertColumn(0, "Name")
|
||||
|
||||
# create a set of dummy ListCtrl entries
|
||||
for Index in range(20):
|
||||
self.listctrl.InsertStringItem(Index, "Item number %d" % Index)
|
||||
|
||||
# re-adjust the width of the column
|
||||
self.listctrl.SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER)
|
||||
|
||||
|
||||
def OnSaveSelection(self, event):
|
||||
self.lastSelection = event.m_itemIndex
|
||||
print self.lastSelection
|
||||
|
||||
|
||||
def OnListRightClick(self, event):
|
||||
menu = wxPyMenu()
|
||||
menu.Append(0, "One")
|
||||
menu.Append(1, "Two")
|
||||
menu.Append(2, "Three")
|
||||
|
||||
pos = self.listctrl.GetItemPosition(self.lastSelection)
|
||||
self.listctrl.PopupMenu(menu, pos.x, pos.y)
|
||||
|
||||
|
||||
class cMyApp(wxApp):
|
||||
|
||||
def OnInit(self):
|
||||
frame = cMyFrame(NULL, -1, "Popup Sample")
|
||||
frame.Show(true)
|
||||
self.SetTopWindow(frame)
|
||||
return true
|
||||
|
||||
|
||||
def main():
|
||||
App = cMyApp(0)
|
||||
App.MainLoop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -1,203 +0,0 @@
|
||||
"""
|
||||
Hello, and welcome to this test of the wxTreeItemData class.
|
||||
|
||||
The wxTreeItemData class can be used to associate a python object with
|
||||
a wxTreeCtrl item. In this sample, its use is demonstrated via a tree
|
||||
control that shows the contents of a python namespace according to the
|
||||
standard dir() command. Every item in the tree has its label taken
|
||||
from the dir() output, and 'behind it' a reference to the python
|
||||
object is stored in a wxTreeItemData object.
|
||||
|
||||
As you may have guessed by now, this sample automatically displays
|
||||
'__doc__' strings if the selected python object happens to have
|
||||
one. Please expand the pyTree object to learn more about the
|
||||
implementation.
|
||||
|
||||
Version 1.0, April 4 1999.
|
||||
Harm van der Heijden (H.v.d.Heijden@phys.tue.nl)
|
||||
|
||||
P.S. Check out the string module. It's imported in this sample not
|
||||
because it's used, but because it's so beautifully documented...
|
||||
"""
|
||||
|
||||
from wxPython import wx
|
||||
import string # Don't use it, but it's fun expanding :-)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def _getindent(line):
|
||||
"""Returns the indentation level of the given line."""
|
||||
indent = 0
|
||||
for c in line:
|
||||
if c == ' ': indent = indent + 1
|
||||
elif c == '\t': indent = indent + 8
|
||||
else: break
|
||||
return indent
|
||||
|
||||
def _sourcefinder(func):
|
||||
"""Given a func_code object, this function tries to find and return
|
||||
the python source code of the function."""
|
||||
try:
|
||||
f = open(func.co_filename,"r")
|
||||
except:
|
||||
return "(could not open file %s)" % (func.co_filename,)
|
||||
|
||||
for i in range(func.co_firstlineno):
|
||||
line = f.readline()
|
||||
ind = _getindent(line)
|
||||
msg = ""
|
||||
while line:
|
||||
msg = msg + line
|
||||
line = f.readline()
|
||||
# the following should be <= ind, but then we get
|
||||
# confused by multiline docstrings. Using == works most of
|
||||
# the time... but not always!
|
||||
if _getindent(line) == ind: break
|
||||
return msg
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class pyTree(wx.wxTreeCtrl):
|
||||
"""
|
||||
This wxTreeCtrl derivative displays a tree view of a Python namespace.
|
||||
Anything from which the dir() command returns a non-empty list is a branch
|
||||
in this tree.
|
||||
"""
|
||||
|
||||
def __init__(self, parent, id, root):
|
||||
"""
|
||||
Initialize function; because we insert branches into the tree
|
||||
as needed, we use the ITEM_EXPANDING event handler. The
|
||||
ITEM_COLLAPSED handler removes the stuff afterwards. The
|
||||
SEL_CHANGED handler attempts to display interesting
|
||||
information about the selected object.
|
||||
"""
|
||||
wx.wxTreeCtrl.__init__(self, parent, id)
|
||||
self.root = self.AddRoot(str(root), -1, -1, wx.wxTreeItemData(root))
|
||||
if dir(root):
|
||||
self.SetItemHasChildren(self.root, wx.TRUE)
|
||||
wx.EVT_TREE_ITEM_EXPANDING(self, self.GetId(), self.OnItemExpanding)
|
||||
wx.EVT_TREE_ITEM_COLLAPSED(self, self.GetId(), self.OnItemCollapsed)
|
||||
wx.EVT_TREE_SEL_CHANGED(self, self.GetId(), self.OnSelChanged)
|
||||
self.output = None
|
||||
|
||||
|
||||
def SetOutput(self, output):
|
||||
"""
|
||||
Set output function (accepts single string). Used to display string
|
||||
representation of the selected object by OnSelChanged.
|
||||
"""
|
||||
self.output = output
|
||||
|
||||
|
||||
def OnItemExpanding(self,event):
|
||||
"""
|
||||
The real workhorse of this class. First we retrieve the object
|
||||
(parent) belonging to the branch that is to be expanded. This
|
||||
is done by calling GetPyData(parent), which is a short-cut for
|
||||
GetPyItemData(parent).Get().
|
||||
|
||||
Then we get the dir() list of that object. For each item in
|
||||
this list, a tree item is created with associated
|
||||
wxTreeItemData referencing the child object. We get this
|
||||
object using child = getattr(parent, item).
|
||||
|
||||
Finally, we check wether the child returns a non-empty dir()
|
||||
list. If so, it is labeled as 'having children', so that it
|
||||
may be expanded. When it actually is expanded, this function
|
||||
will again figure out what the offspring is.
|
||||
"""
|
||||
item = event.GetItem()
|
||||
obj = self.GetPyData( item )
|
||||
lst = dir(obj)
|
||||
for key in lst:
|
||||
new_obj = getattr(obj,key)
|
||||
new_item = self.AppendItem( item, key, -1, -1,
|
||||
wx.wxTreeItemData(new_obj) )
|
||||
if dir(new_obj):
|
||||
self.SetItemHasChildren(new_item, wx.TRUE)
|
||||
|
||||
def OnItemCollapsed(self, event):
|
||||
"""
|
||||
We need to remove all children here, otherwise we'll see all
|
||||
that old rubbish again after the next expansion.
|
||||
"""
|
||||
item = event.GetItem()
|
||||
self.DeleteChildren(item)
|
||||
|
||||
def OnSelChanged(self, event):
|
||||
"""
|
||||
If an output function is defined, we try to print some
|
||||
informative, interesting and thought-provoking stuff to it.
|
||||
If it has a __doc__ string, we print it. If it's a function or
|
||||
unbound class method, we attempt to find the python source.
|
||||
"""
|
||||
if not self.output:
|
||||
return
|
||||
obj = self.GetPyData( event.GetItem() )
|
||||
msg = str(obj)
|
||||
if hasattr(obj, '__doc__'):
|
||||
msg = msg+"\n\nDocumentation string:\n\n%s" % ( getattr(obj, '__doc__'),)
|
||||
# Is it a function?
|
||||
func = None
|
||||
if hasattr(obj, "func_code"): # normal function
|
||||
func = getattr(obj, "func_code")
|
||||
elif hasattr(obj, "im_func"): # unbound class method
|
||||
func = getattr(getattr(obj, "im_func"), "func_code")
|
||||
if func: # if we found one, let's try to print the source
|
||||
msg = msg+"\n\nFunction source:\n\n" + _sourcefinder(func)
|
||||
|
||||
apply(self.output, (msg,))
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
overview = __doc__
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
split = wx.wxSplitterWindow(nb, -1)
|
||||
tree = pyTree(split, -1, __main__)
|
||||
text = wx.wxTextCtrl(split, -1, "", wx.wxDefaultPosition,
|
||||
wx.wxDefaultSize, wx.wxTE_MULTILINE)
|
||||
split.SplitVertically(tree, text, 200)
|
||||
tree.SetOutput(text.SetValue)
|
||||
tree.SelectItem(tree.root)
|
||||
text.SetBackgroundColour(wxNamedColour("LIGHT BLUE"))
|
||||
tree.SetBackgroundColour(wxNamedColour("LIGHT BLUE"))
|
||||
|
||||
return split
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
|
||||
class MyFrame(wx.wxFrame):
|
||||
"""Very standard Frame class. Nothing special here!"""
|
||||
|
||||
def __init__(self):
|
||||
"""Make a splitter window; left a tree, right a textctrl. Wow."""
|
||||
import __main__
|
||||
wx.wxFrame.__init__(self, wx.NULL, -1, "PyTreeItemData Test",
|
||||
wx.wxDefaultPosition, wx.wxSize(800,500))
|
||||
split = wx.wxSplitterWindow(self, -1)
|
||||
tree = pyTree(split, -1, __main__)
|
||||
text = wx.wxTextCtrl(split, -1, "", wx.wxDefaultPosition,
|
||||
wx.wxDefaultSize, wx.wxTE_MULTILINE)
|
||||
split.SplitVertically(tree, text, 200)
|
||||
tree.SetOutput(text.SetValue)
|
||||
tree.SelectItem(tree.root)
|
||||
|
||||
class MyApp(wx.wxApp):
|
||||
"""This class is even less interesting than MyFrame."""
|
||||
|
||||
def OnInit(self):
|
||||
"""OnInit. Boring, boring, boring!"""
|
||||
frame = MyFrame()
|
||||
frame.Show(wx.TRUE)
|
||||
self.SetTopWindow(frame)
|
||||
return wx.TRUE
|
||||
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
||||
|
||||
|
Before Width: | Height: | Size: 630 B |
@@ -1,36 +0,0 @@
|
||||
from wxPython.wx import *
|
||||
import sys, time
|
||||
|
||||
class WaitingProcess(wxProcess):
|
||||
def __init__(self):
|
||||
wxProcess.__init__(self, None)
|
||||
self.terminated = false
|
||||
def OnTerminate(self, pid, status):
|
||||
print pid, status
|
||||
self.terminated = true
|
||||
def wait(self):
|
||||
while not self.terminated:
|
||||
stream = self.GetInputStream()
|
||||
if not stream.eof():
|
||||
sys.stdout.write(stream.read())
|
||||
stream = self.GetErrorStream()
|
||||
if not stream.eof():
|
||||
sys.stderr.write(stream.read())
|
||||
wxYield()
|
||||
|
||||
try:
|
||||
#raw_input("ready...")
|
||||
if 1:
|
||||
process = WaitingProcess()
|
||||
process.Redirect()
|
||||
pid = wxExecute('python -u wxFrame1.py', false, process)
|
||||
process.wait()
|
||||
else:
|
||||
wxExecute('python -u wxFrame1.py')
|
||||
|
||||
finally:
|
||||
#raw_input("done...")
|
||||
pass
|
||||
|
||||
|
||||
|
@@ -1,38 +0,0 @@
|
||||
from wxPython.wx import *
|
||||
|
||||
class MyWindow(wxScrolledWindow):
|
||||
def __init__(self,parent,id,pos,size,style):
|
||||
wxScrolledWindow.__init__(self,parent,id,pos,size,style)
|
||||
self.SetBackgroundColour(wxWHITE)
|
||||
|
||||
def OnPaint(self,evt):
|
||||
dc = wxPaintDC(self)
|
||||
# normally call a redraw/draw function here.
|
||||
# this time, print 'redraw!'
|
||||
print "redraw!"
|
||||
|
||||
|
||||
class MyFrame(wxFrame):
|
||||
def __init__(self, parent, id, title):
|
||||
wxFrame.__init__(self, parent, id, title,
|
||||
wxPoint(100, 100), wxSize(500, 300))
|
||||
|
||||
self.sw = MyWindow(self, -1,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
wxVSCROLL|wxSUNKEN_BORDER)
|
||||
|
||||
self.sw.SetScrollbars(1,20,0,30)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
|
||||
self.frame = MyFrame(NULL, -1, "Scrolling Test App")
|
||||
self.frame.Show(true)
|
||||
self.exiting = FALSE;
|
||||
return true
|
||||
|
||||
app = MyApp(0) # Create an instance of the app class
|
||||
app.MainLoop() # Tell it to start processing events
|
||||
|
@@ -1,136 +0,0 @@
|
||||
## import all of the wxPython GUI package
|
||||
from wxPython.wx import *
|
||||
|
||||
"""
|
||||
I am trying to write a routine which will produce an entryform which I can
|
||||
later use to write GUI entryforms for databasis work. When you run this
|
||||
program and chose option 150 (Invoer) under "L=EAers" the following error
|
||||
appears (repeated 6 times):
|
||||
|
||||
Gtk-CRITICAL **: file gtkwidget.c: line 1592 (gtk_widget_map): assertion
|
||||
`GTK_WIDGET_VISIBLE (widget) == TRUE' failed.=20
|
||||
"""
|
||||
|
||||
class ToetsInvoer(wxPanel):
|
||||
def __init__(self, parent):
|
||||
wxPanel.__init__(self, parent, -1)
|
||||
|
||||
wxStaticText(self, -1, "wxTextCtrl", wxPoint(5, 25), wxSize(75, 20))
|
||||
wxTextCtrl(self, 10, "", wxPoint(80, 25), wxSize(150, 20))
|
||||
EVT_TEXT(self, 10, self.EvtText)
|
||||
|
||||
wxStaticText(self, -1, "Passsword", wxPoint(5, 50), wxSize(75, 20))
|
||||
wxTextCtrl(self, 20, "", wxPoint(80, 50), wxSize(150, 20), wxTE_PASSWORD)
|
||||
EVT_TEXT(self, 20, self.EvtText)
|
||||
|
||||
wxStaticText(self, -1, "Multi-line", wxPoint(5, 75), wxSize(75, 20))
|
||||
wxTextCtrl(self, 30, "", wxPoint(80, 75), wxSize(200, 150), wxTE_MULTILINE)
|
||||
EVT_TEXT(self, 30, self.EvtText)
|
||||
|
||||
self.Show(true)
|
||||
|
||||
def EvtText(self, event):
|
||||
self.log.WriteText('EvtText: %s\n' % event.GetString())
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
## Create a new frame class, derived from the wxPython Frame.
|
||||
class HoofRaam(wxFrame):
|
||||
|
||||
def __init__(self, pa, id, titel):
|
||||
# First, call the base class' __init__ method to create the frame
|
||||
wxFrame.__init__(self, pa, id, titel,wxPyDefaultPosition,
|
||||
wxSize(420, 200))
|
||||
|
||||
self.CreateStatusBar(2)
|
||||
mainmenu = wxMenuBar()
|
||||
menu = wxMenu()
|
||||
menu.Append(100, '&Kopieer', 'Maak rugsteun')
|
||||
menu.Append(101, '&Nuwe stel', 'Begin nuwe databasis')
|
||||
menu.Append(150, '&Invoer', 'Toets invoervorm')
|
||||
menu.AppendSeparator()
|
||||
menu.Append(200, 'Kl&aar', 'Gaan uit die program uit!')
|
||||
mainmenu.Append(menu, "&L=EAers")
|
||||
self.SetMenuBar(mainmenu)
|
||||
# if wxPlatform == '__WXMSW__':
|
||||
# print menu.GetHelpString(100)
|
||||
# print mainmenu.GetHelpString(101)
|
||||
# print mainmenu.GetHelpString(200)
|
||||
# self.DragAcceptFiles(true)
|
||||
|
||||
|
||||
|
||||
# Associate some events with methods of this class
|
||||
self.Connect(-1, -1, wxEVT_SIZE, self.OnSize)
|
||||
self.Connect(-1, -1, wxEVT_MOVE, self.OnMove)
|
||||
self.Connect(-1, -1, wxEVT_COMMAND_MENU_SELECTED, self.OnMenuCommand)
|
||||
self.Connect(-1, -1, wxEVT_DROP_FILES, self.OnDropFiles)
|
||||
|
||||
self.child = None
|
||||
#self.child = ToetsInvoer(self)
|
||||
|
||||
# This method is called automatically when the CLOSE event is
|
||||
# sent to this window
|
||||
def OnCloseWindow(self, event):
|
||||
# tell the window to kill itself
|
||||
self.Destroy()
|
||||
|
||||
|
||||
# This method is called by the System when the window is resized,
|
||||
# because of the association above.
|
||||
def OnSize(self, event):
|
||||
size = event.GetSize()
|
||||
print "grootte:", size.width, size.height
|
||||
event.Skip()
|
||||
|
||||
# This method is called by the System when the window is moved,
|
||||
# because of the association above.
|
||||
def OnMove(self, event):
|
||||
pos = event.GetPosition()
|
||||
print "pos:", pos.x, pos.y
|
||||
|
||||
def OnMenuCommand(self, event):
|
||||
# why isn't this a wxMenuEvent???
|
||||
print event, event.GetInt()
|
||||
if event.GetInt() == 200:
|
||||
self.Close()
|
||||
if event.GetInt() == 150:
|
||||
x = ToetsInvoer(self)
|
||||
if event.GetInt() == 101:
|
||||
print "Nommer 101 is gekies"
|
||||
|
||||
def OnDropFiles(self, event): #werk net in windows
|
||||
fileList = event.GetFiles()
|
||||
for file in fileList:
|
||||
print file
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
print 'Klaar'
|
||||
self.Destroy()
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
# Every wxWindows application must have a class derived from wxApp
|
||||
class MyProg(wxApp):
|
||||
|
||||
# wxWindows calls this method to initialize the application
|
||||
def OnInit(self):
|
||||
|
||||
# Create an instance of our customized Frame class
|
||||
raam = HoofRaam(NULL, -1, "Taalunie")
|
||||
raam.Show(true)
|
||||
|
||||
# Tell wxWindows that this is our main window
|
||||
self.SetTopWindow(raam)
|
||||
|
||||
# Return a success flag
|
||||
return true
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
app = MyProg(0) # Create an instance of the application class
|
||||
app.MainLoop() # Tell it to start processing events
|
||||
|
||||
|
||||
|
@@ -1,69 +0,0 @@
|
||||
from wxPython.wx import *
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class TestComboBox(wxDialog):
|
||||
def __init__(self, parent):
|
||||
|
||||
wxDialog.__init__(self, parent, -1, "This is a test",
|
||||
wxDefaultPosition, wxSize(550, 250))
|
||||
self.s = ['aaaaaaaaaaaaaa',
|
||||
'bbbbbbb',
|
||||
'cccccccccccccccccccccccccccccccccccc',
|
||||
'ddddddddddd',
|
||||
'eeeeeeeeeee',
|
||||
'ffffffff',
|
||||
'gggggggggggggggggggggggg',
|
||||
'hhhhhhhhhhhhhhhhhh',
|
||||
'iiiiiiiiii']
|
||||
|
||||
|
||||
wxStaticText(self, -1, "This example uses the wxListBox control.",
|
||||
wxPoint(45, 10))
|
||||
xwaarde = 35*12
|
||||
wxStaticText(self, -1, "Select one:", wxPoint(15, 50), wxSize(65, -1))
|
||||
|
||||
dv = self.s[4]
|
||||
self.lb= wxComboBox(self, 50, dv, wxPoint(80, 50), wxSize(xwaarde, -1),
|
||||
self.s, wxCB_DROPDOWN)
|
||||
|
||||
wxButton(self, wxID_OK, "Okay", wxPoint(10,90)).SetDefault()
|
||||
wxButton(self, wxID_CANCEL, "Cancel", wxPoint(60, 90))
|
||||
|
||||
|
||||
def GetSelection(self,leer):
|
||||
|
||||
val1 = self.lb.GetStringSelection()
|
||||
#leer.commit()
|
||||
return val1
|
||||
|
||||
|
||||
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
|
||||
frame = wxFrame(NULL, -1, "")
|
||||
wxButton(frame, 101, "test it", wxDefaultPosition, wxSize(50, 25))
|
||||
EVT_BUTTON(frame, 101, self.OnClick)
|
||||
frame.Fit()
|
||||
frame.Show(true)
|
||||
|
||||
self.SetTopWindow(frame)
|
||||
return true
|
||||
|
||||
def OnClick(self, event):
|
||||
|
||||
dlg = TestComboBox(NULL)
|
||||
|
||||
if dlg.ShowModal() == wxID_OK:
|
||||
values = dlg.GetSelection(NULL)
|
||||
print "Your values are: %s" % str(values)
|
||||
else:
|
||||
print "You canceled!"
|
||||
|
||||
dlg.Destroy()
|
||||
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
||||
|
||||
|
@@ -1,24 +0,0 @@
|
||||
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.ste import wxStyledTextCtrl
|
||||
|
||||
|
||||
app = wxPySimpleApp()
|
||||
frame = wxFrame(None, -1, "Testing...", (0,0), (320,480))
|
||||
ed = wxStyledTextCtrl(frame, -1)
|
||||
ed.AddText(open('test7.py').read())
|
||||
|
||||
#ed.AddText("This is a test\nThis is only a test.\n\nHere we go cowboys, here we go!!!\nThe End")
|
||||
#ed.SetBufferedDraw(false)
|
||||
|
||||
#ed.StyleSetFontAttr(1, 14, "Times New Roman", true, false)
|
||||
#ed.StyleSetForeground(1, wxBLUE)
|
||||
#ed.StyleSetFont(2, wxFont(12, wxMODERN, wxNORMAL, wxNORMAL, false))
|
||||
|
||||
#ed.StartStyling(48, 0xff)
|
||||
#ed.SetStyleFor(7, 1)
|
||||
|
||||
|
||||
frame.Show(true)
|
||||
app.MainLoop()
|
Before Width: | Height: | Size: 630 B |
@@ -1,37 +0,0 @@
|
||||
from wxPython.wx import *
|
||||
|
||||
class Test:
|
||||
def __init__(self):
|
||||
self.panel = wxPanel(frame, -1)
|
||||
self.box = wxListBox(self.panel, 100, wxPoint(10,10),
|
||||
wxSize(300,100), [], wxLB_SINGLE|wxLB_SORT)
|
||||
self.text = wxTextCtrl(self.panel, 110,'', wxPoint(310,10),
|
||||
wxSize(300,100),wxTE_MULTILINE|wxTE_READONLY)
|
||||
self.FillList()
|
||||
|
||||
def FillList(self):
|
||||
line = 'This is a test'
|
||||
self.box.Append(line)
|
||||
self.text.AppendText(line)
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.panel.Close(true)
|
||||
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
global frame
|
||||
frame = wxFrame(NULL,-1,'Main',wxDefaultPosition,wxSize(630,150))
|
||||
test = Test()
|
||||
frame.Show(true)
|
||||
self.SetTopWindow(frame)
|
||||
return true
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.Destroy()
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
@@ -1,83 +0,0 @@
|
||||
#!/bin/env python
|
||||
#----------------------------------------------------------------------------
|
||||
# Name: test1.py
|
||||
# Purpose: A minimal wxPython program
|
||||
#
|
||||
# Author: Robin Dunn
|
||||
#
|
||||
# Created: A long time ago, in a galaxy far, far away...
|
||||
# RCS-ID: $Id$
|
||||
# Copyright: (c) 1998 by Total Control Software
|
||||
# Licence: wxWindows license
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
## Create a new frame class, derived from the wxPython Frame.
|
||||
class MyFrame(wxFrame):
|
||||
|
||||
def __init__(self, parent, id, title):
|
||||
# First, call the base class' __init__ method to create the frame
|
||||
wxFrame.__init__(self, parent, id, title,
|
||||
wxPoint(100, 100), wxSize(160, 100))
|
||||
|
||||
# Associate some events with methods of this class
|
||||
EVT_SIZE(self, self.OnSize)
|
||||
EVT_MOVE(self, self.OnMove)
|
||||
|
||||
|
||||
# This method is called automatically when the CLOSE event is
|
||||
# sent to this window
|
||||
def OnCloseWindow(self, event):
|
||||
# tell the window to kill itself
|
||||
self.Destroy()
|
||||
|
||||
|
||||
# This method is called by the System when the window is resized,
|
||||
# because of the association above.
|
||||
def OnSize(self, event):
|
||||
size = event.GetSize()
|
||||
print "size:", size.width, size.height
|
||||
|
||||
# This method is called by the System when the window is moved,
|
||||
# because of the association above.
|
||||
def OnMove(self, event):
|
||||
pos = event.GetPosition()
|
||||
print "pos:", pos.x, pos.y
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
# Every wxWindows application must have a class derived from wxApp
|
||||
class MyApp(wxApp):
|
||||
|
||||
# wxWindows calls this method to initialize the application
|
||||
def OnInit(self):
|
||||
|
||||
# Create an instance of our customized Frame class
|
||||
frame = MyFrame(NULL, -1, "This is a test")
|
||||
frame.Show(true)
|
||||
|
||||
# Tell wxWindows that this is our main window
|
||||
self.SetTopWindow(frame)
|
||||
|
||||
# Return a success flag
|
||||
return true
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
app = MyApp(1) # Create an instance of the application class
|
||||
app.MainLoop() # Tell it to start processing events
|
||||
|
||||
print 'done!'
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
@@ -1,212 +0,0 @@
|
||||
#!/bin/env python
|
||||
#----------------------------------------------------------------------------
|
||||
# Name: test2.py
|
||||
# Purpose: Testing GDI stuff and events.
|
||||
#
|
||||
# Author: Robin Dunn
|
||||
#
|
||||
# Created:
|
||||
# RCS-ID: $Id$
|
||||
# Copyright: (c) 1998 by Total Control Software
|
||||
# Licence: wxWindows license
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
class MyCanvas(wxScrolledWindow):
|
||||
def __init__(self, parent):
|
||||
wxScrolledWindow.__init__(self, parent, -1, wxPoint(0, 0), wxPyDefaultSize, wxSUNKEN_BORDER)
|
||||
|
||||
self.SetBackgroundColour(wxNamedColor("WHITE"))
|
||||
self.Connect(-1, -1, wxEVT_LEFT_DOWN, self.OnLeftButtonEvent)
|
||||
self.Connect(-1, -1, wxEVT_LEFT_UP, self.OnLeftButtonEvent)
|
||||
self.Connect(-1, -1, wxEVT_MOTION, self.OnLeftButtonEvent)
|
||||
|
||||
self.SetCursor(wxStockCursor(wxCURSOR_PENCIL))
|
||||
bmp = wxBitmap('bitmaps/test2.bmp', wxBITMAP_TYPE_BMP)
|
||||
self.bmp = bmp
|
||||
|
||||
self.SetScrollbars(20, 20, 50, 50)
|
||||
|
||||
self.lines = []
|
||||
|
||||
|
||||
|
||||
def OnPaint(self, event):
|
||||
dc = wxPaintDC(self)
|
||||
self.PrepareDC(dc)
|
||||
self.DoDrawing(dc)
|
||||
|
||||
|
||||
|
||||
def DoDrawing(self, dc):
|
||||
dc.BeginDrawing()
|
||||
#dc.Clear()
|
||||
pen1 = wxPen(wxNamedColour('RED'))
|
||||
dc.SetPen(pen1)
|
||||
dc.DrawRectangle(5, 5, 50, 50)
|
||||
|
||||
dc.SetBrush(wxLIGHT_GREY_BRUSH)
|
||||
dc.SetPen(wxPen(wxNamedColour('BLUE'), 4))
|
||||
dc.DrawRectangle(15, 15, 50, 50)
|
||||
|
||||
font = wxFont(14, wxSWISS, wxNORMAL, wxNORMAL)
|
||||
dc.SetFont(font)
|
||||
dc.SetTextForeground(wxColour(0xFF, 0x20, 0xFF))
|
||||
te = dc.GetTextExtent("Hello World")
|
||||
dc.DrawText("Hello World", 60, 65)
|
||||
|
||||
dc.SetPen(wxPen(wxNamedColour('VIOLET'), 4))
|
||||
dc.DrawLine(5, 65+te[1], 60+te[0], 65+te[1])
|
||||
|
||||
lst = [(100,110), (150,110), (150,160), (100,160)]
|
||||
dc.DrawLines(lst, -60)
|
||||
dc.SetPen(wxGREY_PEN)
|
||||
dc.DrawPolygon(lst, 75)
|
||||
dc.SetPen(wxGREEN_PEN)
|
||||
dc.DrawSpline(lst+[(100,100)])
|
||||
|
||||
dc.DrawBitmap(self.bmp, 200, 20)
|
||||
dc.SetTextForeground(wxColour(0, 0xFF, 0x80))
|
||||
dc.DrawText("a bitmap", 200, 80)
|
||||
|
||||
self.DrawSavedLines(dc)
|
||||
dc.EndDrawing()
|
||||
|
||||
|
||||
def DrawSavedLines(self, dc):
|
||||
dc.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
|
||||
for line in self.lines:
|
||||
for coords in line:
|
||||
apply(dc.DrawLine, coords)
|
||||
|
||||
|
||||
|
||||
def OnLeftButtonEvent(self, event):
|
||||
if event.LeftDown():
|
||||
self.x, self.y = event.GetX(), event.GetY()
|
||||
self.curLine = []
|
||||
elif event.Dragging():
|
||||
dc = wxClientDC(self)
|
||||
dc.BeginDrawing()
|
||||
dc.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
|
||||
coords = (self.x, self.y, event.GetX(), event.GetY())
|
||||
self.curLine.append(coords)
|
||||
apply(dc.DrawLine, coords)
|
||||
self.x, self.y = event.GetX(), event.GetY()
|
||||
dc.EndDrawing()
|
||||
elif event.LeftUp():
|
||||
self.lines.append(self.curLine)
|
||||
self.curLine = []
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class MyFrame(wxFrame):
|
||||
def __init__(self, parent, id, title):
|
||||
wxFrame.__init__(self, parent, id, title, wxPyDefaultPosition, wxSize(320, 200))
|
||||
self.canvas = MyCanvas(self)
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.Destroy()
|
||||
|
||||
def OnSize(self, event):
|
||||
size = self.GetClientSize()
|
||||
self.canvas.SetDimensions(5, 5, size.width-10, size.height-10)
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
frame = MyFrame(NULL, -1, "Test 2")
|
||||
frame.Show(true)
|
||||
self.SetTopWindow(frame)
|
||||
return true
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def main():
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
def t():
|
||||
import pdb
|
||||
pdb.run('main()')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
#
|
||||
# $Log$
|
||||
# Revision 1.4 2001/02/16 08:19:38 robind
|
||||
# Copied/merged from the 2.2 branch.
|
||||
#
|
||||
# Changes needed to build with new event system
|
||||
#
|
||||
# Revision 1.1.2.2 2001/01/30 20:54:16 robind
|
||||
#
|
||||
# Gobs of changes move from the main trunk to the 2.2 branch in
|
||||
# preparataion for 2.2.5 release. See CHANGES.txt for details.
|
||||
#
|
||||
# Revision 1.3 2000/10/30 21:05:22 robind
|
||||
#
|
||||
# Merged wxPython 2.2.2 over to the main branch
|
||||
#
|
||||
# Revision 1.1.2.1 2000/05/16 02:07:01 RD
|
||||
#
|
||||
# Moved and reorganized wxPython directories
|
||||
#
|
||||
# Now builds into an intermediate wxPython package directory before
|
||||
# installing
|
||||
#
|
||||
# Revision 1.3 1999/04/30 03:29:53 RD
|
||||
#
|
||||
# wxPython 2.0b9, first phase (win32)
|
||||
# Added gobs of stuff, see wxPython/README.txt for details
|
||||
#
|
||||
# Revision 1.2.4.1 1999/03/27 23:30:00 RD
|
||||
#
|
||||
# wxPython 2.0b8
|
||||
# Python thread support
|
||||
# various minor additions
|
||||
# various minor fixes
|
||||
#
|
||||
# Revision 1.2 1998/12/15 20:44:34 RD
|
||||
# Changed the import semantics from "from wxPython import *" to "from
|
||||
# wxPython.wx import *" This is for people who are worried about
|
||||
# namespace pollution, they can use "from wxPython import wx" and then
|
||||
# prefix all the wxPython identifiers with "wx."
|
||||
#
|
||||
# Added wxTaskbarIcon for wxMSW.
|
||||
#
|
||||
# Made the events work for wxGrid.
|
||||
#
|
||||
# Added wxConfig.
|
||||
#
|
||||
# Added wxMiniFrame for wxGTK, (untested.)
|
||||
#
|
||||
# Changed many of the args and return values that were pointers to gdi
|
||||
# objects to references to reflect changes in the wxWindows API.
|
||||
#
|
||||
# Other assorted fixes and additions.
|
||||
#
|
||||
# Revision 1.1 1998/08/09 08:28:05 RD
|
||||
# Initial version
|
||||
#
|
||||
#
|
@@ -1,216 +0,0 @@
|
||||
#!/bin/env python
|
||||
#----------------------------------------------------------------------------
|
||||
# Name: test3.py
|
||||
# Purpose: Testing menus and status lines
|
||||
#
|
||||
# Author: Robin Dunn
|
||||
#
|
||||
# Created:
|
||||
# RCS-ID: $Id$
|
||||
# Copyright: (c) 1998 by Total Control Software
|
||||
# Licence: wxWindows license
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class MyCanvas(wxWindow):
|
||||
def __init__(self, parent, ID):
|
||||
wxWindow.__init__(self, parent, ID)
|
||||
self.SetBackgroundColour(wxNamedColor("WHITE"))
|
||||
|
||||
def OnPaint(self, event):
|
||||
dc = wxPaintDC(self)
|
||||
dc.BeginDrawing()
|
||||
size = self.GetClientSize()
|
||||
font = wxFont(42, wxSWISS, wxNORMAL, wxNORMAL)
|
||||
dc.SetFont(font)
|
||||
st = "Python Rules!"
|
||||
tw,th = dc.GetTextExtent(st)
|
||||
dc.DrawText(st, (size.width-tw)/2, (size.height-th)/2)
|
||||
dc.EndDrawing()
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
#if wxPlatform == '__WXMSW__':
|
||||
class MyMiniFrame(wxMiniFrame):
|
||||
def __init__(self, parent, ID, title, pos, size, style):
|
||||
wxMiniFrame.__init__(self, parent, ID, title, pos, size, style)
|
||||
panel = wxPanel(self, -1)
|
||||
ID = NewId()
|
||||
button = wxButton(panel, ID, "Close Me")
|
||||
button.SetPosition(wxPoint(15, 15))
|
||||
self.Connect(ID, -1, wxEVT_COMMAND_BUTTON_CLICKED, self.OnCloseMe)
|
||||
|
||||
def OnCloseMe(self, event):
|
||||
self.Close(true)
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.Destroy()
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class MyFrame(wxFrame):
|
||||
def __init__(self, parent, id, title):
|
||||
wxFrame.__init__(self, parent, id, title, wxPyDefaultPosition,
|
||||
wxSize(420, 200))
|
||||
self.canvas = MyCanvas(self, -1)
|
||||
self.CreateStatusBar(2)
|
||||
mainmenu = wxMenuBar()
|
||||
menu = wxMenu()
|
||||
menu.Append(100, 'A &Menu Item', 'the help text')
|
||||
menu.Append(101, '&Another', 'Grok!')
|
||||
menu.AppendSeparator()
|
||||
menu.Append(200, 'E&xit', 'Get the heck outta here!')
|
||||
mainmenu.Append(menu, "&It's a menu!")
|
||||
self.SetMenuBar(mainmenu)
|
||||
if wxPlatform == '__WXMSW__':
|
||||
print menu.GetHelpString(100)
|
||||
print mainmenu.GetHelpString(101)
|
||||
print mainmenu.GetHelpString(200)
|
||||
self.DragAcceptFiles(true)
|
||||
|
||||
self.Connect(-1, -1, wxEVT_COMMAND_MENU_SELECTED, self.OnMenuCommand)
|
||||
self.Connect(-1, -1, wxEVT_DROP_FILES, self.OnDropFiles)
|
||||
|
||||
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
print 'OnCloseWindow'
|
||||
self.Destroy()
|
||||
|
||||
|
||||
def OnSize(self, event):
|
||||
size = self.GetClientSize()
|
||||
self.canvas.SetSize(size)
|
||||
self.SetStatusText("hello, this is a test: (%d, %d)" % (size.width, size.height), 1)
|
||||
|
||||
## def OnMenuHighlight(self, event):
|
||||
## mainmenu = self.GetMenuBar()
|
||||
## st = mainmenu.GetHelpString(event.GetMenuId())
|
||||
## self.SetStatusText('['+st+']', 0)
|
||||
|
||||
def OnMenuCommand(self, event):
|
||||
# why isn't this a wxMenuEvent???
|
||||
print event, event.GetInt()
|
||||
if event.GetInt() == 200:
|
||||
self.Close()
|
||||
elif event.GetInt() == 101:
|
||||
#if wxPlatform == '__WXMSW__':
|
||||
win = MyMiniFrame(self, -1, "This is a Mini...",
|
||||
wxPoint(-1, -1), #wxPyDefaultPosition,
|
||||
wxSize(150, 150),
|
||||
wxMINIMIZE_BOX | wxMAXIMIZE_BOX |
|
||||
wxTHICK_FRAME | wxSYSTEM_MENU |
|
||||
wxTINY_CAPTION_HORIZ)
|
||||
win.Show(true)
|
||||
#else:
|
||||
# print 'Sorry, can\'t do mini\'s...'
|
||||
|
||||
|
||||
|
||||
def OnDropFiles(self, event):
|
||||
fileList = event.GetFiles()
|
||||
for file in fileList:
|
||||
print file
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
frame = MyFrame(NULL, -1, "Test 3")
|
||||
frame.Show(true)
|
||||
self.SetTopWindow(frame)
|
||||
return true
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def main():
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
def t():
|
||||
import pdb
|
||||
pdb.run('main()')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
#
|
||||
# $Log$
|
||||
# Revision 1.4 2001/02/16 08:19:38 robind
|
||||
# Copied/merged from the 2.2 branch.
|
||||
#
|
||||
# Changes needed to build with new event system
|
||||
#
|
||||
# Revision 1.1.2.2 2001/01/30 20:54:16 robind
|
||||
#
|
||||
# Gobs of changes move from the main trunk to the 2.2 branch in
|
||||
# preparataion for 2.2.5 release. See CHANGES.txt for details.
|
||||
#
|
||||
# Revision 1.3 2000/10/30 21:05:22 robind
|
||||
#
|
||||
# Merged wxPython 2.2.2 over to the main branch
|
||||
#
|
||||
# Revision 1.1.2.1 2000/05/16 02:07:01 RD
|
||||
#
|
||||
# Moved and reorganized wxPython directories
|
||||
#
|
||||
# Now builds into an intermediate wxPython package directory before
|
||||
# installing
|
||||
#
|
||||
# Revision 1.6 1999/04/30 03:29:53 RD
|
||||
#
|
||||
# wxPython 2.0b9, first phase (win32)
|
||||
# Added gobs of stuff, see wxPython/README.txt for details
|
||||
#
|
||||
# Revision 1.5 1999/02/20 09:04:43 RD
|
||||
# Added wxWindow_FromHWND(hWnd) for wxMSW to construct a wxWindow from a
|
||||
# window handle. If you can get the window handle into the python code,
|
||||
# it should just work... More news on this later.
|
||||
#
|
||||
# Added wxImageList, wxToolTip.
|
||||
#
|
||||
# Re-enabled wxConfig.DeleteAll() since it is reportedly fixed for the
|
||||
# wxRegConfig class.
|
||||
#
|
||||
# As usual, some bug fixes, tweaks, etc.
|
||||
#
|
||||
# Revision 1.4 1998/12/16 22:12:46 RD
|
||||
#
|
||||
# Tweaks needed to be able to build wxPython with wxGTK.
|
||||
#
|
||||
# Revision 1.3 1998/12/15 20:44:35 RD
|
||||
# Changed the import semantics from "from wxPython import *" to "from
|
||||
# wxPython.wx import *" This is for people who are worried about
|
||||
# namespace pollution, they can use "from wxPython import wx" and then
|
||||
# prefix all the wxPython identifiers with "wx."
|
||||
#
|
||||
# Added wxTaskbarIcon for wxMSW.
|
||||
#
|
||||
# Made the events work for wxGrid.
|
||||
#
|
||||
# Added wxConfig.
|
||||
#
|
||||
# Added wxMiniFrame for wxGTK, (untested.)
|
||||
#
|
||||
# Changed many of the args and return values that were pointers to gdi
|
||||
# objects to references to reflect changes in the wxWindows API.
|
||||
#
|
||||
# Other assorted fixes and additions.
|
||||
#
|
||||
# Revision 1.2 1998/08/22 19:51:17 RD
|
||||
# some tweaks for wxGTK
|
||||
#
|
||||
# Revision 1.1 1998/08/09 08:28:05 RD
|
||||
# Initial version
|
||||
#
|
||||
#
|
@@ -1,91 +0,0 @@
|
||||
#!/bin/env python
|
||||
#----------------------------------------------------------------------------
|
||||
# Name: test5.py
|
||||
# Purpose: Testing wxTaskBarIcon for win32 systems
|
||||
#
|
||||
# Author: Robin Dunn
|
||||
#
|
||||
# Created: 17-Nov-1998
|
||||
# RCS-ID: $Id$
|
||||
# Copyright: (c) 1998 by Total Control Software
|
||||
# Licence: wxWindows license
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class MyDialog(wxDialog):
|
||||
def __init__(self):
|
||||
wxDialog.__init__(self, NULL, -1, "wxTaskBarIcon Test",
|
||||
wxPoint(-1,-1), wxSize(380,250),
|
||||
wxDIALOG_MODELESS|wxDEFAULT_DIALOG_STYLE)
|
||||
|
||||
# build the contents of the Dialog
|
||||
wxStaticText(self, -1,
|
||||
"Press OK to hide me, Exit to quit.",
|
||||
wxPoint(10, 20))
|
||||
wxStaticText(self, -1,
|
||||
"Double-click on the taskbar icon to show me again.",
|
||||
wxPoint(10, 40))
|
||||
|
||||
okButton = wxButton(self, wxID_OK, "OK", wxPoint(100, 180), wxSize(80, 25))
|
||||
exitButton = wxButton(self, wxID_EXIT, "Exit", wxPoint(185, 180), wxSize(80, 25))
|
||||
okButton.SetDefault()
|
||||
self.Centre(wxBOTH)
|
||||
|
||||
EVT_BUTTON(self, wxID_OK, self.OnOK)
|
||||
EVT_BUTTON(self, wxID_EXIT, self.OnExit)
|
||||
|
||||
|
||||
# make the TaskBar icon
|
||||
self.tbIcon = wxTaskBarIcon()
|
||||
icon = wxIcon('bitmaps/smiles.ico', wxBITMAP_TYPE_ICO)
|
||||
self.tbIcon.SetIcon(icon, "Test ToolTip")
|
||||
EVT_TASKBAR_LEFT_DCLICK(self.tbIcon, self.OnTaskBarActivate)
|
||||
|
||||
|
||||
|
||||
def OnTaskBarActivate(self, event):
|
||||
self.Show(true)
|
||||
|
||||
def OnOK(self, event):
|
||||
self.Show(false)
|
||||
|
||||
def OnExit(self, event):
|
||||
self.Close(true)
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.Destroy()
|
||||
del self.tbIcon # ensure the tbIcon is cleaned up...
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
self.dlg = MyDialog()
|
||||
self.dlg.Show(true)
|
||||
self.SetTopWindow(self.dlg)
|
||||
return true
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def main():
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
def t():
|
||||
import pdb
|
||||
pdb.run('main()')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
@@ -1,81 +0,0 @@
|
||||
#!/bin/env python
|
||||
#----------------------------------------------------------------------------
|
||||
# Name: test6.py
|
||||
# Purpose: Testing wxConfig
|
||||
#
|
||||
# Author: Robin Dunn
|
||||
#
|
||||
# Created: 26-Nov-1998
|
||||
# RCS-ID: $Id$
|
||||
# Copyright: (c) 1998 by Total Control Software
|
||||
# Licence: wxWindows license
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
import sys
|
||||
from wxPython.utils import wxConfig
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
def main():
|
||||
|
||||
cfg = wxConfig('test6', 'TCS', ".testconfig")
|
||||
|
||||
cmd = ''
|
||||
if len(sys.argv) > 1:
|
||||
cmd = sys.argv[1]
|
||||
|
||||
if cmd == 'add':
|
||||
cfg.SetPath('one/two/three')
|
||||
cfg.Flush()
|
||||
|
||||
cfg.Write('aaa', 'The quick brown fox jummped over the lazy dog.')
|
||||
cfg.Write('bbb', 'This is a test of the emergency broadcast system')
|
||||
|
||||
aList = ['one', 'two', 'buckle', 'my', 'shoe', 1966]
|
||||
cfg.Write('ccc', str(aList))
|
||||
|
||||
cfg.Write('zzz/yyy', 'foobar')
|
||||
cfg.Write('zzz/xxx', 'spam and eggs')
|
||||
|
||||
cfg.Flush()
|
||||
|
||||
elif cmd == 'enum':
|
||||
traverse(cfg, '/')
|
||||
|
||||
elif cmd == 'del':
|
||||
cfg.DeleteAll()
|
||||
|
||||
else:
|
||||
print 'Specify command: add, enum, or del.'
|
||||
|
||||
|
||||
|
||||
def traverse(cfg, path):
|
||||
print path
|
||||
cont, val, idx = cfg.GetFirstEntry()
|
||||
while cont:
|
||||
print "%s/%s = %s" % (path, val, cfg.Read(val))
|
||||
cont, val, idx = cfg.GetNextEntry(idx)
|
||||
|
||||
cont, val, idx = cfg.GetFirstGroup()
|
||||
while cont:
|
||||
if path == '/':
|
||||
newpath = path+val
|
||||
else:
|
||||
newpath = path+'/'+val
|
||||
|
||||
cfg.SetPath(newpath)
|
||||
traverse(cfg, newpath)
|
||||
cfg.SetPath(path)
|
||||
cont, val, idx = cfg.GetNextGroup(idx)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
#import pdb
|
||||
#pdb.run('main()')
|
||||
main()
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
@@ -1,123 +0,0 @@
|
||||
#!/bin/env python
|
||||
#----------------------------------------------------------------------------
|
||||
# Name: test7.py
|
||||
# Purpose: A minimal wxPython program that is a bit smarter than test1.
|
||||
#
|
||||
# Author: Robin Dunn
|
||||
#
|
||||
# Created: A long time ago, in a galaxy far, far away...
|
||||
# RCS-ID: $Id$
|
||||
# Copyright: (c) 1998 by Total Control Software
|
||||
# Licence: wxWindows license
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
||||
## import all of the wxPython GUI package
|
||||
from wxPython.wx import *
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
## Create a new frame class, derived from the wxPython Frame.
|
||||
class MyFrame(wxFrame):
|
||||
|
||||
def __init__(self, parent, id, title):
|
||||
# First, call the base class' __init__ method to create the frame
|
||||
wxFrame.__init__(self, parent, id, title,
|
||||
wxPoint(100, 100), wxSize(160, 100))
|
||||
|
||||
# Associate some events with methods of this class
|
||||
EVT_SIZE(self, self.OnSize)
|
||||
EVT_MOVE(self, self.OnMove)
|
||||
|
||||
# Add a panel and some controls to display the size and position
|
||||
panel = wxPanel(self, -1)
|
||||
wxStaticText(panel, -1, "Size:",
|
||||
wxDLG_PNT(panel, wxPoint(4, 4)), wxDefaultSize)
|
||||
wxStaticText(panel, -1, "Pos:",
|
||||
wxDLG_PNT(panel, wxPoint(4, 18)), wxDefaultSize)
|
||||
wxStaticText(panel, -1, "ScreenPos:",
|
||||
wxDLG_PNT(panel, wxPoint(4, 32)), wxDefaultSize)
|
||||
self.sizeCtrl = wxTextCtrl(panel, -1, "",
|
||||
wxDLG_PNT(panel, wxPoint(36, 4)),
|
||||
wxDLG_SZE(panel, wxSize(36, -1)),
|
||||
wxTE_READONLY)
|
||||
|
||||
self.posCtrl = wxTextCtrl(panel, -1, "",
|
||||
wxDLG_PNT(panel, wxPoint(36, 18)),
|
||||
wxDLG_SZE(panel, wxSize(36, -1)),
|
||||
wxTE_READONLY)
|
||||
|
||||
self.sposCtrl = wxTextCtrl(panel, -1, "",
|
||||
wxDLG_PNT(panel, wxPoint(36, 32)),
|
||||
wxDLG_SZE(panel, wxSize(36, -1)),
|
||||
wxTE_READONLY)
|
||||
|
||||
panel.Fit()
|
||||
self.Fit()
|
||||
|
||||
# This method is called automatically when the CLOSE event is
|
||||
# sent to this window
|
||||
def OnCloseWindow(self, event):
|
||||
# tell the window to kill itself
|
||||
self.Destroy()
|
||||
|
||||
|
||||
# This method is called by the System when the window is resized,
|
||||
# because of the association above.
|
||||
def OnSize(self, event):
|
||||
size = event.GetSize()
|
||||
self.sizeCtrl.SetValue("%s, %s" % (size.width, size.height))
|
||||
p = self.ClientToScreen((0,0))
|
||||
self.sposCtrl.SetValue("%s, %s" % (p.x, p.y))
|
||||
|
||||
# tell the event system to continue looking for an event handler,
|
||||
# so the default handler will get called.
|
||||
event.Skip()
|
||||
|
||||
# This method is called by the System when the window is moved,
|
||||
# because of the association above.
|
||||
def OnMove(self, event):
|
||||
pos = event.GetPosition()
|
||||
self.posCtrl.SetValue("%s, %s" % (pos.x, pos.y))
|
||||
p = self.ClientToScreen((0,0))
|
||||
self.sposCtrl.SetValue("%s, %s" % (p.x, p.y))
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
# Every wxWindows application must have a class derived from wxApp
|
||||
class MyApp(wxApp):
|
||||
|
||||
# wxWindows calls this method to initialize the application
|
||||
def OnInit(self):
|
||||
|
||||
# Create an instance of our customized Frame class
|
||||
frame = MyFrame(NULL, -1, "This is a test")
|
||||
frame.Show(true)
|
||||
|
||||
# Tell wxWindows that this is our main window
|
||||
self.SetTopWindow(frame)
|
||||
|
||||
# Return a success flag
|
||||
return true
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
app = MyApp(0) # Create an instance of the application class
|
||||
app.MainLoop() # Tell it to start processing events
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
#
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -1,85 +0,0 @@
|
||||
# Thread testing example. Harm van der Heijden, March 26 1999.
|
||||
#
|
||||
# Rule One in threading: make sure only one thread interacts with the
|
||||
# user interface. See the wxTextCtrlQueue class for an example of how
|
||||
# to accomplish this
|
||||
|
||||
import thread
|
||||
import time
|
||||
from whrandom import random
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
# Set this to zero to prevent entering the wxApp mainloop
|
||||
# (for testing whether threads work at all in the absense of wxWindows)
|
||||
use_wxpython = 1
|
||||
|
||||
# write a message to stdout every second
|
||||
def DoThread(mesg):
|
||||
while 1:
|
||||
sleeptime = (random() * 3) + 0.5
|
||||
print "Hello from %s (%1.3f)" % (mesg, sleeptime)
|
||||
time.sleep(sleeptime)
|
||||
|
||||
# the same, but write it to a textctrl.
|
||||
def DoTextCtrlThread(text, mesg):
|
||||
while 1:
|
||||
sleeptime = (random() * 3) + 0.5
|
||||
text.WriteText("Hello from %s (%1.3f)\n" % (mesg, sleeptime))
|
||||
time.sleep(sleeptime)
|
||||
|
||||
# A very simple queue for textctrls.
|
||||
# Nice demonstration of the power of OO programming too (at least I think so!)
|
||||
# WriteText puts text in the queue, rather than writing it immediately.
|
||||
# The main (UI) thread must call Flush to force output. (see MyFrame::OnIdle)
|
||||
class wxTextCtrlQueue(wxTextCtrl):
|
||||
def __init__(self, parent, id, value, pos, size, flags):
|
||||
wxTextCtrl.__init__(self,parent, id, value, pos, size, flags)
|
||||
self.queue = []
|
||||
def WriteText(self, value):
|
||||
self.queue.append(value)
|
||||
def Flush(self):
|
||||
queue = self.queue
|
||||
self.queue = []
|
||||
for value in queue:
|
||||
wxTextCtrl.WriteText(self,value)
|
||||
|
||||
# MyFrame and MyApp are very simple classes to test python threads in
|
||||
# wxPython.
|
||||
class MyFrame(wxFrame):
|
||||
def __init__(self):
|
||||
wxFrame.__init__(self, NULL, -1, "test threads", wxDefaultPosition, wxSize(300,200))
|
||||
self.text = wxTextCtrlQueue(self, -1, "thread output\n", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE)
|
||||
menu = wxMenu()
|
||||
menu.Append(1001, "Start thread")
|
||||
self.cnt = 0;
|
||||
menubar = wxMenuBar()
|
||||
menubar.Append(menu, "Action")
|
||||
self.SetMenuBar(menubar)
|
||||
EVT_MENU(self, 1001, self.StartThread)
|
||||
def StartThread(self, event):
|
||||
self.cnt = self.cnt + 1
|
||||
thread.start_new_thread(DoTextCtrlThread, (self.text, "thread %d" % self.cnt))
|
||||
def OnIdle(self, event):
|
||||
self.text.Flush()
|
||||
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
frame = MyFrame()
|
||||
self.SetTopWindow(frame)
|
||||
frame.Show(TRUE)
|
||||
return TRUE
|
||||
|
||||
# Start two threads that print a message every second
|
||||
thread.start_new_thread(DoThread, ("thread A",))
|
||||
thread.start_new_thread(DoThread, ("thread B",))
|
||||
|
||||
# if using wxpython, open a frame. Otherwise, just hang in while 1
|
||||
if use_wxpython:
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
||||
else:
|
||||
while 1:
|
||||
print "main loop"
|
||||
time.sleep(4)
|
||||
print 'done!'
|
@@ -1,49 +0,0 @@
|
||||
## import all of the wxPython GUI package
|
||||
from wxPython.wx import *
|
||||
|
||||
|
||||
## Create a new frame class, derived from the wxPython Frame.
|
||||
class Dialog(wxDialog):
|
||||
|
||||
def __init__(self, parent, title):
|
||||
# First, call the base class' __init__ method to create the frame
|
||||
wxDialog.__init__( self, parent, -1, title, wxDefaultPosition, wxDefaultSize )
|
||||
|
||||
wxButton(self, wxID_OK, "OK", (10, 10))
|
||||
wxButton(self, wxID_CANCEL, "Cancel", (50,50))
|
||||
self.Centre( wxBOTH )
|
||||
|
||||
|
||||
# This method is called automatically when the CLOSE event is
|
||||
# sent to this window
|
||||
#def OnCloseWindow(self, event):
|
||||
# self.Destroy()
|
||||
|
||||
#def OnCloseMe(self, event):
|
||||
#self.Close(true)
|
||||
|
||||
|
||||
def main():
|
||||
# Every wxWindows application must have a class derived from wxApp
|
||||
class App(wxApp):
|
||||
|
||||
# wxWindows calls this method to initialize the application
|
||||
def OnInit(self):
|
||||
|
||||
# Create an instance of our customized Frame class
|
||||
dialog = Dialog( NULL, 'test' )
|
||||
dialog.ShowModal()
|
||||
print "got here"
|
||||
dialog.Destroy()
|
||||
|
||||
# Tell wxWindows that this is our main window
|
||||
# Return a success flag
|
||||
return true
|
||||
|
||||
app = App(0) # Create an instance of the application class
|
||||
app.MainLoop() # Tell it to start processing events
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@@ -1,116 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from wxPython import wx
|
||||
import sys, os
|
||||
from stat import *
|
||||
|
||||
GlobalObjList = []
|
||||
|
||||
class Obj:
|
||||
def __init__(self, obj):
|
||||
self.obj = obj
|
||||
# Uncomment next line to eliminate crash.
|
||||
# GlobalObjList.append(self)
|
||||
|
||||
def Name(self):
|
||||
head, tail = os.path.split(self.obj)
|
||||
if tail:
|
||||
return tail
|
||||
else:
|
||||
return head
|
||||
|
||||
def HasChildren(self):
|
||||
return os.path.isdir(self.obj)
|
||||
|
||||
def Children(self):
|
||||
objList = os.listdir(self.obj)
|
||||
objList.sort()
|
||||
objList = map(lambda obj,parent=self.obj: os.path.join(parent,obj),
|
||||
objList)
|
||||
objectList = map(Obj, objList)
|
||||
return objectList
|
||||
|
||||
def __str__(self):
|
||||
return self.obj
|
||||
|
||||
def __repr__(self):
|
||||
return self.obj
|
||||
|
||||
def __del__(self):
|
||||
print 'del', self.obj
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class pyTree(wx.wxTreeCtrl):
|
||||
|
||||
def __init__(self, parent, id, obj):
|
||||
wx.wxTreeCtrl.__init__(self, parent, id)
|
||||
self.root = self.AddRoot(obj.Name(), -1, -1, wx.wxTreeItemData(''))
|
||||
self.SetPyData(self.root, obj)
|
||||
if obj.HasChildren():
|
||||
self.SetItemHasChildren(self.root, wx.TRUE)
|
||||
wx.EVT_TREE_ITEM_EXPANDING(self, self.GetId(), self.OnItemExpanding)
|
||||
wx.EVT_TREE_ITEM_COLLAPSED(self, self.GetId(), self.OnItemCollapsed)
|
||||
wx.EVT_TREE_SEL_CHANGED(self, self.GetId(), self.OnSelChanged)
|
||||
self.output = None
|
||||
|
||||
def SetOutput(self, output):
|
||||
self.output = output
|
||||
|
||||
def OnItemExpanding(self,event):
|
||||
item = event.GetItem()
|
||||
obj = self.GetPyData(item)
|
||||
children = obj.Children()
|
||||
for child in children:
|
||||
new_item = self.AppendItem(item, child.Name(), -1, -1,
|
||||
wx.wxTreeItemData(''))
|
||||
self.SetPyData(new_item, child)
|
||||
if child.HasChildren():
|
||||
self.SetItemHasChildren(new_item, wx.TRUE)
|
||||
|
||||
def OnItemCollapsed(self, event):
|
||||
item = event.GetItem()
|
||||
self.DeleteChildren(item)
|
||||
|
||||
def OnSelChanged(self, event):
|
||||
if not self.output:
|
||||
return
|
||||
obj = self.GetPyData( event.GetItem() )
|
||||
apply(self.output, (`obj`,))
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
|
||||
class MyFrame(wx.wxFrame):
|
||||
|
||||
def __init__(self):
|
||||
wx.wxFrame.__init__(self, wx.NULL, -1, 'PyTreeItemData Test',
|
||||
wx.wxDefaultPosition, wx.wxSize(600,500))
|
||||
split = wx.wxSplitterWindow(self, -1)
|
||||
|
||||
if sys.platform == 'win32':
|
||||
tree = pyTree(split, -1, Obj('C:\\'))
|
||||
else:
|
||||
tree = pyTree(split, -1, Obj('/'))
|
||||
|
||||
text = wx.wxTextCtrl(split, -1, '', wx.wxDefaultPosition,
|
||||
wx.wxDefaultSize, wx.wxTE_MULTILINE)
|
||||
split.SplitVertically(tree, text, 200)
|
||||
tree.SetOutput(text.SetValue)
|
||||
tree.SelectItem(tree.root)
|
||||
|
||||
class MyApp(wx.wxApp):
|
||||
|
||||
def OnInit(self):
|
||||
frame = MyFrame()
|
||||
frame.Show(wx.TRUE)
|
||||
self.SetTopWindow(frame)
|
||||
return wx.TRUE
|
||||
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
||||
|
||||
|
@@ -1,25 +0,0 @@
|
||||
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
def t():
|
||||
r1 = wxRect(0,0, 25, 500)
|
||||
r2 = wxRect(10, 10, 50, 100)
|
||||
|
||||
r = wxIntersectRect(r1, r2)
|
||||
print r
|
||||
|
||||
r = wxIntersectRect(r1, (50, 10, 50, 100))
|
||||
print r
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
t()
|
||||
return false
|
||||
|
||||
app = MyApp(0)
|
||||
|
@@ -1,39 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.grids import wxFlexGridSizer
|
||||
|
||||
import time
|
||||
from threading import Thread
|
||||
def foo():
|
||||
for x in range(20):
|
||||
print x, "Fooing!"
|
||||
time.sleep(0.5)
|
||||
Thread(target=foo).start()
|
||||
|
||||
class MyFrame(wxFrame):
|
||||
def __init__(self, parent, ID, title, pos, size):
|
||||
wxFrame.__init__(self, parent, ID, title, pos, size)
|
||||
panel = wxPanel(self, -1)
|
||||
self.panel=panel
|
||||
box = wxFlexGridSizer(1, 2, 10, 10)
|
||||
box.Add(wxButton(panel, 11211, "Foo"), 0, wxCENTER)
|
||||
box.Add(wxButton(panel, 11211, "Bar"), 0, wxCENTER)
|
||||
box.AddGrowableCol(1)
|
||||
panel.SetSizer(box)
|
||||
panel.SetAutoLayout(true)
|
||||
#EVT_SIZE(panel, lambda e, p=panel: p.Layout())
|
||||
EVT_BUTTON(self, 11211, self.Click)
|
||||
|
||||
def Click(self, event):
|
||||
print "Click"
|
||||
|
||||
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
win = MyFrame(None, -1, "Bummer", wxDefaultPosition, (200, 100))
|
||||
win.Show(true)
|
||||
self.SetTopWindow(win)
|
||||
return true
|
||||
|
||||
MyApp(0).MainLoop()
|
||||
|
@@ -1,29 +0,0 @@
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
class someData:
|
||||
def __init__(self, data="spam"):
|
||||
self.data = data
|
||||
|
||||
class errApp(wxApp):
|
||||
def OnInit(self):
|
||||
frame = wxFrame(NULL, -1, "Close to get an error", wxDefaultPosition,
|
||||
wxSize(200,200))
|
||||
|
||||
tree = wxTreeCtrl(frame, -1, wxDefaultPosition, wxDefaultSize)
|
||||
|
||||
root = tree.AddRoot("Spam")
|
||||
tree.SetPyData(root, someData())
|
||||
#tree.SetPyData(root, "A string")
|
||||
#tree.SetPyData(root, ["a list", "A string"])
|
||||
|
||||
frame.Show(true)
|
||||
self.SetTopWindow(frame)
|
||||
self.frame = frame
|
||||
return true
|
||||
|
||||
|
||||
app = errApp(0)
|
||||
app.MainLoop()
|
||||
print "got to the end"
|
||||
|
@@ -1,87 +0,0 @@
|
||||
"""
|
||||
Build a GUI Tree (wxWindows) from an XML file
|
||||
using pyExpat
|
||||
"""
|
||||
|
||||
import sys
|
||||
from xml.parsers import pyexpat
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
class MyFrame(wxFrame):
|
||||
def __init__(self, parent, id, title):
|
||||
wxFrame.__init__(self, parent, id, title, wxPoint(100, 100), wxSize(160,100))
|
||||
menu = wxMenu()
|
||||
menu.Append (1001,"Open")
|
||||
menu.Append (1002,"Close")
|
||||
menu.Append (1003,"Exit")
|
||||
menubar = wxMenuBar()
|
||||
menubar.Append (menu,"File")
|
||||
self.SetMenuBar(menubar)
|
||||
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
self.frame = MyFrame(NULL, -1, "Tree View of XML")
|
||||
self.tree = wx.wxTreeCtrl(self.frame, -1)
|
||||
EVT_MENU(self, 1001, self.OnOpen)
|
||||
EVT_MENU(self, 1002, self.OnClose)
|
||||
EVT_MENU(self, 1003, self.OnExit)
|
||||
self.frame.Show(true)
|
||||
self.SetTopWindow(self.frame)
|
||||
return true
|
||||
|
||||
def OnOpen(self,event):
|
||||
f = wxFileDialog(self.frame,"Select a file",".","","*.xml",wxOPEN)
|
||||
if f.ShowModal() == wxID_OK:
|
||||
LoadTree(f.GetPath())
|
||||
|
||||
def OnClose(self,event):
|
||||
self.tree = wx.wxTreeCtrl(self.frame, -1)
|
||||
pass
|
||||
|
||||
def OnExit(self,event):
|
||||
self.OnCloseWindow(event)
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.frame.Destroy()
|
||||
|
||||
|
||||
NodeStack = []
|
||||
|
||||
# Define a handler for start element events
|
||||
def StartElement( name, attrs ):
|
||||
global NodeStack
|
||||
NodeStack.append(app.tree.AppendItem(NodeStack[-1],name))
|
||||
|
||||
def EndElement( name ):
|
||||
global NodeStack
|
||||
NodeStack = NodeStack[:-1]
|
||||
|
||||
def CharacterData ( data ):
|
||||
global NodeStack
|
||||
if data.strip():
|
||||
app.tree.AppendItem(NodeStack[-1],data)
|
||||
|
||||
|
||||
def LoadTree (f):
|
||||
print f
|
||||
# Create a parser
|
||||
Parser = pyexpat.ParserCreate()
|
||||
|
||||
# Tell the parser what the start element handler is
|
||||
Parser.StartElementHandler = StartElement
|
||||
Parser.EndElementHandler = EndElement
|
||||
Parser.CharacterDataHandler = CharacterData
|
||||
|
||||
# Parse the XML File
|
||||
ParserStatus = Parser.Parse(open(f,'r').read(), 1)
|
||||
if ParserStatus == 0:
|
||||
print "oops!"
|
||||
raise SystemExit
|
||||
|
||||
app = MyApp(0)
|
||||
NodeStack = [app.tree.AddRoot("Root")]
|
||||
|
||||
|
||||
app.MainLoop()
|
||||
raise SystemExit
|
@@ -1,107 +0,0 @@
|
||||
from wxPython.wx import *
|
||||
|
||||
|
||||
class floatValidator(wxPyValidator):
|
||||
|
||||
def __init__(self, obj=None, attrName=""):
|
||||
wxPyValidator.__init__(self)
|
||||
self.numList = ['1','2','3','4','5','6','7','8','9','0','.']
|
||||
EVT_CHAR(self, self.OnChar)
|
||||
self.obj = obj
|
||||
self.attrName = attrName
|
||||
|
||||
def Clone(self):
|
||||
return floatValidator(self.obj, self.attrName)
|
||||
|
||||
def TransferToWindow(self):
|
||||
if self.obj and hasattr(self.obj, self.attrName):
|
||||
tc = wxPyTypeCast(self.GetWindow(), "wxTextCtrl")
|
||||
tc.SetValue(str(getattr(self.obj, self.attrName)))
|
||||
return true
|
||||
|
||||
def TransferFromWindow(self):
|
||||
if self.obj and self.attrName:
|
||||
tc = wxPyTypeCast(self.GetWindow(), "wxTextCtrl")
|
||||
text = tc.GetValue()
|
||||
setattr(self.obj, self.attrName, float(text))
|
||||
return true
|
||||
|
||||
|
||||
def Validate(self, win):
|
||||
tc = wxPyTypeCast(self.GetWindow(), "wxTextCtrl")
|
||||
val = tc.GetValue()
|
||||
|
||||
for x in val:
|
||||
if x not in self.numList:
|
||||
return false
|
||||
|
||||
return true
|
||||
|
||||
def OnChar(self, event):
|
||||
key = event.KeyCode()
|
||||
if key < WXK_SPACE or key == WXK_DELETE or key > 255:
|
||||
event.Skip()
|
||||
return
|
||||
|
||||
if chr(key) in self.numList:
|
||||
event.Skip()
|
||||
return
|
||||
|
||||
if not wxValidator_IsSilent():
|
||||
wxBell()
|
||||
|
||||
# Returning without calling even.Skip eats the event before it
|
||||
# gets to the text control
|
||||
return
|
||||
|
||||
|
||||
|
||||
class MyDialog(wxDialog):
|
||||
def __init__(self, parent):
|
||||
wxDialog.__init__(self, parent, -1, "hello")
|
||||
|
||||
self.theValue = 555.12
|
||||
fltValidator = floatValidator(self, "theValue")
|
||||
|
||||
Vbox = wxBoxSizer(wxVERTICAL)
|
||||
Tbox = wxBoxSizer(wxHORIZONTAL)
|
||||
Tbox.Add(wxStaticText(self, -1, "Initial Balance"), 0, wxALL,5)
|
||||
Tbox.Add(wxTextCtrl(self, 13, "123.45", validator = fltValidator,
|
||||
size=(100, -1)), 0, wxALL,5)
|
||||
|
||||
Vbox.Add(Tbox, 0, 0)
|
||||
|
||||
Tbox = wxBoxSizer(wxHORIZONTAL)
|
||||
Tbox.Add(wxButton(self, wxID_OK, "Ok"), 0, wxALL,5)
|
||||
Tbox.Add(wxButton(self, wxID_CANCEL, "Cancel"), 0, wxALL,5)
|
||||
|
||||
Vbox.Add(Tbox, 0, 0)
|
||||
|
||||
self.SetAutoLayout(true)
|
||||
self.SetSizer(Vbox)
|
||||
Vbox.Fit(self)
|
||||
|
||||
|
||||
class TestFrame(wxFrame):
|
||||
def __init__(self, parent):
|
||||
wxFrame.__init__(self, parent, -1, "Testing...", size=(150,75))
|
||||
wxButton(self, 25, "Click Me")
|
||||
EVT_BUTTON(self, 25, self.OnClick)
|
||||
|
||||
|
||||
def OnClick(self, event):
|
||||
dlg = MyDialog(self)
|
||||
dlg.ShowModal()
|
||||
print dlg.theValue
|
||||
dlg.Destroy()
|
||||
|
||||
|
||||
|
||||
app = wxPySimpleApp()
|
||||
frame = TestFrame(None)
|
||||
frame.Show(true)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
@@ -1,81 +0,0 @@
|
||||
#Boa:Frame:wxFrame1
|
||||
|
||||
from wxPython.wx import *
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
def create(parent):
|
||||
return wxFrame1(parent)
|
||||
|
||||
frame_count = 0
|
||||
|
||||
[wxID_WXFRAME1BUTTON1, wxID_WXFRAME1] = map(lambda _init_ctrls: wxNewId(), range(2))
|
||||
|
||||
class wxFrame1(wxFrame):
|
||||
def _init_utils(self):
|
||||
pass
|
||||
|
||||
def _init_ctrls(self, prnt):
|
||||
wxFrame.__init__(self, size = wxSize(960, 662), id = wxID_WXFRAME1, title = 'wxFrame1', parent = prnt, name = '', style = wxDEFAULT_FRAME_STYLE, pos = (-1, -1))
|
||||
self._init_utils()
|
||||
|
||||
self.button1 = wxButton(label = 'button1', id = wxID_WXFRAME1BUTTON1, parent = self, name = 'button1', size = wxSize(75, 23), style = 0, pos = wxPoint(216, 152))
|
||||
EVT_BUTTON(self.button1, wxID_WXFRAME1BUTTON1, self.OnButton1Button)
|
||||
|
||||
def __init__(self, parent):
|
||||
self._init_ctrls(parent)
|
||||
global frame_count
|
||||
frame_count += 1
|
||||
self.SetTitle('Frame %d' % frame_count)
|
||||
print 'Frame %d' % frame_count
|
||||
self.shown = 0
|
||||
EVT_IDLE(self, self.OnIdle)
|
||||
|
||||
def OnButton1Button(self, event):
|
||||
print 'Closing %s' % self.GetTitle()
|
||||
self.Close()
|
||||
|
||||
def OnIdle(self, evt):
|
||||
if not self.shown:
|
||||
#print self.GetTitle(), "shown"
|
||||
#print self.Show(false), self.Show(true)
|
||||
#import win32gui, win32con
|
||||
#win32gui.ShowWindow(self.GetHandle(), win32con.SW_SHOW)
|
||||
self.shown = 1
|
||||
|
||||
|
||||
class BoaApp(wxApp):
|
||||
def OnInit(self):
|
||||
frame1 = create(None)
|
||||
|
||||
## import win32gui, win32con
|
||||
## win32gui.ShowWindow(frame1.GetHandle(), win32con.SW_SHOW)
|
||||
## frame1.Show(true)
|
||||
|
||||
frame1.Show(true)
|
||||
frame1.Show(false)
|
||||
frame1.Show(true)
|
||||
|
||||
frame2 = create(None)
|
||||
print frame2.Show(true)
|
||||
return true
|
||||
|
||||
def main():
|
||||
application = BoaApp(0)
|
||||
application.MainLoop()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
##if __name__ == '__main__':
|
||||
## app = wxPySimpleApp()
|
||||
##
|
||||
## frame1 = create(None)
|
||||
## frame1.Show(true)
|
||||
##
|
||||
## frame2 = create(None)
|
||||
## frame2.Show(true)
|
||||
##
|
||||
## app.MainLoop()
|
||||
##
|
@@ -1,459 +0,0 @@
|
||||
"""
|
||||
This is a port of Konrad Hinsen's tkPlotCanvas.py plotting module.
|
||||
After thinking long and hard I came up with the name "wxPlotCanvas.py".
|
||||
|
||||
This file contains two parts; first the re-usable library stuff, then, after
|
||||
a "if __name__=='__main__'" test, a simple frame and a few default plots
|
||||
for testing.
|
||||
|
||||
Harm van der Heijden, feb 1999
|
||||
|
||||
Original comment follows below:
|
||||
# This module defines a plot widget for Tk user interfaces.
|
||||
# It supports only elementary line plots at the moment.
|
||||
# See the example at the end for documentation...
|
||||
#
|
||||
# Written by Konrad Hinsen <hinsen@cnrs-orleans.fr>
|
||||
# With contributions from RajGopal Srinivasan <raj@cherubino.med.jhmi.edu>
|
||||
# Last revision: 1998-7-28
|
||||
#
|
||||
"""
|
||||
|
||||
from wxPython import wx
|
||||
|
||||
# Not everybody will have Numeric, so let's be cool about it...
|
||||
try:
|
||||
import Numeric
|
||||
except:
|
||||
# bummer!
|
||||
d = wx.wxMessageDialog(wx.NULL,
|
||||
"""This module requires the Numeric module, which could not be imported.
|
||||
It probably is not installed (it's not part of the standard Python
|
||||
distribution). See the Python site (http://www.python.org) for
|
||||
information on downloading source or binaries.""",
|
||||
"Numeric not found")
|
||||
if d.ShowModal() == wx.wxID_CANCEL:
|
||||
d = wx.wxMessageDialog(wx.NULL, "I kid you not! Pressing Cancel won't help you!", "Not a joke", wx.wxOK)
|
||||
d.ShowModal()
|
||||
import sys
|
||||
sys.exit()
|
||||
|
||||
#
|
||||
# Plotting classes...
|
||||
#
|
||||
class PolyPoints:
|
||||
|
||||
def __init__(self, points, attr):
|
||||
self.points = Numeric.array(points)
|
||||
self.scaled = self.points
|
||||
self.attributes = {}
|
||||
for name, value in self._attributes.items():
|
||||
try:
|
||||
value = attr[name]
|
||||
except KeyError: pass
|
||||
self.attributes[name] = value
|
||||
|
||||
def boundingBox(self):
|
||||
return Numeric.minimum.reduce(self.points), \
|
||||
Numeric.maximum.reduce(self.points)
|
||||
|
||||
def scaleAndShift(self, scale=1, shift=0):
|
||||
self.scaled = scale*self.points+shift
|
||||
|
||||
|
||||
class PolyLine(PolyPoints):
|
||||
|
||||
def __init__(self, points, **attr):
|
||||
PolyPoints.__init__(self, points, attr)
|
||||
|
||||
_attributes = {'color': 'black',
|
||||
'width': 1}
|
||||
|
||||
def draw(self, dc):
|
||||
color = self.attributes['color']
|
||||
width = self.attributes['width']
|
||||
arguments = []
|
||||
dc.SetPen(wx.wxPen(wx.wxNamedColour(color), width))
|
||||
dc.DrawLines(map(tuple,self.scaled))
|
||||
|
||||
|
||||
class PolyMarker(PolyPoints):
|
||||
|
||||
def __init__(self, points, **attr):
|
||||
|
||||
PolyPoints.__init__(self, points, attr)
|
||||
|
||||
_attributes = {'color': 'black',
|
||||
'width': 1,
|
||||
'fillcolor': None,
|
||||
'size': 2,
|
||||
'fillstyle': wx.wxSOLID,
|
||||
'outline': 'black',
|
||||
'marker': 'circle'}
|
||||
|
||||
def draw(self, dc):
|
||||
color = self.attributes['color']
|
||||
width = self.attributes['width']
|
||||
size = self.attributes['size']
|
||||
fillcolor = self.attributes['fillcolor']
|
||||
fillstyle = self.attributes['fillstyle']
|
||||
marker = self.attributes['marker']
|
||||
|
||||
dc.SetPen(wx.wxPen(wx.wxNamedColour(color),width))
|
||||
if fillcolor:
|
||||
dc.SetBrush(wx.wxBrush(wx.wxNamedColour(fillcolor),fillstyle))
|
||||
else:
|
||||
dc.SetBrush(wx.wxBrush(wx.wxNamedColour('black'), wx.wxTRANSPARENT))
|
||||
|
||||
self._drawmarkers(dc, self.scaled, marker, size)
|
||||
|
||||
def _drawmarkers(self, dc, coords, marker,size=1):
|
||||
f = eval('self._' +marker)
|
||||
for xc, yc in coords:
|
||||
f(dc, xc, yc, size)
|
||||
|
||||
def _circle(self, dc, xc, yc, size=1):
|
||||
dc.DrawEllipse(xc-2.5*size,yc-2.5*size,5.*size,5.*size)
|
||||
|
||||
def _dot(self, dc, xc, yc, size=1):
|
||||
dc.DrawPoint(xc,yc)
|
||||
|
||||
def _square(self, dc, xc, yc, size=1):
|
||||
dc.DrawRectangle(xc-2.5*size,yc-2.5*size,5.*size,5.*size)
|
||||
|
||||
def _triangle(self, dc, xc, yc, size=1):
|
||||
dc.DrawPolygon([(-0.5*size*5,0.2886751*size*5),
|
||||
(0.5*size*5,0.2886751*size*5),
|
||||
(0.0,-0.577350*size*5)],xc,yc)
|
||||
|
||||
def _triangle_down(self, dc, xc, yc, size=1):
|
||||
dc.DrawPolygon([(-0.5*size*5,-0.2886751*size*5),
|
||||
(0.5*size*5,-0.2886751*size*5),
|
||||
(0.0,0.577350*size*5)],xc,yc)
|
||||
|
||||
def _cross(self, dc, xc, yc, size=1):
|
||||
dc.DrawLine(xc-2.5*size,yc-2.5*size,xc+2.5*size,yc+2.5*size)
|
||||
dc.DrawLine(xc-2.5*size,yc+2.5*size,xc+2.5*size,yc-2.5*size)
|
||||
|
||||
def _plus(self, dc, xc, yc, size=1):
|
||||
dc.DrawLine(xc-2.5*size,yc,xc+2.5*size,yc)
|
||||
dc.DrawLine(xc,yc-2.5*size,xc,yc+2.5*size)
|
||||
|
||||
class PlotGraphics:
|
||||
|
||||
def __init__(self, objects):
|
||||
self.objects = objects
|
||||
|
||||
def boundingBox(self):
|
||||
p1, p2 = self.objects[0].boundingBox()
|
||||
for o in self.objects[1:]:
|
||||
p1o, p2o = o.boundingBox()
|
||||
p1 = Numeric.minimum(p1, p1o)
|
||||
p2 = Numeric.maximum(p2, p2o)
|
||||
return p1, p2
|
||||
|
||||
def scaleAndShift(self, scale=1, shift=0):
|
||||
for o in self.objects:
|
||||
o.scaleAndShift(scale, shift)
|
||||
|
||||
def draw(self, canvas):
|
||||
for o in self.objects:
|
||||
o.draw(canvas)
|
||||
|
||||
def __len__(self):
|
||||
return len(self.objects)
|
||||
|
||||
def __getitem__(self, item):
|
||||
return self.objects[item]
|
||||
|
||||
|
||||
class PlotCanvas(wx.wxWindow):
|
||||
|
||||
def __init__(self, parent, id = -1):
|
||||
wx.wxWindow.__init__(self, parent, id, wx.wxPyDefaultPosition, wx.wxPyDefaultSize)
|
||||
self.border = (1,1)
|
||||
self.SetClientSizeWH(400,400)
|
||||
self.SetBackgroundColour(wx.wxNamedColour("white"))
|
||||
|
||||
wx.EVT_SIZE(self,self.reconfigure)
|
||||
self._setsize()
|
||||
self.last_draw = None
|
||||
# self.font = self._testFont(font)
|
||||
|
||||
def OnPaint(self, event):
|
||||
pdc = wx.wxPaintDC(self)
|
||||
if self.last_draw is not None:
|
||||
apply(self.draw, self.last_draw + (pdc,))
|
||||
|
||||
def reconfigure(self, event):
|
||||
(new_width,new_height) = self.GetClientSizeTuple()
|
||||
if new_width == self.width and new_height == self.height:
|
||||
return
|
||||
self._setsize()
|
||||
# self.redraw()
|
||||
|
||||
def _testFont(self, font):
|
||||
if font is not None:
|
||||
bg = self.canvas.cget('background')
|
||||
try:
|
||||
item = CanvasText(self.canvas, 0, 0, anchor=NW,
|
||||
text='0', fill=bg, font=font)
|
||||
self.canvas.delete(item)
|
||||
except TclError:
|
||||
font = None
|
||||
return font
|
||||
|
||||
def _setsize(self):
|
||||
(self.width,self.height) = self.GetClientSizeTuple();
|
||||
self.plotbox_size = 0.97*Numeric.array([self.width, -self.height])
|
||||
xo = 0.5*(self.width-self.plotbox_size[0])
|
||||
yo = self.height-0.5*(self.height+self.plotbox_size[1])
|
||||
self.plotbox_origin = Numeric.array([xo, yo])
|
||||
|
||||
def draw(self, graphics, xaxis = None, yaxis = None, dc = None):
|
||||
if dc == None: dc = wx.wxClientDC(self)
|
||||
dc.BeginDrawing()
|
||||
dc.Clear()
|
||||
self.last_draw = (graphics, xaxis, yaxis)
|
||||
p1, p2 = graphics.boundingBox()
|
||||
xaxis = self._axisInterval(xaxis, p1[0], p2[0])
|
||||
yaxis = self._axisInterval(yaxis, p1[1], p2[1])
|
||||
text_width = [0., 0.]
|
||||
text_height = [0., 0.]
|
||||
if xaxis is not None:
|
||||
p1[0] = xaxis[0]
|
||||
p2[0] = xaxis[1]
|
||||
xticks = self._ticks(xaxis[0], xaxis[1])
|
||||
bb = dc.GetTextExtent(xticks[0][1])
|
||||
text_height[1] = bb[1]
|
||||
text_width[0] = 0.5*bb[0]
|
||||
bb = dc.GetTextExtent(xticks[-1][1])
|
||||
text_width[1] = 0.5*bb[0]
|
||||
else:
|
||||
xticks = None
|
||||
if yaxis is not None:
|
||||
p1[1] = yaxis[0]
|
||||
p2[1] = yaxis[1]
|
||||
yticks = self._ticks(yaxis[0], yaxis[1])
|
||||
for y in yticks:
|
||||
bb = dc.GetTextExtent(y[1])
|
||||
text_width[0] = max(text_width[0],bb[0])
|
||||
h = 0.5*bb[1]
|
||||
text_height[0] = h
|
||||
text_height[1] = max(text_height[1], h)
|
||||
else:
|
||||
yticks = None
|
||||
text1 = Numeric.array([text_width[0], -text_height[1]])
|
||||
text2 = Numeric.array([text_width[1], -text_height[0]])
|
||||
scale = (self.plotbox_size-text1-text2) / (p2-p1)
|
||||
shift = -p1*scale + self.plotbox_origin + text1
|
||||
self._drawAxes(dc, xaxis, yaxis, p1, p2,
|
||||
scale, shift, xticks, yticks)
|
||||
graphics.scaleAndShift(scale, shift)
|
||||
graphics.draw(dc)
|
||||
dc.EndDrawing()
|
||||
|
||||
def _axisInterval(self, spec, lower, upper):
|
||||
if spec is None:
|
||||
return None
|
||||
if spec == 'minimal':
|
||||
if lower == upper:
|
||||
return lower-0.5, upper+0.5
|
||||
else:
|
||||
return lower, upper
|
||||
if spec == 'automatic':
|
||||
range = upper-lower
|
||||
if range == 0.:
|
||||
return lower-0.5, upper+0.5
|
||||
log = Numeric.log10(range)
|
||||
power = Numeric.floor(log)
|
||||
fraction = log-power
|
||||
if fraction <= 0.05:
|
||||
power = power-1
|
||||
grid = 10.**power
|
||||
lower = lower - lower % grid
|
||||
mod = upper % grid
|
||||
if mod != 0:
|
||||
upper = upper - mod + grid
|
||||
return lower, upper
|
||||
if type(spec) == type(()):
|
||||
lower, upper = spec
|
||||
if lower <= upper:
|
||||
return lower, upper
|
||||
else:
|
||||
return upper, lower
|
||||
raise ValueError, str(spec) + ': illegal axis specification'
|
||||
|
||||
def _drawAxes(self, dc, xaxis, yaxis,
|
||||
bb1, bb2, scale, shift, xticks, yticks):
|
||||
dc.SetPen(wx.wxPen(wx.wxNamedColour('BLACK'),1))
|
||||
if xaxis is not None:
|
||||
lower, upper = xaxis
|
||||
text = 1
|
||||
for y, d in [(bb1[1], -3), (bb2[1], 3)]:
|
||||
p1 = scale*Numeric.array([lower, y])+shift
|
||||
p2 = scale*Numeric.array([upper, y])+shift
|
||||
dc.DrawLine(p1[0],p1[1],p2[0],p2[1])
|
||||
for x, label in xticks:
|
||||
p = scale*Numeric.array([x, y])+shift
|
||||
dc.DrawLine(p[0],p[1],p[0],p[1]+d)
|
||||
if text:
|
||||
dc.DrawText(label,p[0],p[1])
|
||||
text = 0
|
||||
|
||||
if yaxis is not None:
|
||||
lower, upper = yaxis
|
||||
text = 1
|
||||
h = dc.GetCharHeight()
|
||||
for x, d in [(bb1[0], -3), (bb2[0], 3)]:
|
||||
p1 = scale*Numeric.array([x, lower])+shift
|
||||
p2 = scale*Numeric.array([x, upper])+shift
|
||||
dc.DrawLine(p1[0],p1[1],p2[0],p2[1])
|
||||
for y, label in yticks:
|
||||
p = scale*Numeric.array([x, y])+shift
|
||||
dc.DrawLine(p[0],p[1],p[0]-d,p[1])
|
||||
if text:
|
||||
dc.DrawText(label,p[0]-dc.GetTextExtent(label)[0],
|
||||
p[1]-0.5*h)
|
||||
text = 0
|
||||
|
||||
def _ticks(self, lower, upper):
|
||||
ideal = (upper-lower)/7.
|
||||
log = Numeric.log10(ideal)
|
||||
power = Numeric.floor(log)
|
||||
fraction = log-power
|
||||
factor = 1.
|
||||
error = fraction
|
||||
for f, lf in self._multiples:
|
||||
e = Numeric.fabs(fraction-lf)
|
||||
if e < error:
|
||||
error = e
|
||||
factor = f
|
||||
grid = factor * 10.**power
|
||||
if power > 3 or power < -3:
|
||||
format = '%+7.0e'
|
||||
elif power >= 0:
|
||||
digits = max(1, int(power))
|
||||
format = '%' + `digits`+'.0f'
|
||||
else:
|
||||
digits = -int(power)
|
||||
format = '%'+`digits+2`+'.'+`digits`+'f'
|
||||
ticks = []
|
||||
t = -grid*Numeric.floor(-lower/grid)
|
||||
while t <= upper:
|
||||
ticks.append(t, format % (t,))
|
||||
t = t + grid
|
||||
return ticks
|
||||
|
||||
_multiples = [(2., Numeric.log10(2.)), (5., Numeric.log10(5.))]
|
||||
|
||||
def redraw(self,dc=None):
|
||||
if self.last_draw is not None:
|
||||
apply(self.draw, self.last_draw + (dc,))
|
||||
|
||||
def clear(self):
|
||||
self.canvas.delete('all')
|
||||
|
||||
#
|
||||
# Now a sample implementation using the above...
|
||||
#
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
class AppFrame(wx.wxFrame):
|
||||
def __init__(self, parent, id, title):
|
||||
wx.wxFrame.__init__(self, parent, id, title,
|
||||
wx.wxPyDefaultPosition, wx.wxSize(400, 400))
|
||||
|
||||
# Now Create the menu bar and items
|
||||
self.mainmenu = wx.wxMenuBar()
|
||||
|
||||
menu = wx.wxMenu()
|
||||
menu.Append(200, '&Print...', 'Print the current plot')
|
||||
wx.EVT_MENU(self, 200, self.OnFilePrint)
|
||||
menu.Append(209, 'E&xit', 'Enough of this already!')
|
||||
wx.EVT_MENU(self, 209, self.OnFileExit)
|
||||
self.mainmenu.Append(menu, '&File')
|
||||
|
||||
menu = wx.wxMenu()
|
||||
menu.Append(210, '&Draw', 'Draw plots')
|
||||
wx.EVT_MENU(self,210,self.OnPlotDraw)
|
||||
menu.Append(211, '&Redraw', 'Redraw plots')
|
||||
wx.EVT_MENU(self,211,self.OnPlotRedraw)
|
||||
menu.Append(212, '&Clear', 'Clear canvas')
|
||||
wx.EVT_MENU(self,212,self.OnPlotClear)
|
||||
self.mainmenu.Append(menu, '&Plot')
|
||||
|
||||
menu = wx.wxMenu()
|
||||
menu.Append(220, '&About', 'About this thing...')
|
||||
wx.EVT_MENU(self, 220, self.OnHelpAbout)
|
||||
self.mainmenu.Append(menu, '&Help')
|
||||
|
||||
self.SetMenuBar(self.mainmenu)
|
||||
|
||||
# A status bar to tell people what's happening
|
||||
self.CreateStatusBar(1)
|
||||
|
||||
self.client = PlotCanvas(self)
|
||||
|
||||
def OnFilePrint(self, event):
|
||||
d = wx.wxMessageDialog(self,
|
||||
"""As of this writing, printing support in wxPython is shaky at best.
|
||||
Are you sure you want to do this?""", "Danger!", wx.wxYES_NO)
|
||||
if d.ShowModal() == wx.wxID_YES:
|
||||
psdc = wx.wxPostScriptDC("out.ps", wx.TRUE, self)
|
||||
self.client.redraw(psdc)
|
||||
|
||||
def OnFileExit(self, event):
|
||||
self.Close()
|
||||
|
||||
def OnPlotDraw(self, event):
|
||||
self.client.draw(InitObjects(),'automatic','automatic');
|
||||
|
||||
def OnPlotRedraw(self,event):
|
||||
self.client.redraw()
|
||||
|
||||
def OnPlotClear(self,event):
|
||||
self.client.last_draw = None
|
||||
dc = wx.wxClientDC(self.client)
|
||||
dc.Clear()
|
||||
|
||||
def OnHelpAbout(self, event):
|
||||
about = wx.wxMessageDialog(self, __doc__, "About...", wx.wxOK)
|
||||
about.ShowModal()
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.Destroy()
|
||||
|
||||
def InitObjects():
|
||||
# 100 points sin function, plotted as green circles
|
||||
data1 = 2.*Numeric.pi*Numeric.arange(200)/200.
|
||||
data1.shape = (100, 2)
|
||||
data1[:,1] = Numeric.sin(data1[:,0])
|
||||
markers1 = PolyMarker(data1, color='green', marker='circle',size=1)
|
||||
|
||||
# 50 points cos function, plotted as red line
|
||||
data1 = 2.*Numeric.pi*Numeric.arange(100)/100.
|
||||
data1.shape = (50,2)
|
||||
data1[:,1] = Numeric.cos(data1[:,0])
|
||||
lines = PolyLine(data1, color='red')
|
||||
|
||||
# A few more points...
|
||||
pi = Numeric.pi
|
||||
markers2 = PolyMarker([(0., 0.), (pi/4., 1.), (pi/2, 0.),
|
||||
(3.*pi/4., -1)], color='blue',
|
||||
fillcolor='green', marker='cross')
|
||||
|
||||
return PlotGraphics([markers1, lines, markers2])
|
||||
|
||||
|
||||
class MyApp(wx.wxApp):
|
||||
def OnInit(self):
|
||||
frame = AppFrame(wx.NULL, -1, "wxPlotCanvas")
|
||||
frame.Show(wx.TRUE)
|
||||
self.SetTopWindow(frame)
|
||||
return wx.TRUE
|
||||
|
||||
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
@@ -1,359 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
"""This is wxSlash 1.1
|
||||
|
||||
It's the obligatory Slashdot.org headlines reader that any modern
|
||||
widget set/library must have in order to be taken seriously :-)
|
||||
|
||||
Usage is quite simple; wxSlash attempts to download the 'ultramode.txt'
|
||||
file from http://slashdot.org, which contains the headlines in a computer
|
||||
friendly format. It then displays said headlines in a wxWindows list control.
|
||||
|
||||
You can read articles using either Python's html library or an external
|
||||
browser. Uncheck the 'browser->internal' menu item to use the latter option.
|
||||
Use the settings dialog box to set which external browser is started.
|
||||
|
||||
This code is available under the wxWindows license, see elsewhere. If you
|
||||
modify this code, be aware of the fact that slashdot.org's maintainer,
|
||||
CmdrTaco, explicitly asks 'ultramode.txt' downloaders not to do this
|
||||
automatically more than twice per hour. If this feature is abused, CmdrTaco
|
||||
may remove the ultramode file completely and that will make a *lot* of people
|
||||
unhappy.
|
||||
|
||||
I want to thank Alex Shnitman whose slashes.pl (Perl/GTK) script gave me
|
||||
the idea for this applet.
|
||||
|
||||
Have fun with it,
|
||||
|
||||
Harm van der Heijden (H.v.d.Heijden@phys.tue.nl)
|
||||
"""
|
||||
|
||||
from wxPython.wx import *
|
||||
from httplib import HTTP
|
||||
from htmllib import HTMLParser
|
||||
import os
|
||||
import re
|
||||
import formatter
|
||||
|
||||
class HTMLTextView(wxFrame):
|
||||
def __init__(self, parent, id, title='HTMLTextView', url=None):
|
||||
wxFrame.__init__(self, parent, id, title, wxPyDefaultPosition,
|
||||
wxSize(600,400))
|
||||
|
||||
self.mainmenu = wxMenuBar()
|
||||
|
||||
menu = wxMenu()
|
||||
menu.Append(201, '&Open URL...', 'Open URL')
|
||||
EVT_MENU(self, 201, self.OnFileOpen)
|
||||
menu.Append(209, 'E&xit', 'Exit viewer')
|
||||
EVT_MENU(self, 209, self.OnFileExit)
|
||||
|
||||
self.mainmenu.Append(menu, '&File')
|
||||
self.SetMenuBar(self.mainmenu)
|
||||
self.CreateStatusBar(1)
|
||||
|
||||
self.text = wxTextCtrl(self, -1, "", wxPyDefaultPosition,
|
||||
wxPyDefaultSize, wxTE_MULTILINE | wxTE_READONLY)
|
||||
|
||||
if (url):
|
||||
self.OpenURL(url)
|
||||
|
||||
def logprint(self, x):
|
||||
self.SetStatusText(x)
|
||||
|
||||
def OpenURL(self, url):
|
||||
self.url = url
|
||||
m = re.match('file:(\S+)\s*', url)
|
||||
if m:
|
||||
f = open(m.groups()[0],'r')
|
||||
else:
|
||||
m = re.match('http://([^/]+)(/\S*)\s*', url)
|
||||
if m:
|
||||
host = m.groups()[0]
|
||||
path = m.groups()[1]
|
||||
else:
|
||||
m = re.match('http://(\S+)\s*', url)
|
||||
if not m:
|
||||
# Invalid URL
|
||||
self.logprint("Invalid or unsupported URL: %s" % (url))
|
||||
return
|
||||
host = m.groups()[0]
|
||||
path = ''
|
||||
f = RetrieveAsFile(host,path,self.logprint)
|
||||
if not f:
|
||||
self.logprint("Could not open %s" % (url))
|
||||
return
|
||||
self.logprint("Receiving data...")
|
||||
data = f.read()
|
||||
tmp = open('tmphtml.txt','w')
|
||||
fmt = formatter.AbstractFormatter(formatter.DumbWriter(tmp))
|
||||
p = HTMLParser(fmt)
|
||||
self.logprint("Parsing data...")
|
||||
p.feed(data)
|
||||
p.close()
|
||||
tmp.close()
|
||||
tmp = open('tmphtml.txt', 'r')
|
||||
self.text.SetValue(tmp.read())
|
||||
self.SetTitle(url)
|
||||
self.logprint(url)
|
||||
|
||||
def OnFileOpen(self, event):
|
||||
dlg = wxTextEntryDialog(self, "Enter URL to open:", "")
|
||||
if dlg.ShowModal() == wxID_OK:
|
||||
url = dlg.GetValue()
|
||||
else:
|
||||
url = None
|
||||
if url:
|
||||
self.OpenURL(url)
|
||||
|
||||
def OnFileExit(self, event):
|
||||
self.Close()
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.Destroy()
|
||||
|
||||
|
||||
def ParseSlashdot(f):
|
||||
art_sep = re.compile('%%\r?\n')
|
||||
line_sep = re.compile('\r?\n')
|
||||
data = f.read()
|
||||
list = art_sep.split(data)
|
||||
art_list = []
|
||||
for i in range(1,len(list)-1):
|
||||
art_list.append(line_sep.split(list[i]))
|
||||
return art_list
|
||||
|
||||
def myprint(x):
|
||||
print x
|
||||
|
||||
def RetrieveAsFile(host, path='', logprint = myprint):
|
||||
try:
|
||||
h = HTTP(host)
|
||||
except:
|
||||
logprint("Failed to create HTTP connection to %s... is the network available?" % (host))
|
||||
return None
|
||||
h.putrequest('GET',path)
|
||||
h.putheader('Accept','text/html')
|
||||
h.putheader('Accept','text/plain')
|
||||
h.endheaders()
|
||||
errcode, errmsg, headers = h.getreply()
|
||||
if errcode != 200:
|
||||
logprint("HTTP error code %d: %s" % (errcode, errmsg))
|
||||
return None
|
||||
f = h.getfile()
|
||||
# f = open('/home/harm/ultramode.txt','r')
|
||||
return f
|
||||
|
||||
|
||||
class AppStatusBar(wxStatusBar):
|
||||
def __init__(self, parent):
|
||||
wxStatusBar.__init__(self,parent, -1)
|
||||
self.SetFieldsCount(2)
|
||||
self.SetStatusWidths([-1, 100])
|
||||
self.but = wxButton(self, 1001, "Refresh")
|
||||
EVT_BUTTON(self, 1001, parent.OnViewRefresh)
|
||||
self.OnSize(None)
|
||||
|
||||
def logprint(self,x):
|
||||
self.SetStatusText(x,0)
|
||||
|
||||
def OnSize(self, event):
|
||||
rect = self.GetFieldRect(1)
|
||||
self.but.SetPosition(wxPoint(rect.x+2, rect.y+2))
|
||||
self.but.SetSize(wxSize(rect.width-4, rect.height-4))
|
||||
|
||||
# This is a simple timer class to start a function after a short delay;
|
||||
class QuickTimer(wxTimer):
|
||||
def __init__(self, func, wait=100):
|
||||
wxTimer.__init__(self)
|
||||
self.callback = func
|
||||
self.Start(wait); # wait .1 second (.001 second doesn't work. why?)
|
||||
def Notify(self):
|
||||
self.Stop();
|
||||
apply(self.callback, ());
|
||||
|
||||
class AppFrame(wxFrame):
|
||||
def __init__(self, parent, id, title):
|
||||
wxFrame.__init__(self, parent, id, title, wxPyDefaultPosition,
|
||||
wxSize(650, 250))
|
||||
|
||||
# if the window manager closes the window:
|
||||
EVT_CLOSE(self, self.OnCloseWindow);
|
||||
|
||||
# Now Create the menu bar and items
|
||||
self.mainmenu = wxMenuBar()
|
||||
|
||||
menu = wxMenu()
|
||||
menu.Append(209, 'E&xit', 'Enough of this already!')
|
||||
EVT_MENU(self, 209, self.OnFileExit)
|
||||
self.mainmenu.Append(menu, '&File')
|
||||
menu = wxMenu()
|
||||
menu.Append(210, '&Refresh', 'Refresh headlines')
|
||||
EVT_MENU(self, 210, self.OnViewRefresh)
|
||||
menu.Append(211, '&Slashdot Index', 'View Slashdot index')
|
||||
EVT_MENU(self, 211, self.OnViewIndex)
|
||||
menu.Append(212, 'Selected &Article', 'View selected article')
|
||||
EVT_MENU(self, 212, self.OnViewArticle)
|
||||
self.mainmenu.Append(menu, '&View')
|
||||
menu = wxMenu()
|
||||
menu.Append(220, '&Internal', 'Use internal text browser',TRUE)
|
||||
menu.Check(220, true)
|
||||
self.UseInternal = 1;
|
||||
EVT_MENU(self, 220, self.OnBrowserInternal)
|
||||
menu.Append(222, '&Settings...', 'External browser Settings')
|
||||
EVT_MENU(self, 222, self.OnBrowserSettings)
|
||||
self.mainmenu.Append(menu, '&Browser')
|
||||
menu = wxMenu()
|
||||
menu.Append(230, '&About', 'Some documentation');
|
||||
EVT_MENU(self, 230, self.OnAbout)
|
||||
self.mainmenu.Append(menu, '&Help')
|
||||
|
||||
self.SetMenuBar(self.mainmenu)
|
||||
|
||||
if wxPlatform == '__WXGTK__':
|
||||
# I like lynx. Also Netscape 4.5 doesn't react to my cmdline opts
|
||||
self.BrowserSettings = "xterm -e lynx %s &"
|
||||
elif wxPlatform == '__WXMSW__':
|
||||
# netscape 4.x likes to hang out here...
|
||||
self.BrowserSettings = '\\progra~1\\Netscape\\Communicator\\Program\\netscape.exe %s'
|
||||
else:
|
||||
# a wild guess...
|
||||
self.BrowserSettings = 'netscape %s'
|
||||
|
||||
# A status bar to tell people what's happening
|
||||
self.sb = AppStatusBar(self)
|
||||
self.SetStatusBar(self.sb)
|
||||
|
||||
self.list = wxListCtrl(self, 1100)
|
||||
self.list.SetSingleStyle(wxLC_REPORT)
|
||||
self.list.InsertColumn(0, 'Subject')
|
||||
self.list.InsertColumn(1, 'Date')
|
||||
self.list.InsertColumn(2, 'Posted by')
|
||||
self.list.InsertColumn(3, 'Comments')
|
||||
self.list.SetColumnWidth(0, 300)
|
||||
self.list.SetColumnWidth(1, 150)
|
||||
self.list.SetColumnWidth(2, 100)
|
||||
self.list.SetColumnWidth(3, 100)
|
||||
|
||||
EVT_LIST_ITEM_SELECTED(self, 1100, self.OnItemSelected)
|
||||
EVT_LEFT_DCLICK(self.list, self.OnLeftDClick)
|
||||
|
||||
self.logprint("Connecting to slashdot... Please wait.")
|
||||
# wxYield doesn't yet work here. That's why we use a timer
|
||||
# to make sure that we see some GUI stuff before the slashdot
|
||||
# file is transfered.
|
||||
self.timer = QuickTimer(self.DoRefresh, 1000)
|
||||
|
||||
def logprint(self, x):
|
||||
self.sb.logprint(x)
|
||||
|
||||
def OnFileExit(self, event):
|
||||
self.Destroy()
|
||||
|
||||
def DoRefresh(self):
|
||||
f = RetrieveAsFile('slashdot.org','/ultramode.txt',self.sb.logprint)
|
||||
art_list = ParseSlashdot(f)
|
||||
self.list.DeleteAllItems()
|
||||
self.url = []
|
||||
self.current = -1
|
||||
i = 0;
|
||||
for article in art_list:
|
||||
self.list.InsertStringItem(i, article[0])
|
||||
self.list.SetStringItem(i, 1, article[2])
|
||||
self.list.SetStringItem(i, 2, article[3])
|
||||
self.list.SetStringItem(i, 3, article[6])
|
||||
self.url.append(article[1])
|
||||
i = i + 1
|
||||
self.logprint("File retrieved OK.")
|
||||
|
||||
def OnViewRefresh(self, event):
|
||||
self.logprint("Connecting to slashdot... Please wait.");
|
||||
wxYield()
|
||||
self.DoRefresh()
|
||||
|
||||
def DoViewIndex(self):
|
||||
if self.UseInternal:
|
||||
self.view = HTMLTextView(self, -1, 'slashdot.org',
|
||||
'http://slashdot.org')
|
||||
self.view.Show(true)
|
||||
else:
|
||||
self.logprint(self.BrowserSettings % ('http://slashdot.org'))
|
||||
os.system(self.BrowserSettings % ('http://slashdot.org'))
|
||||
self.logprint("OK")
|
||||
|
||||
def OnViewIndex(self, event):
|
||||
self.logprint("Starting browser... Please wait.")
|
||||
wxYield()
|
||||
self.DoViewIndex()
|
||||
|
||||
def DoViewArticle(self):
|
||||
if self.current<0: return
|
||||
url = self.url[self.current]
|
||||
if self.UseInternal:
|
||||
self.view = HTMLTextView(self, -1, url, url)
|
||||
self.view.Show(true)
|
||||
else:
|
||||
self.logprint(self.BrowserSettings % (url))
|
||||
os.system(self.BrowserSettings % (url))
|
||||
self.logprint("OK")
|
||||
|
||||
def OnViewArticle(self, event):
|
||||
self.logprint("Starting browser... Please wait.")
|
||||
wxYield()
|
||||
self.DoViewArticle()
|
||||
|
||||
def OnBrowserInternal(self, event):
|
||||
if self.mainmenu.Checked(220):
|
||||
self.UseInternal = 1
|
||||
else:
|
||||
self.UseInternal = 0
|
||||
|
||||
def OnBrowserSettings(self, event):
|
||||
dlg = wxTextEntryDialog(self, "Enter command to view URL.\nUse %s as a placeholder for the URL.", "", self.BrowserSettings);
|
||||
if dlg.ShowModal() == wxID_OK:
|
||||
self.BrowserSettings = dlg.GetValue()
|
||||
|
||||
def OnAbout(self, event):
|
||||
dlg = wxMessageDialog(self, __doc__, "wxSlash", wxOK | wxICON_INFORMATION)
|
||||
dlg.ShowModal()
|
||||
|
||||
def OnItemSelected(self, event):
|
||||
self.current = event.m_itemIndex
|
||||
self.logprint("URL: %s" % (self.url[self.current]))
|
||||
|
||||
def OnLeftDClick(self, event):
|
||||
(x,y) = event.Position();
|
||||
# Actually, we should convert x,y to logical coords using
|
||||
# a dc, but only for a wxScrolledWindow widget.
|
||||
# Now wxGTK derives wxListCtrl from wxScrolledWindow,
|
||||
# and wxMSW from wxControl... So that doesn't work.
|
||||
#dc = wxClientDC(self.list)
|
||||
##self.list.PrepareDC(dc)
|
||||
#x = dc.DeviceToLogicalX( event.GetX() )
|
||||
#y = dc.DeviceToLogicalY( event.GetY() )
|
||||
id = self.list.HitTest(wxPoint(x,y))
|
||||
#print "Double click at %d %d" % (x,y), id
|
||||
# Okay, we got a double click. Let's assume it's the current selection
|
||||
wxYield()
|
||||
self.OnViewArticle(event)
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.Destroy()
|
||||
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
frame = AppFrame(NULL, -1, "Slashdot Breaking News")
|
||||
frame.Show(true)
|
||||
self.SetTopWindow(frame)
|
||||
return true
|
||||
|
||||
#
|
||||
# main thingy
|
||||
#
|
||||
if __name__ == '__main__':
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -1,75 +0,0 @@
|
||||
#!/bin/env python
|
||||
#----------------------------------------------------------------------------
|
||||
## import all of the wxPython GUI package
|
||||
from wxPython.wx import *
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
class GeneralTab(wxWindow):
|
||||
def __init__(self,parent,id):
|
||||
wxWindow.__init__(self,parent,id,wxPoint(5,25))
|
||||
self.Opts = {}
|
||||
hdr = wxStaticText(self,-1,"This space left intentionally blank.",wxPoint(5,10))
|
||||
def GetOpts(self):
|
||||
return self.Opts
|
||||
|
||||
class ServersTab(wxWindow):
|
||||
def __init__(self,parent,id):
|
||||
wxWindow.__init__(self,parent,id,wxPoint(5,25))
|
||||
hdr = wxStaticText(self,-1,"This is also blank on purpose.",wxPoint(5,10))
|
||||
self.Opts = {}
|
||||
def GetOpts(self):
|
||||
return self.Opts
|
||||
|
||||
class OptionsTab(wxWindow):
|
||||
def __init__(self,parent,id):
|
||||
wxWindow.__init__(self,parent,id,wxPoint(5,25))
|
||||
hdr = wxStaticText(self,-1,"Quit bugging me!.",wxPoint(5,10))
|
||||
self.Opts = {}
|
||||
def GetOpts(self):
|
||||
return self.Opts
|
||||
|
||||
class SettingsWindow(wxFrame):
|
||||
NOTEBOOK = 3201
|
||||
GENERAL_TAB = 3210
|
||||
OPTIONS_TAB = 3211
|
||||
SERVERS_TAB = 3212
|
||||
|
||||
def __init__(self,parent,id):
|
||||
self.id = id
|
||||
self.parent = parent
|
||||
wxFrame.__init__(self,parent,id,'Pyces Settings',
|
||||
wxPoint(50,50), wxSize(350,475),
|
||||
wxDIALOG_MODAL|wxSTATIC_BORDER|wxCAPTION|wxSYSTEM_MENU)
|
||||
nb = wxNotebook(self, self.NOTEBOOK)
|
||||
self.GeneralTab = GeneralTab(self,-1)
|
||||
self.OptionsTab = OptionsTab(self,-1)
|
||||
self.ServersTab = ServersTab(self,-1)
|
||||
nb.AddPage(self.GeneralTab,'General')
|
||||
nb.AddPage(self.OptionsTab,'Options')
|
||||
nb.AddPage(self.ServersTab,'Servers')
|
||||
nb.SetSelection(0)
|
||||
nb.SetSize(wxSize(350,420))
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
frame = SettingsWindow(NULL, -1)
|
||||
#frame.ShowModal()
|
||||
#return false
|
||||
frame.Show(true)
|
||||
self.SetTopWindow(frame)
|
||||
return true
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
app = MyApp(0) # Create an instance of the application class
|
||||
app.MainLoop() # Tell it to start processing events
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
#
|
||||
|