def setUp(self): self.mgr = doctools.DocPositionMgr() # Populate some data self.mgr.AddRecord(('test.py', 20)) self.mgr.AddRecord(('test2.py', 100)) self.mgr.AddRecord(('test3.py', 1200))
def __init__(self, parent, id_num): """Initialize a notebook with a blank text control in it @param parent: parent window of the notebook @param id_num: this notebooks id """ FNB.FlatNotebook.__init__( self, parent, id_num, style=FNB.FNB_FF2 | FNB.FNB_X_ON_TAB | FNB.FNB_SMART_TABS | FNB.FNB_BACKGROUND_GRADIENT | FNB.FNB_DROPDOWN_TABS_LIST | FNB.FNB_ALLOW_FOREIGN_DND) # Notebook attributes self.LOG = wx.GetApp().GetLog() self._searchctrl = ed_search.SearchController(self, self.GetCurrentCtrl) self.DocMgr = doctools.DocPositionMgr(ed_glob.CONFIG['CACHE_DIR'] + \ os.sep + u'positions') self.pg_num = -1 # Track new pages (aka untitled docs) self.control = None self.frame = self.GetTopLevelParent() # MainWindow self._index = dict() # image list index self._ses_load = False self._menu = None # Set Additional Style Parameters self.SetNonActiveTabTextColour(wx.Colour(102, 102, 102)) ed_icon = ed_glob.CONFIG['SYSPIX_DIR'] + u"editra.png" self.SetNavigatorIcon(wx.Bitmap(ed_icon, wx.BITMAP_TYPE_PNG)) # Setup the ImageList and the default image imgl = wx.ImageList(16, 16) txtbmp = wx.ArtProvider.GetBitmap(str(synglob.ID_LANG_TXT), wx.ART_MENU) self._index[synglob.ID_LANG_TXT] = imgl.Add(txtbmp) self.SetImageList(imgl) # Notebook Events self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CHANGING, self.OnPageChanging) self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.OnPageChanged) self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CLOSING, self.OnPageClosing) self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CLOSED, self.OnPageClosed) self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnUpdatePageText) self._pages.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CONTEXT_MENU, self.OnTabMenu) self.Bind(wx.EVT_MENU, self.OnCopyTabPath, id=ed_glob.ID_COPY_PATH) self.Bind(wx.EVT_IDLE, self.OnIdle) # Message handlers ed_msg.Subscribe(self.OnThemeChanged, ed_msg.EDMSG_THEME_CHANGED) ed_msg.Subscribe(self.OnThemeChanged, ed_msg.EDMSG_THEME_NOTEBOOK) # Add a blank page self.NewPage()
class NavigationService(Service.BaseService): DocMgr = doctools.DocPositionMgr() def __init__(self): pass def InstallControls(self, frame, menuBar = None, toolBar = None, statusBar = None, document = None): if document and document.GetDocumentTemplate().GetDocumentType() != STCTextEditor.TextDocument: return if not document and wx.GetApp().GetDocumentManager().GetFlags() & wx.lib.docview.DOC_SDI: return viewMenu = menuBar.GetMenu(menuBar.FindMenu(_("&View"))) viewMenu.AppendSeparator() item = wx.MenuItem(viewMenu,ID_NEXT_POS, _("Next Position"), _("Goto next position in history.")) forward_image_path = os.path.join(sysutilslib.mainModuleDir, "noval", "tool", "bmp_source", "forward.png") item.SetBitmap(wx.BitmapFromImage(wx.Image(forward_image_path,wx.BITMAP_TYPE_ANY))) viewMenu.AppendItem(item) item = wx.MenuItem(viewMenu,ID_PRE_POS, _("Previous Position"), _("Goto previous position in history.")) backward_image_path = os.path.join(sysutilslib.mainModuleDir, "noval", "tool", "bmp_source", "backward.png") item.SetBitmap(wx.BitmapFromImage(wx.Image(backward_image_path,wx.BITMAP_TYPE_ANY))) viewMenu.AppendItem(item) wx.EVT_MENU(frame, ID_NEXT_POS, frame.ProcessEvent) wx.EVT_MENU(frame, ID_PRE_POS, frame.ProcessEvent) wx.EVT_UPDATE_UI(frame, ID_NEXT_POS, frame.ProcessUpdateUIEvent) wx.EVT_UPDATE_UI(frame, ID_PRE_POS, frame.ProcessUpdateUIEvent) forward_bmp_path = os.path.join(sysutilslib.mainModuleDir, "noval", "tool", "bmp_source", "forward.png") forward_bmp = wx.Bitmap(forward_bmp_path, wx.BITMAP_TYPE_PNG) backward_bmp_path = os.path.join(sysutilslib.mainModuleDir, "noval", "tool", "bmp_source", "backward.png") backward_bmp = wx.Bitmap(backward_bmp_path, wx.BITMAP_TYPE_PNG) toolBar.AddTool(ID_PRE_POS, backward_bmp, shortHelpString = _("Previous Position"), longHelpString = _("Goto previous position in history.")) toolBar.AddTool(ID_NEXT_POS, forward_bmp, shortHelpString = _("Next Position"), longHelpString = _("Goto next position in history.")) def ProcessEvent(self, event): return self.OnNavigateToPos(event) def ProcessUpdateUIEvent(self, event): return self.OnUpdateNaviUI(event) def OnNavigateToPos(self, evt): """Handle buffer position history navigation events""" e_id = evt.GetId() fname, pos = (None, None) text_view = self.GetActiveView() if text_view is None: return False cname = text_view.GetDocument().GetFilename() cpos = text_view.GetCtrl().GetCurrentPos() #when go to next position,current cache pos is current caret pos if e_id == ID_NEXT_POS: if self.DocMgr.CanNavigateNext(): fname, pos = self.DocMgr.GetNextNaviPos() if (fname, pos) == (cname, cpos): fname, pos = (None, None) tmp = self.DocMgr.GetNextNaviPos() if tmp is not None: fname, pos = tmp #while go to previous position,current cache pos is previous caret pos elif e_id == ID_PRE_POS: if self.DocMgr.CanNavigatePrev(): fname, pos = self.DocMgr.GetPreviousNaviPos() if (fname, pos) == (cname, cpos): fname, pos = (None, None) tmp = self.DocMgr.GetPreviousNaviPos() if tmp is not None: fname, pos = tmp else: return False if fname is not None: wx.GetApp().GotoView(fname,-1,pos=pos) return True def OnUpdateNaviUI(self, evt): """UpdateUI handler for position navigator""" e_id = evt.Id if e_id == ID_NEXT_POS: evt.Enable(self.DocMgr.CanNavigateNext()) return True elif e_id == ID_PRE_POS: evt.Enable(self.DocMgr.CanNavigatePrev()) return True else: return False