Coverage for PyRx.textView : 57%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
#$Id: textView.py 91 2011-02-07 23:01:27Z sarkiss $ """
"This was taken from wxPython-src-2.8.6.0/wxPython/samples/docview/DocViewDemo.py" view = self.GetFirstView() if not view.GetTextCtrl().SaveFile(filename): return False self.Modify(False) self.SetDocumentSaved(True) ## if wx.Platform == "__WXMAC__": ## fn = wx.Filename(filename) ## fn.MacSetDefaultTypeAndCreator() return True
return False
else: return wx.lib.docview.Document.IsModified(self)
"This was taken from wxPython-src-2.8.6.0/wxPython/samples/docview/DocViewDemo.py" (wx.ACCEL_NORMAL, wx.WXK_F3, wx.ID_FIND) ])
""" Called when the filename has changed. The default implementation constructs a suitable title and sets the title of the view frame (if any). """
""" Called when the view should be updated. sender is a pointer to the view that sent the update request, or NULL if no single view requested the update (for instance, when the document is opened). hint is as yet unused but may in future contain application-specific information for making updating more efficient. """
""" Implements closing behaviour. The default implementation calls wxDocument.Close to close the associated document. Does not delete the view. The application may wish to do some cleaning up operations in this function, if a call to wxDocument::Close succeeded. For example, if your application's all share the same window, you need to disassociate the window from the view and perhaps clear the window. If deleteWindow is true, delete the frame associated with the view. """ #tmp = self.GetDocument().Close() #print inst else: return True
# Since ProcessEvent is not virtual, we have to trap the relevant events using this pseudo-ProcessEvent instead of EVT_MENU id = event.GetId() if id == wx.ID_UNDO: if not self._textCtrl: return False self._textCtrl.Undo() return True elif id == wx.ID_REDO: if not self._textCtrl: return False self._textCtrl.Redo() return True elif id == wx.ID_CUT: if not self._textCtrl: return False self._textCtrl.Cut() return True elif id == wx.ID_COPY: if not self._textCtrl: return False self._textCtrl.Copy() return True elif id == wx.ID_PASTE: if not self._textCtrl: return False self._textCtrl.Paste() return True # elif id == wx.ID_CLEAR: # if not self._textCtrl: # return False # self._textCtrl.Replace(self._textCtrl.GetSelection()[0], self._textCtrl.GetSelection()[1], '') # return True # elif id == wx.ID_SELECTALL: # if not self._textCtrl: # return False # self._textCtrl.SetSelection(-1, -1) # return True # elif id == TextService.CHOOSE_FONT_ID: # if not self._textCtrl: # return False # self.OnChooseFont(event) # return True # elif id == TextService.WORD_WRAP_ID: # if not self._textCtrl: # return False # self.OnWordWrap(event) # return True elif id == wx.ID_FIND: self.OnHelpFind(event) return True # elif id == FindService.FindService.FIND_PREVIOUS_ID: # self.DoFind(forceFindPrevious = True) # return True # elif id == FindService.FindService.FIND_NEXT_ID: # self.DoFind(forceFindNext = True) # return True # elif id == FindService.FindService.REPLACE_ID: # self.OnFind(replace = True) # return True # elif id == FindService.FindService.FINDONE_ID: # self.DoFind() # return True # elif id == FindService.FindService.REPLACEONE_ID: # self.DoFind(replace = True) # return True # elif id == FindService.FindService.REPLACEALL_ID: # self.DoFind(replaceAll = True) # return True # elif id == FindService.FindService.GOTO_LINE_ID: # self.OnGotoLine(event) # return True else: return wx.lib.docview.View.ProcessEvent(self, event)
if not self._textCtrl: return False
id = event.GetId() if id == wx.ID_UNDO: event.Enable(self._textCtrl.CanUndo()) return True elif id == wx.ID_REDO: event.Enable(self._textCtrl.CanRedo()) return True if id == wx.ID_CUT: return True elif id == wx.ID_COPY: return True elif id == wx.ID_PASTE: event.Enable(self._textCtrl.CanPaste()) return True # elif id == wx.ID_CLEAR: # event.Enable(self._textCtrl.CanCopy()) # return True # elif id == wx.ID_SELECTALL: # event.Enable(hasText) # return True # elif id == TextService.CHOOSE_FONT_ID: # event.Enable(True) # return True # elif id == TextService.WORD_WRAP_ID: # event.Enable(True) # return True # elif id == FindService.FindService.FIND_ID: # event.Enable(hasText) # return True # elif id == FindService.FindService.FIND_PREVIOUS_ID: # event.Enable(hasText and # self._FindServiceHasString() and # self._textCtrl.GetSelection()[0] > 0) # return True # elif id == FindService.FindService.FIND_NEXT_ID: # event.Enable(hasText and # self._FindServiceHasString() and # self._textCtrl.GetSelection()[0] < len(self._textCtrl.GetValue())) # return True # elif id == FindService.FindService.REPLACE_ID: # event.Enable(hasText) # return True # elif id == FindService.FindService.GOTO_LINE_ID: # event.Enable(True) # return True else: return wx.lib.docview.View.ProcessUpdateUIEvent(self, event)
if self.finddlg != None: return self.finddlg = wx.FindReplaceDialog(self._textCtrl, self.finddata, "Find", wx.FR_NOMATCHCASE | wx.FR_NOWHOLEWORD) self.finddlg.Show(True)
evt.Enable(self.finddlg == None)
editor = self._textCtrl
end = editor.GetLength() textstring = editor.GetTextRange(0, end).lower() findstring = self.finddata.GetFindString().lower() backward = not (self.finddata.GetFlags() & wx.FR_DOWN) if backward: start = editor.GetAnchor() loc = textstring.rfind(findstring, 0, start) else: start = editor.GetCurrentPos() loc = textstring.find(findstring, start) if loc == -1 and start != 0: # string not found, start at beginning if backward: start = end loc = textstring.rfind(findstring, 0, start) else: start = 0 loc = textstring.find(findstring, start) if loc == -1: dlg = wx.MessageDialog(editor, 'Find String Not Found', 'Find String Not Found in Demo File', wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy() if self.finddlg: if loc == -1: self.finddlg.SetFocus() return else: self.finddlg.Destroy() self.finddlg = None line = editor.LineFromPosition(loc) editor.GotoLine(line) editor.SetSelectionStart(loc) editor.SetSelectionEnd(loc + len(findstring))
if self.finddata.GetFindString(): self.OnFind(event) else: self.OnHelpFind(event)
event.GetDialog().Destroy() self.finddlg = None
"This was taken from wxPython/samples/docview/DocViewDemo.py"
""" This was taken from wx.lib.docview.wxDocMDIChildFrame. Modified to work with wx.aui.AuiNotebook and provides a Panel for displaying documents on separate pages of the AuiNotebook. T """
""" Constructor. Note that the event table must be rebuilt for the frame since the EvtHandler is not virtual. """
# self.Create(doc, view, frame, id, title, pos, size, style, name) #self.notebook.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSED, self.PageClosed)
""" This ensures that EVT_AUINOTEBOOK_PAGE_CLOSE is called with appropriate Panel. Otherwise it was called for the last panel and caused problems with closing. """ pageIndex = event.EventObject.GetSelection() if pageIndex == -1: return panel = event.EventObject.GetPage(pageIndex) panel.notebook.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, panel.OnCloseWindow) if hasattr(panel, '_childDocument'): #we need this to update toolbar panel._childDocument.GetDocumentManager().ActivateView(panel._childView) return wx.lib.docview.View.ProcessUpdateUIEvent(panel._childView, event)
""" Closes and deletes the current view and document. """ if self._childView: ans = self._childView.Close(deleteWindow = False) if ans: self._childView.Activate(False) self._childView.Destroy() self._childView = None 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 else: event.Veto() else: event.Veto()
""" Returns the document associated with this frame. """
""" Sets the document for this frame. """ self._childDocument = document
""" Returns the view associated with this frame. """ return self._childView
""" Sets the view for this frame. """ self._childView = view
""" Add/remove to the frame's title an indication that the document is dirty. If the document is dirty, an '*' is appended to the title This method has been added to wxPython and is not in wxWindows. """ if title.endswith("*"): return else: title = title + "*" self.SetTitle(title) else: title = title[:-1] self.SetTitle(title) else:
###################################
""" This class is used to display documents using wx.lib.docview The icons were taken wx.lib.pydocview and the main reason for not using pydocview directly is because we are using wx.aui and only part of the application requires docview. """ _("Text"), "*.*", _("."), _(".txt"), _("Text Document"), _("Text View"), TextEditDocument, TextEditView))
wx.aui.AUI_NB_TAB_SPLIT | wx.aui.AUI_NB_TAB_MOVE | wx.aui.AUI_NB_TAB_EXTERNAL_MOVE | wx.aui.AUI_NB_SCROLL_BUTTONS | wx.aui.AUI_NB_TAB_FIXED_WIDTH | wx.aui.AUI_NB_WINDOWLIST_BUTTON| wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB)
#self.Bind(wx.EVT_WINDOW_DESTROY, self.OnCloseWindow) #wx.EVT_CLOSE(self, self.OnCloseWindow)
""" Processes an event, searching event tables and calling zero or more suitable event handler function(s). Note that the ProcessEvent method is called from the wxPython docview framework directly since wxPython does not have a virtual ProcessEvent function. """ try: return self._docManager and self._docManager.ProcessEvent(event) except: pass
""" Processes a UI event, searching event tables and calling zero or more suitable event handler function(s). Note that the ProcessEvent method is called from the wxPython docview framework directly since wxPython does not have a virtual ProcessEvent function. """ try: return self._docManager and self._docManager.ProcessUpdateUIEvent(event) except: pass
#activate Documents tab
if document.GetFilename() and os.path.normcase(document.GetFilename()) == os.path.normcase(path): pageindex = self.notebook.GetPageIndex(document.GetFirstView()._frame) self._docManager._currentView = None document.OnCloseDocument() document.DeleteAllViews() if document in self._docManager._docs: document.Destroy() self.notebook.DeletePage(pageindex)
""" Deletes all views and documents. If no user input cancelled the operation, the frame will be destroyed and the application will exit. """ #self.Destroy() else: event.Veto()
#---------------------------------------------------------------------------- # From wxPython/samples/pydocview/FindService.py #----------------------------------------------------------------------------
\x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ \x00\x01\xb1IDAT8\x8d\xa5\x93=o\xd3P\x14\x86\x1f\xa7\x11\x95<\xdc\xc6\xecN+5\ [\x86B\x99\xacLQ2Zr[\x89\xa1\xfd\x0b%\x95\x90\x00\xf1\x03\x80\x01\x98\x80\ \x19G\xac\x0cm\xff@Y\xd9:\xd9Ck\x94\xd6\xddb\x94\x9b\x98\xc8\xd2e1C\xe5\x8b\ \xdd\x14\x96\xbe\xdb=\x1f\xefy\xef\xf90\x8c\xda\x12wA\xbd\xfc\x18\xfa\x9fs\ \x80\xf9|\x0e\xc0\x93\xc1\x81\x01\xf0\xe6\xf5\xab\x1c`:\x9d\x02\xf0\xf6\xdd{\ \xa3\xc8\xa9\xddd\xec\xf5z\xb4Z\xeb\x00\x1c\x1f\x1d\xe6\x85\xdd\xf3<\x06\x83\ \xc1\x82\xbd\xa2 \x0cCL\xd3d<\x1e\x13\xc71\xb6m\x030\x1a\x8d\x08\x82\x00\x80\ \xb3\xb3s:\x9d\x8e\xce\xa9(h6\x9b8\x8e\x83m\xdb4\x1a\r\x82 \xe0\xc5\xf3g\xb9\ eY\xb4\xdbm\x1c\xc7Y\xe8\x81&\xf8\xf4\xf1C\xde\xedv+\xce\x97Owx\xfc\xe8k\xc5\ \xb6\xb7\xb7\x8b\xef\x0foW \x84\xe0\xea\xea\x02\xa5\x94n\x18\x80\x94\x92\xd9\ l\x02@\x96e\x95>\xd4nVO\xd3\xb9\x0e\xba\r\xa6i\xd2\xef\xf7\xf0\xfd!\xc7G\x87\ y\xed:)\xd5\x01J\xfd\xd6c\xfc~\x9a\xfc\x93\xe8\xf2\xf2\x02(Ma6\x9b \x84@)\ \xa5\t}\xff\x0b\xd0\'I~R\x14\xca\xb2L\xfb\x97\x97\xef-\xeeA!_J\x89\xeb\xba\ \xb8\xae\xab\xbf\x06\x7f\x97\xacP[\x87\xeb9\x0b!H\x92\ta\x18"\xa5\xd4U\xbd\ \xadm\xe3\xe1\x83\x8d<\x8a~\x90\xa6\xbf\x88\xe3\x18)\xa5&\xa9\x03X\x96E\xab\ \xb5\x8em7\xf5\xc2\x94\xb1\xba\xba\xc6\xe6\xe6\x06++\xf7\x89\xa2\xa8\xe2\xd3\ =89\xf9Va.\x14\x14\xd8\xdf?X VJa\x14\xd7X\xde\xef2\xbc\xadm\xe3\x7f~\xe3\xae\ \xe7\xfc\x07\x84;\xc5\x82\xa1m&\x95\x00\x00\x00\x00IEND\xaeB`\x82'
def getFindBitmap():
def getFindImage(): |