API and etc. updates

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25142 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2004-01-13 03:28:11 +00:00
parent 35095c028d
commit 2571247b80
5 changed files with 94 additions and 87 deletions

View File

@@ -38,26 +38,28 @@ class DoodleWindow(wx.Window):
self.thickness = 1
self.SetColour("Black")
self.lines = []
self.x = self.y = 0
self.pos = wx.Point(0,0)
self.MakeMenu()
self.InitBuffer()
self.SetCursor(wx.StockCursor(wx.CURSOR_PENCIL))
# hook some mouse events
wx.EVT_LEFT_DOWN(self, self.OnLeftDown)
wx.EVT_LEFT_UP(self, self.OnLeftUp)
wx.EVT_RIGHT_UP(self, self.OnRightUp)
wx.EVT_MOTION(self, self.OnMotion)
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
self.Bind(wx.EVT_MOTION, self.OnMotion)
# the window resize event and idle events for managing the buffer
wx.EVT_SIZE(self, self.OnSize)
wx.EVT_IDLE(self, self.OnIdle)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.Bind(wx.EVT_IDLE, self.OnIdle)
# and the refresh event
wx.EVT_PAINT(self, self.OnPaint)
self.Bind(wx.EVT_PAINT, self.OnPaint)
# When the window is destroyed, clean up resources.
wx.EVT_WINDOW_DESTROY(self, self.Cleanup)
self.Bind(wx.EVT_WINDOW_DESTROY, self.Cleanup)
def Cleanup(self, evt):
@@ -109,14 +111,15 @@ class DoodleWindow(wx.Window):
for k in keys:
text = self.menuColours[k]
menu.Append(k, text, kind=wx.ITEM_CHECK)
wx.EVT_MENU_RANGE(self, 100, 200, self.OnMenuSetColour)
wx.EVT_UPDATE_UI_RANGE(self, 100, 200, self.OnCheckMenuColours)
self.Bind(wx.EVT_MENU_RANGE, self.OnMenuSetColour, id=100, id2=200)
self.Bind(wx.EVT_UPDATE_UI_RANGE, self.OnCheckMenuColours, id=100, id2=200)
menu.Break()
for x in range(1, self.maxThickness+1):
menu.Append(x, str(x), kind=wx.ITEM_CHECK)
wx.EVT_MENU_RANGE(self, 1, self.maxThickness, self.OnMenuSetThickness)
wx.EVT_UPDATE_UI_RANGE(self, 1, self.maxThickness, self.OnCheckMenuThickness)
self.Bind(wx.EVT_MENU_RANGE, self.OnMenuSetThickness, id=1, id2=self.maxThickness)
self.Bind(wx.EVT_UPDATE_UI_RANGE, self.OnCheckMenuThickness, id=1, id2=self.maxThickness)
self.menu = menu
@@ -141,7 +144,7 @@ class DoodleWindow(wx.Window):
def OnLeftDown(self, event):
"""called when the left mouse button is pressed"""
self.curLine = []
self.x, self.y = event.GetPositionTuple()
self.pos = event.GetPosition()
self.CaptureMouse()
@@ -170,11 +173,11 @@ class DoodleWindow(wx.Window):
dc = wx.BufferedDC(wx.ClientDC(self), self.buffer)
dc.BeginDrawing()
dc.SetPen(self.pen)
pos = event.GetPositionTuple()
coords = (self.x, self.y) + pos
pos = event.GetPosition()
coords = (self.pos, pos)
self.curLine.append(coords)
dc.DrawLine(self.x, self.y, pos[0], pos[1])
self.x, self.y = pos
dc.DrawLine(*coords)
self.pos = pos
dc.EndDrawing()
@@ -218,7 +221,7 @@ class DoodleWindow(wx.Window):
pen = wx.Pen(colour, thickness, wx.SOLID)
dc.SetPen(pen)
for coords in line:
apply(dc.DrawLine, coords)
dc.DrawLine(*coords)
dc.EndDrawing()

