Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: /leo/plugins/nav_buttons.py

leo
Discussion topic

Hide all messages in topic

All messages in topic

CVS update: /leo/plugins/nav_buttons.py

Author plumloco
Full name Robert Ledger
Date 2008-01-07 03:59:47 PST
Message User: plumloco
Date: 2008-01-07 03:59:47-0800
Log:
 fixed to work in multiple gui environment

File Changes:

Directory: /leo/plugins/
========================

File [changed]: nav_buttons.py
Url: http://leo.tigris.or​g/source/browse/leo/​plugins/nav_buttons.​py?r1=1.9&r2=1.1​0
Delta lines: +408 -359
-----------------------
--- nav_buttons.py 2007-12-19 06:44:53-0800 1.9
+++ nav_buttons.py 2008-01-07 03:59:44-0800 1.10
@@ -1,6 +1,25 @@
 #@+leo-ver=4-thin
 #@+node:edream.11020​3113231.758:@thin nav_buttons.py
-"""Adds navigation buttons to icon bar"""
+#@<< docstring >>
+#@+node:bob.2008010​3150617:<< docstring >>
+"""Adds navigation buttons to icon bar
+
+This plugin supplies the gui components for the tkinter gui.
+
+Any non-tkinter gui's wishing to support this plugin should supply:
+
+ a marksDialog class as g.app.gui.marksDialog
+ a recentSectionsDialog class as g.app.gui.recentSectionsDialog
+
+Obviously these classes should mimic the behaviour of the Tk classes for
+the relevant gui.
+
+The dialogs will be automatically detected by the plugin and used if supplied.
+
+
+"""
+#@-node:bob.2008010​3150617:<< docstring >>
+#@nl
 
 #@@language python
 #@@tabwidth -4
@@ -11,16 +30,11 @@
 import leoGlobals as g
 import leoPlugins
 
-from leoTkinterDialog import tkinterListBoxDialog
-
-try: import Tkinter as Tk
-except ImportError: Tk = None
-
 import os
 #@nonl
 #@-node:ekr.20050219​114353:<< imports >>
 #@nl
-__version__ = "1.6"
+__version__ = "1.7"
 #@<< version history >>
 #@+node:ekr.20050219​114353.1:<< version history >>
 #@@killcolor
@@ -47,6 +61,7 @@
 # 1.5 EKR: Fixed crasher in tkinterListBoxDialog.go().
 # updateMarks must set positionList ivar in the base class.
 # 1.6 EKR: Use c.nodeHistory methods instead of raw ivars of the commander.
+# 1.7 plumloco: Modified to be gui-independant.
 #@-at
 #@-node:ekr.20050219​114353.1:<< version history >>
 #@nl
@@ -57,49 +72,43 @@
 #@+others
 #@+node:ekr.20050219​114353.2:init
 def init ():
+ global Tk, imageClass
 
- if Tk is None: return False
+ imageClass = lambda : None
+ Tk = None
 
     if g.app.gui is None:
- g.app.createTkGui(__file__)
-
- ok = g.app.gui.guiName() == "tkinter"
-
- # print 'navButtons:init','o​k',ok,g.app.gui.guiN​ame()
 
- if ok:
- leoPlugins.registerH​andler('after-create​-leo-frame',onCreate​)
- g.plugin_signon(__name__)
+ g.app.createTkGui(__file__)
 
- return ok
-#@-node:ekr.2005021​9114353.2:init
-#@+node:ekr.2005021​9115116:onCreate
-def onCreate (tag,keywords):
+ if g.app.gui.guiName() != "tkinter":
+ return False
 
- # Not ok for unit testing: can't use unitTestGui.
- if g.app.unitTesting or g.app.gui.guiName() != 'tkinter':
- return
+ if g.app.gui.guiName() == 'tkinter':
 
- c = keywords.get("c")
- r = leoPlugins.registerHandler
+ try:
+ import Tkinter as Tk
+ from leoTkinterDialog import tkinterListBoxDialog
 
- images = imageClass()
+ except ImportError:
+ Tk = None
 
- # Create the marks dialog and hooks.
- marks = marksDialog(c,images)
- r(('open2','new2','s​et-mark','clear-mark​'),marks.updateMarks​)
+ if Tk is None:
+ return False
 
