Update of /cvsroot/pythoncard/PythonCard/tools/oneEditor/scriptlets In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10092/scriptlets Added Files: documentWordCount.py insertDateAndTime.py insertDialog.py selectionWordCount.py testIgnore.py unorderedList.py Log Message: Initial version of a tabbed code editor, with associated (future) resource editor --- NEW FILE: documentWordCount.py --- import wx from PythonCard import dialog, util def wordCount(text): chars = len(text) words = len(text.split()) # this doesn't always match the getNumberOfLines() method # so this should probably be changed lines = len(text.splitlines()) return chars, words, lines if bg.documentPath is None: filename = 'Untitled' else: filename = os.path.basename(bg.documentPath) dialog.MessageDialog(bg, "Document: %s\n" % filename + "%d chars, %d words, %d lines" % wordCount(util.normalizeEOL(bg.components.document.text)), 'Word Count', wx.ICON_INFORMATION | wx.OK) --- NEW FILE: unorderedList.py --- # inserts "\t* " before each line in the selection text = bg.components.document.GetSelectedText() unorderedList = "" for i in text.splitlines(1): unorderedList += "\t* " + i bg.components.document.ReplaceSelection(unorderedList) --- NEW FILE: insertDateAndTime.py --- import time now = time.localtime(time.time()) dateStr = time.strftime("%A, %B %d, %Y, %I:%M %p", now) comp.document.ReplaceSelection(dateStr) --- NEW FILE: insertDialog.py --- from PythonCard import dialog alertDialogTemplate = """result = dialog.alertDialog(self, 'a message', 'a title') if result.accepted: returned = result.returnedString """ colorDialogTemplate = """result = dialog.colorDialog(self) if result.accepted: color = result.color """ directoryDialogTemplate = """result = dialog.directoryDialog(self, 'Choose a directory', '') if result.accepted: path = result.path """ findDialogTemplate = """result = dialog.findDialog(self) if result.accepted: searchText = result.searchText wholeWordsOnly = result.wholeWordsOnly caseSensitive = result.caseSensitive """ fontDialogTemplate = """result = dialog.fontDialog(self) if result.accepted: color = result.color font = result.font """ messageDialogTemplate = """result = dialog.messageDialog(self, 'a message', 'a title', wx.ICON_INFORMATION | wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL) if result.accepted: returned = result.returnedString """ multipleChoiceDialogTemplate = """result = dialog.multipleChoiceDialog(self, "message", "title", ['one', 'two', 'three']) if result.accepted: sel = result.selection """ openFileDialogTemplate = """wildcard = "JPG files (*.jpg;*.jpeg)|*.jpg;*.jpeg;*.JPG;*.JPEG|GIF files (*.gif)|*.gif;*.GIF|All Files (*.*)|*.*" result = dialog.openFileDialog(self, 'Open', '', '', wildcard ) if result.accepted: path = result.paths[0] """ saveFileDialogTemplate = """wildcard = "JPG files (*.jpg;*.jpeg)|*.jpg;*.jpeg;*.JPG;*.JPEG|GIF files (*.gif)|*.gif;*.GIF|All Files (*.*)|*.*" result = dialog.saveFileDialog(self, 'Save', '', '', wildcard ) if result.accepted: path = result.paths[0] """ scrolledMessageDialogTemplate = """dialog.scrolledMessageDialog(self, 'message', 'title') if result.accepted: # you don't really need the accepted test, since there isn't a result # to check for a scrolledMessageDialog pass """ singleChoiceDialogTemplate = """result = dialog.singleChoiceDialog(self, "message", "title", ['one', 'two', 'three']) if result.accepted: sel = result.selection """ textEntryDialogTemplate = """result = dialog.textEntryDialog(self, 'message', 'title', 'text') if result.accepted: returned = result.returnedString text = result.text """ dialogsList = ['alertDialog', 'colorDialog', 'directoryDialog', 'findDialog', 'fontDialog', 'messageDialog', 'multipleChoiceDialog', 'openFileDialog', 'saveFileDialog', 'scrolledMessageDialog', 'singleChoiceDialog', 'textEntryDialog'] dialogsList.sort() result = dialog.singleChoiceDialog(None, "Pick a dialog:", "Dialogs", dialogsList) if result.accepted: dialogText = eval(result.selection + 'Template') # could get the current indent and insert the appropriate # number of spaces before each line of the template here comp.document.ReplaceSelection(dialogText) --- NEW FILE: selectionWordCount.py --- import wx from PythonCard import dialog, util def wordCount(text): chars = len(text) words = len(text.split()) # this doesn't always match the getNumberOfLines() method # so this should probably be changed lines = len(text.splitlines()) return chars, words, lines if bg.documentPath is None: filename = 'Untitled' else: filename = os.path.basename(bg.documentPath) text = util.normalizeEOL(bg.components.document.GetSelectedText()) dialog.MessageDialog(bg, "Document: %s\n" % filename + "%d chars, %d words, %d lines" % wordCount(text), 'Word Count', wx.ICON_INFORMATION | wx.OK) --- NEW FILE: testIgnore.py --- # ignore is a regular expression that will match the filenames # for the modules to exclude. ignore = '.*\.py$' |