Update of /cvsroot/pythoncard/PythonCard/tools/oneEditor/modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10092/modules Added Files: __init__.py backgroundInfoDialog.py backgroundInfoDialog.rsrc.py colorizer.py dialogInfoDialog.py dialogInfoDialog.rsrc.py menuDialog.py menuDialog.rsrc.py newComponentDialog.py newComponentDialog.rsrc.py propertyEditor.py propertyEditor.rsrc.py resourceOutput.py scriptutils.py stackInfoDialog.py stackInfoDialog.rsrc.py stringDialog.py stringDialog.rsrc.py Log Message: Initial version of a tabbed code editor, with associated (future) resource editor --- NEW FILE: backgroundInfoDialog.py --- """ __version__ = "$Revision: 1.1 $" __date__ = "$Date: 2004/10/03 23:58:01 $" """ from PythonCard import dialog, model, util import os class BackgroundInfoDialog(model.CustomDialog): def __init__(self, aBg, rsrc): model.CustomDialog.__init__(self, aBg) self.parent = aBg # if some special setup is necessary, do it here self.components.fldName.text = rsrc.name self.components.fldTitle.text = rsrc.title self.components.fldPosition.text = str(rsrc.position) self.components.fldSize.text = str(rsrc.size) self.components.chkStatusBar.checked = rsrc.statusBar if rsrc.foregroundColor is not None: #self.components.fldForegroundColor.text = colorDescription(rsrc.foregroundColor) self.components.fldForegroundColor.text = str(rsrc.foregroundColor) if rsrc.backgroundColor is not None: #self.components.fldBackgroundColor.text = colorDescription(rsrc.backgroundColor) self.components.fldBackgroundColor.text = str(rsrc.backgroundColor) if rsrc.image is not None: self.components.fldImage.text = rsrc.image self.components.chkTiled.checked = rsrc.tiled self.components.chkVisible.checked = rsrc.visible self.components.chkResizeable.checked = (rsrc.style != []) if rsrc.icon is not None: self.components.fldIcon.text = rsrc.icon def on_btnForegroundColor_mouseClick(self, event): result = dialog.colorDialog(self, color=util.colorFromString(self.components.fldForegroundColor.text)) if result.accepted: self.components.fldForegroundColor.text = str(result.color) def on_btnBackgroundColor_mouseClick(self, event): result = dialog.colorDialog(self, color=util.colorFromString(self.components.fldBackgroundColor.text)) if result.accepted: self.components.fldBackgroundColor.text = str(result.color) def on_btnFile_mouseClick(self, event): result = dialog.openFileDialog() if result.accepted: path = result.paths[0] filename = util.relativePath(self.parent.filename, path) self.components.fldImage.text = filename def on_btnIconFile_mouseClick(self, event): wildcard = "Icon Files (*.ico)|*.ico|XPM Files (*.xpm)|*.xpm|All Files (*.*)|*.*" result = dialog.openFileDialog(wildcard=wildcard) if result.accepted: path = result.paths[0] filename = util.relativePath(self.parent.filename, path) self.components.fldIcon.text = filename def backgroundInfoDialog(parent, rsrc): dlg = BackgroundInfoDialog(parent, rsrc) result = dlg.showModal() if result.accepted: result.name = dlg.components.fldName.text result.title = dlg.components.fldTitle.text result.position = eval(dlg.components.fldPosition.text) result.size = eval(dlg.components.fldSize.text) result.statusBar = dlg.components.chkStatusBar.checked result.foregroundColor = util.colorFromString(dlg.components.fldForegroundColor.text) result.backgroundColor = util.colorFromString(dlg.components.fldBackgroundColor.text) if dlg.components.fldImage.text != '': result.image = dlg.components.fldImage.text else: result.image = None result.tiled = dlg.components.chkTiled.checked result.visible = dlg.components.chkVisible.checked if dlg.components.chkResizeable.checked: result.style = ['resizeable'] else: result.style = [] if dlg.components.fldIcon.text != '': result.icon = dlg.components.fldIcon.text else: result.icon = None dlg.destroy() return result --- NEW FILE: scriptutils.py --- """ __version__ = "$Revision: 1.1 $" __date__ = "$Date: 2004/10/03 23:58:01 $" modified version of Pythonwin scriptutils.py """ import os, sys import traceback # KEA 2002-05-08 # should probably refactor this so we're not passing around the background def CheckFile(background, pathName): what = "check" background.statusBar.text = what.capitalize()+'ing module...' try: f = open(pathName) except IOError, details: background.statusBar.text = "Cant open file '%s' - %s" % (pathName, details) return try: code = f.read() + "\n" finally: f.close() try: codeObj = compile(code, pathName,'exec') if RunTabNanny(background, pathName): #win32ui.SetStatusText("Python and the TabNanny successfully checked the file '"+os.path.basename(pathName)+"'") background.statusBar.text = "Python and the TabNanny successfully checked the file '"+os.path.basename(pathName)+"'" except SyntaxError: #background.statusBar.text = 'SyntaxError' _HandlePythonFailure(background, what, pathName) def RunTabNanny(background, filename): import cStringIO import tabnanny # Capture the tab-nanny output newout = cStringIO.StringIO() old_out = sys.stderr, sys.stdout sys.stderr = sys.stdout = newout try: tabnanny.check(filename) finally: # Restore output sys.stderr, sys.stdout = old_out data = newout.getvalue() if data: try: lineno = data.split()[1] lineno = int(lineno) _JumpToPosition(background, filename, lineno) try: # Try and display whitespace #GetActiveEditControl().SCISetViewWS(1) pass except: pass #win32ui.SetStatusText("The TabNanny found trouble at line %d" % lineno) background.statusBar.text = "The TabNanny found trouble at line %d" % lineno except (IndexError, TypeError, ValueError): background.statusBar.text = "The tab nanny complained, but I cant see where!" print data return 0 return 1 def _JumpToPosition(background, fileName, lineno, col = 1): #JumpToDocument(fileName, lineno, col) #print fileName, lineno, col doc = background.components.document doc.GotoLine(lineno - 1) if col == 1: pos = doc.PositionFromLine(lineno - 1) doc.SetSelection(pos, doc.GetLineEndPosition(lineno - 1)) doc.SetCurrentPos(pos) else: pos = doc.PositionFromLine(lineno - 1) + col - 1 doc.SetSelection(pos, pos) doc.SetCurrentPos(pos) def _HandlePythonFailure(background, what, syntaxErrorPathName = None): typ, details, tb = sys.exc_info() if typ == SyntaxError: try: msg, (fileName, line, col, text) = details if (not fileName or fileName =="<string>") and syntaxErrorPathName: fileName = syntaxErrorPathName _JumpToPosition(background, fileName, line, col) except (TypeError, ValueError): msg = str(details) #win32ui.SetStatusText('Failed to ' + what + ' - syntax error - %s' % msg) background.statusBar.text = 'Failed to ' + what + ' - syntax error - %s' % msg else: traceback.print_exc() #win32ui.SetStatusText('Failed to ' + what + ' - ' + str(details) ) # KEA 2002-06-03 # this needs to be more robust, but it is better than nothing for # simple indentation errors #try: # see if we have something of the form # (line 10) # for an error message that indicates the line number # the proper solution is to probably get the line number from the # traceback stack frame but I don't know how to do that #print traceback.tb_lineno(tb) try: msg, (fileName, line, col, text) = details _JumpToPosition(background, fileName, line, col) except: pass background.statusBar.text = 'Failed to ' + what + ' - ' + str(details) tb = None # Clean up a cycle. --- NEW FILE: stringDialog.rsrc.py --- {'type':'CustomDialog', 'name':'stringDialog', 'title':'String Editor', 'size':(480, 300), 'components': [ {'type':'List', 'name':'listStrings', 'position':(0, 0), 'size':(185, 185), 'items':[], }, {'type':'Button', 'name':'btnNew', 'position':(5, 190), 'label':'New', }, {'type':'Button', 'name':'btnDelete', 'position':(108, 191), 'label':'Delete', }, {'type':'StaticText', 'name':'stcName', 'position':(200, 10), 'text':'Name:', }, {'type':'StaticText', 'name':'stcValue', 'position':(200, 35), 'text':'Value:', }, {'type':'TextField', 'name':'fldListIndex', 'position':(460, 5), 'visible':0, }, {'type':'TextField', 'name':'fldName', 'position':(260, 5), 'size':(188, -1), }, {'type':'TextArea', 'name':'fldValue', 'position':(260, 35), 'size':(188, 197), }, {'type':'Button', 'name':'btnOK', 'position':(10, 240), 'label':'OK', 'default':1, 'id':5100, }, {'type':'Button', 'name':'btnCancel', 'position':(115, 240), 'label':'Cancel', 'id':5101, }, ] # end components } # end CustomDialog --- NEW FILE: menuDialog.py --- """ __version__ = "$Revision: 1.1 $" __date__ = "$Date: 2004/10/03 23:58:01 $" """ from PythonCard import log, model, resource import os import wx MENULIST_PADDING = '....' def menuItemAttributes(menuItem): desc = " {'type':'MenuItem',\n" desc += " 'name':'%s',\n" % menuItem['name'] # KEA 2002-05-16 # work on string repr to get strings with mixed ' and " to work correctly if menuItem['shortcut'] == '': desc += """ 'label':%s,\n""" % repr(menuItem['label']) else: desc += """ 'label':%s,\n""" % repr(menuItem['label'] + '\t' + menuItem['shortcut']) try: if menuItem['command'] is not None: desc += " 'command':'%s',\n" % menuItem['command'] except: pass try: if not menuItem['enabled']: desc += " 'enabled':0,\n" except: pass try: if menuItem['checkable']: desc += " 'checkable':1,\n" if menuItem['checked']: desc += " 'checked':1,\n" except: pass desc += " },\n" return desc def menuAttributes(menu): desc = " {'type':'Menu',\n" desc += " 'name':'%s',\n" % menu['name'] desc += """ 'label':%s,\n""" % repr(menu['label']) desc += " 'items': [\n" return desc def menuResourceFromList(menuList): #desc = " 'menubar': {'type':'MenuBar',\n" desc = "{'type':'MenuBar',\n" desc += " 'menus': [\n" inMenu = 0 for m in menuList: if m['type'] == 'Menu': if inMenu: # close Menu desc += " ]\n" desc += " },\n" desc += menuAttributes(m) inMenu = 1 else: desc += menuItemAttributes(m) # close Menu desc += " ]\n" desc += " },\n" # close MenuBar desc += " ]\n" desc += "}\n" d = eval(desc) return resource.Resource(d) class MenuDialog(model.CustomDialog): def __init__(self, aBg, rsrc): model.CustomDialog.__init__(self, aBg) self.parent = aBg # if some special setup is necessary, do it here if rsrc is not None: #aBg.printMenubar(rsrc) self.menuList = self.parseMenus(rsrc) else: self.menuList = [] for m in self.menuList: if m['type'] == 'Menu': self.components.listMenus.append(m['label']) else: self.components.listMenus.append(MENULIST_PADDING + m['label']) #self.components.listMenus.items = self.parseMenus(rsrc) # Esc doesn't seem to work, it ends up closing the dialog # so need to work on that self.keyCodes = {wx.WXK_ESCAPE:'ESC', wx.WXK_SPACE:'Space', wx.WXK_DELETE:'Del', wx.WXK_F1:'F1', wx.WXK_F2:'F2', wx.WXK_F3:'F3', wx.WXK_F4:'F4', wx.WXK_F5:'F5', wx.WXK_F6:'F6', wx.WXK_F7:'F7', wx.WXK_F8:'F8', wx.WXK_F9:'F9', wx.WXK_F10:'F10', wx.WXK_F11:'F11', wx.WXK_F12:'F12', } #self.components.fldName.text = rsrc.application.name #self.components.fldTitle.text = rsrc.application.title #self.components.fldPosition.text = str(rsrc.application.position) #self.components.fldSize.text = str(rsrc.application.size) #self.components.chkStatusBar.checked = rsrc.application.statusBar def buildMenu(self, name, label): m = {} m['type'] = 'Menu' m['name'] = name m['label'] = label return m def buildMenuItem(self, name, label, shortcut, command, enabled, checkable, checked): m = {} m['type'] = 'MenuItem' m['name'] = name m['label'] = label m['shortcut'] = shortcut m['command'] = command m['enabled'] = enabled m['checkable'] = checkable m['checked'] = checked return m def parseMenus(self, menubar): menuList = [] for menu in menubar.menus: #menuList.append(menu.label) #print menu.type, menu.name, menu.label menuList.append(self.buildMenu(menu.name, menu.label)) for menuItem in menu.items: itemParts = menuItem.label.split("\t") label = itemParts[0] try: shortcut = itemParts[1] except: shortcut = '' #menuList.append("....%s" % itemParts[0]) #print menuItem.type, menuItem.name, itemParts, menuItem.command, menuItem.enabled, menuItem.checkable, menuItem.checked menuList.append(self.buildMenuItem(menuItem.name, label, shortcut, menuItem.command, menuItem.enabled, menuItem.checkable, menuItem.checked)) return menuList def on_fldShortcut_keyDown(self, event): # this should handle the special key codes keyCode = event.keyCode if keyCode > 32 and keyCode < 127: keyStr = chr(keyCode).upper() elif keyCode in self.keyCodes: keyStr = self.keyCodes[keyCode] else: event.target.text = '' return if event.shiftDown: keyStr = 'Shift+' + keyStr if event.altDown: keyStr = 'Alt+' + keyStr if event.controlDown: keyStr = 'Ctrl+' + keyStr if len(keyStr) > 1: # don't allow just a number or letter # without a modifier # might also need a leading Ctrl or Alt event.target.text = keyStr def on_fldShortcut_keyPress(self, event): pass def on_fldName_loseFocus(self, event): sel = self.components.listMenus.selection try: self.menuList[sel]['name'] = event.target.text log.info(self.menuList[sel]) except: pass def on_fldLabel_loseFocus(self, event): def normalize(label): name = label.replace("&", "").replace(".", "").replace(" ", "") return name sel = self.components.listMenus.selection try: label = event.target.text if self.menuList[sel]['type'] == 'Menu' and self.menuList[sel]['label'] == 'New Menu': oldname = self.menuList[sel]['name'] if oldname == 'menuNewMenu': name = 'menu'+normalize(label) self.menuList[sel]['name'] = name self.components.fldName.text = name elif self.menuList[sel]['type'] == 'MenuItem' and self.menuList[sel]['label'] == 'New Item': oldname = self.menuList[sel]['name'] menuname = 'menuMenu' for i in range(sel+1): if self.menuList[sel-i]['type'] == 'Menu': menuname = self.menuList[sel-i]['name'] break if oldname == menuname+'NewItem': name = menuname+normalize(label) self.menuList[sel]['name'] = name self.components.fldName.text = name self.menuList[sel]['label'] = label if self.menuList[sel]['type'] == 'MenuItem': label = MENULIST_PADDING + label self.components.listMenus.setString(sel, label) log.info(self.menuList[sel]) except: pass def on_fldShortcut_loseFocus(self, event): sel = self.components.listMenus.selection try: if self.menuList[sel]['type'] == 'MenuItem': self.menuList[sel]['shortcut'] = event.target.text log.info(self.menuList[sel]) except: pass def on_fldCommand_loseFocus(self, event): sel = self.components.listMenus.selection try: if self.menuList[sel]['type'] == 'MenuItem': if event.target.text == '': self.menuList[sel]['command'] = None else: self.menuList[sel]['command'] = event.target.text log.info(self.menuList[sel]) except: pass def on_chkEnabled_mouseClick(self, event): sel = self.components.listMenus.selection try: if self.menuList[sel]['type'] == 'MenuItem': self.menuList[sel]['enabled'] = event.target.checked log.info(self.menuList[sel]) except: pass def on_chkCheckable_mouseClick(self, event): sel = self.components.listMenus.selection try: if self.menuList[sel]['type'] == 'MenuItem': self.menuList[sel]['checkable'] = event.target.checked log.info(self.menuList[sel]) except: pass def on_chkChecked_mouseClick(self, event): sel = self.components.listMenus.selection try: if self.menuList[sel]['type'] == 'MenuItem': self.menuList[sel]['checked'] = event.target.checked log.info(self.menuList[sel]) except: pass def displayItemAttributes(self, sel): m = self.menuList[sel] self.components.fldListIndex.text = str(sel) self.components.fldName.text = m['name'] self.components.fldLabel.text = m['label'] if m['type'] == 'MenuItem': self.components.fldShortcut.text = m['shortcut'] if m['command'] is None: self.components.fldCommand.text = '' else: self.components.fldCommand.text = m['command'] self.components.chkEnabled.checked = m['enabled'] self.components.chkCheckable.checked = m['checkable'] self.components.chkChecked.checked = m['checked'] self.components.stcShortcut.visible = 1 self.components.stcCommand.visible = 1 self.components.fldShortcut.visible = 1 self.components.fldCommand.visible = 1 self.components.chkEnabled.visible = 1 self.components.chkCheckable.visible = 1 self.components.chkChecked.visible = 1 else: self.components.stcShortcut.visible = 0 self.components.stcCommand.visible = 0 self.components.fldShortcut.visible = 0 self.components.fldCommand.visible = 0 self.components.chkEnabled.visible = 0 self.components.chkCheckable.visible = 0 self.components.chkChecked.visible = 0 def on_listMenus_select(self, event): self.displayItemAttributes(event.target.selection) def rebuildListMenus(self, sel=-1): self.components.listMenus.clear() for m in self.menuList: if m['type'] == 'Menu': self.components.listMenus.append(m['label']) else: self.components.listMenus.append(MENULIST_PADDING + m['label']) if sel != -1: self.components.listMenus.selection = sel def on_btnUp_mouseClick(self, event): sel = self.components.listMenus.selection # a selection of -1 means no selection # a selection of 0 is the first item in the list if sel > 0: temp = self.menuList[sel] self.menuList[sel] = self.menuList[sel - 1] self.menuList[sel - 1] = temp self.rebuildListMenus(sel - 1) def on_btnDown_mouseClick(self, event): sel = self.components.listMenus.selection if sel != -1 and sel < len(self.menuList) - 1: temp = self.menuList[sel] self.menuList[sel] = self.menuList[sel + 1] self.menuList[sel + 1] = temp self.rebuildListMenus(sel + 1) def on_btnDelete_mouseClick(self, event): sel = self.components.listMenus.selection if sel != -1: del self.menuList[sel] self.components.listMenus.delete(sel) if len(self.menuList) > 0: if sel > 0: sel = sel - 1 self.components.listMenus.selection = sel self.displayItemAttributes(sel) def on_btnNewMenu_mouseClick(self, event): sel = self.components.listMenus.selection self.menuList.append(" ") # extend list if sel == -1: sel = len(self.menuList) - 1 else: self.menuList[sel+1:] = self.menuList[sel:-1] sel = sel+1 self.menuList[sel] = self.buildMenu('menuNewMenu', 'New Menu') self.rebuildListMenus(sel) self.displayItemAttributes(sel) def on_btnNewMenuItem_mouseClick(self, event): sel = self.components.listMenus.selection self.menuList.append(" ") # extend list if sel == -1: sel = len(self.menuList) - 1 else: self.menuList[sel+1:] = self.menuList[sel:-1] sel = sel+1 name = 'menuMenu' for i in range(1, sel+1): if self.menuList[sel-i]['type'] == 'Menu': name = self.menuList[sel-i]['name'] break self.menuList[sel] = self.buildMenuItem(name+'NewItem', 'New Item', '', None, 1, 0, 0) self.rebuildListMenus(sel) self.displayItemAttributes(sel) def menuDialog(parent, rsrc): dlg = MenuDialog(parent, rsrc) result = dlg.showModal() if result.accepted: if len(dlg.menuList) == 0: result.menubar = None else: result.menubar = menuResourceFromList(dlg.menuList) dlg.destroy() return result --- NEW FILE: __init__.py --- # turn modules into a package --- NEW FILE: propertyEditor.py --- #!/usr/bin/python """ __version__ = "$Revision: 1.1 $" __date__ = "$Date: 2004/10/03 23:58:01 $" """ from PythonCard import dialog, font, model, registry, util from PythonCard.event import ChangeListener import resourceOutput import time import os import string import wx # KEA this is a load of dingos' kidneys and needs to be rewritten # 2002-02-22 # now I'm compounding the problem by porting from the original # Property Editor to a PythonCard background class PropertyEditor(model.Background, ChangeListener): def on_initialize(self, event): self._parent = self.GetParent() self._comp = self._parent.components self._updatingComponent = 0 self.autoAttributeUpdate = True ##self.components.addChangeEventListener(self) self._comp.addChangeEventListener(self) self.editItems = [self.components.wField, self.components.wColor, self.components.wFont, self.components.wTextArea, self.components.wChecked, self.components.wPop, self.components.wFile,] # KEA 2001-08-14 # this was causing an assertion error with the hybrid wxPython #self.components.wComponentList.SetSelection(0) if self.components.wComponentList.stringSelection == "": wClass = "" else: wName, wClass = self.components.wComponentList.stringSelection.split(" : ") self.setValidProps(wClass) #self.displayComponents(self.components) self.displayComponents(self._comp) self.visible = True # KEA 2004-08-23 # support updating of attributes without the need # for clicking the Update button def on_wField_closeField(self, event): if self.autoAttributeUpdate: self.updateComponent() def on_wTextArea_closeField(self, event): if self.autoAttributeUpdate: self.updateComponent() def on_wChecked_mouseClick(self, event): if self.autoAttributeUpdate: self.updateComponent() def on_wPop_select(self, event): if self.autoAttributeUpdate: self.updateComponent() def on_wColor_mouseClick(self, event): result = dialog.colorDialog(self, color=util.colorFromString(self.components.wField.text)) if result.accepted: self.components.wField.text = str(result.color) if self.autoAttributeUpdate: self.updateComponent() def on_wFont_mouseClick(self, event): wName, wClass = self.components.wComponentList.stringSelection.split(" : ") ##widget = self.components[wName] widget = self._comp[wName] f = widget.font if f is None: desc = font.fontDescription(widget.GetFont()) f = font.Font(desc) result = dialog.fontDialog(self, f) if result.accepted: #color = dlg.getColor() f = result.font #self.components.wField.SetValue("%s;%s" % (f, color)) self.components.wField.text = "%s" % f if self.autoAttributeUpdate: self.updateComponent() def on_wFile_mouseClick(self, event): path, filename = os.path.split(self.components.wField.text) result = dialog.openFileDialog(self, directory=path, filename=filename) if result.accepted: self.components.wField.text = util.relativePath(self._parent.filename, result.paths[0]) if self.autoAttributeUpdate: self.updateComponent() def addWidgetToComponentList(self, widget): wName = widget.name # KEA 2004-01-25 # just use __name__, the other code must have been something from wxPython 2.3 #wClass = str(widget.__class__).split('.') #self.components.wComponentList.Append(wName + " : " + wClass[len(wClass) - 1]) wClass = widget.__class__.__name__ self.components.wComponentList.Append(wName + " : " + wClass) # KEA 2002-02-23 # need to redo the logic below to avoid asserts in hybrid # versions of wxPython, but also be cleaner def deleteWidgetFromComponentList(self, wName, wClass): i = self.components.wComponentList.GetSelection() j = self.components.wComponentList.FindString(wName + " : " + wClass) if i == -1 or i != j: if j != -1: self.components.wComponentList.Delete(j) else: if j > 0: self.components.wComponentList.SetSelection(j - 1) if j != -1: self.components.wComponentList.Delete(j) if self.components.wComponentList.GetSelection() == -1: self.setValidProps("") self.hideAllBut(self.components.wField) else: wName, wClass = self.components.wComponentList.stringSelection.split(" : ") # deselect the name from properties list self.setValidProps(wClass) propName = self.components.wPropertyList.stringSelection if propName == "": propName = "name" self.components.wPropertyList.stringSelection = "name" self.displayProperty(wName, wClass, propName) def selectComponentList(self, wName, wClass): self.components.wComponentList.stringSelection = wName + " : " + wClass self.setValidProps(wClass) propName = self.components.wPropertyList.stringSelection #print propName if propName == "": propName = "name" self.components.wPropertyList.stringSelection = "name" self.displayProperty(wName, wClass, propName) c = self._parent.components[wName] self._parent.setToolTipDrag(wName, c.position, c.size) def changed(self, event): ##comp = self.components if self._updatingComponent: # KEA 2003-01-04 # hack to speed up updates in place return comp = self._comp wName, wClass = event.getOldValue().... [truncated message content] |