Docview and IDE patch from Morag Hua with fix for bug #1217890

"Closing view crashes Python" plus some new features:

    New feature added to the IDE is 'Extensions'.  Under
    Tools|Options|Extensions, you can add calls to external programs.
    For example you can add a "Notepad" extension (under windows) that
    will exec Notepad on the currently open file.  A new "Notepad"
    menu item will appear under the Tools menu.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34638 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn 2005-06-11 23:18:57 +00:00
parent 94211100ea
commit 2eeaec1909
19 changed files with 1285 additions and 533 deletions

View File

@ -20,11 +20,23 @@ Fixes for bug #1217872, pydocview.DocService not correctly initialized
Fix for bug #1217874, Error in parameter name in DocManager.CreateView
Added wrappers for the wx.RendererNative class.
Added the wx.lib.splitter module, which contains the
MultiSplitterWindow class. This class is much like the standard
wx.SplitterWindow class, except it allows more than one split, so it
can manage more than two child windows.
Docview and IDE patch from Morag Hua with fix for bug #1217890
"Closing view crashes Python" plus some new features::
New feature added to the IDE is 'Extensions'. Under
Tools|Options|Extensions, you can add calls to external programs.
For example you can add a "Notepad" extension (under windows) that
will exec Notepad on the currently open file. A new "Notepad"
menu item will appear under the Tools menu.

View File

@ -122,6 +122,7 @@ class TextEditView(wx.lib.docview.View):
def OnDraw(self, dc):
""" For Print and Print Preview """
pass

View File

@ -86,11 +86,15 @@ class CanvasView(wx.lib.docview.View):
def OnFocus(self, event):
self.SetFocus()
self.FocusColorPropertyShape(True)
event.Skip()
def FocusOnClick(self, event):
self.SetFocus()
event.Skip()
def OnKillFocus(self, event):
self.FocusColorPropertyShape(False)
event.Skip()
@ -129,12 +133,12 @@ class CanvasView(wx.lib.docview.View):
wx.EVT_KEY_DOWN(self._canvas, self.OnKeyPressed)
# need this otherwise mouse clicks don't set focus to this view
wx.EVT_LEFT_DOWN(self._canvas, self.OnFocus)
wx.EVT_LEFT_DCLICK(self._canvas, self.OnFocus)
wx.EVT_RIGHT_DOWN(self._canvas, self.OnFocus)
wx.EVT_RIGHT_DCLICK(self._canvas, self.OnFocus)
wx.EVT_MIDDLE_DOWN(self._canvas, self.OnFocus)
wx.EVT_MIDDLE_DCLICK(self._canvas, self.OnFocus)
wx.EVT_LEFT_DOWN(self._canvas, self.FocusOnClick)
wx.EVT_LEFT_DCLICK(self._canvas, self.FocusOnClick)
wx.EVT_RIGHT_DOWN(self._canvas, self.FocusOnClick)
wx.EVT_RIGHT_DCLICK(self._canvas, self.FocusOnClick)
wx.EVT_MIDDLE_DOWN(self._canvas, self.FocusOnClick)
wx.EVT_MIDDLE_DCLICK(self._canvas, self.FocusOnClick)
wx.EVT_KILL_FOCUS(self._canvas, self.OnKillFocus)
wx.EVT_SET_FOCUS(self._canvas, self.OnFocus)
@ -397,7 +401,7 @@ class CanvasView(wx.lib.docview.View):
shape.SetBrush(brush)
if text:
shape.AddText(text)
shape.SetShadowMode(ogl.SHADOW_RIGHT)
shape.SetShadowMode(ogl.SHADOW_NONE)
self._diagram.AddShape(shape)
shape.Show(True)
if not eventHandler:
@ -417,9 +421,28 @@ class CanvasView(wx.lib.docview.View):
if shape:
shape.Select(False)
for line in shape.GetLines():
shape.RemoveLine(line)
self._diagram.RemoveShape(line)
for obj in self._diagram.GetShapeList():
for line in obj.GetLines():
if self.IsShapeContained(shape, line.GetTo()) or self.IsShapeContained(shape, line.GetFrom()):
obj.RemoveLine(line)
self._diagram.RemoveShape(line)
if line == shape:
obj.RemoveLine(line)
shape.RemoveFromCanvas(self._canvas)
self._diagram.RemoveShape(shape)
if isinstance(shape, ogl.CompositeShape):
shape.RemoveFromCanvas(self._canvas)
def IsShapeContained(self, parent, shape):
if parent == shape:
return True
elif shape.GetParent():
return self.IsShapeContained(parent, shape.GetParent())
return False
def UpdateShape(self, model):

View File

@ -378,7 +378,8 @@ class DebuggerHarness(object):
sys.stdout = output
sys.stderr = output
try:
exec command in frame.f_globals, frame.f_locals
code = compile(command, '<string>', 'single')
exec code in frame.f_globals, frame.f_locals
return output.getvalue()
sys.stdout = out
sys.stderr = err

View File

@ -41,7 +41,7 @@ import pickle
import DebuggerHarness
import traceback
import StringIO
import UICommon
if wx.Platform == '__WXMSW__':
try:
import win32api
@ -132,8 +132,7 @@ import wx.lib.newevent
class Executor:
def GetPythonExecutablePath():
config = wx.ConfigBase_Get()
path = config.Read("ActiveGridPythonLocation")
path = UICommon.GetPythonExecPath()
if path:
return path
wx.MessageBox(_("To proceed I need to know the location of the python.exe you would like to use.\nTo set this, go to Tools-->Options and use the 'Python' tab to enter a value.\n"), _("Python Executable Location Unknown"))
@ -149,24 +148,29 @@ class Executor:
path = Executor.GetPythonExecutablePath()
self._cmd = '"' + path + '" -u \"' + fileName + '\"'
#Better way to do this? Quotes needed for windows file paths.
def spaceAndQuote(text):
if text.startswith("\"") and text.endswith("\""):
return ' ' + text
else:
return ' \"' + text + '\"'
if(arg1 != None):
self._cmd += ' \"' + arg1 + '\"'
self._cmd += spaceAndQuote(arg1)
if(arg2 != None):
self._cmd += ' \"' + arg2 + '\"'
self._cmd += spaceAndQuote(arg2)
if(arg3 != None):
self._cmd += ' \"' + arg3 + '\"'
self._cmd += spaceAndQuote(arg3)
if(arg4 != None):
self._cmd += ' \"' + arg4 + '\"'
self._cmd += spaceAndQuote(arg4)
if(arg5 != None):
self._cmd += ' \"' + arg5 + '\"'
self._cmd += spaceAndQuote(arg5)
if(arg6 != None):
self._cmd += ' \"' + arg6 + '\"'
self._cmd += spaceAndQuote(arg6)
if(arg7 != None):
self._cmd += ' \"' + arg7 + '\"'
self._cmd += spaceAndQuote(arg7)
if(arg8 != None):
self._cmd += ' \"' + arg8 + '\"'
self._cmd += spaceAndQuote(arg8)
if(arg9 != None):
self._cmd += ' \"' + arg9 + '\"'
self._cmd += spaceAndQuote(arg9)
self._stdOutReader = None
self._stdErrReader = None
@ -621,7 +625,7 @@ class DebugCommandUI(wx.Panel):
self._tb.EnableTool(self.BREAK_INTO_DEBUGGER_ID, False)
self._tb.EnableTool(self.KILL_PROCESS_ID, False)
def SynchCurrentLine(self, filename, lineNum):
def SynchCurrentLine(self, filename, lineNum, noArrow=False):
# FACTOR THIS INTO DocManager
self.DeleteCurrentLineMarkers()
@ -651,8 +655,9 @@ class DebugCommandUI(wx.Panel):
foundView.Activate()
foundView.GotoLine(lineNum)
startPos = foundView.PositionFromLine(lineNum)
foundView.GetCtrl().MarkerAdd(lineNum -1, CodeEditor.CodeCtrl.CURRENT_LINE_MARKER_NUM)
if not noArrow:
foundView.GetCtrl().MarkerAdd(lineNum -1, CodeEditor.CodeCtrl.CURRENT_LINE_MARKER_NUM)
def DeleteCurrentLineMarkers(self):
openDocs = wx.GetApp().GetDocumentManager().GetDocuments()
@ -803,7 +808,7 @@ class BreakpointsUI(wx.Panel):
list = self._bpListCtrl
fileName = list.GetItem(self.currentItem, 2).GetText()
lineNumber = list.GetItem(self.currentItem, 1).GetText()
self._ui.SynchCurrentLine( fileName, int(lineNumber) )
self._ui.SynchCurrentLine( fileName, int(lineNumber) , noArrow=True)
def ClearBreakPoint(self, event):
if self.currentItem >= 0:
@ -1810,7 +1815,7 @@ class DebuggerService(Service.Service):
wsService = wx.GetApp().GetService(WebServerService.WebServerService)
fileName, args = wsService.StopAndPrepareToDebug()
try:
page = DebugCommandUI(Service.ServiceView.bottomTab, -1, str(fileName), self)
page = DebugCommandUI(Service.ServiceView.bottomTab, -1, fileName, self)
count = Service.ServiceView.bottomTab.GetPageCount()
Service.ServiceView.bottomTab.AddPage(page, _("Debugging: Internal WebServer"))
Service.ServiceView.bottomTab.SetSelection(count)
@ -2124,7 +2129,7 @@ class CommandPropertiesDialog(wx.Dialog):
flexGridSizer.Add(self._pythonPathEntry, 1, wx.EXPAND)
flexGridSizer.Add(wx.StaticText(parent, -1, ""), 0)
flexGridSizer.Add(wx.StaticText(parent, -1, ""), 0)
if debugging:
if debugging and _WINDOWS:
self._postpendCheckBox = wx.CheckBox(self, -1, postpendStaticText)
checked = bool(config.ReadInt("PythonPathPostpend", 1))
self._postpendCheckBox.SetValue(checked)

