Removed TABs
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@18755 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -555,12 +555,12 @@ if __name__ == '__main__':
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
wxFrame.__init__(self, None, -1, "Testing...")
|
wxFrame.__init__(self, None, -1, "Testing...")
|
||||||
|
|
||||||
self.CreateStatusBar()
|
self.CreateStatusBar()
|
||||||
mainmenu = wxMenuBar()
|
mainmenu = wxMenuBar()
|
||||||
menu = wxMenu()
|
menu = wxMenu()
|
||||||
menu.Append(200, 'E&xit', 'Get the heck outta here!')
|
menu.Append(200, 'E&xit', 'Get the heck outta here!')
|
||||||
mainmenu.Append(menu, "&File")
|
mainmenu.Append(menu, "&File")
|
||||||
self.SetMenuBar(mainmenu)
|
self.SetMenuBar(mainmenu)
|
||||||
EVT_MENU(self, 200, self.OnExit)
|
EVT_MENU(self, 200, self.OnExit)
|
||||||
self.panel = TestSelectionPanel(self, self)
|
self.panel = TestSelectionPanel(self, self)
|
||||||
self.SetSize(wxSize(400, 380))
|
self.SetSize(wxSize(400, 380))
|
||||||
|
@@ -170,22 +170,22 @@ class AppStatusBar(wxStatusBar):
|
|||||||
# This is a simple timer class to start a function after a short delay;
|
# This is a simple timer class to start a function after a short delay;
|
||||||
class QuickTimer(wxTimer):
|
class QuickTimer(wxTimer):
|
||||||
def __init__(self, func, wait=100):
|
def __init__(self, func, wait=100):
|
||||||
wxTimer.__init__(self)
|
wxTimer.__init__(self)
|
||||||
self.callback = func
|
self.callback = func
|
||||||
self.Start(wait); # wait .1 second (.001 second doesn't work. why?)
|
self.Start(wait); # wait .1 second (.001 second doesn't work. why?)
|
||||||
def Notify(self):
|
def Notify(self):
|
||||||
self.Stop();
|
self.Stop();
|
||||||
apply(self.callback, ());
|
apply(self.callback, ());
|
||||||
|
|
||||||
class AppFrame(wxFrame):
|
class AppFrame(wxFrame):
|
||||||
def __init__(self, parent, id, title):
|
def __init__(self, parent, id, title):
|
||||||
wxFrame.__init__(self, parent, id, title, wxPyDefaultPosition,
|
wxFrame.__init__(self, parent, id, title, wxPyDefaultPosition,
|
||||||
wxSize(650, 250))
|
wxSize(650, 250))
|
||||||
|
|
||||||
# if the window manager closes the window:
|
# if the window manager closes the window:
|
||||||
EVT_CLOSE(self, self.OnCloseWindow);
|
EVT_CLOSE(self, self.OnCloseWindow);
|
||||||
|
|
||||||
# Now Create the menu bar and items
|
# Now Create the menu bar and items
|
||||||
self.mainmenu = wxMenuBar()
|
self.mainmenu = wxMenuBar()
|
||||||
|
|
||||||
menu = wxMenu()
|
menu = wxMenu()
|
||||||
@@ -208,45 +208,45 @@ class AppFrame(wxFrame):
|
|||||||
menu.Append(222, '&Settings...', 'External browser Settings')
|
menu.Append(222, '&Settings...', 'External browser Settings')
|
||||||
EVT_MENU(self, 222, self.OnBrowserSettings)
|
EVT_MENU(self, 222, self.OnBrowserSettings)
|
||||||
self.mainmenu.Append(menu, '&Browser')
|
self.mainmenu.Append(menu, '&Browser')
|
||||||
menu = wxMenu()
|
menu = wxMenu()
|
||||||
menu.Append(230, '&About', 'Some documentation');
|
menu.Append(230, '&About', 'Some documentation');
|
||||||
EVT_MENU(self, 230, self.OnAbout)
|
EVT_MENU(self, 230, self.OnAbout)
|
||||||
self.mainmenu.Append(menu, '&Help')
|
self.mainmenu.Append(menu, '&Help')
|
||||||
|
|
||||||
self.SetMenuBar(self.mainmenu)
|
self.SetMenuBar(self.mainmenu)
|
||||||
|
|
||||||
if wxPlatform == '__WXGTK__':
|
if wxPlatform == '__WXGTK__':
|
||||||
# I like lynx. Also Netscape 4.5 doesn't react to my cmdline opts
|
# I like lynx. Also Netscape 4.5 doesn't react to my cmdline opts
|
||||||
self.BrowserSettings = "xterm -e lynx %s &"
|
self.BrowserSettings = "xterm -e lynx %s &"
|
||||||
elif wxPlatform == '__WXMSW__':
|
elif wxPlatform == '__WXMSW__':
|
||||||
# netscape 4.x likes to hang out here...
|
# netscape 4.x likes to hang out here...
|
||||||
self.BrowserSettings = '\\progra~1\\Netscape\\Communicator\\Program\\netscape.exe %s'
|
self.BrowserSettings = '\\progra~1\\Netscape\\Communicator\\Program\\netscape.exe %s'
|
||||||
else:
|
else:
|
||||||
# a wild guess...
|
# a wild guess...
|
||||||
self.BrowserSettings = 'netscape %s'
|
self.BrowserSettings = 'netscape %s'
|
||||||
|
|
||||||
# A status bar to tell people what's happening
|
# A status bar to tell people what's happening
|
||||||
self.sb = AppStatusBar(self)
|
self.sb = AppStatusBar(self)
|
||||||
self.SetStatusBar(self.sb)
|
self.SetStatusBar(self.sb)
|
||||||
|
|
||||||
self.list = wxListCtrl(self, 1100, style=wxLC_REPORT)
|
self.list = wxListCtrl(self, 1100, style=wxLC_REPORT)
|
||||||
self.list.InsertColumn(0, 'Subject')
|
self.list.InsertColumn(0, 'Subject')
|
||||||
self.list.InsertColumn(1, 'Date')
|
self.list.InsertColumn(1, 'Date')
|
||||||
self.list.InsertColumn(2, 'Posted by')
|
self.list.InsertColumn(2, 'Posted by')
|
||||||
self.list.InsertColumn(3, 'Comments')
|
self.list.InsertColumn(3, 'Comments')
|
||||||
self.list.SetColumnWidth(0, 300)
|
self.list.SetColumnWidth(0, 300)
|
||||||
self.list.SetColumnWidth(1, 150)
|
self.list.SetColumnWidth(1, 150)
|
||||||
self.list.SetColumnWidth(2, 100)
|
self.list.SetColumnWidth(2, 100)
|
||||||
self.list.SetColumnWidth(3, 100)
|
self.list.SetColumnWidth(3, 100)
|
||||||
|
|
||||||
EVT_LIST_ITEM_SELECTED(self, 1100, self.OnItemSelected)
|
EVT_LIST_ITEM_SELECTED(self, 1100, self.OnItemSelected)
|
||||||
EVT_LEFT_DCLICK(self.list, self.OnLeftDClick)
|
EVT_LEFT_DCLICK(self.list, self.OnLeftDClick)
|
||||||
|
|
||||||
self.logprint("Connecting to slashdot... Please wait.")
|
self.logprint("Connecting to slashdot... Please wait.")
|
||||||
# wxYield doesn't yet work here. That's why we use a timer
|
# 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
|
# to make sure that we see some GUI stuff before the slashdot
|
||||||
# file is transfered.
|
# file is transfered.
|
||||||
self.timer = QuickTimer(self.DoRefresh, 1000)
|
self.timer = QuickTimer(self.DoRefresh, 1000)
|
||||||
|
|
||||||
def logprint(self, x):
|
def logprint(self, x):
|
||||||
self.sb.logprint(x)
|
self.sb.logprint(x)
|
||||||
@@ -268,12 +268,12 @@ class AppFrame(wxFrame):
|
|||||||
self.list.SetStringItem(i, 3, article[6])
|
self.list.SetStringItem(i, 3, article[6])
|
||||||
self.url.append(article[1])
|
self.url.append(article[1])
|
||||||
i = i + 1
|
i = i + 1
|
||||||
self.logprint("File retrieved OK.")
|
self.logprint("File retrieved OK.")
|
||||||
|
|
||||||
def OnViewRefresh(self, event):
|
def OnViewRefresh(self, event):
|
||||||
self.logprint("Connecting to slashdot... Please wait.");
|
self.logprint("Connecting to slashdot... Please wait.");
|
||||||
wxYield()
|
wxYield()
|
||||||
self.DoRefresh()
|
self.DoRefresh()
|
||||||
|
|
||||||
def DoViewIndex(self):
|
def DoViewIndex(self):
|
||||||
if self.UseInternal:
|
if self.UseInternal:
|
||||||
@@ -284,12 +284,12 @@ class AppFrame(wxFrame):
|
|||||||
self.logprint(self.BrowserSettings % ('http://slashdot.org'))
|
self.logprint(self.BrowserSettings % ('http://slashdot.org'))
|
||||||
#os.system(self.BrowserSettings % ('http://slashdot.org'))
|
#os.system(self.BrowserSettings % ('http://slashdot.org'))
|
||||||
wxExecute(self.BrowserSettings % ('http://slashdot.org'))
|
wxExecute(self.BrowserSettings % ('http://slashdot.org'))
|
||||||
self.logprint("OK")
|
self.logprint("OK")
|
||||||
|
|
||||||
def OnViewIndex(self, event):
|
def OnViewIndex(self, event):
|
||||||
self.logprint("Starting browser... Please wait.")
|
self.logprint("Starting browser... Please wait.")
|
||||||
wxYield()
|
wxYield()
|
||||||
self.DoViewIndex()
|
self.DoViewIndex()
|
||||||
|
|
||||||
def DoViewArticle(self):
|
def DoViewArticle(self):
|
||||||
if self.current<0: return
|
if self.current<0: return
|
||||||
@@ -300,12 +300,12 @@ class AppFrame(wxFrame):
|
|||||||
else:
|
else:
|
||||||
self.logprint(self.BrowserSettings % (url))
|
self.logprint(self.BrowserSettings % (url))
|
||||||
os.system(self.BrowserSettings % (url))
|
os.system(self.BrowserSettings % (url))
|
||||||
self.logprint("OK")
|
self.logprint("OK")
|
||||||
|
|
||||||
def OnViewArticle(self, event):
|
def OnViewArticle(self, event):
|
||||||
self.logprint("Starting browser... Please wait.")
|
self.logprint("Starting browser... Please wait.")
|
||||||
wxYield()
|
wxYield()
|
||||||
self.DoViewArticle()
|
self.DoViewArticle()
|
||||||
|
|
||||||
def OnBrowserInternal(self, event):
|
def OnBrowserInternal(self, event):
|
||||||
if self.mainmenu.Checked(220):
|
if self.mainmenu.Checked(220):
|
||||||
@@ -319,28 +319,28 @@ class AppFrame(wxFrame):
|
|||||||
self.BrowserSettings = dlg.GetValue()
|
self.BrowserSettings = dlg.GetValue()
|
||||||
|
|
||||||
def OnAbout(self, event):
|
def OnAbout(self, event):
|
||||||
dlg = wxMessageDialog(self, __doc__, "wxSlash", wxOK | wxICON_INFORMATION)
|
dlg = wxMessageDialog(self, __doc__, "wxSlash", wxOK | wxICON_INFORMATION)
|
||||||
dlg.ShowModal()
|
dlg.ShowModal()
|
||||||
|
|
||||||
def OnItemSelected(self, event):
|
def OnItemSelected(self, event):
|
||||||
self.current = event.m_itemIndex
|
self.current = event.m_itemIndex
|
||||||
self.logprint("URL: %s" % (self.url[self.current]))
|
self.logprint("URL: %s" % (self.url[self.current]))
|
||||||
|
|
||||||
def OnLeftDClick(self, event):
|
def OnLeftDClick(self, event):
|
||||||
(x,y) = event.Position();
|
(x,y) = event.Position();
|
||||||
# Actually, we should convert x,y to logical coords using
|
# Actually, we should convert x,y to logical coords using
|
||||||
# a dc, but only for a wxScrolledWindow widget.
|
# a dc, but only for a wxScrolledWindow widget.
|
||||||
# Now wxGTK derives wxListCtrl from wxScrolledWindow,
|
# Now wxGTK derives wxListCtrl from wxScrolledWindow,
|
||||||
# and wxMSW from wxControl... So that doesn't work.
|
# and wxMSW from wxControl... So that doesn't work.
|
||||||
#dc = wxClientDC(self.list)
|
#dc = wxClientDC(self.list)
|
||||||
##self.list.PrepareDC(dc)
|
##self.list.PrepareDC(dc)
|
||||||
#x = dc.DeviceToLogicalX( event.GetX() )
|
#x = dc.DeviceToLogicalX( event.GetX() )
|
||||||
#y = dc.DeviceToLogicalY( event.GetY() )
|
#y = dc.DeviceToLogicalY( event.GetY() )
|
||||||
id = self.list.HitTest(wxPoint(x,y))
|
id = self.list.HitTest(wxPoint(x,y))
|
||||||
#print "Double click at %d %d" % (x,y), id
|
#print "Double click at %d %d" % (x,y), id
|
||||||
# Okay, we got a double click. Let's assume it's the current selection
|
# Okay, we got a double click. Let's assume it's the current selection
|
||||||
wxYield()
|
wxYield()
|
||||||
self.OnViewArticle(event)
|
self.OnViewArticle(event)
|
||||||
|
|
||||||
def OnCloseWindow(self, event):
|
def OnCloseWindow(self, event):
|
||||||
self.Destroy()
|
self.Destroy()
|
||||||
|
@@ -203,6 +203,7 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin):
|
|||||||
|
|
||||||
|
|
||||||
def OnItemSelected(self, event):
|
def OnItemSelected(self, event):
|
||||||
|
print event.GetItem().GetTextColour()
|
||||||
self.currentItem = event.m_itemIndex
|
self.currentItem = event.m_itemIndex
|
||||||
self.log.WriteText("OnItemSelected: %s, %s, %s, %s\n" %
|
self.log.WriteText("OnItemSelected: %s, %s, %s, %s\n" %
|
||||||
(self.currentItem,
|
(self.currentItem,
|
||||||
|
@@ -175,7 +175,7 @@ class PythonSTC(wxStyledTextCtrl):
|
|||||||
def OnUpdateUI(self, evt):
|
def OnUpdateUI(self, evt):
|
||||||
# check for matching braces
|
# check for matching braces
|
||||||
braceAtCaret = -1
|
braceAtCaret = -1
|
||||||
braceOpposite = -1
|
braceOpposite = -1
|
||||||
charBefore = None
|
charBefore = None
|
||||||
caretPos = self.GetCurrentPos()
|
caretPos = self.GetCurrentPos()
|
||||||
if caretPos > 0:
|
if caretPos > 0:
|
||||||
@@ -260,7 +260,7 @@ class PythonSTC(wxStyledTextCtrl):
|
|||||||
|
|
||||||
def Expand(self, line, doExpand, force=false, visLevels=0, level=-1):
|
def Expand(self, line, doExpand, force=false, visLevels=0, level=-1):
|
||||||
lastChild = self.GetLastChild(line, level)
|
lastChild = self.GetLastChild(line, level)
|
||||||
line = line + 1
|
line = line + 1
|
||||||
while line <= lastChild:
|
while line <= lastChild:
|
||||||
if force:
|
if force:
|
||||||
if visLevels > 0:
|
if visLevels > 0:
|
||||||
|
@@ -47,6 +47,9 @@ class TestPanel(wxPanel):
|
|||||||
b3 = wxButton(self, -1, "Test WriteText")
|
b3 = wxButton(self, -1, "Test WriteText")
|
||||||
EVT_BUTTON(self, b3.GetId(), self.OnTestWriteText)
|
EVT_BUTTON(self, b3.GetId(), self.OnTestWriteText)
|
||||||
self.tc = t3
|
self.tc = t3
|
||||||
|
b4 = wxButton(self, -1, "Test Simulated Event")
|
||||||
|
EVT_BUTTON(self, b4.GetId(), self.OnTestEvent)
|
||||||
|
|
||||||
|
|
||||||
l4 = wxStaticText(self, -1, "Rich Text")
|
l4 = wxStaticText(self, -1, "Rich Text")
|
||||||
t4 = wxTextCtrl(self, -1, "If supported by the native control, this is red, and this is a different font.",
|
t4 = wxTextCtrl(self, -1, "If supported by the native control, this is red, and this is a different font.",
|
||||||
@@ -71,6 +74,7 @@ class TestPanel(wxPanel):
|
|||||||
bsizer.Add(b, 0, wxGROW|wxALL, 4)
|
bsizer.Add(b, 0, wxGROW|wxALL, 4)
|
||||||
bsizer.Add(b2, 0, wxGROW|wxALL, 4)
|
bsizer.Add(b2, 0, wxGROW|wxALL, 4)
|
||||||
bsizer.Add(b3, 0, wxGROW|wxALL, 4)
|
bsizer.Add(b3, 0, wxGROW|wxALL, 4)
|
||||||
|
bsizer.Add(b4, 0, wxGROW|wxALL, 4)
|
||||||
|
|
||||||
sizer = wxFlexGridSizer(cols=3, hgap=6, vgap=6)
|
sizer = wxFlexGridSizer(cols=3, hgap=6, vgap=6)
|
||||||
sizer.AddMany([ l1, t1, (0,0),
|
sizer.AddMany([ l1, t1, (0,0),
|
||||||
@@ -129,6 +133,13 @@ class TestPanel(wxPanel):
|
|||||||
% (ip, text[ip], lp, len(text)))
|
% (ip, text[ip], lp, len(text)))
|
||||||
|
|
||||||
|
|
||||||
|
def OnTestEvent(self, evt):
|
||||||
|
ke = wxKeyEvent(wxEVT_CHAR)
|
||||||
|
ke.SetEventObject(self.tc1)
|
||||||
|
ke.SetId(self.tc1.GetId())
|
||||||
|
ke.m_keyCode = ord('A')
|
||||||
|
self.tc1.GetEventHandler().ProcessEvent(ke)
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@@ -185,7 +185,7 @@ class MyBCPPCompiler(BCPPCompiler):
|
|||||||
# This needs to be compiled to a .res file -- do it now.
|
# This needs to be compiled to a .res file -- do it now.
|
||||||
try:
|
try:
|
||||||
self.spawn (["brcc32"] + pp_opts + ["-fo"] +
|
self.spawn (["brcc32"] + pp_opts + ["-fo"] +
|
||||||
[obj] + [src]) ### RPD changed this lines only
|
[obj] + [src]) ### RPD changed this lines only
|
||||||
except DistutilsExecError, msg:
|
except DistutilsExecError, msg:
|
||||||
raise CompileError, msg
|
raise CompileError, msg
|
||||||
continue # the 'for' loop
|
continue # the 'for' loop
|
||||||
@@ -222,7 +222,7 @@ class MyBCPPCompiler(BCPPCompiler):
|
|||||||
# with cw32mti library as in wxWindows DLL make file
|
# with cw32mti library as in wxWindows DLL make file
|
||||||
# Othervise we obtain Windows "Core dump" ;-).
|
# Othervise we obtain Windows "Core dump" ;-).
|
||||||
#
|
#
|
||||||
# Evgeny A Cherkashin <eugeneai@icc.ru>
|
# Evgeny A Cherkashin <eugeneai@icc.ru>
|
||||||
#
|
#
|
||||||
####################################################################
|
####################################################################
|
||||||
|
|
||||||
@@ -335,7 +335,7 @@ class MyBCPPCompiler(BCPPCompiler):
|
|||||||
|
|
||||||
# some default libraries
|
# some default libraries
|
||||||
ld_args.append ('import32')
|
ld_args.append ('import32')
|
||||||
ld_args.append ('cw32mti') ### mt->mti (as in wx2)
|
ld_args.append ('cw32mti') ### mt->mti (as in wx2)
|
||||||
|
|
||||||
# def file for export symbols
|
# def file for export symbols
|
||||||
ld_args.extend([',',def_file])
|
ld_args.extend([',',def_file])
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
# Name: CreateBatchFiles.py
|
# Name: CreateBatchFiles.py
|
||||||
# Purpose: Run by the InnoSetup installer to create a DOS batch
|
# Purpose: Run by the InnoSetup installer to create a DOS batch
|
||||||
# file for each of the wxPython tool scripts.
|
# file for each of the wxPython tool scripts.
|
||||||
#
|
#
|
||||||
# Author: Robin Dunn
|
# Author: Robin Dunn
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
# Name: CreateMacScripts.py
|
# Name: CreateMacScripts.py
|
||||||
# Purpose: Massages the scripts to be usable with MachoPython
|
# Purpose: Massages the scripts to be usable with MachoPython
|
||||||
#
|
#
|
||||||
# Author: Robin Dunn
|
# Author: Robin Dunn
|
||||||
#
|
#
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Name: _extra.py
|
# Name: _extra.py
|
||||||
# Purpose: This file is appended to the shadow class file generated
|
# Purpose: This file is appended to the shadow class file generated
|
||||||
# by SWIG. We add some unSWIGable things here.
|
# by SWIG. We add some unSWIGable things here.
|
||||||
#
|
#
|
||||||
# Author: Robin Dunn
|
# Author: Robin Dunn
|
||||||
|
@@ -291,3 +291,4 @@ static wxPyCoreAPI API = {
|
|||||||
|
|
||||||
%pragma(python) include="_extras.py";
|
%pragma(python) include="_extras.py";
|
||||||
|
|
||||||
|
|
||||||
|
@@ -19,30 +19,30 @@ from wxPython.wx import *
|
|||||||
|
|
||||||
class WordFetcher:
|
class WordFetcher:
|
||||||
def __init__(self, filename, min_length = 5):
|
def __init__(self, filename, min_length = 5):
|
||||||
self.min_length = min_length
|
self.min_length = min_length
|
||||||
print "Trying to open file %s" % (filename,)
|
print "Trying to open file %s" % (filename,)
|
||||||
try:
|
try:
|
||||||
f = open(filename, "r")
|
f = open(filename, "r")
|
||||||
except:
|
except:
|
||||||
print "Couldn't open dictionary file %s, using build-ins" % (filename,)
|
print "Couldn't open dictionary file %s, using build-ins" % (filename,)
|
||||||
self.words = self.builtin_words
|
self.words = self.builtin_words
|
||||||
self.filename = None
|
self.filename = None
|
||||||
return
|
return
|
||||||
self.words = f.read()
|
self.words = f.read()
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
print "Got %d bytes." % (len(self.words),)
|
print "Got %d bytes." % (len(self.words),)
|
||||||
def SetMinLength(min_length):
|
def SetMinLength(min_length):
|
||||||
self.min_length = min_length
|
self.min_length = min_length
|
||||||
def Get(self):
|
def Get(self):
|
||||||
reg = re.compile('\s+([a-zA-Z]+)\s+')
|
reg = re.compile('\s+([a-zA-Z]+)\s+')
|
||||||
n = 50 # safety valve; maximum number of tries to find a suitable word
|
n = 50 # safety valve; maximum number of tries to find a suitable word
|
||||||
while n:
|
while n:
|
||||||
index = int(random.random()*len(self.words))
|
index = int(random.random()*len(self.words))
|
||||||
m = reg.search(self.words[index:])
|
m = reg.search(self.words[index:])
|
||||||
if m and len(m.groups()[0]) >= self.min_length: break
|
if m and len(m.groups()[0]) >= self.min_length: break
|
||||||
n = n - 1
|
n = n - 1
|
||||||
if n: return string.lower(m.groups()[0])
|
if n: return string.lower(m.groups()[0])
|
||||||
return "error"
|
return "error"
|
||||||
builtin_words = ' albatros banana electrometer eggshell'
|
builtin_words = ' albatros banana electrometer eggshell'
|
||||||
|
|
||||||
def stdprint(x):
|
def stdprint(x):
|
||||||
@@ -50,47 +50,47 @@ def stdprint(x):
|
|||||||
|
|
||||||
class URLWordFetcher(WordFetcher):
|
class URLWordFetcher(WordFetcher):
|
||||||
def __init__(self, url):
|
def __init__(self, url):
|
||||||
self.OpenURL(url)
|
self.OpenURL(url)
|
||||||
WordFetcher.__init__(self, "hangman_dict.txt")
|
WordFetcher.__init__(self, "hangman_dict.txt")
|
||||||
def logprint(self,x):
|
def logprint(self,x):
|
||||||
print x
|
print x
|
||||||
def RetrieveAsFile(self, host, path=''):
|
def RetrieveAsFile(self, host, path=''):
|
||||||
from httplib import HTTP
|
from httplib import HTTP
|
||||||
try:
|
try:
|
||||||
h = HTTP(host)
|
h = HTTP(host)
|
||||||
except:
|
except:
|
||||||
self.logprint("Failed to create HTTP connection to %s... is the network available?" % (host))
|
self.logprint("Failed to create HTTP connection to %s... is the network available?" % (host))
|
||||||
return None
|
return None
|
||||||
h.putrequest('GET',path)
|
h.putrequest('GET',path)
|
||||||
h.putheader('Accept','text/html')
|
h.putheader('Accept','text/html')
|
||||||
h.putheader('Accept','text/plain')
|
h.putheader('Accept','text/plain')
|
||||||
h.endheaders()
|
h.endheaders()
|
||||||
errcode, errmsg, headers = h.getreply()
|
errcode, errmsg, headers = h.getreply()
|
||||||
if errcode != 200:
|
if errcode != 200:
|
||||||
self.logprint("HTTP error code %d: %s" % (errcode, errmsg))
|
self.logprint("HTTP error code %d: %s" % (errcode, errmsg))
|
||||||
return None
|
return None
|
||||||
f = h.getfile()
|
f = h.getfile()
|
||||||
return f
|
return f
|
||||||
def OpenURL(self,url):
|
def OpenURL(self,url):
|
||||||
from htmllib import HTMLParser
|
from htmllib import HTMLParser
|
||||||
import formatter
|
import formatter
|
||||||
self.url = url
|
self.url = url
|
||||||
m = re.match('http://([^/]+)(/\S*)\s*', url)
|
m = re.match('http://([^/]+)(/\S*)\s*', url)
|
||||||
if m:
|
if m:
|
||||||
host = m.groups()[0]
|
host = m.groups()[0]
|
||||||
path = m.groups()[1]
|
path = m.groups()[1]
|
||||||
else:
|
else:
|
||||||
m = re.match('http://(\S+)\s*', url)
|
m = re.match('http://(\S+)\s*', url)
|
||||||
if not m:
|
if not m:
|
||||||
# Invalid URL
|
# Invalid URL
|
||||||
self.logprint("Invalid or unsupported URL: %s" % (url))
|
self.logprint("Invalid or unsupported URL: %s" % (url))
|
||||||
return
|
return
|
||||||
host = m.groups()[0]
|
host = m.groups()[0]
|
||||||
path = ''
|
path = ''
|
||||||
f = self.RetrieveAsFile(host,path)
|
f = self.RetrieveAsFile(host,path)
|
||||||
if not f:
|
if not f:
|
||||||
self.logprint("Could not open %s" % (url))
|
self.logprint("Could not open %s" % (url))
|
||||||
return
|
return
|
||||||
self.logprint("Receiving data...")
|
self.logprint("Receiving data...")
|
||||||
data = f.read()
|
data = f.read()
|
||||||
tmp = open('hangman_dict.txt','w')
|
tmp = open('hangman_dict.txt','w')
|
||||||
@@ -103,287 +103,287 @@ class URLWordFetcher(WordFetcher):
|
|||||||
|
|
||||||
class HangmanWnd(wxWindow):
|
class HangmanWnd(wxWindow):
|
||||||
def __init__(self, parent, id, pos=wxDefaultPosition, size=wxDefaultSize):
|
def __init__(self, parent, id, pos=wxDefaultPosition, size=wxDefaultSize):
|
||||||
wxWindow.__init__(self, parent, id, pos, size)
|
wxWindow.__init__(self, parent, id, pos, size)
|
||||||
self.SetBackgroundColour(wxNamedColour('white'))
|
self.SetBackgroundColour(wxNamedColour('white'))
|
||||||
if wxPlatform == '__WXGTK__':
|
if wxPlatform == '__WXGTK__':
|
||||||
self.font = wxFont(12, wxMODERN, wxNORMAL, wxNORMAL)
|
self.font = wxFont(12, wxMODERN, wxNORMAL, wxNORMAL)
|
||||||
else:
|
else:
|
||||||
self.font = wxFont(10, wxMODERN, wxNORMAL, wxNORMAL)
|
self.font = wxFont(10, wxMODERN, wxNORMAL, wxNORMAL)
|
||||||
self.SetFocus()
|
self.SetFocus()
|
||||||
def StartGame(self, word):
|
def StartGame(self, word):
|
||||||
self.word = word
|
self.word = word
|
||||||
self.guess = []
|
self.guess = []
|
||||||
self.tries = 0
|
self.tries = 0
|
||||||
self.misses = 0
|
self.misses = 0
|
||||||
self.Draw()
|
self.Draw()
|
||||||
def EndGame(self):
|
def EndGame(self):
|
||||||
self.misses = 7;
|
self.misses = 7;
|
||||||
self.guess = map(chr, range(ord('a'),ord('z')+1))
|
self.guess = map(chr, range(ord('a'),ord('z')+1))
|
||||||
self.Draw()
|
self.Draw()
|
||||||
def HandleKey(self, key):
|
def HandleKey(self, key):
|
||||||
self.message = ""
|
self.message = ""
|
||||||
if self.guess.count(key):
|
if self.guess.count(key):
|
||||||
self.message = 'Already guessed %s' % (key,)
|
self.message = 'Already guessed %s' % (key,)
|
||||||
return 0
|
return 0
|
||||||
self.guess.append(key)
|
self.guess.append(key)
|
||||||
self.guess.sort()
|
self.guess.sort()
|
||||||
self.tries = self.tries+1
|
self.tries = self.tries+1
|
||||||
if not key in self.word:
|
if not key in self.word:
|
||||||
self.misses = self.misses+1
|
self.misses = self.misses+1
|
||||||
if self.misses == 7:
|
if self.misses == 7:
|
||||||
self.EndGame()
|
self.EndGame()
|
||||||
return 1
|
return 1
|
||||||
has_won = 1
|
has_won = 1
|
||||||
for letter in self.word:
|
for letter in self.word:
|
||||||
if not self.guess.count(letter):
|
if not self.guess.count(letter):
|
||||||
has_won = 0
|
has_won = 0
|
||||||
break
|
break
|
||||||
if has_won:
|
if has_won:
|
||||||
self.Draw()
|
self.Draw()
|
||||||
return 2
|
return 2
|
||||||
self.Draw()
|
self.Draw()
|
||||||
return 0
|
return 0
|
||||||
def Draw(self, dc = None):
|
def Draw(self, dc = None):
|
||||||
if not dc:
|
if not dc:
|
||||||
dc = wxClientDC(self)
|
dc = wxClientDC(self)
|
||||||
dc.SetFont(self.font)
|
dc.SetFont(self.font)
|
||||||
dc.Clear()
|
dc.Clear()
|
||||||
(x,y) = self.GetSizeTuple()
|
(x,y) = self.GetSizeTuple()
|
||||||
x1 = x-200; y1 = 20
|
x1 = x-200; y1 = 20
|
||||||
for letter in self.word:
|
for letter in self.word:
|
||||||
if self.guess.count(letter):
|
if self.guess.count(letter):
|
||||||
dc.DrawText(letter, x1, y1)
|
dc.DrawText(letter, x1, y1)
|
||||||
else:
|
else:
|
||||||
dc.DrawText('.', x1, y1)
|
dc.DrawText('.', x1, y1)
|
||||||
x1 = x1 + 10
|
x1 = x1 + 10
|
||||||
x1 = x-200
|
x1 = x-200
|
||||||
dc.DrawText("tries %d misses %d" % (self.tries,self.misses),x1,50)
|
dc.DrawText("tries %d misses %d" % (self.tries,self.misses),x1,50)
|
||||||
guesses = ""
|
guesses = ""
|
||||||
for letter in self.guess:
|
for letter in self.guess:
|
||||||
guesses = guesses + letter
|
guesses = guesses + letter
|
||||||
dc.DrawText("guessed:", x1, 70)
|
dc.DrawText("guessed:", x1, 70)
|
||||||
dc.DrawText(guesses[:13], x1+80, 70)
|
dc.DrawText(guesses[:13], x1+80, 70)
|
||||||
dc.DrawText(guesses[13:], x1+80, 90)
|
dc.DrawText(guesses[13:], x1+80, 90)
|
||||||
dc.SetUserScale(x/1000., y/1000.)
|
dc.SetUserScale(x/1000., y/1000.)
|
||||||
self.DrawVictim(dc)
|
self.DrawVictim(dc)
|
||||||
def DrawVictim(self, dc):
|
def DrawVictim(self, dc):
|
||||||
dc.SetPen(wxPen(wxNamedColour('black'), 20))
|
dc.SetPen(wxPen(wxNamedColour('black'), 20))
|
||||||
dc.DrawLines([(10, 980), (10,900), (700,900), (700,940), (720,940),
|
dc.DrawLines([(10, 980), (10,900), (700,900), (700,940), (720,940),
|
||||||
(720,980), (900,980)])
|
(720,980), (900,980)])
|
||||||
dc.DrawLines([(100,900), (100, 100), (300,100)])
|
dc.DrawLines([(100,900), (100, 100), (300,100)])
|
||||||
dc.DrawLine(100,200,200,100)
|
dc.DrawLine(100,200,200,100)
|
||||||
if ( self.misses == 0 ): return
|
if ( self.misses == 0 ): return
|
||||||
dc.SetPen(wxPen(wxNamedColour('blue'), 10))
|
dc.SetPen(wxPen(wxNamedColour('blue'), 10))
|
||||||
dc.DrawLine(300,100,300,200)
|
dc.DrawLine(300,100,300,200)
|
||||||
if ( self.misses == 1 ): return
|
if ( self.misses == 1 ): return
|
||||||
dc.DrawEllipse(250,200,100,100)
|
dc.DrawEllipse(250,200,100,100)
|
||||||
if ( self.misses == 2 ): return
|
if ( self.misses == 2 ): return
|
||||||
dc.DrawLine(300,300,300,600)
|
dc.DrawLine(300,300,300,600)
|
||||||
if ( self.misses == 3) : return
|
if ( self.misses == 3) : return
|
||||||
dc.DrawLine(300,300,250,550)
|
dc.DrawLine(300,300,250,550)
|
||||||
if ( self.misses == 4) : return
|
if ( self.misses == 4) : return
|
||||||
dc.DrawLine(300,300,350,550)
|
dc.DrawLine(300,300,350,550)
|
||||||
if ( self.misses == 5) : return
|
if ( self.misses == 5) : return
|
||||||
dc.DrawLine(300,600,350,850)
|
dc.DrawLine(300,600,350,850)
|
||||||
if ( self.misses == 6) : return
|
if ( self.misses == 6) : return
|
||||||
dc.DrawLine(300,600,250,850)
|
dc.DrawLine(300,600,250,850)
|
||||||
def OnPaint(self, event):
|
def OnPaint(self, event):
|
||||||
dc = wxPaintDC(self)
|
dc = wxPaintDC(self)
|
||||||
self.Draw(dc)
|
self.Draw(dc)
|
||||||
|
|
||||||
class HangmanDemo(HangmanWnd):
|
class HangmanDemo(HangmanWnd):
|
||||||
def __init__(self, wf, parent, id, pos, size):
|
def __init__(self, wf, parent, id, pos, size):
|
||||||
HangmanWnd.__init__(self, parent, id, pos, size)
|
HangmanWnd.__init__(self, parent, id, pos, size)
|
||||||
self.StartGame("dummy")
|
self.StartGame("dummy")
|
||||||
self.start_new = 1
|
self.start_new = 1
|
||||||
self.wf = wf
|
self.wf = wf
|
||||||
self.delay = 500
|
self.delay = 500
|
||||||
self.timer = self.PlayTimer(self.MakeMove)
|
self.timer = self.PlayTimer(self.MakeMove)
|
||||||
def MakeMove(self):
|
def MakeMove(self):
|
||||||
self.timer.Stop()
|
self.timer.Stop()
|
||||||
if self.start_new:
|
if self.start_new:
|
||||||
self.StartGame(self.wf.Get())
|
self.StartGame(self.wf.Get())
|
||||||
self.start_new = 0
|
self.start_new = 0
|
||||||
self.left = list('aaaabcdeeeeefghiiiiijklmnnnoooopqrssssttttuuuuvwxyz')
|
self.left = list('aaaabcdeeeeefghiiiiijklmnnnoooopqrssssttttuuuuvwxyz')
|
||||||
else:
|
else:
|
||||||
key = self.left[int(random.random()*len(self.left))]
|
key = self.left[int(random.random()*len(self.left))]
|
||||||
while self.left.count(key): self.left.remove(key)
|
while self.left.count(key): self.left.remove(key)
|
||||||
self.start_new = self.HandleKey(key)
|
self.start_new = self.HandleKey(key)
|
||||||
self.timer.Start(self.delay)
|
self.timer.Start(self.delay)
|
||||||
def Stop(self):
|
def Stop(self):
|
||||||
self.timer.Stop()
|
self.timer.Stop()
|
||||||
class PlayTimer(wxTimer):
|
class PlayTimer(wxTimer):
|
||||||
def __init__(self,func):
|
def __init__(self,func):
|
||||||
wxTimer.__init__(self)
|
wxTimer.__init__(self)
|
||||||
self.func = func
|
self.func = func
|
||||||
self.Start(1000)
|
self.Start(1000)
|
||||||
def Notify(self):
|
def Notify(self):
|
||||||
apply(self.func, ())
|
apply(self.func, ())
|
||||||
|
|
||||||
class HangmanDemoFrame(wxFrame):
|
class HangmanDemoFrame(wxFrame):
|
||||||
def __init__(self, wf, parent, id, pos, size):
|
def __init__(self, wf, parent, id, pos, size):
|
||||||
wxFrame.__init__(self, parent, id, "Hangman demo", pos, size)
|
wxFrame.__init__(self, parent, id, "Hangman demo", pos, size)
|
||||||
self.demo = HangmanDemo(wf, self, -1, wxDefaultPosition, wxDefaultSize)
|
self.demo = HangmanDemo(wf, self, -1, wxDefaultPosition, wxDefaultSize)
|
||||||
def OnCloseWindow(self, event):
|
def OnCloseWindow(self, event):
|
||||||
self.demo.timer.Stop()
|
self.demo.timer.Stop()
|
||||||
self.Destroy()
|
self.Destroy()
|
||||||
|
|
||||||
class AboutBox(wxDialog):
|
class AboutBox(wxDialog):
|
||||||
def __init__(self, parent,wf):
|
def __init__(self, parent,wf):
|
||||||
wxDialog.__init__(self, parent, -1, "About Hangman", wxDefaultPosition, wxSize(350,450))
|
wxDialog.__init__(self, parent, -1, "About Hangman", wxDefaultPosition, wxSize(350,450))
|
||||||
self.wnd = HangmanDemo(wf, self, -1, wxPoint(1,1), wxSize(350,150))
|
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.static = wxStaticText(self, -1, __doc__, wxPoint(1,160), wxSize(350, 250))
|
||||||
self.button = wxButton(self, 2001, "OK", wxPoint(150,420), wxSize(50,-1))
|
self.button = wxButton(self, 2001, "OK", wxPoint(150,420), wxSize(50,-1))
|
||||||
EVT_BUTTON(self, 2001, self.OnOK)
|
EVT_BUTTON(self, 2001, self.OnOK)
|
||||||
def OnOK(self, event):
|
def OnOK(self, event):
|
||||||
self.wnd.Stop()
|
self.wnd.Stop()
|
||||||
self.EndModal(wxID_OK)
|
self.EndModal(wxID_OK)
|
||||||
|
|
||||||
class MyFrame(wxFrame):
|
class MyFrame(wxFrame):
|
||||||
def __init__(self, wf):
|
def __init__(self, wf):
|
||||||
self.wf = wf
|
self.wf = wf
|
||||||
wxFrame.__init__(self, NULL, -1, "hangman", wxDefaultPosition, wxSize(400,300))
|
wxFrame.__init__(self, NULL, -1, "hangman", wxDefaultPosition, wxSize(400,300))
|
||||||
self.wnd = HangmanWnd(self, -1)
|
self.wnd = HangmanWnd(self, -1)
|
||||||
menu = wxMenu()
|
menu = wxMenu()
|
||||||
menu.Append(1001, "New")
|
menu.Append(1001, "New")
|
||||||
menu.Append(1002, "End")
|
menu.Append(1002, "End")
|
||||||
menu.AppendSeparator()
|
menu.AppendSeparator()
|
||||||
menu.Append(1003, "Reset")
|
menu.Append(1003, "Reset")
|
||||||
menu.Append(1004, "Demo...")
|
menu.Append(1004, "Demo...")
|
||||||
menu.AppendSeparator()
|
menu.AppendSeparator()
|
||||||
menu.Append(1005, "Exit")
|
menu.Append(1005, "Exit")
|
||||||
menubar = wxMenuBar()
|
menubar = wxMenuBar()
|
||||||
menubar.Append(menu, "Game")
|
menubar.Append(menu, "Game")
|
||||||
menu = wxMenu()
|
menu = wxMenu()
|
||||||
#menu.Append(1010, "Internal", "Use internal dictionary", TRUE)
|
#menu.Append(1010, "Internal", "Use internal dictionary", TRUE)
|
||||||
menu.Append(1011, "ASCII File...")
|
menu.Append(1011, "ASCII File...")
|
||||||
urls = [ 'wxPython home', 'http://208.240.253.245/wxPython/main.html',
|
urls = [ 'wxPython home', 'http://208.240.253.245/wxPython/main.html',
|
||||||
'slashdot.org', 'http://slashdot.org/',
|
'slashdot.org', 'http://slashdot.org/',
|
||||||
'cnn.com', 'http://cnn.com',
|
'cnn.com', 'http://cnn.com',
|
||||||
'The New York Times', 'http://www.nytimes.com',
|
'The New York Times', 'http://www.nytimes.com',
|
||||||
'De Volkskrant', 'http://www.volkskrant.nl/frameless/25000006.html',
|
'De Volkskrant', 'http://www.volkskrant.nl/frameless/25000006.html',
|
||||||
'Gnu GPL', 'http://www.fsf.org/copyleft/gpl.html',
|
'Gnu GPL', 'http://www.fsf.org/copyleft/gpl.html',
|
||||||
'Bijbel: Genesis', 'http://www.coas.com/bijbel/gn1.htm']
|
'Bijbel: Genesis', 'http://www.coas.com/bijbel/gn1.htm']
|
||||||
urlmenu = wxMenu()
|
urlmenu = wxMenu()
|
||||||
for item in range(0,len(urls),2):
|
for item in range(0,len(urls),2):
|
||||||
urlmenu.Append(1020+item/2, urls[item], urls[item+1])
|
urlmenu.Append(1020+item/2, urls[item], urls[item+1])
|
||||||
urlmenu.Append(1080, 'Other...', 'Enter an URL')
|
urlmenu.Append(1080, 'Other...', 'Enter an URL')
|
||||||
menu.AppendMenu(1012, 'URL', urlmenu, 'Use a webpage')
|
menu.AppendMenu(1012, 'URL', urlmenu, 'Use a webpage')
|
||||||
menu.Append(1013, 'Dump', 'Write contents to stdout')
|
menu.Append(1013, 'Dump', 'Write contents to stdout')
|
||||||
menubar.Append(menu, "Dictionary")
|
menubar.Append(menu, "Dictionary")
|
||||||
self.urls = urls
|
self.urls = urls
|
||||||
self.urloffset = 1020
|
self.urloffset = 1020
|
||||||
menu = wxMenu()
|
menu = wxMenu()
|
||||||
menu.Append(1090, "About...")
|
menu.Append(1090, "About...")
|
||||||
menubar.Append(menu, "Help")
|
menubar.Append(menu, "Help")
|
||||||
self.SetMenuBar(menubar)
|
self.SetMenuBar(menubar)
|
||||||
self.CreateStatusBar(2)
|
self.CreateStatusBar(2)
|
||||||
EVT_MENU(self, 1001, self.OnGameNew)
|
EVT_MENU(self, 1001, self.OnGameNew)
|
||||||
EVT_MENU(self, 1002, self.OnGameEnd)
|
EVT_MENU(self, 1002, self.OnGameEnd)
|
||||||
EVT_MENU(self, 1003, self.OnGameReset)
|
EVT_MENU(self, 1003, self.OnGameReset)
|
||||||
EVT_MENU(self, 1004, self.OnGameDemo)
|
EVT_MENU(self, 1004, self.OnGameDemo)
|
||||||
EVT_MENU(self, 1005, self.OnWindowClose)
|
EVT_MENU(self, 1005, self.OnWindowClose)
|
||||||
EVT_MENU(self, 1011, self.OnDictFile)
|
EVT_MENU(self, 1011, self.OnDictFile)
|
||||||
EVT_MENU_RANGE(self, 1020, 1020+len(urls)/2, self.OnDictURL)
|
EVT_MENU_RANGE(self, 1020, 1020+len(urls)/2, self.OnDictURL)
|
||||||
EVT_MENU(self, 1080, self.OnDictURLSel)
|
EVT_MENU(self, 1080, self.OnDictURLSel)
|
||||||
EVT_MENU(self, 1013, self.OnDictDump)
|
EVT_MENU(self, 1013, self.OnDictDump)
|
||||||
EVT_MENU(self, 1090, self.OnHelpAbout)
|
EVT_MENU(self, 1090, self.OnHelpAbout)
|
||||||
EVT_CHAR(self.wnd, self.OnChar)
|
EVT_CHAR(self.wnd, self.OnChar)
|
||||||
self.OnGameReset()
|
self.OnGameReset()
|
||||||
def OnGameNew(self, event):
|
def OnGameNew(self, event):
|
||||||
word = self.wf.Get()
|
word = self.wf.Get()
|
||||||
self.in_progress = 1
|
self.in_progress = 1
|
||||||
self.SetStatusText("",0)
|
self.SetStatusText("",0)
|
||||||
self.wnd.StartGame(word)
|
self.wnd.StartGame(word)
|
||||||
def OnGameEnd(self, event):
|
def OnGameEnd(self, event):
|
||||||
self.UpdateAverages(0)
|
self.UpdateAverages(0)
|
||||||
self.in_progress = 0
|
self.in_progress = 0
|
||||||
self.SetStatusText("",0)
|
self.SetStatusText("",0)
|
||||||
self.wnd.EndGame()
|
self.wnd.EndGame()
|
||||||
def OnGameReset(self, event=None):
|
def OnGameReset(self, event=None):
|
||||||
self.played = 0
|
self.played = 0
|
||||||
self.won = 0
|
self.won = 0
|
||||||
self.history = []
|
self.history = []
|
||||||
self.average = 0.0
|
self.average = 0.0
|
||||||
self.OnGameNew(None)
|
self.OnGameNew(None)
|
||||||
def OnGameDemo(self, event):
|
def OnGameDemo(self, event):
|
||||||
frame = HangmanDemoFrame(self.wf, self, -1, wxDefaultPosition, self.GetSize())
|
frame = HangmanDemoFrame(self.wf, self, -1, wxDefaultPosition, self.GetSize())
|
||||||
frame.Show(TRUE)
|
frame.Show(TRUE)
|
||||||
def OnDictFile(self, event):
|
def OnDictFile(self, event):
|
||||||
fd = wxFileDialog(self)
|
fd = wxFileDialog(self)
|
||||||
if (self.wf.filename):
|
if (self.wf.filename):
|
||||||
fd.SetFilename(self.wf.filename)
|
fd.SetFilename(self.wf.filename)
|
||||||
if fd.ShowModal() == wxID_OK:
|
if fd.ShowModal() == wxID_OK:
|
||||||
file = fd.GetPath()
|
file = fd.GetPath()
|
||||||
self.wf = WordFetcher(file)
|
self.wf = WordFetcher(file)
|
||||||
def OnDictURL(self, event):
|
def OnDictURL(self, event):
|
||||||
item = (event.GetId() - self.urloffset)*2
|
item = (event.GetId() - self.urloffset)*2
|
||||||
print "Trying to open %s at %s" % (self.urls[item], self.urls[item+1])
|
print "Trying to open %s at %s" % (self.urls[item], self.urls[item+1])
|
||||||
self.wf = URLWordFetcher(self.urls[item+1])
|
self.wf = URLWordFetcher(self.urls[item+1])
|
||||||
def OnDictURLSel(self, event):
|
def OnDictURLSel(self, event):
|
||||||
msg = wxTextEntryDialog(self, "Enter the URL of the dictionary document", "Enter URL")
|
msg = wxTextEntryDialog(self, "Enter the URL of the dictionary document", "Enter URL")
|
||||||
if msg.ShowModal() == wxID_OK:
|
if msg.ShowModal() == wxID_OK:
|
||||||
url = msg.GetValue()
|
url = msg.GetValue()
|
||||||
self.wf = URLWordFetcher(url)
|
self.wf = URLWordFetcher(url)
|
||||||
def OnDictDump(self, event):
|
def OnDictDump(self, event):
|
||||||
print self.wf.words
|
print self.wf.words
|
||||||
def OnHelpAbout(self, event):
|
def OnHelpAbout(self, event):
|
||||||
about = AboutBox(self, self.wf)
|
about = AboutBox(self, self.wf)
|
||||||
about.ShowModal()
|
about.ShowModal()
|
||||||
about.wnd.Stop() # that damn timer won't stop!
|
about.wnd.Stop() # that damn timer won't stop!
|
||||||
def UpdateAverages(self, has_won):
|
def UpdateAverages(self, has_won):
|
||||||
if has_won:
|
if has_won:
|
||||||
self.won = self.won + 1
|
self.won = self.won + 1
|
||||||
self.played = self.played+1
|
self.played = self.played+1
|
||||||
self.history.append(self.wnd.misses) # ugly
|
self.history.append(self.wnd.misses) # ugly
|
||||||
total = 0.0
|
total = 0.0
|
||||||
for m in self.history:
|
for m in self.history:
|
||||||
total = total + m
|
total = total + m
|
||||||
self.average = float(total/len(self.history))
|
self.average = float(total/len(self.history))
|
||||||
def OnChar(self, event):
|
def OnChar(self, event):
|
||||||
if not self.in_progress:
|
if not self.in_progress:
|
||||||
self.OnGameNew(None)
|
self.OnGameNew(None)
|
||||||
return
|
return
|
||||||
key = event.KeyCode();
|
key = event.KeyCode();
|
||||||
if key >= ord('A') and key <= ord('Z'):
|
if key >= ord('A') and key <= ord('Z'):
|
||||||
key = key + ord('a') - ord('A')
|
key = key + ord('a') - ord('A')
|
||||||
key = chr(key)
|
key = chr(key)
|
||||||
if key < 'a' or key > 'z':
|
if key < 'a' or key > 'z':
|
||||||
event.Skip()
|
event.Skip()
|
||||||
return
|
return
|
||||||
res = self.wnd.HandleKey(key)
|
res = self.wnd.HandleKey(key)
|
||||||
if res == 0:
|
if res == 0:
|
||||||
self.SetStatusText(self.wnd.message)
|
self.SetStatusText(self.wnd.message)
|
||||||
elif res == 1:
|
elif res == 1:
|
||||||
self.UpdateAverages(0)
|
self.UpdateAverages(0)
|
||||||
self.SetStatusText("Too bad, you're dead!",0)
|
self.SetStatusText("Too bad, you're dead!",0)
|
||||||
self.in_progress = 0
|
self.in_progress = 0
|
||||||
elif res == 2:
|
elif res == 2:
|
||||||
self.in_progress = 0
|
self.in_progress = 0
|
||||||
self.UpdateAverages(1)
|
self.UpdateAverages(1)
|
||||||
self.SetStatusText("Congratulations!",0)
|
self.SetStatusText("Congratulations!",0)
|
||||||
if self.played:
|
if self.played:
|
||||||
percent = (100.*self.won)/self.played
|
percent = (100.*self.won)/self.played
|
||||||
else:
|
else:
|
||||||
percent = 0.0
|
percent = 0.0
|
||||||
self.SetStatusText("p %d, w %d (%g %%), av %g" % (self.played,self.won, percent, self.average),1)
|
self.SetStatusText("p %d, w %d (%g %%), av %g" % (self.played,self.won, percent, self.average),1)
|
||||||
|
|
||||||
def OnWindowClose(self, event):
|
def OnWindowClose(self, event):
|
||||||
self.Destroy()
|
self.Destroy()
|
||||||
|
|
||||||
class MyApp(wxApp):
|
class MyApp(wxApp):
|
||||||
def OnInit(self):
|
def OnInit(self):
|
||||||
if wxPlatform == '__WXGTK__':
|
if wxPlatform == '__WXGTK__':
|
||||||
defaultfile = "/usr/share/games/hangman-words"
|
defaultfile = "/usr/share/games/hangman-words"
|
||||||
elif wxPlatform == '__WXMSW__':
|
elif wxPlatform == '__WXMSW__':
|
||||||
defaultfile = "c:\\windows\\hardware.txt"
|
defaultfile = "c:\\windows\\hardware.txt"
|
||||||
else:
|
else:
|
||||||
defaultfile = ""
|
defaultfile = ""
|
||||||
wf = WordFetcher(defaultfile)
|
wf = WordFetcher(defaultfile)
|
||||||
frame = MyFrame(wf)
|
frame = MyFrame(wf)
|
||||||
self.SetTopWindow(frame)
|
self.SetTopWindow(frame)
|
||||||
frame.Show(TRUE)
|
frame.Show(TRUE)
|
||||||
return TRUE
|
return TRUE
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app = MyApp(0)
|
app = MyApp(0)
|
||||||
|
@@ -35,17 +35,26 @@ class MyFrame(wxFrame):
|
|||||||
wxStaticText(panel, -1, "Size:",
|
wxStaticText(panel, -1, "Size:",
|
||||||
wxDLG_PNT(panel, wxPoint(4, 4)), wxDefaultSize)
|
wxDLG_PNT(panel, wxPoint(4, 4)), wxDefaultSize)
|
||||||
wxStaticText(panel, -1, "Pos:",
|
wxStaticText(panel, -1, "Pos:",
|
||||||
wxDLG_PNT(panel, wxPoint(4, 14)), wxDefaultSize)
|
wxDLG_PNT(panel, wxPoint(4, 18)), wxDefaultSize)
|
||||||
|
wxStaticText(panel, -1, "ScreenPos:",
|
||||||
|
wxDLG_PNT(panel, wxPoint(4, 32)), wxDefaultSize)
|
||||||
self.sizeCtrl = wxTextCtrl(panel, -1, "",
|
self.sizeCtrl = wxTextCtrl(panel, -1, "",
|
||||||
wxDLG_PNT(panel, wxPoint(24, 4)),
|
wxDLG_PNT(panel, wxPoint(36, 4)),
|
||||||
wxDLG_SZE(panel, wxSize(36, -1)),
|
wxDLG_SZE(panel, wxSize(36, -1)),
|
||||||
wxTE_READONLY)
|
wxTE_READONLY)
|
||||||
|
|
||||||
self.posCtrl = wxTextCtrl(panel, -1, "",
|
self.posCtrl = wxTextCtrl(panel, -1, "",
|
||||||
wxDLG_PNT(panel, wxPoint(24, 14)),
|
wxDLG_PNT(panel, wxPoint(36, 18)),
|
||||||
wxDLG_SZE(panel, wxSize(36, -1)),
|
wxDLG_SZE(panel, wxSize(36, -1)),
|
||||||
wxTE_READONLY)
|
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
|
# This method is called automatically when the CLOSE event is
|
||||||
# sent to this window
|
# sent to this window
|
||||||
@@ -59,6 +68,8 @@ class MyFrame(wxFrame):
|
|||||||
def OnSize(self, event):
|
def OnSize(self, event):
|
||||||
size = event.GetSize()
|
size = event.GetSize()
|
||||||
self.sizeCtrl.SetValue("%s, %s" % (size.width, size.height))
|
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,
|
# tell the event system to continue looking for an event handler,
|
||||||
# so the default handler will get called.
|
# so the default handler will get called.
|
||||||
@@ -69,6 +80,8 @@ class MyFrame(wxFrame):
|
|||||||
def OnMove(self, event):
|
def OnMove(self, event):
|
||||||
pos = event.GetPosition()
|
pos = event.GetPosition()
|
||||||
self.posCtrl.SetValue("%s, %s" % (pos.x, pos.y))
|
self.posCtrl.SetValue("%s, %s" % (pos.x, pos.y))
|
||||||
|
p = self.ClientToScreen((0,0))
|
||||||
|
self.sposCtrl.SetValue("%s, %s" % (p.x, p.y))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -18,15 +18,15 @@ use_wxpython = 1
|
|||||||
def DoThread(mesg):
|
def DoThread(mesg):
|
||||||
while 1:
|
while 1:
|
||||||
sleeptime = (random() * 3) + 0.5
|
sleeptime = (random() * 3) + 0.5
|
||||||
print "Hello from %s (%1.3f)" % (mesg, sleeptime)
|
print "Hello from %s (%1.3f)" % (mesg, sleeptime)
|
||||||
time.sleep(sleeptime)
|
time.sleep(sleeptime)
|
||||||
|
|
||||||
# the same, but write it to a textctrl.
|
# the same, but write it to a textctrl.
|
||||||
def DoTextCtrlThread(text, mesg):
|
def DoTextCtrlThread(text, mesg):
|
||||||
while 1:
|
while 1:
|
||||||
sleeptime = (random() * 3) + 0.5
|
sleeptime = (random() * 3) + 0.5
|
||||||
text.WriteText("Hello from %s (%1.3f)\n" % (mesg, sleeptime))
|
text.WriteText("Hello from %s (%1.3f)\n" % (mesg, sleeptime))
|
||||||
time.sleep(sleeptime)
|
time.sleep(sleeptime)
|
||||||
|
|
||||||
# A very simple queue for textctrls.
|
# A very simple queue for textctrls.
|
||||||
# Nice demonstration of the power of OO programming too (at least I think so!)
|
# Nice demonstration of the power of OO programming too (at least I think so!)
|
||||||
@@ -34,41 +34,41 @@ def DoTextCtrlThread(text, mesg):
|
|||||||
# The main (UI) thread must call Flush to force output. (see MyFrame::OnIdle)
|
# The main (UI) thread must call Flush to force output. (see MyFrame::OnIdle)
|
||||||
class wxTextCtrlQueue(wxTextCtrl):
|
class wxTextCtrlQueue(wxTextCtrl):
|
||||||
def __init__(self, parent, id, value, pos, size, flags):
|
def __init__(self, parent, id, value, pos, size, flags):
|
||||||
wxTextCtrl.__init__(self,parent, id, value, pos, size, flags)
|
wxTextCtrl.__init__(self,parent, id, value, pos, size, flags)
|
||||||
self.queue = []
|
self.queue = []
|
||||||
def WriteText(self, value):
|
def WriteText(self, value):
|
||||||
self.queue.append(value)
|
self.queue.append(value)
|
||||||
def Flush(self):
|
def Flush(self):
|
||||||
queue = self.queue
|
queue = self.queue
|
||||||
self.queue = []
|
self.queue = []
|
||||||
for value in queue:
|
for value in queue:
|
||||||
wxTextCtrl.WriteText(self,value)
|
wxTextCtrl.WriteText(self,value)
|
||||||
|
|
||||||
# MyFrame and MyApp are very simple classes to test python threads in
|
# MyFrame and MyApp are very simple classes to test python threads in
|
||||||
# wxPython.
|
# wxPython.
|
||||||
class MyFrame(wxFrame):
|
class MyFrame(wxFrame):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
wxFrame.__init__(self, NULL, -1, "test threads", wxDefaultPosition, wxSize(300,200))
|
wxFrame.__init__(self, NULL, -1, "test threads", wxDefaultPosition, wxSize(300,200))
|
||||||
self.text = wxTextCtrlQueue(self, -1, "thread output\n", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE)
|
self.text = wxTextCtrlQueue(self, -1, "thread output\n", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE)
|
||||||
menu = wxMenu()
|
menu = wxMenu()
|
||||||
menu.Append(1001, "Start thread")
|
menu.Append(1001, "Start thread")
|
||||||
self.cnt = 0;
|
self.cnt = 0;
|
||||||
menubar = wxMenuBar()
|
menubar = wxMenuBar()
|
||||||
menubar.Append(menu, "Action")
|
menubar.Append(menu, "Action")
|
||||||
self.SetMenuBar(menubar)
|
self.SetMenuBar(menubar)
|
||||||
EVT_MENU(self, 1001, self.StartThread)
|
EVT_MENU(self, 1001, self.StartThread)
|
||||||
def StartThread(self, event):
|
def StartThread(self, event):
|
||||||
self.cnt = self.cnt + 1
|
self.cnt = self.cnt + 1
|
||||||
thread.start_new_thread(DoTextCtrlThread, (self.text, "thread %d" % self.cnt))
|
thread.start_new_thread(DoTextCtrlThread, (self.text, "thread %d" % self.cnt))
|
||||||
def OnIdle(self, event):
|
def OnIdle(self, event):
|
||||||
self.text.Flush()
|
self.text.Flush()
|
||||||
|
|
||||||
class MyApp(wxApp):
|
class MyApp(wxApp):
|
||||||
def OnInit(self):
|
def OnInit(self):
|
||||||
frame = MyFrame()
|
frame = MyFrame()
|
||||||
self.SetTopWindow(frame)
|
self.SetTopWindow(frame)
|
||||||
frame.Show(TRUE)
|
frame.Show(TRUE)
|
||||||
return TRUE
|
return TRUE
|
||||||
|
|
||||||
# Start two threads that print a message every second
|
# Start two threads that print a message every second
|
||||||
thread.start_new_thread(DoThread, ("thread A",))
|
thread.start_new_thread(DoThread, ("thread A",))
|
||||||
@@ -80,6 +80,6 @@ if use_wxpython:
|
|||||||
app.MainLoop()
|
app.MainLoop()
|
||||||
else:
|
else:
|
||||||
while 1:
|
while 1:
|
||||||
print "main loop"
|
print "main loop"
|
||||||
time.sleep(4)
|
time.sleep(4)
|
||||||
print 'done!'
|
print 'done!'
|
||||||
|
@@ -5,43 +5,43 @@ from wxPython.wx import *
|
|||||||
## Create a new frame class, derived from the wxPython Frame.
|
## Create a new frame class, derived from the wxPython Frame.
|
||||||
class Dialog(wxDialog):
|
class Dialog(wxDialog):
|
||||||
|
|
||||||
def __init__(self, parent, title):
|
def __init__(self, parent, title):
|
||||||
# First, call the base class' __init__ method to create the frame
|
# First, call the base class' __init__ method to create the frame
|
||||||
wxDialog.__init__( self, parent, -1, title, wxDefaultPosition, wxDefaultSize )
|
wxDialog.__init__( self, parent, -1, title, wxDefaultPosition, wxDefaultSize )
|
||||||
|
|
||||||
wxButton(self, wxID_OK, "OK", (10, 10))
|
wxButton(self, wxID_OK, "OK", (10, 10))
|
||||||
wxButton(self, wxID_CANCEL, "Cancel", (50,50))
|
wxButton(self, wxID_CANCEL, "Cancel", (50,50))
|
||||||
self.Centre( wxBOTH )
|
self.Centre( wxBOTH )
|
||||||
|
|
||||||
|
|
||||||
# This method is called automatically when the CLOSE event is
|
# This method is called automatically when the CLOSE event is
|
||||||
# sent to this window
|
# sent to this window
|
||||||
#def OnCloseWindow(self, event):
|
#def OnCloseWindow(self, event):
|
||||||
# self.Destroy()
|
# self.Destroy()
|
||||||
|
|
||||||
#def OnCloseMe(self, event):
|
#def OnCloseMe(self, event):
|
||||||
#self.Close(true)
|
#self.Close(true)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Every wxWindows application must have a class derived from wxApp
|
# Every wxWindows application must have a class derived from wxApp
|
||||||
class App(wxApp):
|
class App(wxApp):
|
||||||
|
|
||||||
# wxWindows calls this method to initialize the application
|
# wxWindows calls this method to initialize the application
|
||||||
def OnInit(self):
|
def OnInit(self):
|
||||||
|
|
||||||
# Create an instance of our customized Frame class
|
# Create an instance of our customized Frame class
|
||||||
dialog = Dialog( NULL, 'test' )
|
dialog = Dialog( NULL, 'test' )
|
||||||
dialog.ShowModal()
|
dialog.ShowModal()
|
||||||
print "got here"
|
print "got here"
|
||||||
dialog.Destroy()
|
dialog.Destroy()
|
||||||
|
|
||||||
# Tell wxWindows that this is our main window
|
# Tell wxWindows that this is our main window
|
||||||
# Return a success flag
|
# Return a success flag
|
||||||
return true
|
return true
|
||||||
|
|
||||||
app = App(0) # Create an instance of the application class
|
app = App(0) # Create an instance of the application class
|
||||||
app.MainLoop() # Tell it to start processing events
|
app.MainLoop() # Tell it to start processing events
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -7,110 +7,110 @@ from stat import *
|
|||||||
GlobalObjList = []
|
GlobalObjList = []
|
||||||
|
|
||||||
class Obj:
|
class Obj:
|
||||||
def __init__(self, obj):
|
def __init__(self, obj):
|
||||||
self.obj = obj
|
self.obj = obj
|
||||||
# Uncomment next line to eliminate crash.
|
# Uncomment next line to eliminate crash.
|
||||||
# GlobalObjList.append(self)
|
# GlobalObjList.append(self)
|
||||||
|
|
||||||
def Name(self):
|
def Name(self):
|
||||||
head, tail = os.path.split(self.obj)
|
head, tail = os.path.split(self.obj)
|
||||||
if tail:
|
if tail:
|
||||||
return tail
|
return tail
|
||||||
else:
|
else:
|
||||||
return head
|
return head
|
||||||
|
|
||||||
def HasChildren(self):
|
def HasChildren(self):
|
||||||
return os.path.isdir(self.obj)
|
return os.path.isdir(self.obj)
|
||||||
|
|
||||||
def Children(self):
|
def Children(self):
|
||||||
objList = os.listdir(self.obj)
|
objList = os.listdir(self.obj)
|
||||||
objList.sort()
|
objList.sort()
|
||||||
objList = map(lambda obj,parent=self.obj: os.path.join(parent,obj),
|
objList = map(lambda obj,parent=self.obj: os.path.join(parent,obj),
|
||||||
objList)
|
objList)
|
||||||
objectList = map(Obj, objList)
|
objectList = map(Obj, objList)
|
||||||
return objectList
|
return objectList
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.obj
|
return self.obj
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.obj
|
return self.obj
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
print 'del', self.obj
|
print 'del', self.obj
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
class pyTree(wx.wxTreeCtrl):
|
class pyTree(wx.wxTreeCtrl):
|
||||||
|
|
||||||
def __init__(self, parent, id, obj):
|
def __init__(self, parent, id, obj):
|
||||||
wx.wxTreeCtrl.__init__(self, parent, id)
|
wx.wxTreeCtrl.__init__(self, parent, id)
|
||||||
self.root = self.AddRoot(obj.Name(), -1, -1, wx.wxTreeItemData(''))
|
self.root = self.AddRoot(obj.Name(), -1, -1, wx.wxTreeItemData(''))
|
||||||
self.SetPyData(self.root, obj)
|
self.SetPyData(self.root, obj)
|
||||||
if obj.HasChildren():
|
if obj.HasChildren():
|
||||||
self.SetItemHasChildren(self.root, wx.TRUE)
|
self.SetItemHasChildren(self.root, wx.TRUE)
|
||||||
wx.EVT_TREE_ITEM_EXPANDING(self, self.GetId(), self.OnItemExpanding)
|
wx.EVT_TREE_ITEM_EXPANDING(self, self.GetId(), self.OnItemExpanding)
|
||||||
wx.EVT_TREE_ITEM_COLLAPSED(self, self.GetId(), self.OnItemCollapsed)
|
wx.EVT_TREE_ITEM_COLLAPSED(self, self.GetId(), self.OnItemCollapsed)
|
||||||
wx.EVT_TREE_SEL_CHANGED(self, self.GetId(), self.OnSelChanged)
|
wx.EVT_TREE_SEL_CHANGED(self, self.GetId(), self.OnSelChanged)
|
||||||
self.output = None
|
self.output = None
|
||||||
|
|
||||||
def SetOutput(self, output):
|
def SetOutput(self, output):
|
||||||
self.output = output
|
self.output = output
|
||||||
|
|
||||||
def OnItemExpanding(self,event):
|
def OnItemExpanding(self,event):
|
||||||
item = event.GetItem()
|
item = event.GetItem()
|
||||||
obj = self.GetPyData(item)
|
obj = self.GetPyData(item)
|
||||||
children = obj.Children()
|
children = obj.Children()
|
||||||
for child in children:
|
for child in children:
|
||||||
new_item = self.AppendItem(item, child.Name(), -1, -1,
|
new_item = self.AppendItem(item, child.Name(), -1, -1,
|
||||||
wx.wxTreeItemData(''))
|
wx.wxTreeItemData(''))
|
||||||
self.SetPyData(new_item, child)
|
self.SetPyData(new_item, child)
|
||||||
if child.HasChildren():
|
if child.HasChildren():
|
||||||
self.SetItemHasChildren(new_item, wx.TRUE)
|
self.SetItemHasChildren(new_item, wx.TRUE)
|
||||||
|
|
||||||
def OnItemCollapsed(self, event):
|
def OnItemCollapsed(self, event):
|
||||||
item = event.GetItem()
|
item = event.GetItem()
|
||||||
self.DeleteChildren(item)
|
self.DeleteChildren(item)
|
||||||
|
|
||||||
def OnSelChanged(self, event):
|
def OnSelChanged(self, event):
|
||||||
if not self.output:
|
if not self.output:
|
||||||
return
|
return
|
||||||
obj = self.GetPyData( event.GetItem() )
|
obj = self.GetPyData( event.GetItem() )
|
||||||
apply(self.output, (`obj`,))
|
apply(self.output, (`obj`,))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
class MyFrame(wx.wxFrame):
|
class MyFrame(wx.wxFrame):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
wx.wxFrame.__init__(self, wx.NULL, -1, 'PyTreeItemData Test',
|
wx.wxFrame.__init__(self, wx.NULL, -1, 'PyTreeItemData Test',
|
||||||
wx.wxDefaultPosition, wx.wxSize(600,500))
|
wx.wxDefaultPosition, wx.wxSize(600,500))
|
||||||
split = wx.wxSplitterWindow(self, -1)
|
split = wx.wxSplitterWindow(self, -1)
|
||||||
|
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
tree = pyTree(split, -1, Obj('C:\\'))
|
tree = pyTree(split, -1, Obj('C:\\'))
|
||||||
else:
|
else:
|
||||||
tree = pyTree(split, -1, Obj('/'))
|
tree = pyTree(split, -1, Obj('/'))
|
||||||
|
|
||||||
text = wx.wxTextCtrl(split, -1, '', wx.wxDefaultPosition,
|
text = wx.wxTextCtrl(split, -1, '', wx.wxDefaultPosition,
|
||||||
wx.wxDefaultSize, wx.wxTE_MULTILINE)
|
wx.wxDefaultSize, wx.wxTE_MULTILINE)
|
||||||
split.SplitVertically(tree, text, 200)
|
split.SplitVertically(tree, text, 200)
|
||||||
tree.SetOutput(text.SetValue)
|
tree.SetOutput(text.SetValue)
|
||||||
tree.SelectItem(tree.root)
|
tree.SelectItem(tree.root)
|
||||||
|
|
||||||
class MyApp(wx.wxApp):
|
class MyApp(wx.wxApp):
|
||||||
|
|
||||||
def OnInit(self):
|
def OnInit(self):
|
||||||
frame = MyFrame()
|
frame = MyFrame()
|
||||||
frame.Show(wx.TRUE)
|
frame.Show(wx.TRUE)
|
||||||
self.SetTopWindow(frame)
|
self.SetTopWindow(frame)
|
||||||
return wx.TRUE
|
return wx.TRUE
|
||||||
|
|
||||||
app = MyApp(0)
|
app = MyApp(0)
|
||||||
app.MainLoop()
|
app.MainLoop()
|
||||||
|
|
||||||
|
|
||||||
|
@@ -34,8 +34,8 @@ distribution). See the Python site (http://www.python.org) for
|
|||||||
information on downloading source or binaries.""",
|
information on downloading source or binaries.""",
|
||||||
"Numeric not found")
|
"Numeric not found")
|
||||||
if d.ShowModal() == wx.wxID_CANCEL:
|
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 = wx.wxMessageDialog(wx.NULL, "I kid you not! Pressing Cancel won't help you!", "Not a joke", wx.wxOK)
|
||||||
d.ShowModal()
|
d.ShowModal()
|
||||||
import sys
|
import sys
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ class PolyPoints:
|
|||||||
|
|
||||||
def __init__(self, points, attr):
|
def __init__(self, points, attr):
|
||||||
self.points = Numeric.array(points)
|
self.points = Numeric.array(points)
|
||||||
self.scaled = self.points
|
self.scaled = self.points
|
||||||
self.attributes = {}
|
self.attributes = {}
|
||||||
for name, value in self._attributes.items():
|
for name, value in self._attributes.items():
|
||||||
try:
|
try:
|
||||||
@@ -71,11 +71,11 @@ class PolyLine(PolyPoints):
|
|||||||
'width': 1}
|
'width': 1}
|
||||||
|
|
||||||
def draw(self, dc):
|
def draw(self, dc):
|
||||||
color = self.attributes['color']
|
color = self.attributes['color']
|
||||||
width = self.attributes['width']
|
width = self.attributes['width']
|
||||||
arguments = []
|
arguments = []
|
||||||
dc.SetPen(wx.wxPen(wx.wxNamedColour(color), width))
|
dc.SetPen(wx.wxPen(wx.wxNamedColour(color), width))
|
||||||
dc.DrawLines(map(tuple,self.scaled))
|
dc.DrawLines(map(tuple,self.scaled))
|
||||||
|
|
||||||
|
|
||||||
class PolyMarker(PolyPoints):
|
class PolyMarker(PolyPoints):
|
||||||
@@ -93,20 +93,20 @@ class PolyMarker(PolyPoints):
|
|||||||
'marker': 'circle'}
|
'marker': 'circle'}
|
||||||
|
|
||||||
def draw(self, dc):
|
def draw(self, dc):
|
||||||
color = self.attributes['color']
|
color = self.attributes['color']
|
||||||
width = self.attributes['width']
|
width = self.attributes['width']
|
||||||
size = self.attributes['size']
|
size = self.attributes['size']
|
||||||
fillcolor = self.attributes['fillcolor']
|
fillcolor = self.attributes['fillcolor']
|
||||||
fillstyle = self.attributes['fillstyle']
|
fillstyle = self.attributes['fillstyle']
|
||||||
marker = self.attributes['marker']
|
marker = self.attributes['marker']
|
||||||
|
|
||||||
dc.SetPen(wx.wxPen(wx.wxNamedColour(color),width))
|
dc.SetPen(wx.wxPen(wx.wxNamedColour(color),width))
|
||||||
if fillcolor:
|
if fillcolor:
|
||||||
dc.SetBrush(wx.wxBrush(wx.wxNamedColour(fillcolor),fillstyle))
|
dc.SetBrush(wx.wxBrush(wx.wxNamedColour(fillcolor),fillstyle))
|
||||||
else:
|
else:
|
||||||
dc.SetBrush(wx.wxBrush(wx.wxNamedColour('black'), wx.wxTRANSPARENT))
|
dc.SetBrush(wx.wxBrush(wx.wxNamedColour('black'), wx.wxTRANSPARENT))
|
||||||
|
|
||||||
self._drawmarkers(dc, self.scaled, marker, size)
|
self._drawmarkers(dc, self.scaled, marker, size)
|
||||||
|
|
||||||
def _drawmarkers(self, dc, coords, marker,size=1):
|
def _drawmarkers(self, dc, coords, marker,size=1):
|
||||||
f = eval('self._' +marker)
|
f = eval('self._' +marker)
|
||||||
@@ -114,31 +114,31 @@ class PolyMarker(PolyPoints):
|
|||||||
f(dc, xc, yc, size)
|
f(dc, xc, yc, size)
|
||||||
|
|
||||||
def _circle(self, dc, xc, yc, size=1):
|
def _circle(self, dc, xc, yc, size=1):
|
||||||
dc.DrawEllipse(xc-2.5*size,yc-2.5*size,5.*size,5.*size)
|
dc.DrawEllipse(xc-2.5*size,yc-2.5*size,5.*size,5.*size)
|
||||||
|
|
||||||
def _dot(self, dc, xc, yc, size=1):
|
def _dot(self, dc, xc, yc, size=1):
|
||||||
dc.DrawPoint(xc,yc)
|
dc.DrawPoint(xc,yc)
|
||||||
|
|
||||||
def _square(self, dc, xc, yc, size=1):
|
def _square(self, dc, xc, yc, size=1):
|
||||||
dc.DrawRectangle(xc-2.5*size,yc-2.5*size,5.*size,5.*size)
|
dc.DrawRectangle(xc-2.5*size,yc-2.5*size,5.*size,5.*size)
|
||||||
|
|
||||||
def _triangle(self, dc, xc, yc, size=1):
|
def _triangle(self, dc, xc, yc, size=1):
|
||||||
dc.DrawPolygon([(-0.5*size*5,0.2886751*size*5),
|
dc.DrawPolygon([(-0.5*size*5,0.2886751*size*5),
|
||||||
(0.5*size*5,0.2886751*size*5),
|
(0.5*size*5,0.2886751*size*5),
|
||||||
(0.0,-0.577350*size*5)],xc,yc)
|
(0.0,-0.577350*size*5)],xc,yc)
|
||||||
|
|
||||||
def _triangle_down(self, dc, xc, yc, size=1):
|
def _triangle_down(self, dc, xc, yc, size=1):
|
||||||
dc.DrawPolygon([(-0.5*size*5,-0.2886751*size*5),
|
dc.DrawPolygon([(-0.5*size*5,-0.2886751*size*5),
|
||||||
(0.5*size*5,-0.2886751*size*5),
|
(0.5*size*5,-0.2886751*size*5),
|
||||||
(0.0,0.577350*size*5)],xc,yc)
|
(0.0,0.577350*size*5)],xc,yc)
|
||||||
|
|
||||||
def _cross(self, dc, xc, yc, size=1):
|
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)
|
||||||
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):
|
def _plus(self, dc, xc, yc, size=1):
|
||||||
dc.DrawLine(xc-2.5*size,yc,xc+2.5*size,yc)
|
dc.DrawLine(xc-2.5*size,yc,xc+2.5*size,yc)
|
||||||
dc.DrawLine(xc,yc-2.5*size,xc,yc+2.5*size)
|
dc.DrawLine(xc,yc-2.5*size,xc,yc+2.5*size)
|
||||||
|
|
||||||
class PlotGraphics:
|
class PlotGraphics:
|
||||||
|
|
||||||
@@ -146,191 +146,191 @@ class PlotGraphics:
|
|||||||
self.objects = objects
|
self.objects = objects
|
||||||
|
|
||||||
def boundingBox(self):
|
def boundingBox(self):
|
||||||
p1, p2 = self.objects[0].boundingBox()
|
p1, p2 = self.objects[0].boundingBox()
|
||||||
for o in self.objects[1:]:
|
for o in self.objects[1:]:
|
||||||
p1o, p2o = o.boundingBox()
|
p1o, p2o = o.boundingBox()
|
||||||
p1 = Numeric.minimum(p1, p1o)
|
p1 = Numeric.minimum(p1, p1o)
|
||||||
p2 = Numeric.maximum(p2, p2o)
|
p2 = Numeric.maximum(p2, p2o)
|
||||||
return p1, p2
|
return p1, p2
|
||||||
|
|
||||||
def scaleAndShift(self, scale=1, shift=0):
|
def scaleAndShift(self, scale=1, shift=0):
|
||||||
for o in self.objects:
|
for o in self.objects:
|
||||||
o.scaleAndShift(scale, shift)
|
o.scaleAndShift(scale, shift)
|
||||||
|
|
||||||
def draw(self, canvas):
|
def draw(self, canvas):
|
||||||
for o in self.objects:
|
for o in self.objects:
|
||||||
o.draw(canvas)
|
o.draw(canvas)
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.objects)
|
return len(self.objects)
|
||||||
|
|
||||||
def __getitem__(self, item):
|
def __getitem__(self, item):
|
||||||
return self.objects[item]
|
return self.objects[item]
|
||||||
|
|
||||||
|
|
||||||
class PlotCanvas(wx.wxWindow):
|
class PlotCanvas(wx.wxWindow):
|
||||||
|
|
||||||
def __init__(self, parent, id = -1):
|
def __init__(self, parent, id = -1):
|
||||||
wx.wxWindow.__init__(self, parent, id, wx.wxPyDefaultPosition, wx.wxPyDefaultSize)
|
wx.wxWindow.__init__(self, parent, id, wx.wxPyDefaultPosition, wx.wxPyDefaultSize)
|
||||||
self.border = (1,1)
|
self.border = (1,1)
|
||||||
self.SetClientSizeWH(400,400)
|
self.SetClientSizeWH(400,400)
|
||||||
self.SetBackgroundColour(wx.wxNamedColour("white"))
|
self.SetBackgroundColour(wx.wxNamedColour("white"))
|
||||||
|
|
||||||
wx.EVT_SIZE(self,self.reconfigure)
|
wx.EVT_SIZE(self,self.reconfigure)
|
||||||
self._setsize()
|
self._setsize()
|
||||||
self.last_draw = None
|
self.last_draw = None
|
||||||
# self.font = self._testFont(font)
|
# self.font = self._testFont(font)
|
||||||
|
|
||||||
def OnPaint(self, event):
|
def OnPaint(self, event):
|
||||||
pdc = wx.wxPaintDC(self)
|
pdc = wx.wxPaintDC(self)
|
||||||
if self.last_draw is not None:
|
if self.last_draw is not None:
|
||||||
apply(self.draw, self.last_draw + (pdc,))
|
apply(self.draw, self.last_draw + (pdc,))
|
||||||
|
|
||||||
def reconfigure(self, event):
|
def reconfigure(self, event):
|
||||||
(new_width,new_height) = self.GetClientSizeTuple()
|
(new_width,new_height) = self.GetClientSizeTuple()
|
||||||
if new_width == self.width and new_height == self.height:
|
if new_width == self.width and new_height == self.height:
|
||||||
return
|
return
|
||||||
self._setsize()
|
self._setsize()
|
||||||
# self.redraw()
|
# self.redraw()
|
||||||
|
|
||||||
def _testFont(self, font):
|
def _testFont(self, font):
|
||||||
if font is not None:
|
if font is not None:
|
||||||
bg = self.canvas.cget('background')
|
bg = self.canvas.cget('background')
|
||||||
try:
|
try:
|
||||||
item = CanvasText(self.canvas, 0, 0, anchor=NW,
|
item = CanvasText(self.canvas, 0, 0, anchor=NW,
|
||||||
text='0', fill=bg, font=font)
|
text='0', fill=bg, font=font)
|
||||||
self.canvas.delete(item)
|
self.canvas.delete(item)
|
||||||
except TclError:
|
except TclError:
|
||||||
font = None
|
font = None
|
||||||
return font
|
return font
|
||||||
|
|
||||||
def _setsize(self):
|
def _setsize(self):
|
||||||
(self.width,self.height) = self.GetClientSizeTuple();
|
(self.width,self.height) = self.GetClientSizeTuple();
|
||||||
self.plotbox_size = 0.97*Numeric.array([self.width, -self.height])
|
self.plotbox_size = 0.97*Numeric.array([self.width, -self.height])
|
||||||
xo = 0.5*(self.width-self.plotbox_size[0])
|
xo = 0.5*(self.width-self.plotbox_size[0])
|
||||||
yo = self.height-0.5*(self.height+self.plotbox_size[1])
|
yo = self.height-0.5*(self.height+self.plotbox_size[1])
|
||||||
self.plotbox_origin = Numeric.array([xo, yo])
|
self.plotbox_origin = Numeric.array([xo, yo])
|
||||||
|
|
||||||
def draw(self, graphics, xaxis = None, yaxis = None, dc = None):
|
def draw(self, graphics, xaxis = None, yaxis = None, dc = None):
|
||||||
if dc == None: dc = wx.wxClientDC(self)
|
if dc == None: dc = wx.wxClientDC(self)
|
||||||
dc.BeginDrawing()
|
dc.BeginDrawing()
|
||||||
dc.Clear()
|
dc.Clear()
|
||||||
self.last_draw = (graphics, xaxis, yaxis)
|
self.last_draw = (graphics, xaxis, yaxis)
|
||||||
p1, p2 = graphics.boundingBox()
|
p1, p2 = graphics.boundingBox()
|
||||||
xaxis = self._axisInterval(xaxis, p1[0], p2[0])
|
xaxis = self._axisInterval(xaxis, p1[0], p2[0])
|
||||||
yaxis = self._axisInterval(yaxis, p1[1], p2[1])
|
yaxis = self._axisInterval(yaxis, p1[1], p2[1])
|
||||||
text_width = [0., 0.]
|
text_width = [0., 0.]
|
||||||
text_height = [0., 0.]
|
text_height = [0., 0.]
|
||||||
if xaxis is not None:
|
if xaxis is not None:
|
||||||
p1[0] = xaxis[0]
|
p1[0] = xaxis[0]
|
||||||
p2[0] = xaxis[1]
|
p2[0] = xaxis[1]
|
||||||
xticks = self._ticks(xaxis[0], xaxis[1])
|
xticks = self._ticks(xaxis[0], xaxis[1])
|
||||||
bb = dc.GetTextExtent(xticks[0][1])
|
bb = dc.GetTextExtent(xticks[0][1])
|
||||||
text_height[1] = bb[1]
|
text_height[1] = bb[1]
|
||||||
text_width[0] = 0.5*bb[0]
|
text_width[0] = 0.5*bb[0]
|
||||||
bb = dc.GetTextExtent(xticks[-1][1])
|
bb = dc.GetTextExtent(xticks[-1][1])
|
||||||
text_width[1] = 0.5*bb[0]
|
text_width[1] = 0.5*bb[0]
|
||||||
else:
|
else:
|
||||||
xticks = None
|
xticks = None
|
||||||
if yaxis is not None:
|
if yaxis is not None:
|
||||||
p1[1] = yaxis[0]
|
p1[1] = yaxis[0]
|
||||||
p2[1] = yaxis[1]
|
p2[1] = yaxis[1]
|
||||||
yticks = self._ticks(yaxis[0], yaxis[1])
|
yticks = self._ticks(yaxis[0], yaxis[1])
|
||||||
for y in yticks:
|
for y in yticks:
|
||||||
bb = dc.GetTextExtent(y[1])
|
bb = dc.GetTextExtent(y[1])
|
||||||
text_width[0] = max(text_width[0],bb[0])
|
text_width[0] = max(text_width[0],bb[0])
|
||||||
h = 0.5*bb[1]
|
h = 0.5*bb[1]
|
||||||
text_height[0] = h
|
text_height[0] = h
|
||||||
text_height[1] = max(text_height[1], h)
|
text_height[1] = max(text_height[1], h)
|
||||||
else:
|
else:
|
||||||
yticks = None
|
yticks = None
|
||||||
text1 = Numeric.array([text_width[0], -text_height[1]])
|
text1 = Numeric.array([text_width[0], -text_height[1]])
|
||||||
text2 = Numeric.array([text_width[1], -text_height[0]])
|
text2 = Numeric.array([text_width[1], -text_height[0]])
|
||||||
scale = (self.plotbox_size-text1-text2) / (p2-p1)
|
scale = (self.plotbox_size-text1-text2) / (p2-p1)
|
||||||
shift = -p1*scale + self.plotbox_origin + text1
|
shift = -p1*scale + self.plotbox_origin + text1
|
||||||
self._drawAxes(dc, xaxis, yaxis, p1, p2,
|
self._drawAxes(dc, xaxis, yaxis, p1, p2,
|
||||||
scale, shift, xticks, yticks)
|
scale, shift, xticks, yticks)
|
||||||
graphics.scaleAndShift(scale, shift)
|
graphics.scaleAndShift(scale, shift)
|
||||||
graphics.draw(dc)
|
graphics.draw(dc)
|
||||||
dc.EndDrawing()
|
dc.EndDrawing()
|
||||||
|
|
||||||
def _axisInterval(self, spec, lower, upper):
|
def _axisInterval(self, spec, lower, upper):
|
||||||
if spec is None:
|
if spec is None:
|
||||||
return None
|
return None
|
||||||
if spec == 'minimal':
|
if spec == 'minimal':
|
||||||
if lower == upper:
|
if lower == upper:
|
||||||
return lower-0.5, upper+0.5
|
return lower-0.5, upper+0.5
|
||||||
else:
|
else:
|
||||||
return lower, upper
|
return lower, upper
|
||||||
if spec == 'automatic':
|
if spec == 'automatic':
|
||||||
range = upper-lower
|
range = upper-lower
|
||||||
if range == 0.:
|
if range == 0.:
|
||||||
return lower-0.5, upper+0.5
|
return lower-0.5, upper+0.5
|
||||||
log = Numeric.log10(range)
|
log = Numeric.log10(range)
|
||||||
power = Numeric.floor(log)
|
power = Numeric.floor(log)
|
||||||
fraction = log-power
|
fraction = log-power
|
||||||
if fraction <= 0.05:
|
if fraction <= 0.05:
|
||||||
power = power-1
|
power = power-1
|
||||||
grid = 10.**power
|
grid = 10.**power
|
||||||
lower = lower - lower % grid
|
lower = lower - lower % grid
|
||||||
mod = upper % grid
|
mod = upper % grid
|
||||||
if mod != 0:
|
if mod != 0:
|
||||||
upper = upper - mod + grid
|
upper = upper - mod + grid
|
||||||
return lower, upper
|
return lower, upper
|
||||||
if type(spec) == type(()):
|
if type(spec) == type(()):
|
||||||
lower, upper = spec
|
lower, upper = spec
|
||||||
if lower <= upper:
|
if lower <= upper:
|
||||||
return lower, upper
|
return lower, upper
|
||||||
else:
|
else:
|
||||||
return upper, lower
|
return upper, lower
|
||||||
raise ValueError, str(spec) + ': illegal axis specification'
|
raise ValueError, str(spec) + ': illegal axis specification'
|
||||||
|
|
||||||
def _drawAxes(self, dc, xaxis, yaxis,
|
def _drawAxes(self, dc, xaxis, yaxis,
|
||||||
bb1, bb2, scale, shift, xticks, yticks):
|
bb1, bb2, scale, shift, xticks, yticks):
|
||||||
dc.SetPen(wx.wxPen(wx.wxNamedColour('BLACK'),1))
|
dc.SetPen(wx.wxPen(wx.wxNamedColour('BLACK'),1))
|
||||||
if xaxis is not None:
|
if xaxis is not None:
|
||||||
lower, upper = xaxis
|
lower, upper = xaxis
|
||||||
text = 1
|
text = 1
|
||||||
for y, d in [(bb1[1], -3), (bb2[1], 3)]:
|
for y, d in [(bb1[1], -3), (bb2[1], 3)]:
|
||||||
p1 = scale*Numeric.array([lower, y])+shift
|
p1 = scale*Numeric.array([lower, y])+shift
|
||||||
p2 = scale*Numeric.array([upper, y])+shift
|
p2 = scale*Numeric.array([upper, y])+shift
|
||||||
dc.DrawLine(p1[0],p1[1],p2[0],p2[1])
|
dc.DrawLine(p1[0],p1[1],p2[0],p2[1])
|
||||||
for x, label in xticks:
|
for x, label in xticks:
|
||||||
p = scale*Numeric.array([x, y])+shift
|
p = scale*Numeric.array([x, y])+shift
|
||||||
dc.DrawLine(p[0],p[1],p[0],p[1]+d)
|
dc.DrawLine(p[0],p[1],p[0],p[1]+d)
|
||||||
if text:
|
if text:
|
||||||
dc.DrawText(label,p[0],p[1])
|
dc.DrawText(label,p[0],p[1])
|
||||||
text = 0
|
text = 0
|
||||||
|
|
||||||
if yaxis is not None:
|
if yaxis is not None:
|
||||||
lower, upper = yaxis
|
lower, upper = yaxis
|
||||||
text = 1
|
text = 1
|
||||||
h = dc.GetCharHeight()
|
h = dc.GetCharHeight()
|
||||||
for x, d in [(bb1[0], -3), (bb2[0], 3)]:
|
for x, d in [(bb1[0], -3), (bb2[0], 3)]:
|
||||||
p1 = scale*Numeric.array([x, lower])+shift
|
p1 = scale*Numeric.array([x, lower])+shift
|
||||||
p2 = scale*Numeric.array([x, upper])+shift
|
p2 = scale*Numeric.array([x, upper])+shift
|
||||||
dc.DrawLine(p1[0],p1[1],p2[0],p2[1])
|
dc.DrawLine(p1[0],p1[1],p2[0],p2[1])
|
||||||
for y, label in yticks:
|
for y, label in yticks:
|
||||||
p = scale*Numeric.array([x, y])+shift
|
p = scale*Numeric.array([x, y])+shift
|
||||||
dc.DrawLine(p[0],p[1],p[0]-d,p[1])
|
dc.DrawLine(p[0],p[1],p[0]-d,p[1])
|
||||||
if text:
|
if text:
|
||||||
dc.DrawText(label,p[0]-dc.GetTextExtent(label)[0],
|
dc.DrawText(label,p[0]-dc.GetTextExtent(label)[0],
|
||||||
p[1]-0.5*h)
|
p[1]-0.5*h)
|
||||||
text = 0
|
text = 0
|
||||||
|
|
||||||
def _ticks(self, lower, upper):
|
def _ticks(self, lower, upper):
|
||||||
ideal = (upper-lower)/7.
|
ideal = (upper-lower)/7.
|
||||||
log = Numeric.log10(ideal)
|
log = Numeric.log10(ideal)
|
||||||
power = Numeric.floor(log)
|
power = Numeric.floor(log)
|
||||||
fraction = log-power
|
fraction = log-power
|
||||||
factor = 1.
|
factor = 1.
|
||||||
error = fraction
|
error = fraction
|
||||||
for f, lf in self._multiples:
|
for f, lf in self._multiples:
|
||||||
e = Numeric.fabs(fraction-lf)
|
e = Numeric.fabs(fraction-lf)
|
||||||
if e < error:
|
if e < error:
|
||||||
error = e
|
error = e
|
||||||
factor = f
|
factor = f
|
||||||
grid = factor * 10.**power
|
grid = factor * 10.**power
|
||||||
if power > 3 or power < -3:
|
if power > 3 or power < -3:
|
||||||
format = '%+7.0e'
|
format = '%+7.0e'
|
||||||
elif power >= 0:
|
elif power >= 0:
|
||||||
@@ -339,18 +339,18 @@ class PlotCanvas(wx.wxWindow):
|
|||||||
else:
|
else:
|
||||||
digits = -int(power)
|
digits = -int(power)
|
||||||
format = '%'+`digits+2`+'.'+`digits`+'f'
|
format = '%'+`digits+2`+'.'+`digits`+'f'
|
||||||
ticks = []
|
ticks = []
|
||||||
t = -grid*Numeric.floor(-lower/grid)
|
t = -grid*Numeric.floor(-lower/grid)
|
||||||
while t <= upper:
|
while t <= upper:
|
||||||
ticks.append(t, format % (t,))
|
ticks.append(t, format % (t,))
|
||||||
t = t + grid
|
t = t + grid
|
||||||
return ticks
|
return ticks
|
||||||
|
|
||||||
_multiples = [(2., Numeric.log10(2.)), (5., Numeric.log10(5.))]
|
_multiples = [(2., Numeric.log10(2.)), (5., Numeric.log10(5.))]
|
||||||
|
|
||||||
def redraw(self,dc=None):
|
def redraw(self,dc=None):
|
||||||
if self.last_draw is not None:
|
if self.last_draw is not None:
|
||||||
apply(self.draw, self.last_draw + (dc,))
|
apply(self.draw, self.last_draw + (dc,))
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
self.canvas.delete('all')
|
self.canvas.delete('all')
|
||||||
@@ -362,98 +362,98 @@ class PlotCanvas(wx.wxWindow):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
class AppFrame(wx.wxFrame):
|
class AppFrame(wx.wxFrame):
|
||||||
def __init__(self, parent, id, title):
|
def __init__(self, parent, id, title):
|
||||||
wx.wxFrame.__init__(self, parent, id, title,
|
wx.wxFrame.__init__(self, parent, id, title,
|
||||||
wx.wxPyDefaultPosition, wx.wxSize(400, 400))
|
wx.wxPyDefaultPosition, wx.wxSize(400, 400))
|
||||||
|
|
||||||
# Now Create the menu bar and items
|
# Now Create the menu bar and items
|
||||||
self.mainmenu = wx.wxMenuBar()
|
self.mainmenu = wx.wxMenuBar()
|
||||||
|
|
||||||
menu = wx.wxMenu()
|
menu = wx.wxMenu()
|
||||||
menu.Append(200, '&Print...', 'Print the current plot')
|
menu.Append(200, '&Print...', 'Print the current plot')
|
||||||
wx.EVT_MENU(self, 200, self.OnFilePrint)
|
wx.EVT_MENU(self, 200, self.OnFilePrint)
|
||||||
menu.Append(209, 'E&xit', 'Enough of this already!')
|
menu.Append(209, 'E&xit', 'Enough of this already!')
|
||||||
wx.EVT_MENU(self, 209, self.OnFileExit)
|
wx.EVT_MENU(self, 209, self.OnFileExit)
|
||||||
self.mainmenu.Append(menu, '&File')
|
self.mainmenu.Append(menu, '&File')
|
||||||
|
|
||||||
menu = wx.wxMenu()
|
menu = wx.wxMenu()
|
||||||
menu.Append(210, '&Draw', 'Draw plots')
|
menu.Append(210, '&Draw', 'Draw plots')
|
||||||
wx.EVT_MENU(self,210,self.OnPlotDraw)
|
wx.EVT_MENU(self,210,self.OnPlotDraw)
|
||||||
menu.Append(211, '&Redraw', 'Redraw plots')
|
menu.Append(211, '&Redraw', 'Redraw plots')
|
||||||
wx.EVT_MENU(self,211,self.OnPlotRedraw)
|
wx.EVT_MENU(self,211,self.OnPlotRedraw)
|
||||||
menu.Append(212, '&Clear', 'Clear canvas')
|
menu.Append(212, '&Clear', 'Clear canvas')
|
||||||
wx.EVT_MENU(self,212,self.OnPlotClear)
|
wx.EVT_MENU(self,212,self.OnPlotClear)
|
||||||
self.mainmenu.Append(menu, '&Plot')
|
self.mainmenu.Append(menu, '&Plot')
|
||||||
|
|
||||||
menu = wx.wxMenu()
|
menu = wx.wxMenu()
|
||||||
menu.Append(220, '&About', 'About this thing...')
|
menu.Append(220, '&About', 'About this thing...')
|
||||||
wx.EVT_MENU(self, 220, self.OnHelpAbout)
|
wx.EVT_MENU(self, 220, self.OnHelpAbout)
|
||||||
self.mainmenu.Append(menu, '&Help')
|
self.mainmenu.Append(menu, '&Help')
|
||||||
|
|
||||||
self.SetMenuBar(self.mainmenu)
|
self.SetMenuBar(self.mainmenu)
|
||||||
|
|
||||||
# A status bar to tell people what's happening
|
# A status bar to tell people what's happening
|
||||||
self.CreateStatusBar(1)
|
self.CreateStatusBar(1)
|
||||||
|
|
||||||
self.client = PlotCanvas(self)
|
self.client = PlotCanvas(self)
|
||||||
|
|
||||||
def OnFilePrint(self, event):
|
def OnFilePrint(self, event):
|
||||||
d = wx.wxMessageDialog(self,
|
d = wx.wxMessageDialog(self,
|
||||||
"""As of this writing, printing support in wxPython is shaky at best.
|
"""As of this writing, printing support in wxPython is shaky at best.
|
||||||
Are you sure you want to do this?""", "Danger!", wx.wxYES_NO)
|
Are you sure you want to do this?""", "Danger!", wx.wxYES_NO)
|
||||||
if d.ShowModal() == wx.wxID_YES:
|
if d.ShowModal() == wx.wxID_YES:
|
||||||
psdc = wx.wxPostScriptDC("out.ps", wx.TRUE, self)
|
psdc = wx.wxPostScriptDC("out.ps", wx.TRUE, self)
|
||||||
self.client.redraw(psdc)
|
self.client.redraw(psdc)
|
||||||
|
|
||||||
def OnFileExit(self, event):
|
def OnFileExit(self, event):
|
||||||
self.Close()
|
self.Close()
|
||||||
|
|
||||||
def OnPlotDraw(self, event):
|
def OnPlotDraw(self, event):
|
||||||
self.client.draw(InitObjects(),'automatic','automatic');
|
self.client.draw(InitObjects(),'automatic','automatic');
|
||||||
|
|
||||||
def OnPlotRedraw(self,event):
|
def OnPlotRedraw(self,event):
|
||||||
self.client.redraw()
|
self.client.redraw()
|
||||||
|
|
||||||
def OnPlotClear(self,event):
|
def OnPlotClear(self,event):
|
||||||
self.client.last_draw = None
|
self.client.last_draw = None
|
||||||
dc = wx.wxClientDC(self.client)
|
dc = wx.wxClientDC(self.client)
|
||||||
dc.Clear()
|
dc.Clear()
|
||||||
|
|
||||||
def OnHelpAbout(self, event):
|
def OnHelpAbout(self, event):
|
||||||
about = wx.wxMessageDialog(self, __doc__, "About...", wx.wxOK)
|
about = wx.wxMessageDialog(self, __doc__, "About...", wx.wxOK)
|
||||||
about.ShowModal()
|
about.ShowModal()
|
||||||
|
|
||||||
def OnCloseWindow(self, event):
|
def OnCloseWindow(self, event):
|
||||||
self.Destroy()
|
self.Destroy()
|
||||||
|
|
||||||
def InitObjects():
|
def InitObjects():
|
||||||
# 100 points sin function, plotted as green circles
|
# 100 points sin function, plotted as green circles
|
||||||
data1 = 2.*Numeric.pi*Numeric.arange(200)/200.
|
data1 = 2.*Numeric.pi*Numeric.arange(200)/200.
|
||||||
data1.shape = (100, 2)
|
data1.shape = (100, 2)
|
||||||
data1[:,1] = Numeric.sin(data1[:,0])
|
data1[:,1] = Numeric.sin(data1[:,0])
|
||||||
markers1 = PolyMarker(data1, color='green', marker='circle',size=1)
|
markers1 = PolyMarker(data1, color='green', marker='circle',size=1)
|
||||||
|
|
||||||
# 50 points cos function, plotted as red line
|
# 50 points cos function, plotted as red line
|
||||||
data1 = 2.*Numeric.pi*Numeric.arange(100)/100.
|
data1 = 2.*Numeric.pi*Numeric.arange(100)/100.
|
||||||
data1.shape = (50,2)
|
data1.shape = (50,2)
|
||||||
data1[:,1] = Numeric.cos(data1[:,0])
|
data1[:,1] = Numeric.cos(data1[:,0])
|
||||||
lines = PolyLine(data1, color='red')
|
lines = PolyLine(data1, color='red')
|
||||||
|
|
||||||
# A few more points...
|
# A few more points...
|
||||||
pi = Numeric.pi
|
pi = Numeric.pi
|
||||||
markers2 = PolyMarker([(0., 0.), (pi/4., 1.), (pi/2, 0.),
|
markers2 = PolyMarker([(0., 0.), (pi/4., 1.), (pi/2, 0.),
|
||||||
(3.*pi/4., -1)], color='blue',
|
(3.*pi/4., -1)], color='blue',
|
||||||
fillcolor='green', marker='cross')
|
fillcolor='green', marker='cross')
|
||||||
|
|
||||||
return PlotGraphics([markers1, lines, markers2])
|
return PlotGraphics([markers1, lines, markers2])
|
||||||
|
|
||||||
|
|
||||||
class MyApp(wx.wxApp):
|
class MyApp(wx.wxApp):
|
||||||
def OnInit(self):
|
def OnInit(self):
|
||||||
frame = AppFrame(wx.NULL, -1, "wxPlotCanvas")
|
frame = AppFrame(wx.NULL, -1, "wxPlotCanvas")
|
||||||
frame.Show(wx.TRUE)
|
frame.Show(wx.TRUE)
|
||||||
self.SetTopWindow(frame)
|
self.SetTopWindow(frame)
|
||||||
return wx.TRUE
|
return wx.TRUE
|
||||||
|
|
||||||
|
|
||||||
app = MyApp(0)
|
app = MyApp(0)
|
||||||
|
@@ -164,22 +164,22 @@ class AppStatusBar(wxStatusBar):
|
|||||||
# This is a simple timer class to start a function after a short delay;
|
# This is a simple timer class to start a function after a short delay;
|
||||||
class QuickTimer(wxTimer):
|
class QuickTimer(wxTimer):
|
||||||
def __init__(self, func, wait=100):
|
def __init__(self, func, wait=100):
|
||||||
wxTimer.__init__(self)
|
wxTimer.__init__(self)
|
||||||
self.callback = func
|
self.callback = func
|
||||||
self.Start(wait); # wait .1 second (.001 second doesn't work. why?)
|
self.Start(wait); # wait .1 second (.001 second doesn't work. why?)
|
||||||
def Notify(self):
|
def Notify(self):
|
||||||
self.Stop();
|
self.Stop();
|
||||||
apply(self.callback, ());
|
apply(self.callback, ());
|
||||||
|
|
||||||
class AppFrame(wxFrame):
|
class AppFrame(wxFrame):
|
||||||
def __init__(self, parent, id, title):
|
def __init__(self, parent, id, title):
|
||||||
wxFrame.__init__(self, parent, id, title, wxPyDefaultPosition,
|
wxFrame.__init__(self, parent, id, title, wxPyDefaultPosition,
|
||||||
wxSize(650, 250))
|
wxSize(650, 250))
|
||||||
|
|
||||||
# if the window manager closes the window:
|
# if the window manager closes the window:
|
||||||
EVT_CLOSE(self, self.OnCloseWindow);
|
EVT_CLOSE(self, self.OnCloseWindow);
|
||||||
|
|
||||||
# Now Create the menu bar and items
|
# Now Create the menu bar and items
|
||||||
self.mainmenu = wxMenuBar()
|
self.mainmenu = wxMenuBar()
|
||||||
|
|
||||||
menu = wxMenu()
|
menu = wxMenu()
|
||||||
@@ -202,46 +202,46 @@ class AppFrame(wxFrame):
|
|||||||
menu.Append(222, '&Settings...', 'External browser Settings')
|
menu.Append(222, '&Settings...', 'External browser Settings')
|
||||||
EVT_MENU(self, 222, self.OnBrowserSettings)
|
EVT_MENU(self, 222, self.OnBrowserSettings)
|
||||||
self.mainmenu.Append(menu, '&Browser')
|
self.mainmenu.Append(menu, '&Browser')
|
||||||
menu = wxMenu()
|
menu = wxMenu()
|
||||||
menu.Append(230, '&About', 'Some documentation');
|
menu.Append(230, '&About', 'Some documentation');
|
||||||
EVT_MENU(self, 230, self.OnAbout)
|
EVT_MENU(self, 230, self.OnAbout)
|
||||||
self.mainmenu.Append(menu, '&Help')
|
self.mainmenu.Append(menu, '&Help')
|
||||||
|
|
||||||
self.SetMenuBar(self.mainmenu)
|
self.SetMenuBar(self.mainmenu)
|
||||||
|
|
||||||
if wxPlatform == '__WXGTK__':
|
if wxPlatform == '__WXGTK__':
|
||||||
# I like lynx. Also Netscape 4.5 doesn't react to my cmdline opts
|
# I like lynx. Also Netscape 4.5 doesn't react to my cmdline opts
|
||||||
self.BrowserSettings = "xterm -e lynx %s &"
|
self.BrowserSettings = "xterm -e lynx %s &"
|
||||||
elif wxPlatform == '__WXMSW__':
|
elif wxPlatform == '__WXMSW__':
|
||||||
# netscape 4.x likes to hang out here...
|
# netscape 4.x likes to hang out here...
|
||||||
self.BrowserSettings = '\\progra~1\\Netscape\\Communicator\\Program\\netscape.exe %s'
|
self.BrowserSettings = '\\progra~1\\Netscape\\Communicator\\Program\\netscape.exe %s'
|
||||||
else:
|
else:
|
||||||
# a wild guess...
|
# a wild guess...
|
||||||
self.BrowserSettings = 'netscape %s'
|
self.BrowserSettings = 'netscape %s'
|
||||||
|
|
||||||
# A status bar to tell people what's happening
|
# A status bar to tell people what's happening
|
||||||
self.sb = AppStatusBar(self)
|
self.sb = AppStatusBar(self)
|
||||||
self.SetStatusBar(self.sb)
|
self.SetStatusBar(self.sb)
|
||||||
|
|
||||||
self.list = wxListCtrl(self, 1100)
|
self.list = wxListCtrl(self, 1100)
|
||||||
self.list.SetSingleStyle(wxLC_REPORT)
|
self.list.SetSingleStyle(wxLC_REPORT)
|
||||||
self.list.InsertColumn(0, 'Subject')
|
self.list.InsertColumn(0, 'Subject')
|
||||||
self.list.InsertColumn(1, 'Date')
|
self.list.InsertColumn(1, 'Date')
|
||||||
self.list.InsertColumn(2, 'Posted by')
|
self.list.InsertColumn(2, 'Posted by')
|
||||||
self.list.InsertColumn(3, 'Comments')
|
self.list.InsertColumn(3, 'Comments')
|
||||||
self.list.SetColumnWidth(0, 300)
|
self.list.SetColumnWidth(0, 300)
|
||||||
self.list.SetColumnWidth(1, 150)
|
self.list.SetColumnWidth(1, 150)
|
||||||
self.list.SetColumnWidth(2, 100)
|
self.list.SetColumnWidth(2, 100)
|
||||||
self.list.SetColumnWidth(3, 100)
|
self.list.SetColumnWidth(3, 100)
|
||||||
|
|
||||||
EVT_LIST_ITEM_SELECTED(self, 1100, self.OnItemSelected)
|
EVT_LIST_ITEM_SELECTED(self, 1100, self.OnItemSelected)
|
||||||
EVT_LEFT_DCLICK(self.list, self.OnLeftDClick)
|
EVT_LEFT_DCLICK(self.list, self.OnLeftDClick)
|
||||||
|
|
||||||
self.logprint("Connecting to slashdot... Please wait.")
|
self.logprint("Connecting to slashdot... Please wait.")
|
||||||
# wxYield doesn't yet work here. That's why we use a timer
|
# 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
|
# to make sure that we see some GUI stuff before the slashdot
|
||||||
# file is transfered.
|
# file is transfered.
|
||||||
self.timer = QuickTimer(self.DoRefresh, 1000)
|
self.timer = QuickTimer(self.DoRefresh, 1000)
|
||||||
|
|
||||||
def logprint(self, x):
|
def logprint(self, x):
|
||||||
self.sb.logprint(x)
|
self.sb.logprint(x)
|
||||||
@@ -263,12 +263,12 @@ class AppFrame(wxFrame):
|
|||||||
self.list.SetStringItem(i, 3, article[6])
|
self.list.SetStringItem(i, 3, article[6])
|
||||||
self.url.append(article[1])
|
self.url.append(article[1])
|
||||||
i = i + 1
|
i = i + 1
|
||||||
self.logprint("File retrieved OK.")
|
self.logprint("File retrieved OK.")
|
||||||
|
|
||||||
def OnViewRefresh(self, event):
|
def OnViewRefresh(self, event):
|
||||||
self.logprint("Connecting to slashdot... Please wait.");
|
self.logprint("Connecting to slashdot... Please wait.");
|
||||||
wxYield()
|
wxYield()
|
||||||
self.DoRefresh()
|
self.DoRefresh()
|
||||||
|
|
||||||
def DoViewIndex(self):
|
def DoViewIndex(self):
|
||||||
if self.UseInternal:
|
if self.UseInternal:
|
||||||
@@ -278,12 +278,12 @@ class AppFrame(wxFrame):
|
|||||||
else:
|
else:
|
||||||
self.logprint(self.BrowserSettings % ('http://slashdot.org'))
|
self.logprint(self.BrowserSettings % ('http://slashdot.org'))
|
||||||
os.system(self.BrowserSettings % ('http://slashdot.org'))
|
os.system(self.BrowserSettings % ('http://slashdot.org'))
|
||||||
self.logprint("OK")
|
self.logprint("OK")
|
||||||
|
|
||||||
def OnViewIndex(self, event):
|
def OnViewIndex(self, event):
|
||||||
self.logprint("Starting browser... Please wait.")
|
self.logprint("Starting browser... Please wait.")
|
||||||
wxYield()
|
wxYield()
|
||||||
self.DoViewIndex()
|
self.DoViewIndex()
|
||||||
|
|
||||||
def DoViewArticle(self):
|
def DoViewArticle(self):
|
||||||
if self.current<0: return
|
if self.current<0: return
|
||||||
@@ -294,12 +294,12 @@ class AppFrame(wxFrame):
|
|||||||
else:
|
else:
|
||||||
self.logprint(self.BrowserSettings % (url))
|
self.logprint(self.BrowserSettings % (url))
|
||||||
os.system(self.BrowserSettings % (url))
|
os.system(self.BrowserSettings % (url))
|
||||||
self.logprint("OK")
|
self.logprint("OK")
|
||||||
|
|
||||||
def OnViewArticle(self, event):
|
def OnViewArticle(self, event):
|
||||||
self.logprint("Starting browser... Please wait.")
|
self.logprint("Starting browser... Please wait.")
|
||||||
wxYield()
|
wxYield()
|
||||||
self.DoViewArticle()
|
self.DoViewArticle()
|
||||||
|
|
||||||
def OnBrowserInternal(self, event):
|
def OnBrowserInternal(self, event):
|
||||||
if self.mainmenu.Checked(220):
|
if self.mainmenu.Checked(220):
|
||||||
@@ -313,28 +313,28 @@ class AppFrame(wxFrame):
|
|||||||
self.BrowserSettings = dlg.GetValue()
|
self.BrowserSettings = dlg.GetValue()
|
||||||
|
|
||||||
def OnAbout(self, event):
|
def OnAbout(self, event):
|
||||||
dlg = wxMessageDialog(self, __doc__, "wxSlash", wxOK | wxICON_INFORMATION)
|
dlg = wxMessageDialog(self, __doc__, "wxSlash", wxOK | wxICON_INFORMATION)
|
||||||
dlg.ShowModal()
|
dlg.ShowModal()
|
||||||
|
|
||||||
def OnItemSelected(self, event):
|
def OnItemSelected(self, event):
|
||||||
self.current = event.m_itemIndex
|
self.current = event.m_itemIndex
|
||||||
self.logprint("URL: %s" % (self.url[self.current]))
|
self.logprint("URL: %s" % (self.url[self.current]))
|
||||||
|
|
||||||
def OnLeftDClick(self, event):
|
def OnLeftDClick(self, event):
|
||||||
(x,y) = event.Position();
|
(x,y) = event.Position();
|
||||||
# Actually, we should convert x,y to logical coords using
|
# Actually, we should convert x,y to logical coords using
|
||||||
# a dc, but only for a wxScrolledWindow widget.
|
# a dc, but only for a wxScrolledWindow widget.
|
||||||
# Now wxGTK derives wxListCtrl from wxScrolledWindow,
|
# Now wxGTK derives wxListCtrl from wxScrolledWindow,
|
||||||
# and wxMSW from wxControl... So that doesn't work.
|
# and wxMSW from wxControl... So that doesn't work.
|
||||||
#dc = wxClientDC(self.list)
|
#dc = wxClientDC(self.list)
|
||||||
##self.list.PrepareDC(dc)
|
##self.list.PrepareDC(dc)
|
||||||
#x = dc.DeviceToLogicalX( event.GetX() )
|
#x = dc.DeviceToLogicalX( event.GetX() )
|
||||||
#y = dc.DeviceToLogicalY( event.GetY() )
|
#y = dc.DeviceToLogicalY( event.GetY() )
|
||||||
id = self.list.HitTest(wxPoint(x,y))
|
id = self.list.HitTest(wxPoint(x,y))
|
||||||
#print "Double click at %d %d" % (x,y), id
|
#print "Double click at %d %d" % (x,y), id
|
||||||
# Okay, we got a double click. Let's assume it's the current selection
|
# Okay, we got a double click. Let's assume it's the current selection
|
||||||
wxYield()
|
wxYield()
|
||||||
self.OnViewArticle(event)
|
self.OnViewArticle(event)
|
||||||
|
|
||||||
def OnCloseWindow(self, event):
|
def OnCloseWindow(self, event):
|
||||||
self.Destroy()
|
self.Destroy()
|
||||||
|
@@ -11,11 +11,11 @@
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
Month = {2: 'February', 3: 'March', None: 0, 'July': 7, 11:
|
Month = {2: 'February', 3: 'March', None: 0, 'July': 7, 11:
|
||||||
'November', 'December': 12, 'June': 6, 'January': 1, 'September': 9,
|
'November', 'December': 12, 'June': 6, 'January': 1, 'September': 9,
|
||||||
'August': 8, 'March': 3, 'November': 11, 'April': 4, 12: 'December',
|
'August': 8, 'March': 3, 'November': 11, 'April': 4, 12: 'December',
|
||||||
'May': 5, 10: 'October', 9: 'September', 8: 'August', 7: 'July', 6:
|
'May': 5, 10: 'October', 9: 'September', 8: 'August', 7: 'July', 6:
|
||||||
'June', 5: 'May', 4: 'April', 'October': 10, 'February': 2, 1:
|
'June', 5: 'May', 4: 'April', 'October': 10, 'February': 2, 1:
|
||||||
'January', 0: None}
|
'January', 0: None}
|
||||||
|
|
||||||
# Number of days per month (except for February in leap years)
|
# Number of days per month (except for February in leap years)
|
||||||
mdays = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
mdays = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
||||||
|
@@ -126,8 +126,8 @@ class wxGridSizer(wxPySizer):
|
|||||||
|
|
||||||
sz = self.GetSize()
|
sz = self.GetSize()
|
||||||
pt = self.GetPosition()
|
pt = self.GetPosition()
|
||||||
w = (sz.width - (ncols - 1) * self.hgap) / ncols;
|
w = (sz.width - (ncols - 1) * self.hgap) / ncols;
|
||||||
h = (sz.height - (nrows - 1) * self.vgap) / nrows;
|
h = (sz.height - (nrows - 1) * self.vgap) / nrows;
|
||||||
|
|
||||||
x = pt.x
|
x = pt.x
|
||||||
for c in range(ncols):
|
for c in range(ncols):
|
||||||
|
@@ -290,11 +290,11 @@ class FindFiles:
|
|||||||
if pattern.match(value) != None:
|
if pattern.match(value) != None:
|
||||||
filelist.append(i)
|
filelist.append(i)
|
||||||
|
|
||||||
self.files = filelist
|
self.files = filelist
|
||||||
|
|
||||||
def MakeRegex(self, pattern):
|
def MakeRegex(self, pattern):
|
||||||
import re
|
import re
|
||||||
f = "" # Set up a regex for file names
|
f = "" # Set up a regex for file names
|
||||||
for ch in pattern:
|
for ch in pattern:
|
||||||
if ch == "*":
|
if ch == "*":
|
||||||
f = f + ".*"
|
f = f + ".*"
|
||||||
|
@@ -101,7 +101,7 @@ class PrintBase:
|
|||||||
|
|
||||||
cnt = 0
|
cnt = 0
|
||||||
for word in split:
|
for word in split:
|
||||||
bword = " " + word # blank + word
|
bword = " " + word # blank + word
|
||||||
length = len(bword)
|
length = len(bword)
|
||||||
|
|
||||||
w, h = self.DC.GetTextExtent(text + bword)
|
w, h = self.DC.GetTextExtent(text + bword)
|
||||||
|
@@ -248,7 +248,7 @@ class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
|
|||||||
def OnUpdateUI(self, evt):
|
def OnUpdateUI(self, evt):
|
||||||
# check for matching braces
|
# check for matching braces
|
||||||
braceAtCaret = -1
|
braceAtCaret = -1
|
||||||
braceOpposite = -1
|
braceOpposite = -1
|
||||||
charBefore = None
|
charBefore = None
|
||||||
caretPos = self.GetCurrentPos()
|
caretPos = self.GetCurrentPos()
|
||||||
if caretPos > 0:
|
if caretPos > 0:
|
||||||
|
@@ -136,7 +136,7 @@ class wxVTKRenderWindowBase(wxWindow):
|
|||||||
|
|
||||||
|
|
||||||
def OnCreateWindow(self, event):
|
def OnCreateWindow(self, event):
|
||||||
hdl = self.GetHandle()
|
hdl = self.GetHandle()
|
||||||
try:
|
try:
|
||||||
self._RenderWindow.SetParentInfo(str(hdl))
|
self._RenderWindow.SetParentInfo(str(hdl))
|
||||||
except:
|
except:
|
||||||
@@ -163,7 +163,7 @@ class wxVTKRenderWindowBase(wxWindow):
|
|||||||
# Windows.
|
# Windows.
|
||||||
#self._RenderWindow.GetSize()
|
#self._RenderWindow.GetSize()
|
||||||
#
|
#
|
||||||
self._RenderWindow.SetSize(sz.width, sz.height)
|
self._RenderWindow.SetSize(sz.width, sz.height)
|
||||||
|
|
||||||
|
|
||||||
def OnLeftButtonDown(self, event):
|
def OnLeftButtonDown(self, event):
|
||||||
|
@@ -241,27 +241,27 @@ def _my_import(name):
|
|||||||
def _param2dict(param):
|
def _param2dict(param):
|
||||||
i = 0; j = 0; s = len(param); d = {}
|
i = 0; j = 0; s = len(param); d = {}
|
||||||
while 1:
|
while 1:
|
||||||
while i<s and param[i] == " " : i = i+1
|
while i<s and param[i] == " " : i = i+1
|
||||||
if i>=s: break
|
if i>=s: break
|
||||||
j = i
|
j = i
|
||||||
while j<s and param[j] != "=": j=j+1
|
while j<s and param[j] != "=": j=j+1
|
||||||
if j+1>=s:
|
if j+1>=s:
|
||||||
break
|
break
|
||||||
word = param[i:j]
|
word = param[i:j]
|
||||||
i=j+1
|
i=j+1
|
||||||
if (param[i] == '"'):
|
if (param[i] == '"'):
|
||||||
j=i+1
|
j=i+1
|
||||||
while j<s and param[j] != '"' : j=j+1
|
while j<s and param[j] != '"' : j=j+1
|
||||||
if j == s: break
|
if j == s: break
|
||||||
val = param[i+1:j]
|
val = param[i+1:j]
|
||||||
elif (param[i] != " "):
|
elif (param[i] != " "):
|
||||||
j=i+1
|
j=i+1
|
||||||
while j<s and param[j] != " " : j=j+1
|
while j<s and param[j] != " " : j=j+1
|
||||||
val = param[i:j]
|
val = param[i:j]
|
||||||
else:
|
else:
|
||||||
val = ""
|
val = ""
|
||||||
i=j+1
|
i=j+1
|
||||||
d[word] = val
|
d[word] = val
|
||||||
return d
|
return d
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user