[GRASS-SVN] r42257 - grass/trunk/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sat May 15 07:57:12 EDT 2010


Author: martinl
Date: 2010-05-15 07:57:10 -0400 (Sat, 15 May 2010)
New Revision: 42257

Modified:
   grass/trunk/gui/wxpython/gui_modules/gdialogs.py
   grass/trunk/gui/wxpython/gui_modules/ghelp.py
   grass/trunk/gui/wxpython/gui_modules/menuform.py
Log:
wxGUI: track history of open manual pages


Modified: grass/trunk/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gdialogs.py	2010-05-15 10:51:50 UTC (rev 42256)
+++ grass/trunk/gui/wxpython/gui_modules/gdialogs.py	2010-05-15 11:57:10 UTC (rev 42257)
@@ -1455,3 +1455,35 @@
                        'ext'  : 'xpm' })
     
     return filetype, ltype
+
+class StaticWrapText(wx.StaticText):
+    """! A Static Text field that wraps its text to fit its width,
+    enlarging its height if necessary.
+    """
+    def __init__(self, parent, id = wx.ID_ANY, label = '', *args, **kwds):
+        self.parent        = parent
+        self.originalLabel = label
+        
+        wx.StaticText.__init__(self, parent, id, label = '', *args, **kwds)
+        
+        self.SetLabel(label)
+        self.Bind(wx.EVT_SIZE, self.OnResize)
+    
+    def SetLabel(self, label):
+        self.originalLabel = label
+        self.wrappedSize = None
+        self.OnResize(None)
+
+    def OnResize(self, event):
+        if not getattr(self, "resizing", False):
+            self.resizing = True
+            newSize = wx.Size(self.parent.GetSize().width,
+                              self.GetSize().height)
+            if self.wrappedSize != newSize:
+                wx.StaticText.SetLabel(self, self.originalLabel)
+                self.Wrap(newSize.width)
+                self.wrappedSize = newSize
+                
+                self.SetSize(self.wrappedSize)
+            del self.resizing
+

Modified: grass/trunk/gui/wxpython/gui_modules/ghelp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/ghelp.py	2010-05-15 10:51:50 UTC (rev 42256)
+++ grass/trunk/gui/wxpython/gui_modules/ghelp.py	2010-05-15 11:57:10 UTC (rev 42257)
@@ -12,6 +12,8 @@
  - AboutWindow
  - InstallExtensionWindow
  - ExtensionTree
+ - ManualWindow
+ - ManualPanel
 
 (C) 2008-2010 by the GRASS Development Team
 This program is free software under the GNU General Public License
@@ -35,31 +37,23 @@
 import menudata
 import gcmd
 import globalvar
-import menuform
+import gdialogs
 
 class HelpWindow(wx.Frame):
     """!GRASS Quickstart help window"""
     def __init__(self, parent, id, title, size, file):
-
         wx.Frame.__init__(self, parent=parent, id=id, title=title, size=size)
-
+        
         sizer = wx.BoxSizer(wx.VERTICAL)
-
+        
         # text
-        helpFrame = wx.html.HtmlWindow(parent=self, id=wx.ID_ANY)
-        helpFrame.SetStandardFonts (size = 10)
-        helpFrame.SetBorders(10)
-        wx.InitAllImageHandlers()
-
-        helpFrame.LoadFile(file)
-        self.Ok = True
-
-        sizer.Add(item=helpFrame, proportion=1, flag=wx.EXPAND)
-
+        content = ManualPanel(parent = self)
+        content.LoadPage(file)
+        
+        sizer.Add(item = content, proportion=1, flag=wx.EXPAND)
+        
         self.SetAutoLayout(True)
         self.SetSizer(sizer)
-        #        sizer.Fit(self)
-        #        sizer.SetSizeHints(self)
         self.Layout()
 
 class SearchModuleWindow(wx.Panel):
@@ -91,8 +85,8 @@
         self.search.Bind(wx.EVT_TEXT, self.OnSearchModule)
         
         if self.showTip:
-            self.searchTip  = menuform.StaticWrapText(parent = self, id = wx.ID_ANY,
-                                                      size = (-1, 35))
+            self.searchTip = gdialogs.StaticWrapText(parent = self, id = wx.ID_ANY,
+                                                     size = (-1, 35))
         
         if self.showChoice:
             self.searchChoice = wx.Choice(parent = self, id = wx.ID_ANY)
@@ -1012,3 +1006,180 @@
     def IsLoaded(self):
         """Check if items are loaded"""
         return self._loaded