View File

@ -0,0 +1,387 @@
#----------------------------------------------------------------------------
# Name: ExtensionService.py
# Purpose: Extension Service for IDE
#
# Author: Peter Yared
#
# Created: 5/23/05
# CVS-ID: $ID:$
# Copyright: (c) 2005 ActiveGrid, Inc.
# License: wxWindows License
#----------------------------------------------------------------------------
import wx
import wx.lib.pydocview
import MessageService
import os
import os.path
import pickle
_ = wx.GetTranslation
SPACE = 10
HALF_SPACE = 5
EXTENSIONS_CONFIG_STRING = "Extensions"
# TODO: Redo extensions menu on OK, or provide alert that it won't happen until restart
#----------------------------------------------------------------------------
# Classes
#----------------------------------------------------------------------------
class Extension:
def __init__(self, menuItemName):
self.menuItemName = menuItemName
self.id = 0
self.menuItemDesc = ''
self.command = ''
self.commandPreArgs = ''
self.commandPostArgs = ''
self.fileExt = None
class ExtensionService(wx.lib.pydocview.DocService):
def __init__(self):
self.LoadExtensions()
def LoadExtensions(self):
config = wx.ConfigBase_Get()
pickledExtensions = config.Read(EXTENSIONS_CONFIG_STRING)
if pickledExtensions:
try:
self._extensions = pickle.loads(pickledExtensions.encode('ascii'))
except:
tp, val, tb = sys.exc_info()
traceback.print_exception(tp,val,tb)
self._extensions = []
else:
self._extensions = []
def SaveExtensions(self):
config = wx.ConfigBase_Get()
config.Write(EXTENSIONS_CONFIG_STRING, pickle.dumps(self._extensions))
def GetExtensions(self):
return self._extensions
def SetExtensions(self, extensions):
self._extensions = extensions
def InstallControls(self, frame, menuBar = None, toolBar = None, statusBar = None, document = None):
toolsMenuIndex = menuBar.FindMenu(_("&Tools"))
if toolsMenuIndex > -1:
toolsMenu = menuBar.GetMenu(toolsMenuIndex)
else:
toolsMenu = wx.Menu()
if self._extensions:
if toolsMenu.GetMenuItems():
toolsMenu.AppendSeparator()
for ext in self._extensions:
# Append a tool menu item for each extension
ext.id = wx.NewId()
toolsMenu.Append(ext.id, ext.menuItemName)
wx.EVT_MENU(frame, ext.id, frame.ProcessEvent)
wx.EVT_UPDATE_UI(frame, ext.id, frame.ProcessUpdateUIEvent)
if toolsMenuIndex == -1:
formatMenuIndex = menuBar.FindMenu(_("&Format"))
menuBar.Insert(formatMenuIndex + 1, toolsMenu, _("&Tools"))
def ProcessEvent(self, event):
id = event.GetId()
for extension in self._extensions:
if id == extension.id:
self.OnExecuteExtension(extension)
return True
return False
def ProcessUpdateUIEvent(self, event):
id = event.GetId()
for extension in self._extensions:
if id == extension.id:
if extension.fileExt:
doc = wx.GetApp().GetDocumentManager().GetCurrentDocument()
if doc and '*' in extension.fileExt:
event.Enable(True)
return True
if doc:
for fileExt in extension.fileExt:
if fileExt in doc.GetDocumentTemplate().GetFileFilter():
event.Enable(True)
return True
event.Enable(False)
return False
return False
def OnExecuteExtension(self, extension):
if extension.fileExt:
doc = wx.GetApp().GetDocumentManager().GetCurrentDocument()
if not doc:
return
filename = doc.GetFilename()
ext = os.path.splitext(filename)[1]
if not '*' in extension.fileExt:
if not ext or ext[1:] not in extension.fileExt:
return
cmds = [extension.command]
if extension.commandPreArgs:
cmds.append(extension.commandPreArgs)
cmds.append(filename)
if extension.commandPostArgs:
cmds.append(extension.commandPostArgs)
os.spawnv(os.P_NOWAIT, extension.command, cmds)
else:
cmd = extension.command
if extension.commandPreArgs:
cmd = cmd + ' ' + extension.commandPreArgs
if extension.commandPostArgs:
cmd = cmd + ' ' + extension.commandPostArgs
f = os.popen(cmd)
messageService = wx.GetApp().GetService(MessageService.MessageService)
messageService.ShowWindow()
view = messageService.GetView()
for line in f.readlines():
view.AddLines(line)
view.GetControl().EnsureCaretVisible()
f.close()
class ExtensionOptionsPanel(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
extOptionsPanelBorderSizer = wx.BoxSizer(wx.HORIZONTAL)
extOptionsPanelSizer = wx.FlexGridSizer(cols=2, hgap=SPACE, vgap=HALF_SPACE)
extCtrlSizer = wx.BoxSizer(wx.VERTICAL)
extCtrlSizer.Add(wx.StaticText(self, -1, _("Extensions:")), 0)
self._extListBox = wx.ListBox(self, -1, size=(-1,185), style=wx.LB_SINGLE)
self.Bind(wx.EVT_LISTBOX, self.OnListBoxSelect, self._extListBox)
extCtrlSizer.Add(self._extListBox, 1, wx.TOP | wx.BOTTOM | wx.EXPAND, SPACE)
buttonSizer = wx.GridSizer(rows=1, hgap=10, vgap=5)
self._moveUpButton = wx.Button(self, -1, _("Move Up"))
self.Bind(wx.EVT_BUTTON, self.OnMoveUp, self._moveUpButton)
buttonSizer.Add(self._moveUpButton, 0)
self._moveDownButton = wx.Button(self, -1, _("Move Down"))
self.Bind(wx.EVT_BUTTON, self.OnMoveDown, self._moveDownButton)
buttonSizer.Add(self._moveDownButton, 0)
extCtrlSizer.Add(buttonSizer, 0, wx.ALIGN_CENTER | wx.BOTTOM, HALF_SPACE)
buttonSizer = wx.GridSizer(rows=1, hgap=10, vgap=5)
self._addButton = wx.Button(self, -1, _("Add"))
self.Bind(wx.EVT_BUTTON, self.OnAdd, self._addButton)
buttonSizer.Add(self._addButton, 0)
self._deleteButton = wx.Button(self, wx.ID_DELETE)
self.Bind(wx.EVT_BUTTON, self.OnDelete, self._deleteButton)
buttonSizer.Add(self._deleteButton, 0)
extCtrlSizer.Add(buttonSizer, 0, wx.ALIGN_CENTER)
extOptionsPanelSizer.Add(extCtrlSizer, 0)
self._extDetailPanel = wx.Panel(self)
staticBox = wx.StaticBox(self._extDetailPanel, label=_("Selected Extension"))
staticBoxSizer = wx.StaticBoxSizer(staticBox)
self._extDetailPanel.SetSizer(staticBoxSizer)
extDetailSizer = wx.FlexGridSizer(cols=1, hgap=5, vgap=3)
staticBoxSizer.AddSizer(extDetailSizer, 0, wx.ALL, 5)
extDetailSizer.Add(wx.StaticText(self._extDetailPanel, -1, _("Menu Item Name:")))
self._menuItemNameTextCtrl = wx.TextCtrl(self._extDetailPanel, -1, size = (-1, -1))
extDetailSizer.Add(self._menuItemNameTextCtrl, 1, wx.EXPAND)
self.Bind(wx.EVT_TEXT, self.SaveCurrentItem, self._menuItemNameTextCtrl)
extDetailSizer.Add(wx.StaticText(self._extDetailPanel, -1, _("Menu Item Description:")))
self._menuItemDescTextCtrl = wx.TextCtrl(self._extDetailPanel, -1, size = (-1, -1))
extDetailSizer.Add(self._menuItemDescTextCtrl, 1, wx.EXPAND)
extDetailSizer.Add(wx.StaticText(self._extDetailPanel, -1, _("Command Path:")))
self._commandTextCtrl = wx.TextCtrl(self._extDetailPanel, -1, size = (-1, -1))
findFileButton = wx.Button(self._extDetailPanel, -1, _("Browse..."))
def OnBrowseButton(event):
fileDlg = wx.FileDialog(self, _("Choose an Executable:"), style=wx.OPEN | wx.HIDE_READONLY)
path = self._commandTextCtrl.GetValue()
if path:
fileDlg.SetPath(path)
if fileDlg.ShowModal() == wx.ID_OK:
self._commandTextCtrl.SetValue(fileDlg.GetPath())
self._commandTextCtrl.SetInsertionPointEnd()
fileDlg.Destroy()
wx.EVT_BUTTON(findFileButton, -1, OnBrowseButton)
hsizer = wx.BoxSizer(wx.HORIZONTAL)
hsizer.Add(self._commandTextCtrl, 1, wx.EXPAND)
hsizer.Add(findFileButton, 0, wx.LEFT, HALF_SPACE)
extDetailSizer.Add(hsizer, 0)
extDetailSizer.Add(wx.StaticText(self._extDetailPanel, -1, _("Command Pre Arguments:")))
self._commandPreArgsTextCtrl = wx.TextCtrl(self._extDetailPanel, -1, size = (-1, -1))
extDetailSizer.Add(self._commandPreArgsTextCtrl, 1, wx.EXPAND)
extDetailSizer.Add(wx.StaticText(self._extDetailPanel, -1, _("Command Post Arguments:")))
self._commandPostArgsTextCtrl = wx.TextCtrl(self._extDetailPanel, -1, size = (-1, -1))
extDetailSizer.Add(self._commandPostArgsTextCtrl, 1, wx.EXPAND)
extDetailSizer.Add(wx.StaticText(self._extDetailPanel, -1, _("File Extensions (Comma Separated):")))
self._fileExtTextCtrl = wx.TextCtrl(self._extDetailPanel, -1, size = (-1, -1))
self._fileExtTextCtrl.SetToolTipString(_("""For example: "txt, text" or "*" for all files"""))
extDetailSizer.Add(self._fileExtTextCtrl, 1, wx.EXPAND)
extOptionsPanelSizer.Add(self._extDetailPanel, 0)
extOptionsPanelBorderSizer.Add(extOptionsPanelSizer, 0, wx.ALL | wx.EXPAND, SPACE)
self.SetSizer(extOptionsPanelBorderSizer)
self.Layout()
parent.AddPage(self, _("Extensions"))
if self.PopulateItems():
self._extListBox.SetSelection(0)
self.OnListBoxSelect(None)
def OnOK(self, optionsDialog):
self.SaveCurrentItem()
extensionsService = wx.GetApp().GetService(ExtensionService)
oldExtensions = extensionsService.GetExtensions()
extensionsService.SetExtensions(self._extensions)
extensionsService.SaveExtensions()
if oldExtensions.__repr__() != self._extensions.__repr__():
msgTitle = wx.GetApp().GetAppName()
if not msgTitle:
msgTitle = _("Document Options")
wx.MessageBox(_("Extension changes will not appear until the application is restarted."),
msgTitle,
wx.OK | wx.ICON_INFORMATION,
self.GetParent())
def PopulateItems(self):
extensionsService = wx.GetApp().GetService(ExtensionService)
import copy
self._extensions = copy.deepcopy(extensionsService.GetExtensions())
for extension in self._extensions:
self._extListBox.Append(extension.menuItemName, extension)
self._currentItem = None
self._currentItemIndex = -1
return len(self._extensions)
def OnListBoxSelect(self, event):
self.SaveCurrentItem()
if not self._extListBox.GetSelections():
self._currentItemIndex = -1
self._currentItem = None
self._deleteButton.Enable(False)
self._moveUpButton.Enable(False)
self._moveDownButton.Enable(False)
else:
self._currentItemIndex = self._extListBox.GetSelection()
self._currentItem = self._extListBox.GetClientData(self._currentItemIndex)
self._deleteButton.Enable()
self._moveUpButton.Enable(self._extListBox.GetCount() > 1 and self._currentItemIndex > 0)
self._moveDownButton.Enable(self._extListBox.GetCount() > 1 and self._currentItemIndex < self._extListBox.GetCount() - 1)
self.LoadItem(self._currentItem)
def SaveCurrentItem(self, event=None):
extension = self._currentItem
if extension:
if extension.menuItemName != self._menuItemNameTextCtrl.GetValue():
extension.menuItemName = self._menuItemNameTextCtrl.GetValue()
self._extListBox.SetString(self._currentItemIndex, extension.menuItemName)
extension.menuItemDesc = self._menuItemDescTextCtrl.GetValue()
extension.command = self._commandTextCtrl.GetValue()
extension.commandPreArgs = self._commandPreArgsTextCtrl.GetValue()
extension.commandPostArgs = self._commandPostArgsTextCtrl.GetValue()
fileExt = self._fileExtTextCtrl.GetValue().replace(' ','')
if not fileExt:
extension.fileExt = None
else:
extension.fileExt = fileExt.split(',')
def LoadItem(self, extension):
if extension:
self._menuItemDescTextCtrl.SetValue(extension.menuItemDesc or '')
self._commandTextCtrl.SetValue(extension.command or '')
self._commandPreArgsTextCtrl.SetValue(extension.commandPreArgs or '')
self._commandPostArgsTextCtrl.SetValue(extension.commandPostArgs or '')
if extension.fileExt:
self._fileExtTextCtrl.SetValue(extension.fileExt.__repr__()[1:-1].replace("'","")) # Make the list a string, strip the brakcet on either side
else:
self._fileExtTextCtrl.SetValue('')
self._menuItemNameTextCtrl.SetValue(extension.menuItemName or '') # Do the name last since it triggers the write event that updates the entire item
self._extDetailPanel.Enable()
else:
self._menuItemNameTextCtrl.SetValue('')
self._menuItemDescTextCtrl.SetValue('')
self._commandTextCtrl.SetValue('')
self._commandPreArgsTextCtrl.SetValue('')
self._commandPostArgsTextCtrl.SetValue('')
self._fileExtTextCtrl.SetValue('')
self._extDetailPanel.Enable(False)
def OnAdd(self, event):
self.SaveCurrentItem()
extensionNames = map(lambda extension: extension.menuItemName, self._extensions)
name = _("Untitled")
count = 1
while name in extensionNames:
count = count + 1
name = _("Untitled %s") % count
extension = Extension(name)
self._extensions.append(extension)
self._extListBox.Append(extension.menuItemName, extension)
self._extListBox.SetSelection(self._extListBox.GetCount() - 1)
self.OnListBoxSelect(None)
self._menuItemNameTextCtrl.SetFocus()
self._menuItemNameTextCtrl.SetSelection(-1, -1)
def OnDelete(self, event):
self._extListBox.Delete(self._currentItemIndex)
self._extensions.remove(self._currentItem)
self._currentItemIndex = min(self._currentItemIndex, self._extListBox.GetCount() - 1)
if self._currentItemIndex > -1:
self._extListBox.SetSelection(self._currentItemIndex)
self._currentItem = None # Don't update it since it no longer exists
self.OnListBoxSelect(None)
def OnMoveUp(self, event):
itemAboveString = self._extListBox.GetString(self._currentItemIndex - 1)
itemAboveData = self._extListBox.GetClientData(self._currentItemIndex - 1)
self._extListBox.Delete(self._currentItemIndex - 1)
self._extListBox.Insert(itemAboveString, self._currentItemIndex)
self._extListBox.SetClientData(self._currentItemIndex, itemAboveData)
self._currentItemIndex = self._currentItemIndex - 1
self.OnListBoxSelect(None) # Reset buttons
def OnMoveDown(self, event):
itemBelowString = self._extListBox.GetString(self._currentItemIndex + 1)
itemBelowData = self._extListBox.GetClientData(self._currentItemIndex + 1)
self._extListBox.Delete(self._currentItemIndex + 1)
self._extListBox.Insert(itemBelowString, self._currentItemIndex)
self._extListBox.SetClientData(self._currentItemIndex, itemBelowData)
self._currentItemIndex = self._currentItemIndex + 1
self.OnListBoxSelect(None) # Reset buttons

View File

@ -81,6 +81,7 @@ class IDEApplication(wx.lib.pydocview.DocApp):
import DebuggerService
import AboutDialog
import SVNService
import ExtensionService
if not ACTIVEGRID_BASE_IDE:
import DataModelEditor
@ -304,6 +305,7 @@ class IDEApplication(wx.lib.pydocview.DocApp):
deploymentService = self.InstallService(DeploymentService.DeploymentService())
dataModelService = self.InstallService(DataModelEditor.DataModelService())
welcomeService = self.InstallService(WelcomeService.WelcomeService())
extensionService = self.InstallService(ExtensionService.ExtensionService())
optionsService = self.InstallService(wx.lib.pydocview.DocOptionsService(supportedModes=wx.lib.docview.DOC_MDI))
aboutService = self.InstallService(wx.lib.pydocview.AboutService(AboutDialog.AboutDialog))
svnService = self.InstallService(SVNService.SVNService())
@ -326,6 +328,7 @@ class IDEApplication(wx.lib.pydocview.DocApp):
optionsService.AddOptionsPanel(STCTextEditor.TextOptionsPanel)
optionsService.AddOptionsPanel(HtmlEditor.HtmlOptionsPanel)
optionsService.AddOptionsPanel(SVNService.SVNOptionsPanel)
optionsService.AddOptionsPanel(ExtensionService.ExtensionOptionsPanel)
filePropertiesService.AddCustomEventHandler(projectService)
@ -374,7 +377,7 @@ class IDEApplication(wx.lib.pydocview.DocApp):
if os.path.exists(tips_path):
wx.CallAfter(self.ShowTip, docManager.FindSuitableParent(), wx.CreateFileTipProvider(tips_path, 0))
wx.UpdateUIEvent.SetUpdateInterval(200) # Overhead of updating menus was too much. Change to update every 200 milliseconds.
wx.UpdateUIEvent.SetUpdateInterval(400) # Overhead of updating menus was too much. Change to update every 400 milliseconds.
return True

View File

@ -20,7 +20,7 @@ from wxPython.lib.rcsizer import RowColSizer
import time
import Service
import sys
import activegrid.util.objutils
import activegrid.util.xmlutils
import UICommon
import Wizard
import SVNService
@ -49,10 +49,10 @@ HALF_SPACE = 5
#----------------------------------------------------------------------------
def load(fileObject):
return activegrid.util.objutils.defaultLoad(fileObject)
return activegrid.util.xmlutils.defaultLoad(fileObject, knownTypes={"projectmodel" : ProjectModel})
def save(fileObject, projectModel):
activegrid.util.objutils.defaultSave(fileObject, projectModel, prettyPrint=True)
activegrid.util.xmlutils.defaultSave(fileObject, projectModel, prettyPrint=True, knownTypes={"projectmodel" : ProjectModel})
#----------------------------------------------------------------------------
@ -1055,7 +1055,8 @@ class ProjectView(wx.lib.docview.View):
descr = template.GetDescription() + _(" (") + template.GetFileFilter() + _(")")
choices.append(descr)
allfilter = allfilter + template.GetFileFilter()
choices.insert(0, _("All (%s)") % allfilter)
choices.insert(0, _("All (%s)") % allfilter) # first item
choices.append(_("Any (*.*)")) # last item
filterChoice = wx.Choice(frame, -1, size=(250, -1), choices=choices)
filterChoice.SetSelection(0)
filterChoice.SetToolTipString(_("Select file type filter."))
@ -1112,7 +1113,8 @@ class ProjectView(wx.lib.docview.View):
paths = []
index = filterChoice.GetSelection()
if index:
lastIndex = filterChoice.GetCount()-1
if index and index != lastIndex: # if not All or Any
template = visibleTemplates[index-1]
# do search in files on disk
@ -1121,7 +1123,7 @@ class ProjectView(wx.lib.docview.View):
break
for name in files:
if index == 0: # all
if index == 0: # All
for template in visibleTemplates:
if template.FileMatchesTemplate(name):
filename = os.path.join(root, name)
@ -1132,6 +1134,11 @@ class ProjectView(wx.lib.docview.View):
paths.append(filename)
break
elif index == lastIndex: # Any
filename = os.path.join(root, name)
# if already in project, don't add it, otherwise undo will remove it from project even though it was already in it.
if not doc.IsFileInProject(filename):
paths.append(filename)
else: # use selected filter
if template.FileMatchesTemplate(name):
filename = os.path.join(root, name)

View File

@ -14,6 +14,7 @@ import os
import os.path
import wx
import ProjectEditor
import activegrid.util as utillib
_ = wx.GetTranslation
def CreateDirectoryControl( parent, fileLabel, dirLabel, fileExtension, startingName="", startingDirectory=""):
@ -117,4 +118,11 @@ def PluralName(name):
return name[0:-1] + 'ies'
else:
return name + 's'
def GetPythonExecPath():
pythonExecPath = wx.ConfigBase_Get().Read("ActiveGridPythonLocation")
if not pythonExecPath:
pythonExecPath = utillib.pythonExecPath
return pythonExecPath

View File

@ -14,8 +14,10 @@ import traceback
import sys
import os
def _registerMainModuleDir():
global mainModuleDir
def isWindows():
return os.name == 'nt'
def _generateMainModuleDir():
if sys.executable.find('python') != -1:
utilModuleDir = os.path.dirname(__file__)
if not os.path.isabs(utilModuleDir):
@ -25,5 +27,22 @@ def _registerMainModuleDir():
mainModuleDir = os.path.dirname(mainModuleDir) # Get rid of library.zip
else:
mainModuleDir = os.path.dirname(sys.executable)
return mainModuleDir
mainModuleDir = _generateMainModuleDir()
def _generatePythonExecPath():
if sys.executable.find('python') != -1:
pythonExecPath = sys.executable
else:
pythonExecPath = os.path.join(os.path.dirname(sys.executable), '3rdparty\python2.3\python')
return pythonExecPath
pythonExecPath = _generatePythonExecPath()
def getCommandNameForExecPath(execPath):
if isWindows():
return '"%s"' % execPath
return execPath
_registerMainModuleDir()

View File

@ -0,0 +1,103 @@
#----------------------------------------------------------------------------
# Name: aglogging.py
# Purpose: Utilities to help with logging
#
# Author: Jeff Norton
#
# Created: 01/04/05
# CVS-ID: $Id$
# Copyright: (c) 2005 ActiveGrid, Inc.
# License: wxWindows License
#----------------------------------------------------------------------------
import sys
import os
import re
import traceback
import logging
from activegrid.util.lang import *
LEVEL_FATAL = logging.FATAL
LEVEL_ERROR = logging.ERROR
LEVEL_WARN = logging.WARN
LEVEL_INFO = logging.INFO
LEVEL_DEBUG = logging.DEBUG
TEST_MODE_NONE = 0
TEST_MODE_DETERMINISTIC = 1
TEST_MODE_NON_DETERMINISTIC = 2
global agTestMode
agTestMode = TEST_MODE_NONE
def setTestMode(mode):
global agTestMode
agTestMode = mode
def getTestMode():
global agTestMode
return agTestMode
def testMode(normalObj, testObj=None):
if getTestMode() > TEST_MODE_NONE:
return testObj
return normalObj
pythonFileRefPattern = asString(r'(?<=File ")[^"]*(#[^#]*")(, line )[0-9]*')
phpFileRefPattern = asString(r'( in ).*#([^#]*#[^ ]*)(?= on line )')
pathSepPattern = os.sep
if (pathSepPattern == "\\"):
pathSepPattern = "\\\\"
pythonFileRefPattern = pythonFileRefPattern.replace("#", pathSepPattern)
pythonFileRefPattern = re.compile(pythonFileRefPattern)
phpFileRefPattern = phpFileRefPattern.replace("#", pathSepPattern)
phpFileRefPattern = re.compile(phpFileRefPattern)
def removeFileRefs(str):
str = pythonFileRefPattern.sub(_fileNameReplacement, str)
str = phpFileRefPattern.sub(_fileNameReplacementPHP, str)
return str
def removePHPFileRefs(str):
str = phpFileRefPattern.sub(_fileNameReplacementPHP, str)
return str
def _fileNameReplacement(match):
return "...%s" % match.group(1).replace(os.sep, "/")
def _fileNameReplacementPHP(match):
return "%s...%s" % (match.group(1), match.group(2).replace(os.sep, "/"))
def getTraceback():
extype, val, tb = sys.exc_info()
tbs = "\n"
for s in traceback.format_tb(tb):
tbs += s
return tbs
def reportException(out=None, stacktrace=False, diffable=False, exception=None):
if (True): # exception == None):
extype, val, t = sys.exc_info()
else:
extype = type(exception)
val = exception
if (stacktrace):
e,v,t = sys.exc_info()
if (diffable):
exstr = removeFileRefs(str(val))
else:
exstr = str(val)
if (out == None):
print "Got Exception = %s: %s" % (extype, exstr)
else:
print >> out, "Got Exception = %s: %s" % (extype, exstr)
if (stacktrace):
fmt = traceback.format_exception(extype, val, t)
for s in fmt:
if (diffable):
s = removeFileRefs(s)
if (out == None):
print s
else:
print >> out, s

View File

@ -0,0 +1,67 @@
#----------------------------------------------------------------------------
# Name: lang.py
# Purpose: Active grid language specific utilities -- provides portability
# for common idiom's that have language specific implementations
#
# Author: Jeff Norton
#
# Created: 04/27/05
# CVS-ID: $Id$
# Copyright: (c) 2004-2005 ActiveGrid, Inc.
# License: wxWindows License
#----------------------------------------------------------------------------
def isMain(caller):
return caller == '__main__'
def ag_className(obj):
return obj.__class__.__name__
def asDict(src):
return src
def asList(src):
return src
def asTuple(src):
return src
def asString(src):
return src
def asInt(src):
return src
def asBool(src):
return src
def asObject(src):
return src
def cast(src, type):
return src
def asRef(src):
return src
def asClass(src):
return src
def localize(text):
return text
# Pass in Python code as a string. The cross-compiler will convert to PHP
# and in-line the result.
def pyToPHP(expr):
pass
# Pass in PHP code as a string. The cross-compiler will drop it in-line verbatim.
def PHP(expr):
pass
# Bracket Python only code. The Cross-compiler will ignore the bracketed code.
def ifDefPy(comment=False):
pass
def endIfDef():
pass

View File

@ -14,98 +14,7 @@ import logging
import traceback
import sys
import os
import xmlmarshaller
AG_TYPE_MAPPING = { "ag:append" : "activegrid.model.processmodel.AppendOperation",
"ag:body" : "activegrid.model.processmodel.Body",
"ag:copy" : "activegrid.model.processmodel.CopyOperation",
"ag:cssRule" : "activegrid.model.processmodel.CssRule",
"ag:datasource" : "activegrid.data.dataservice.DataSource",
"ag:debug" : "activegrid.model.processmodel.DebugOperation",
"ag:deployment" : "activegrid.server.deployment.Deployment",
"ag:glue" : "activegrid.model.processmodel.Glue",
"ag:hr" : "activegrid.model.processmodel.HorizontalRow",
"ag:image" : "activegrid.model.processmodel.Image",
"ag:inputs" : "activegrid.model.processmodel.Inputs",
"ag:label" : "activegrid.model.processmodel.Label",
"ag:processmodel": "activegrid.model.processmodel.ProcessModel",
"ag:processmodelref" : "activegrid.server.deployment.ProcessModelRef",
"ag:query" : "activegrid.model.processmodel.Query",
"ag:schemaOptions" : "activegrid.model.schema.SchemaOptions",
"ag:schemaref" : "activegrid.server.deployment.SchemaRef",
"ag:set" : "activegrid.model.processmodel.SetOperation",
"ag:text" : "activegrid.model.processmodel.Text",
"ag:title" : "activegrid.model.processmodel.Title",
"ag:view" : "activegrid.model.processmodel.View",
"bpws:case" : "activegrid.model.processmodel.BPELCase",
"bpws:catch" : "activegrid.model.processmodel.BPELCatch",
"bpws:faultHandlers" : "activegrid.model.processmodel.BPELFaultHandlers",
"bpws:invoke" : "activegrid.model.processmodel.BPELInvoke",
"bpws:onMessage" : "activegrid.model.processmodel.BPELOnMessage",
"bpws:otherwise" : "activegrid.model.processmodel.BPELOtherwise",
"bpws:pick" : "activegrid.model.processmodel.BPELPick",
"bpws:process" : "activegrid.model.processmodel.BPELProcess",
"bpws:receive" : "activegrid.model.processmodel.BPELReceive",
"bpws:reply" : "activegrid.model.processmodel.BPELReply",
"bpws:scope" : "activegrid.model.processmodel.BPELScope",
"bpws:sequence" : "activegrid.model.processmodel.BPELSequence",
"bpws:switch" : "activegrid.model.processmodel.BPELSwitch",
"bpws:terminate" : "activegrid.model.processmodel.BPELTerminate",
"bpws:variable" : "activegrid.model.processmodel.BPELVariable",
"bpws:variables" : "activegrid.model.processmodel.BPELVariables",
"bpws:while" : "activegrid.model.processmodel.BPELWhile",
"wsdl:message" : "activegrid.model.processmodel.WSDLMessage",
"wsdl:part" : "activegrid.model.processmodel.WSDLPart",
"xforms:group" : "activegrid.model.processmodel.XFormsGroup",
"xforms:input" : "activegrid.model.processmodel.XFormsInput",
"xforms:label" : "activegrid.model.processmodel.XFormsLabel",
"xforms:output" : "activegrid.model.processmodel.XFormsOutput",
"xforms:secret" : "activegrid.model.processmodel.XFormsSecret",
"xforms:submit" : "activegrid.model.processmodel.XFormsSubmit",
"xs:all" : "activegrid.model.schema.XsdSequence",
"xs:complexType" : "activegrid.model.schema.XsdComplexType",
"xs:element" : "activegrid.model.schema.XsdElement",
"xs:field" : "activegrid.model.schema.XsdKeyField",
"xs:key" : "activegrid.model.schema.XsdKey",
"xs:keyref" : "activegrid.model.schema.XsdKeyRef",
"xs:schema" : "activegrid.model.schema.Schema",
"xs:selector" : "activegrid.model.schema.XsdKeySelector",
"xs:sequence" : "activegrid.model.schema.XsdSequence",
"projectmodel" : "activegrid.tool.ProjectEditor.ProjectModel",
}
def defaultLoad(fileObject, knownTypes=None):
xml = fileObject.read()
loadedObject = defaultUnmarshal(xml, knownTypes=knownTypes)
if hasattr(fileObject, 'name'):
loadedObject.fileName = os.path.abspath(fileObject.name)
loadedObject.initialize()
return loadedObject
def defaultUnmarshal(xml, knownTypes=None):
if not knownTypes: knownTypes = AG_TYPE_MAPPING
return xmlmarshaller.unmarshal(xml, knownTypes=knownTypes)
def defaultSave(fileObject, objectToSave, prettyPrint=True, knownTypes=None, withEncoding=1, encoding='utf-8'):
xml = defaultMarshal(objectToSave, prettyPrint=prettyPrint, knownTypes=knownTypes, withEncoding=withEncoding, encoding=encoding)
fileObject.write(xml)
fileObject.flush()
def defaultMarshal(objectToSave, prettyPrint=True, knownTypes=None, withEncoding=1, encoding='utf-8'):
if not knownTypes: knownTypes = AG_TYPE_MAPPING
return xmlmarshaller.marshal(objectToSave, prettyPrint=prettyPrint, knownTypes=knownTypes, withEncoding=withEncoding, encoding=encoding)
def clone(objectToClone, knownTypes=None, encoding='utf-8'):
if not knownTypes: knownTypes = AG_TYPE_MAPPING
xml = xmlmarshaller.marshal(objectToClone, prettyPrint=True, knownTypes=knownTypes, encoding=encoding)
clonedObject = xmlmarshaller.unmarshal(xml, knownTypes=knownTypes)
if hasattr(objectToClone, 'fileName'):
clonedObject.fileName = objectToClone.fileName
try:
clonedObject.initialize()
except AttributeError:
pass
return clonedObject
from types import *
def classForName(className):
pathList = className.split('.')
@ -115,31 +24,6 @@ def classForName(className):
code = code.__dict__[name]
return code
def hasattrignorecase(object, name):
namelow = name.lower()
for attr in dir(object):
if attr.lower() == namelow:
return True
for attr in dir(object):
if attr.lower() == '_' + namelow:
return True
return False
def setattrignorecase(object, name, value):
namelow = name.lower()
for attr in object.__dict__:
if attr.lower() == namelow:
object.__dict__[attr] = value
return
object.__dict__[name] = value
def getattrignorecase(object, name):
namelow = name.lower()
for attr in object.__dict__:
if attr.lower() == namelow:
return object.__dict__[attr]
return object.__dict__[name]
def hasPropertyValue(obj, attr):
hasProp = False
try:
@ -159,7 +43,7 @@ def hasPropertyValue(obj, attr):
return hasProp
def toDiffableString(value):
s = repr(value)
s = str(value)
ds = ""
i = s.find(" at 0x")
start = 0
@ -171,19 +55,51 @@ def toDiffableString(value):
start = j
i = s.find(" at 0x", start)
return ds + s[start:]
def toString(value, options=0):
if ((options & PRINT_OBJ_DIFFABLE) > 0):
return toDiffableString(value)
return value
def toTypeString(obj):
if (isinstance(obj, BooleanType)):
return "bool"
elif (isinstance(obj, UnicodeType)):
return "unicode"
elif (isinstance(obj, basestring)):
return "string"
elif (isinstance(obj, IntType)):
return "int"
elif (isinstance(obj, FloatType)):
return "float"
elif (type(obj) == ListType):
return "list"
elif (isinstance(obj, DictType)):
return "dict"
elif (isinstance(obj, TupleType)):
return "tuple"
elif (isinstance(obj, InstanceType)):
return type(obj)
else:
return type(obj)
PRINT_OBJ_GETATTR = 1
PRINT_OBJ_HIDE_INTERNAL = 2
PRINT_OBJ_COMPACT = 4
PRINT_OBJ_NONONE = 8
PRINT_OBJ_DIFFABLE = 16
PRINT_OBJ_INTERNAL = 512
def printObject(out, object, name="", indent=0, flags=0, exclude=None, maxIndent=30):
if ((maxIndent != None) and (indent > maxIndent)):
print >> out, " "*indent, name, str(object)
print >> out, " "*indent, "%s: %s" % (name, toString(str(object), flags)),
if ((flags & PRINT_OBJ_INTERNAL) == 0):
print >> out
return True
finalNewLine = False
printed = True
## if (exclude == None):
## exclude = []
if ((flags & PRINT_OBJ_COMPACT) > 0):
if (exclude and object in exclude):
return
@ -191,7 +107,7 @@ def printObject(out, object, name="", indent=0, flags=0, exclude=None, maxIndent
if ((flags & PRINT_OBJ_INTERNAL) == 0):
finalNewLine = True
flags |= PRINT_OBJ_INTERNAL
if (object == None):
if (object is None):
if (flags & PRINT_OBJ_NONONE) == 0:
print >> out, " "*indent, name, " = None",
else:
@ -201,21 +117,21 @@ def printObject(out, object, name="", indent=0, flags=0, exclude=None, maxIndent
finalNewLine = False
printed = False
elif (isinstance(object, (list, tuple))):
if (exclude and object in exclude):
print >> out, " "*indent, name, " : ", type(object), " of length = ", len(object), " (already printed)",
elif (exclude and name in exclude):
print >> out, " "*indent, name, " : ", type(object), " of length = ", len(object), " (excluded)",
if ((exclude != None) and object in exclude):
print >> out, " "*indent, name, " : ", toTypeString(object), " of length = ", len(object), " (already printed)",
elif ((exclude != None) and name in exclude):
print >> out, " "*indent, name, " : ", toTypeString(object), " of length = ", len(object), " (excluded)",
else:
if (exclude != None): exclude.append(object)
print >> out, " "*indent, name, " : ", type(object), " of length = %i" % len(object),
if ((exclude != None) and (len(object) > 0)): exclude.append(object)
print >> out, " "*indent, name, " : ", toTypeString(object), " of length = %d" % len(object),
for i, o in enumerate(object):
print >> out
printObject(out, o, name="[%i]" % i, indent=indent+2, flags=flags, exclude=exclude, maxIndent=maxIndent)
printObject(out, o, name="[%d]" % i, indent=indent+2, flags=flags, exclude=exclude, maxIndent=maxIndent)
elif (isinstance(object, dict)):
if (exclude and object in exclude):
print >> out, " "*indent, name, " : ", type(object), " (already printed)",
if ((exclude != None) and object in exclude):
print >> out, " "*indent, name, " : ", toTypeString(object), " (already printed)",
else:
if (exclude != None): exclude.append(object)
if ((exclude != None) and (len(object) > 0)): exclude.append(object)
if (len(name) > 0):
print >> out, " "*indent, name,
if ((flags & PRINT_OBJ_COMPACT) == 0):
@ -226,25 +142,29 @@ def printObject(out, object, name="", indent=0, flags=0, exclude=None, maxIndent
print >> out
keys = object.keys()
keys.sort()
for n in keys:
if ((n != None) and (not n.startswith("_") or ((flags & PRINT_OBJ_HIDE_INTERNAL) == 0))):
if printObject(out, object[n], name=n, indent=indent+2, flags=flags, exclude=exclude, maxIndent=maxIndent):
if ((flags & PRINT_OBJ_COMPACT) == 0):
print >> out
else:
print >> out, ",",
for key in keys:
if (key != None):
n = key
if (not (isinstance(n, basestring))):
n = str(n)
if ((not n.startswith("_") or ((flags & PRINT_OBJ_HIDE_INTERNAL) == 0))):
if printObject(out, object[key], name=n, indent=indent+2, flags=(flags | PRINT_OBJ_INTERNAL), exclude=exclude, maxIndent=maxIndent):
if ((flags & PRINT_OBJ_COMPACT) == 0):
print >> out
else:
print >> out, ",",
print >> out, " "*indent, "}",
elif (hasattr(object, "__dict__")):
if (exclude and object in exclude):
print >> out, " "*indent, name, " : ", type(object), " (already printed) = ", toDiffableString(object),
if ((exclude != None) and object in exclude):
print >> out, " "*indent, name, " : ", toTypeString(object), " (already printed) = ", toDiffableString(object),
else:
if (exclude != None): exclude.append(object)
if (name.startswith("_")):
print >> out, " "*indent, name, " : ", type(object),
elif (exclude and object.__dict__ in exclude):
print >> out, " "*indent, name, " : ", type(object), " (already printed)",
if (name.startswith("_")): ## and ((flags & PRINT_OBJ_HIDE_INTERNAL) > 0)):
print >> out, " "*indent, name, " : ", toTypeString(object),
elif ((exclude != None) and object.__dict__ in exclude):
print >> out, " "*indent, name, " : ", toTypeString(object), " (already printed)",
else:
print >> out, " "*indent, name, " : ", type(object),
print >> out, " "*indent, name, " : ", toTypeString(object),
if ((flags & PRINT_OBJ_GETATTR) == 0):
if ((flags & PRINT_OBJ_COMPACT) == 0):
print >> out
@ -259,14 +179,19 @@ def printObject(out, object, name="", indent=0, flags=0, exclude=None, maxIndent
elif (indent < 0):
print >> out, object,
elif isinstance(object, basestring):
if (exclude and name in exclude):
print >> out, " "*indent, name, " : ", type(object), " of length = ", len(object), " (excluded)",
if ((exclude != None) and name in exclude):
print >> out, " "*indent, name, " : ", toTypeString(object), " of length = ", len(object), " (excluded)",
elif (len(object) > 100):
print >> out, " "*indent, name, ":", type(object), "[%i] = %s...%s" % (len(object), object[:50], object[-50:]),
print >> out, " "*indent, name, ":", toTypeString(object), "[%d] = %s...%s" % (len(object), object[:50], object[-50:]),
else:
print >> out, " "*indent, name, ":", type(object), "=", str(object),
print >> out, " "*indent, name, ":", toTypeString(object), "=", str(object),
## elif (isinstance(object, float)):
## val = str(object)
## if (len(val) > 17):
## val = val[:17]
## print >> out, " "*indent, name, ":", type(object), "=", val,
else:
print >> out, " "*indent, name, ":", type(object), "=", str(object),
print >> out, " "*indent, name, ":", toTypeString(object), "=", str(object),
if (finalNewLine):
print >> out
return printed

File diff suppressed because it is too large Load Diff

View File

@ -10,8 +10,7 @@
# License: wxWindows License
#----------------------------------------------------------------------------
import xml.sax
import xml.sax.handler
from activegrid.util.lang import *
class XMLPrettyPrinter(xml.sax.ContentHandler):
def __init__(self, indentationChar=' ', newlineChar='\n'):
@ -24,7 +23,7 @@ class XMLPrettyPrinter(xml.sax.ContentHandler):
## ContentHandler methods
def startElement(self, name, attrs):
indentation = self.newlineChar + (self.indentationLevel * self.indentationChar)
indentation = self.newlineChar + (self.indentationChar * self.indentationLevel)
# build attribute string
attrstring = ''
for attr in attrs.getNames():
@ -36,6 +35,7 @@ class XMLPrettyPrinter(xml.sax.ContentHandler):
self.hitCharData = False
def characters(self, content):
## print "--> characters(%s)" % content
self.xmlOutput += content
self.hitCharData = True
@ -43,11 +43,12 @@ class XMLPrettyPrinter(xml.sax.ContentHandler):
self.indentationLevel -= 1
indentation = ''
if not self.hitCharData:
## indentation += self.newlineChar + (self.indentationLevel * self.indentationChar)
indentation += self.indentationLevel * self.indentationChar
indentation += self.newlineChar + (self.indentationChar * self.indentationLevel)
## indentation += self.indentationChar * self.indentationLevel
else:
self.hitCharData = False
self.xmlOutput += '%s</%s>%s' % (indentation, self.elementStack.pop(), self.newlineChar)
## self.xmlOutput += '%s</%s>%s' % (indentation, self.elementStack.pop(), self.newlineChar)
self.xmlOutput += '%s</%s>' % (indentation, self.elementStack.pop())
def getXMLString(self):
return self.xmlOutput[1:]
@ -57,7 +58,7 @@ def xmlprettyprint(xmlstr, spaces=4):
xml.sax.parseString(xmlstr, xpp)
return xpp.getXMLString()
if __name__ == '__main__':
if isMain(__name__):
simpleTestString = """<one>some text<two anattr="booga">two's data</two></one>"""
print prettyprint(simpleTestString)
print xmlprettyprint(simpleTestString)

View File

@ -0,0 +1,128 @@
#----------------------------------------------------------------------------
# Name: xmlutils.py
# Purpose: XML and Marshaller Utilities
#
# Author: Jeff Norton
#
# Created: 6/2/05
# CVS-ID: $Id$
# Copyright: (c) 2004-2005 ActiveGrid, Inc.
# License: wxWindows License
#----------------------------------------------------------------------------
import os
import activegrid.util.objutils as objutils
import activegrid.util.xmlmarshaller as xmlmarshaller
agKnownTypes = None
def defaultLoad(fileObject, knownTypes=None):
xml = fileObject.read()
loadedObject = unmarshal(xml, knownTypes=knownTypes)
if hasattr(fileObject, 'name'):
loadedObject.fileName = os.path.abspath(fileObject.name)
loadedObject.initialize()
return loadedObject
def unmarshal(xml, knownTypes=None):
if not knownTypes: knownTypes = getAgKnownTypes()
return xmlmarshaller.unmarshal(xml, knownTypes=knownTypes)
def defaultSave(fileObject, objectToSave, prettyPrint=True, knownTypes=None, encoding='utf-8'):
xml = marshal(objectToSave, prettyPrint=prettyPrint, knownTypes=knownTypes, encoding=encoding)
fileObject.write(xml)
fileObject.flush()
def marshal(objectToSave, prettyPrint=True, knownTypes=None, encoding='utf-8'):
if not knownTypes: knownTypes = getAgKnownTypes()
return xmlmarshaller.marshal(objectToSave, prettyPrint=prettyPrint, knownTypes=knownTypes, encoding=encoding)
def cloneObject(objectToClone, knownTypes=None, encoding='utf-8'):
if not knownTypes: knownTypes = getAgKnownTypes()
xml = xmlmarshaller.marshal(objectToClone, prettyPrint=True, knownTypes=knownTypes, encoding=encoding)
clonedObject = xmlmarshaller.unmarshal(xml, knownTypes=knownTypes)
if hasattr(objectToClone, 'fileName'):
clonedObject.fileName = objectToClone.fileName
try:
clonedObject.initialize()
except AttributeError:
pass
return clonedObject
def getAgKnownTypes():
import activegrid.model.processmodel
import activegrid.model.schema
import activegrid.data.dataservice
import activegrid.server.deployment
global agKnownTypes
if agKnownTypes == None:
tmpAgKnownTypes = {}
AG_TYPE_MAPPING = {
"ag:append" : "activegrid.model.processmodel.AppendOperation",
"ag:body" : "activegrid.model.processmodel.Body",
"ag:cssRule" : "activegrid.model.processmodel.CssRule",
"ag:datasource" : "activegrid.data.dataservice.DataSource",
"ag:debug" : "activegrid.model.processmodel.DebugOperation",
"ag:deployment" : "activegrid.server.deployment.Deployment",
"ag:glue" : "activegrid.model.processmodel.Glue",
"ag:hr" : "activegrid.model.processmodel.HorizontalRow",
"ag:image" : "activegrid.model.processmodel.Image",
"ag:inputs" : "activegrid.model.processmodel.Inputs",
"ag:label" : "activegrid.model.processmodel.Label",
"ag:processmodel" : "activegrid.model.processmodel.ProcessModel",
"ag:processmodelref" : "activegrid.server.deployment.ProcessModelRef",
"ag:query" : "activegrid.model.processmodel.Query",
"ag:restParameter" : "activegrid.server.deployment.RestParameter",
"ag:restService" : "activegrid.server.deployment.RestService",
"ag:schemaOptions" : "activegrid.model.schema.SchemaOptions",
"ag:schemaref" : "activegrid.server.deployment.SchemaRef",
"ag:serviceref" : "activegrid.server.deployment.ServiceRef",
"ag:set" : "activegrid.model.processmodel.SetOperation",
"ag:text" : "activegrid.model.processmodel.Text",
"ag:title" : "activegrid.model.processmodel.Title",
"ag:view" : "activegrid.model.processmodel.View",
"bpws:case" : "activegrid.model.processmodel.BPELCase",
"bpws:catch" : "activegrid.model.processmodel.BPELCatch",
"bpws:faultHandlers" : "activegrid.model.processmodel.BPELFaultHandlers",
"bpws:invoke" : "activegrid.model.processmodel.BPELInvoke",
"bpws:onMessage" : "activegrid.model.processmodel.BPELOnMessage",
"bpws:otherwise" : "activegrid.model.processmodel.BPELOtherwise",
"bpws:pick" : "activegrid.model.processmodel.BPELPick",
"bpws:process" : "activegrid.model.processmodel.BPELProcess",
"bpws:receive" : "activegrid.model.processmodel.BPELReceive",
"bpws:reply" : "activegrid.model.processmodel.BPELReply",
"bpws:scope" : "activegrid.model.processmodel.BPELScope",
"bpws:sequence" : "activegrid.model.processmodel.BPELSequence",
"bpws:switch" : "activegrid.model.processmodel.BPELSwitch",
"bpws:terminate" : "activegrid.model.processmodel.BPELTerminate",
"bpws:variable" : "activegrid.model.processmodel.BPELVariable",
"bpws:variables" : "activegrid.model.processmodel.BPELVariables",
"bpws:while" : "activegrid.model.processmodel.BPELWhile",
"wsdl:message" : "activegrid.model.processmodel.WSDLMessage",
"wsdl:part" : "activegrid.model.processmodel.WSDLPart",
"xforms:group" : "activegrid.model.processmodel.XFormsGroup",
"xforms:input" : "activegrid.model.processmodel.XFormsInput",
"xforms:label" : "activegrid.model.processmodel.XFormsLabel",
"xforms:output" : "activegrid.model.processmodel.XFormsOutput",
"xforms:secret" : "activegrid.model.processmodel.XFormsSecret",
"xforms:submit" : "activegrid.model.processmodel.XFormsSubmit",
"xs:all" : "activegrid.model.schema.XsdSequence",
"xs:complexType" : "activegrid.model.schema.XsdComplexType",
"xs:element" : "activegrid.model.schema.XsdElement",
"xs:field" : "activegrid.model.schema.XsdKeyField",
"xs:key" : "activegrid.model.schema.XsdKey",
"xs:keyref" : "activegrid.model.schema.XsdKeyRef",
"xs:schema" : "activegrid.model.schema.Schema",
"xs:selector" : "activegrid.model.schema.XsdKeySelector",
"xs:sequence" : "activegrid.model.schema.XsdSequence",
}
for keyName, className in AG_TYPE_MAPPING.iteritems():
try:
tmpAgKnownTypes[keyName] = objutils.classForName(className)
except KeyError:
print "Error mapping knownType", className
pass
if len(tmpAgKnownTypes) > 0:
agKnownTypes = tmpAgKnownTypes
return agKnownTypes

View File

@ -90,6 +90,8 @@ class TextEditorApplication(pydocview.DocApp):
if os.path.exists("tips.txt"):
wx.CallAfter(self.ShowTip, wx.GetApp().GetTopWindow(), wx.CreateFileTipProvider("tips.txt", 0))
wx.UpdateUIEvent.SetUpdateInterval(400) # Overhead of updating menus was too much. Change to update every 400 milliseconds.
# Tell the framework that everything is great
return True

View File

@ -13,6 +13,7 @@
import os
import os.path
import shutil
import wx
import sys
_ = wx.GetTranslation
@ -436,6 +437,7 @@ class Document(wx.EvtHandler):
backupFilename = None
fileObject = None
copied = False
try:
# if current file exists, move it to a safe place temporarily
if os.path.exists(filename):
@ -453,7 +455,8 @@ class Document(wx.EvtHandler):
while os.path.exists(backupFilename):
i += 1
backupFilename = "%s.bak%s" % (filename, i)
os.rename(filename, backupFilename)
shutil.copy(filename, backupFilename)
copied = True
fileObject = file(filename, 'w')
self.SaveObject(fileObject)
@ -470,11 +473,9 @@ class Document(wx.EvtHandler):
if fileObject:
fileObject.close() # file is still open, close it, need to do this before removal
# save failed, restore old file
if backupFilename:
os.remove(filename)
os.rename(backupFilename, filename)
self.SetDocumentModificationDate()
# save failed, remove copied file
if backupFilename and copied:
os.remove(backupFilename)
wx.MessageBox("Could not save '%s'. %s" % (FileNameFromPath(filename), sys.exc_value),
msgTitle,
@ -1247,10 +1248,6 @@ class DocTemplate(wx.Object):
Returns True if the path's extension matches one of this template's
file filter extensions.
"""
## print "*** path", path
## if "*.*" in self.GetFileFilter():
## return True
##
ext = FindExtension(path)
if not ext: return False
return ext in self.GetFileFilter()
@ -2793,8 +2790,10 @@ class DocMDIChildFrame(wx.MDIChildFrame):
self._childView.Activate(False)
self._childView.Destroy()
self._childView = None
if self._childDocument:
self._childDocument.Destroy() # This isn't in the wxWindows codebase but the document needs to be disposed of somehow
if self._childDocument: # This isn't in the wxWindows codebase but the document needs to be disposed of somehow
self._childDocument.DeleteContents()
if self._childDocument.GetDocumentManager():
self._childDocument.GetDocumentManager().RemoveDocument(self._childDocument)
self._childDocument = None
self.Destroy()
else:

View File

@ -1185,7 +1185,7 @@ class DocService(wx.EvtHandler):
def __init__(self):
"""Initializes the DocService."""
wx.EvtHandler.__init__(self)
pass
def GetDocumentManager(self):
@ -1478,7 +1478,7 @@ class GeneralOptionsPanel(wx.Panel):
msgTitle = wx.GetApp().GetAppName()
if not msgTitle:
msgTitle = _("Document Options")
wx.MessageBox("Document interface changes will not appear until the application is restarted.",
wx.MessageBox(_("Document interface changes will not appear until the application is restarted."),
msgTitle,
wx.OK | wx.ICON_INFORMATION,
self.GetParent())
@ -1995,10 +1995,7 @@ class DocApp(wx.PySimpleApp):
if isinstance(document, ChildDocument) and document.GetParentDocument() == parentDocument:
if document.GetFirstView().GetFrame():
document.GetFirstView().GetFrame().SetFocus()
if document.GetFirstView().OnClose(deleteWindow = False):
if document.GetFirstView().GetFrame():
document.GetFirstView().GetFrame().Close() # wxBug: Need to do this for some random reason
else:
if not document.GetFirstView().OnClose():
return False
return True
@ -2338,7 +2335,6 @@ class AboutService(DocService):
"""
Initializes the AboutService.
"""
DocService.__init__(self)
if aboutDialog:
self._dlg = aboutDialog
self._image = None
@ -2406,7 +2402,6 @@ class FilePropertiesService(DocService):
"""
Initializes the PropertyService.
"""
DocService.__init__(self)
self._customEventHandlers = []
@ -2710,7 +2705,6 @@ class WindowMenuService(DocService):
"""
Initializes the WindowMenu and its globals.
"""
DocService.__init__(self)
self.ARRANGE_WINDOWS_ID = wx.NewId()
self.SELECT_WINDOW_1_ID = wx.NewId()
self.SELECT_WINDOW_2_ID = wx.NewId()