View File

@@ -107,12 +107,12 @@ class DoodleFrame(wx.Frame):
menuBar.Append(menu2, "&Help")
self.SetMenuBar(menuBar)
wx.EVT_MENU(self, idOPEN, self.OnMenuOpen)
wx.EVT_MENU(self, idSAVE, self.OnMenuSave)
wx.EVT_MENU(self, idSAVEAS, self.OnMenuSaveAs)
wx.EVT_MENU(self, idCLEAR, self.OnMenuClear)
wx.EVT_MENU(self, idEXIT, self.OnMenuExit)
wx.EVT_MENU(self, idABOUT, self.OnMenuAbout)
self.Bind(wx.EVT_MENU, self.OnMenuOpen, id=idOPEN)
self.Bind(wx.EVT_MENU, self.OnMenuSave, id=idSAVE)
self.Bind(wx.EVT_MENU, self.OnMenuSaveAs, id=idSAVEAS)
self.Bind(wx.EVT_MENU, self.OnMenuClear, id=idCLEAR)
self.Bind(wx.EVT_MENU, self.OnMenuExit, id=idEXIT)
self.Bind(wx.EVT_MENU, self.OnMenuAbout, id=idABOUT)
@@ -202,7 +202,7 @@ class ControlPanel(wx.Panel):
b = buttons.GenBitmapToggleButton(self, k, bmp, size=btnSize )
b.SetBezelWidth(1)
b.SetUseFocusIndicator(False)
wx.EVT_BUTTON(self, k, self.OnSetColour)
self.Bind(wx.EVT_BUTTON, self.OnSetColour, b)
cGrid.Add(b, 0)
self.clrBtns[colours[k]] = b
self.clrBtns[colours[keys[0]]].SetToggle(True)
@@ -217,7 +217,7 @@ class ControlPanel(wx.Panel):
b = buttons.GenToggleButton(self, x, str(x), size=btnSize)
b.SetBezelWidth(1)
b.SetUseFocusIndicator(False)
wx.EVT_BUTTON(self, x, self.OnSetThickness)
self.Bind(wx.EVT_BUTTON, self.OnSetThickness, b)
tGrid.Add(b, 0)
self.thknsBtns[x] = b
self.thknsBtns[1].SetToggle(True)
@@ -297,7 +297,7 @@ class ColourIndicator(wx.Window):
self.SetBackgroundColour(wx.WHITE)
self.SetSize( (-1, 45) )
self.colour = self.thickness = None
wx.EVT_PAINT(self, self.OnPaint)
self.Bind(wx.EVT_PAINT, self.OnPaint)
def Update(self, colour, thickness):
@@ -321,7 +321,7 @@ class ColourIndicator(wx.Window):
pen = wx.Pen(self.colour, self.thickness)
dc.BeginDrawing()
dc.SetPen(pen)
dc.DrawLine(10, sz.height/2, sz.width-10, sz.height/2)
dc.DrawLine((10, sz.height/2), (sz.width-10, sz.height/2))
dc.EndDrawing()

View File

@@ -6,9 +6,13 @@
#
# License: Python
import os, string, re
import os
import re
import string
import sys
from wxPython.wx import *
import wx
from StatusBar import *
from FrogEditor import FrogEditor
@@ -27,23 +31,23 @@ def chomp(line):
##---------------------------------------------------------------------
class OutlinerPanel(wxPanel):
class OutlinerPanel(wx.Panel):
def Close(self, event):
self.parent.Close()
wxPanel.Close(self)
wx.Panel.Close(self)
##----------------------------------------------------------------------
class FrogEditFrame(wxFrame):
def __init__(self, parent, ID, title, pos=wxDefaultPosition,
size=wxDefaultSize, style=wxDEFAULT_FRAME_STYLE):
class FrogEditFrame(wx.Frame):
def __init__(self, parent, ID, title, pos=wx.DefaultPosition,
size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE):
wxFrame.__init__(self, parent, ID, title, pos, size, style)
wx.Frame.__init__(self, parent, ID, title, pos, size, style)
splitter = wxSplitterWindow(self, -1, style=wxNO_3D|wxSP_3D)
win = OutlinerPanel(splitter, -1, style=wxCLIP_CHILDREN)
splitter = wx.SplitterWindow(self, -1, style=wx.NO_3D|wx.SP_3D)
win = OutlinerPanel(splitter, -1, style=wx.CLIP_CHILDREN)
win.parent = self
log = self.MakeLogWindow(splitter)
@@ -61,21 +65,21 @@ class FrogEditFrame(wxFrame):
##------------- Init Misc
def RegisterEventHandlers(self):
EVT_CLOSE(self,self.OnCloseWindow)
self.Bind(wx.EVT_CLOSE,self.OnCloseWindow)
def InitVariables(self):
self.fileName = None
self.edl.UnTouchBuffer()
def MakeMenus(self):
self.MainMenu = wxMenuBar()
self.MainMenu = wx.MenuBar()
self.AddMenus(self.MainMenu)
self.SetMenuBar(self.MainMenu)
##------------- Init Subwindows
def MakeEditorWindow(self, win, log):
self.edl = FrogEditor(win, -1, style=wxSUNKEN_BORDER, statusBar = self.sb)
self.edl = FrogEditor(win, -1, style=wx.SUNKEN_BORDER, statusBar = self.sb)
self.edl.SetControlFuncs = self.SetControlFuncs
self.edl.SetAltFuncs = self.SetAltFuncs
self.edl.SetStatus(log)
@@ -85,10 +89,10 @@ class FrogEditFrame(wxFrame):
self.SetStatusBar(self.sb)
def MakeLogWindow(self, container):
log = wxTextCtrl(container, -1,
style = wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL)
wxLog_SetActiveTarget(wxLogTextCtrl(log))
wxLogMessage('window handle: %s' % self.GetHandle())
log = wx.TextCtrl(container, -1,
style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
wx.Log_SetActiveTarget(wx.LogTextCtrl(log))
wx.LogMessage('window handle: %s' % self.GetHandle())
return log
def SetUpSplitter(self, splitter, win, log):
@@ -97,15 +101,15 @@ class FrogEditFrame(wxFrame):
splitter.SetMinimumPaneSize(40)
def MakeToolbar(self, win):
toolbarBox = wxBoxSizer(wxHORIZONTAL)
toolbarBox = wx.BoxSizer(wx.HORIZONTAL)
self.AddButtons(win, toolbarBox)
return toolbarBox
def MakeMainWindow(self, win):
mainBox = wxBoxSizer(wxVERTICAL)
mainBox = wx.BoxSizer(wx.VERTICAL)
mainBox.Add(self.MakeToolbar(win))
borderWidth = 5
mainBox.Add(self.edl, 1, wxALL|wxGROW, borderWidth)
mainBox.Add(self.edl, 1, wx.ALL|wx.GROW, borderWidth)
win.SetSizer(mainBox)
win.SetAutoLayout(True)
@@ -118,13 +122,13 @@ class FrogEditFrame(wxFrame):
self.AddHelpMenu(menu)
def AddMenuItem(self, menu, itemText, itemDescription, itemHandler):
menuId = wxNewId()
menuId = wx.NewId()
menu.Append(menuId, itemText, itemDescription)
EVT_MENU(self, menuId, itemHandler)
self.Bind(wx.EVT_MENU, itemHandler, id=menuId)
return menuId
def AddFileMenu(self, menu):
fileMenu = wxMenu()
fileMenu = wx.Menu()
self.AddMenuItem(fileMenu, '&New File\tCtrl-N', 'New File', self.OnNewFile)
self.AddMenuItem(fileMenu, '&Open File\tCtrl-O', 'Open File', self.OnOpenFile)
self.AddMenuItem(fileMenu, '&Save File\tCtrl-S', 'Save File', self.OnSaveFile)
@@ -133,7 +137,7 @@ class FrogEditFrame(wxFrame):
menu.Append(fileMenu, 'File')
def AddEditMenu(self, menu):
editMenu = wxMenu()
editMenu = wx.Menu()
self.AddMenuItem(editMenu, 'Cut\tCtrl-X', 'Cut', self.edl.OnCutSelection)
self.AddMenuItem(editMenu, '&Copy\tCtrl-C', 'Copy', self.edl.OnCopySelection)
self.AddMenuItem(editMenu, 'Paste\tCtrl-V', 'Paste', self.edl.OnPaste)
@@ -141,7 +145,7 @@ class FrogEditFrame(wxFrame):
menu.Append(editMenu, 'Edit')
def AddHelpMenu(self, menu):
helpMenu = wxMenu()
helpMenu = wx.Menu()
self.AddMenuItem(helpMenu, 'About', 'About the program', self.OnHelpAbout)
menu.Append(helpMenu, 'Help')
@@ -149,12 +153,12 @@ class FrogEditFrame(wxFrame):
def NewButton(self, window, container, name, pos, size, handler):
buttonId = wxNewId()
buttonId = wx.NewId()
if pos == None or size == None:
container.Add(wxButton(window, buttonId, name), 0, 0)
container.Add(wx.Button(window, buttonId, name), 0, 0)
else:
container.Add(wxButton(window, buttonId, name, pos, size), 0, 0)
EVT_BUTTON(self, buttonId, handler)
container.Add(wx.Button(window, buttonId, name, pos, size), 0, 0)
self.Bind(wx.EVT_BUTTON, handler, id=buttonId)
return buttonId
# override this to make more buttons
@@ -169,15 +173,15 @@ class FrogEditFrame(wxFrame):
##-------------- Init Dialogs
def MessageDialog(self, text, title):
messageDialog = wxMessageDialog(self, text, title, wxOK | wxICON_INFORMATION)
messageDialog = wx.MessageDialog(self, text, title, wx.OK | wx.ICON_INFORMATION)
messageDialog.ShowModal()
messageDialog.Destroy()
def OkCancelDialog(self, text, title):
dialog = wxMessageDialog(self, text, title, wxOK | wxCANCEL | wxICON_INFORMATION)
dialog = wx.MessageDialog(self, text, title, wx.OK | wx.CANCEL | wx.ICON_INFORMATION)
result = dialog.ShowModal()
dialog.Destroy()
if result == wxID_OK:
if result == wx.ID_OK:
return True
else:
return False
@@ -190,21 +194,21 @@ class FrogEditFrame(wxFrame):
if wildCard == None:
wildCard = "*.*"
fileName = None
fileDialog = wxFileDialog(self, "Choose a file", defaultDir, defaultFile, wildCard, wxOPEN|wxMULTIPLE)
fileDialog = wx.FileDialog(self, "Choose a file", defaultDir, defaultFile, wildCard, wx.OPEN|wx.MULTIPLE)
result = fileDialog.ShowModal()
if result == wxID_OK:
if result == wx.ID_OK:
fileName = fileDialog.GetPath()
wxLogMessage('You selected: %s\n' % fileName)
wx.LogMessage('You selected: %s\n' % fileName)
fileDialog.Destroy()
return fileName
def OpenFileError(self, fileName):
wxLogMessage('Open file error.')
wx.LogMessage('Open file error.')
self.MessageDialog("Error opening file '%s'!" % fileName, "Error")
def SaveFileError(self, fileName):
wxLogMessage('Save file error.')
wx.LogMessage('Save file error.')
self.MessageDialog("Error saving file '%s'!" % fileName, "Error")
##---------------- Utility functions
@@ -293,7 +297,7 @@ class FrogEditFrame(wxFrame):
def OnSaveFile(self, event):
if self.fileName is None:
return self.OnSaveFileAs(event)
wxLogMessage("Saving %s..." % self.fileName)
wx.LogMessage("Saving %s..." % self.fileName)
if self.SaveFile(self.fileName) is not True:
self.SaveFileError(self.fileName)
self.edl.SetFocus()
@@ -302,7 +306,7 @@ class FrogEditFrame(wxFrame):
fileName = self.SelectFileDialog(self.GetCurrentDir(),self.GetFileName())
if fileName is not None:
self.fileName = fileName
wxLogMessage("Saving %s..." % self.fileName)
wx.LogMessage("Saving %s..." % self.fileName)
if self.SaveFile(self.fileName) is not True:
self.SaveFileError(self.fileName)
self.edl.SetFocus()
@@ -322,7 +326,7 @@ class FrogEditFrame(wxFrame):
pass
def Show(self, show):
wxFrame.Show(self, show)
wx.Frame.Show(self, show)
self.edl.SetFocus()
##------------- Startup stuff
@@ -341,7 +345,7 @@ class FrogEditLauncher:
def MakeAppFrame(self):
return FrogEditFrame(None, -1, "FrogEdit", size=(640, 480),
style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
def GetArgvFilename(self):
if len(sys.argv) > 1:
@@ -350,7 +354,7 @@ class FrogEditLauncher:
return None
def Main(self):
app = wxPySimpleApp()
app = wx.PySimpleApp()
win = self.MakeAppFrame()
win.Show(True)
win.LoadInitialFile(self.GetArgvFilename())

View File

@@ -6,26 +6,27 @@
# License: Python
import re
from wxPython.wx import *
from wxPython.lib.editor import wxEditor
import wx
from wx.lib.editor import Editor
#---------------------------------------------------------------------
class FrogEditor(wxEditor):
class FrogEditor(Editor):
def __init__(self, parent, id,
pos=wxDefaultPosition, size=wxDefaultSize, style=0, statusBar=None):
pos=wx.DefaultPosition, size=wx.DefaultSize, style=0, statusBar=None):
self.StatusBar = statusBar
wxEditor.__init__(self, parent, id, pos, size, style)
Editor.__init__(self, parent, id, pos, size, style)
self.parent = parent
##------------------------------------
def TouchBuffer(self):
wxEditor.TouchBuffer(self)
Editor.TouchBuffer(self)
self.StatusBar.setDirty(1)
def UnTouchBuffer(self):
wxEditor.UnTouchBuffer(self)
Editor.UnTouchBuffer(self)
self.StatusBar.setDirty(0)
@@ -33,7 +34,7 @@ class FrogEditor(wxEditor):
# override our base class method
def DrawCursor(self, dc = None):
wxEditor.DrawCursor(self,dc)
Editor.DrawCursor(self,dc)
self.StatusBar.setRowCol(self.cy,self.cx)
def lastLine(self):
@@ -67,16 +68,16 @@ class FrogEditor(wxEditor):
self.status.append(data)
if data[-1:] == '\n':
data = data[:-1]
wxLogMessage(data)
wx.LogMessage(data)
#--------- wxEditor keyboard overrides
def SetControlFuncs(self, action):
wxEditor.SetControlFuncs(self, action)
Editor.SetControlFuncs(self, action)
action['-'] = self.PrintSeparator
def SetAltFuncs(self, action):
wxEditor.SetAltFuncs(self, action)
Editor.SetAltFuncs(self, action)
action['x'] = self.Exit
#----------- commands -----------

View File

@@ -1,10 +1,9 @@
from wxPython.wx import *
import os.path
import wx
class CustomStatusBar(wxStatusBar):
class CustomStatusBar(wx.StatusBar):
def __init__(self, parent):
wxStatusBar.__init__(self, parent, -1)
wx.StatusBar.__init__(self, parent, -1)
self.SetFieldsCount(3)
def setFileName(self, fn):