+
+class ManualWindow(wx.html.HtmlWindow):
+    """!This panel holds the text from GRASS docs.
+    
+    GISBASE must be set in the environment to find the html docs dir.
+    The SYNOPSIS section is skipped, since this Panel is supposed to
+    be integrated into the cmdPanel and options are obvious there.
+    """
+    def __init__(self, parent, grass_command, text, skip_description,
+                 **kwargs):
+        """!If grass_command is given, the corresponding HTML help
+        file will be presented, with all links pointing to absolute
+        paths of local files.
+
+        If 'skip_description' is True, the HTML corresponding to
+        SYNOPSIS will be skipped, thus only presenting the help file
+        from the DESCRIPTION section onwards.
+
+        If 'text' is given, it must be the HTML text to be presented
+        in the Panel.
+        """
+        self.parent = parent
+        wx.InitAllImageHandlers()
+        wx.html.HtmlWindow.__init__(self, parent = parent, **kwargs)
+        
+        gisbase = os.getenv("GISBASE")
+        self.loaded = False
+        self.history = list()
+        self.historyIdx = 0
+        self.fspath = os.path.join(gisbase, "docs", "html")
+        
+        self.SetStandardFonts (size = 10)
+        self.SetBorders(10)
+        
+        if text is None:
+            if skip_description:
+                url = os.path.join(self.fspath, grass_command + ".html")
+                self.fillContentsFromFile(url,
+                                          skip_description = skip_description)
+                self.history.append(url)
+                self.loaded = True
+            else:
+                ### FIXME: calling LoadPage() is strangely time-consuming (only first call)
+                # self.LoadPage(self.fspath + grass_command + ".html")
+                self.loaded = False
+        else:
+            self.SetPage(text)
+            self.loaded = True
+        
+    def OnLinkClicked(self, linkinfo):
+        url = linkinfo.GetHref()
+        if url[:4] != 'http':
+            url = os.path.join(self.fspath, url)
+        self.history.append(url)
+        self.historyIdx += 1
+        self.parent.OnHistory()
+        
+        super(ManualWindow, self).OnLinkClicked(linkinfo)
+        
+    def fillContentsFromFile(self, htmlFile, skip_description=True):
+        """!Load content from file"""
+        aLink = re.compile(r'(<a href="?)(.+\.html?["\s]*>)', re.IGNORECASE)
+        imgLink = re.compile(r'(<img src="?)(.+\.[png|gif])', re.IGNORECASE)
+        try:
+            contents = []
+            skip = False
+            for l in file(htmlFile, "rb").readlines():
+                if "DESCRIPTION" in l:
+                    skip = False
+                if not skip:
+                    # do skip the options description if requested
+                    if "SYNOPSIS" in l:
+                        skip = skip_description
+                    else:
+                        # FIXME: find only first item
+                        findALink = aLink.search(l)
+                        if findALink is not None: 
+                            contents.append(aLink.sub(findALink.group(1)+
+                                                      self.fspath+findALink.group(2),l))
+                        findImgLink = imgLink.search(l)
+                        if findImgLink is not None: 
+                            contents.append(imgLink.sub(findImgLink.group(1)+
+                                                        self.fspath+findImgLink.group(2),l))
+                        
+                        if findALink is None and findImgLink is None:
+                            contents.append(l)
+            self.SetPage("".join(contents))
+            self.loaded = True
+        except: # The Manual file was not found
+            self.loaded = False
+        
+class ManualPanel(wx.Panel):
+    def __init__(self, parent, grass_command = "index", text = None,
+                 skip_description = False, **kwargs):
+        self.grass_command = grass_command
+        wx.Panel.__init__(self, parent = parent, id = wx.ID_ANY)
+        
+        self.content = ManualWindow(self, grass_command, text,
+                                    skip_description)
+        
+        self.btnNext = wx.Button(parent = self, id = wx.ID_ANY,
+                                 label = _("&Next"))
+        self.btnNext.Enable(False)
+        self.btnPrev = wx.Button(parent = self, id = wx.ID_ANY,
+                                 label = _("&Previous"))
+        self.btnPrev.Enable(False)
+        
+        self.btnNext.Bind(wx.EVT_BUTTON, self.OnNext)
+        self.btnPrev.Bind(wx.EVT_BUTTON, self.OnPrev)
+        
+        self._layout()
+
+    def _layout(self):
+        """!Do layout"""
+        sizer = wx.BoxSizer(wx.VERTICAL)
+        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
+        
+        btnSizer.Add(item = self.btnPrev, proportion = 0,
+                     flag = wx.ALL, border = 5)
+        btnSizer.Add(item = wx.Size(1, 1), proportion = 1)
+        btnSizer.Add(item = self.btnNext, proportion = 0,
+                     flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
+        
+        sizer.Add(item = self.content, proportion = 1,
+                  flag = wx.EXPAND)
+        sizer.Add(item = btnSizer, proportion = 0,
+                  flag = wx.EXPAND)
+        
+        self.SetSizer(sizer)
+        sizer.Fit(self)
+
+    def LoadPage(self, path = None):
+        """!Load page"""
+        if not path:
+            path = os.path.join(self.content.fspath, self.grass_command + ".html")
+        self.content.history.append(path)
+        self.content.LoadPage(path)
+        
+    def IsFile(self):
+        """!Check if file exists"""
+        return os.path.isfile(os.path.join(self.content.fspath, self.grass_command + ".html"))
+
+    def IsLoaded(self):
+        return self.content.loaded
+
+    def OnHistory(self):
+        """!Update buttons"""
+        nH = len(self.content.history)
+        iH = self.content.historyIdx
+        if iH == nH - 1:
+            self.btnNext.Enable(False)
+        elif iH > -1:
+            self.btnNext.Enable(True)
+        if iH < 1:
+            self.btnPrev.Enable(False)
+        else:
+            self.btnPrev.Enable(True)
+
+    def OnNext(self, event):
+        """Load next page"""
+        self.content.historyIdx += 1
+        idx = self.content.historyIdx
+        path = self.content.history[idx]
+        self.content.LoadPage(path)
+        self.OnHistory()
+        
+        event.Skip()
+        
+    def OnPrev(self, event):
+        """Load previous page"""
+        self.content.historyIdx -= 1
+        idx = self.content.historyIdx
+        path = self.content.history[idx]
+        self.content.LoadPage(path)
+        self.OnHistory()
+        
+        event.Skip()

Modified: grass/trunk/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/menuform.py	2010-05-15 10:51:50 UTC (rev 42256)
+++ grass/trunk/gui/wxpython/gui_modules/menuform.py	2010-05-15 11:57:10 UTC (rev 42257)
@@ -32,7 +32,7 @@
 @todo
  - verify option value types
 
-Copyright (C) 2000-2019 by the GRASS Development Team
+Copyright (C) 2000-2010 by the GRASS Development Team
 This program is free software under the GPL (>=v2) Read the file
 COPYING coming with GRASS for details.
 
@@ -83,7 +83,8 @@
 except ImportError:
     import elementtree.ElementTree as etree # Python <= 2.4
 
-import utils
+import gdialogs
+from ghelp import ManualPanel
 
 gisbase = os.getenv("GISBASE")
 if gisbase is None:
@@ -601,79 +602,7 @@
         """!Get grassTask instance"""
         return self.task
     
-class helpPanel(wx.html.HtmlWindow):
-    """
-    This panel holds the text from GRASS docs.
-
-    GISBASE must be set in the environment to find the html docs dir.
-    The SYNOPSIS section is skipped, since this Panel is supposed to
-    be integrated into the cmdPanel and options are obvious there.
-    """
-    def __init__(self, grass_command = "index", text = None,
-                 skip_description=False, *args, **kwargs):
-        """ If grass_command is given, the corresponding HTML help file will
-        be presented, with all links pointing to absolute paths of
-        local files.
-
-        If 'skip_description' is True, the HTML corresponding to
-        SYNOPSIS will be skipped, thus only presenting the help file
-        from the DESCRIPTION section onwards.
-
-        If 'text' is given, it must be the HTML text to be presented in the Panel.
-        """
-
-        wx.html.HtmlWindow.__init__(self, *args, **kwargs)
-        self.fspath = gisbase + "/docs/html/"
-
-        self.SetStandardFonts ( size = 10 )
-        self.SetBorders(10)
-        wx.InitAllImageHandlers()
-
-        if text is None:
-            if skip_description:
-                self.fillContentsFromFile ( self.fspath + grass_command + ".html",
-                                            skip_description=skip_description )
-                self.Ok = True
-            else:
-                ### FIXME: calling LoadPage() is strangely time-consuming (only first call)
-                # self.LoadPage(self.fspath + grass_command + ".html")
-                self.Ok = False
-        else:
-            self.SetPage( text )
-            self.Ok = True
-
-    def fillContentsFromFile( self, htmlFile, skip_description=True ):
-        aLink = re.compile( r'(<a href="?)(.+\.html?["\s]*>)', re.IGNORECASE )
-        imgLink = re.compile( r'(<img src="?)(.+\.[png|gif])', re.IGNORECASE )
-        try:
-            # contents = [ '<head><base href="%s"></head>' % self.fspath ]
-            contents = []
-            skip = False
-            for l in file( htmlFile, "rb" ).readlines():
-                if "DESCRIPTION" in l:
-                    skip = False
-                if not skip:
-                    # do skip the options description if requested
-                    if "SYNOPSIS" in l:
-                        skip = skip_description
-                    else:
-                        # FIXME: find only first item
-                        findALink = aLink.search( l )
-                        if findALink is not None: 
-                            contents.append( aLink.sub(findALink.group(1)+
-                                                           self.fspath+findALink.group(2),l) )
-                        findImgLink = imgLink.search( l )
-                        if findImgLink is not None: 
-                            contents.append( imgLink.sub(findImgLink.group(1)+
-                                                         self.fspath+findImgLink.group(2),l) )
-        
-                        if findALink is None and findImgLink is None:
-                            contents.append( l )
-            self.SetPage( "".join( contents ) )
-            self.Ok = True
-        except: # The Manual file was not found
-            self.Ok = False
-
+    
 class mainFrame(wx.Frame):
     """!This is the Frame containing the dialog for options input.
 
@@ -745,8 +674,8 @@
             module_desc = self.task.label + ' ' + self.task.description
         else:
             module_desc = self.task.description
-        self.description = StaticWrapText (parent=self.panel,
-                                           label=module_desc)
+        self.description = gdialogs.StaticWrapText(parent=self.panel,
+                                                   label=module_desc)
         topsizer.Add (item=self.description, proportion=1, border=5,
                       flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
                       
@@ -1105,9 +1034,8 @@
             self.goutput = None
             self.goutputId = -1
         
-        self.manual_tab = helpPanel(parent = self.notebook, grass_command = self.task.name)
-        self.manual_tabsizer = wx.BoxSizer(wx.VERTICAL)
-        if not os.path.isfile(self.manual_tab.fspath + self.task.name + ".html"):
+        self.manual_tab = ManualPanel(parent = self, grass_command = self.task.name)
+        if not self.manual_tab.IsFile():
             self.manual_tab.Hide()
         else:
             self.notebook.AddPage(self.manual_tab, text=_("Manual"))
@@ -1700,10 +1628,9 @@
             tab[section].SetMinSize( (self.constrained_size[0], self.panelMinHeight) )
             # tab[section].SetMinSize( constrained_size )
 
-        if self.manual_tab.Ok:
+        if self.manual_tab.IsLoaded():
             self.manual_tab.SetMinSize( (self.constrained_size[0], self.panelMinHeight) )
-            # manual_tab.SetMinSize( constrained_size )
-
+        
         self.SetSizer( panelsizer )
         panelsizer.Fit(self.notebook)
 
@@ -1800,10 +1727,9 @@
                 sel == self.manual_tab_id:
             # calling LoadPage() is strangely time-consuming (only first call)
             # FIXME: move to helpPage.__init__()
-            if not self.manual_tab.Ok:
+            if not self.manual_tab.IsLoaded():
                 wx.Yield()
-                self.manual_tab.LoadPage(self.manual_tab.fspath + self.task.name + ".html")
-                self.manual_tab.Ok = True
+                self.manual_tab.LoadPage()
 
         self.Layout()
 
@@ -2130,37 +2056,6 @@
                         return p.get('name', None)
         return None
 
-class StaticWrapText(wx.StaticText):
-    """! A Static Text field that wraps its text to fit its width,
-    enlarging its height if necessary.
-    """
-    def __init__(self, parent, id = wx.ID_ANY, label = '', *args, **kwds):
-        self.parent        = parent
-        self.originalLabel = label
-        
-        wx.StaticText.__init__(self, parent, id, label = '', *args, **kwds)
-        
-        self.SetLabel(label)
-        self.Bind(wx.EVT_SIZE, self.OnResize)
-    
-    def SetLabel(self, label):
-        self.originalLabel = label
-        self.wrappedSize = None
-        self.OnResize(None)
-
-    def OnResize(self, event):
-        if not getattr(self, "resizing", False):
-            self.resizing = True
-            newSize = wx.Size(self.parent.GetSize().width,
-                              self.GetSize().height)
-            if self.wrappedSize != newSize:
-                wx.StaticText.SetLabel(self, self.originalLabel)
-                self.Wrap(newSize.width)
-                self.wrappedSize = newSize
-                
-                self.SetSize(self.wrappedSize)
-            del self.resizing
-
 if __name__ == "__main__":
 
     if len(sys.argv) == 1:



More information about the grass-commit mailing list