- # Create the recent nodes dialog.
- recent = recentSectionsDialog(c,images)
- r(('open2','new2','s​elect2'),recent.upda​teRecent)
-#@-node:ekr.2005021​9115116:onCreate
-#@+node:ekr.2005021​9115859:class imageClass
-class imageClass:
+ #@ << define Tk dialog classes >>
+ #@+node:bob.20080103​142149:<< define Tk dialog classes >>
+ #@+others
+ #@+node:ekr.20050219​115859:class imageClass
+ class imageClass:
 
     #@ @+others
     #@+node:ekr.20050219​115859.1:ctor
     def __init__ (self):
 
+ if not Tk:
+ return
+
         self.path = g.os_path_join(g.app​.loadDir,'..','Icons​')
 
         # Create images and set ivars.
@@ -111,7 +120,6 @@
         ):
             image = self.createImage(icon)
             setattr(self,ivar,image)
- #@nonl
     #@-node:ekr.20050219​115859.1:ctor
     #@+node:ekr.20050219​115859.2:createImage​
     def createImage (self,iconName):
@@ -128,10 +136,10 @@
     #@nonl
     #@-node:ekr.20050219​115859.2:createImage​
     #@-others
-#@nonl
-#@-node:ekr.2005021​9115859:class imageClass
-#@+node:edream.1102​03113231.775:class marksDialog (listBoxDialog)
-class marksDialog (tkinterListBoxDialog):
+ #@nonl
+ #@-node:ekr.20050219​115859:class imageClass
+ #@+node:edream.11020​3113231.775:class marksDialog (listBoxDialog)
+ class marksDialog (tkinterListBoxDialog):
 
     """A class to create the marks dialog"""
 
@@ -204,10 +212,10 @@
     #@nonl
     #@-node:edream.11020​3113231.779:updateMa​rks
     #@-others
-#@nonl
-#@-node:edream.1102​03113231.775:class marksDialog (listBoxDialog)
-#@+node:edream.1102​03113231.780:class recentSectionsDialog (tkinterListBoxDialog)
-class recentSectionsDialog (tkinterListBoxDialog):
+ #@nonl
+ #@-node:edream.11020​3113231.775:class marksDialog (listBoxDialog)
+ #@+node:edream.11020​3113231.780:class recentSectionsDialog (tkinterListBoxDialog)
+ class recentSectionsDialog (tkinterListBoxDialog):
 
     """A class to create the recent sections dialog"""
 
@@ -443,8 +451,49 @@
     #@nonl
     #@-node:ekr.20050219​162434:updateRecent
     #@-others
-#@nonl
-#@-node:edream.1102​03113231.780:class recentSectionsDialog (tkinterListBoxDialog)
+ #@nonl
+ #@-node:edream.11020​3113231.780:class recentSectionsDialog (tkinterListBoxDialog)
+ #@-others
+ #@-node:bob.20080103​142149:<< define Tk dialog classes >>
+ #@nl
+
+ g.app.gui.marksDialog = marksDialog
+ g.app.gui.recentSectionsDialog = recentSectionsDialog
+
+ # print 'navButtons:init','o​k',ok,g.app.gui.guiN​ame()
+
+ leoPlugins.registerH​andler('after-create​-leo-frame',onCreate​)
+ g.plugin_signon(__name__)
+
+ return True
+
+#@-node:ekr.2005021​9114353.2:init
+#@+node:ekr.2005021​9115116:onCreate
+def onCreate (tag,keywords):
+
+ # Not ok for unit testing: can't use unitTestGui.
+ if g.app.unitTesting:
+ return
+
+ c = keywords.get("c")
+ r = leoPlugins.registerHandler
+
+ images = imageClass()
+
+ # Create the marks dialog and hooks.
+ try:
+ marks = g.app.gui.marksDialog(c,images)
+ r(('open2','new2','s​et-mark','clear-mark​'),marks.updateMarks​)
+ except:
+ pass
+
+ # Create the recent nodes dialog.
+ try:
+ recent = g.app.gui.recentSect​ionsDialog(c,images)​
+ r(('open2','new2','s​elect2'),recent.upda​teRecent)
+ except:
+ pass
+#@-node:ekr.2005021​9115116:onCreate
 #@-others
 #@nonl
 #@-node:edream.11020​3113231.758:@thin nav_buttons.py
Messages per page: