# Module `Gnumed.wxpython.gui.gmManual`

GNUMed manuals in a HTML browser window

A very basic HTML browser with back/forward history buttons with the main pourpose of browsing the gnumed manuals The manuals should reside where the manual_path points to.

@copyright: GPL v2 or later @thanks: this code has been heavily "borrowed" from Robin Dunn's extraordinary wxPython sample

## Classes

`class ManualHtmlPanel (parent, frame)`
  Expand source code

      class ManualHtmlPanel(wx.Panel):
              def __init__(self, parent, frame):
                      wx.Panel.__init__(self, parent, -1)
                      self.frame = frame

                      # get base directory for manuals from broker
                      paths = gmTools.gmPaths(app_name = 'gnumed', wx = wx)
                      candidates = [
                              os.path.join(paths.local_base_dir, 'doc', 'user-manual'),
                              '/usr/share/doc/gnumed/user-manual/',
                              os.path.join(paths.system_app_data_dir, 'doc', 'user-manual')
                      ]
                      for self.docdir in candidates:
                              if os.access(self.docdir, os.R_OK):
                                      _log.info('found Manual path [%s]', self.docdir)
                                      break

                      self.box = wx.BoxSizer(wx.VERTICAL)

                      infobox = wx.BoxSizer(wx.HORIZONTAL)
                      n = wx.NewId()
                      self.infoline = wx.TextCtrl(self, n, style=wx.TE_READONLY)
                      self.infoline.SetBackgroundColour(wx.LIGHT_GREY)
                      infobox.Add(self.infoline, 1, wx.GROW|wx.ALL)
                      self.box.Add(infobox, 0, wx.GROW)

                      self.html = ManualHtmlWindow(self, -1)
                      self.html.SetRelatedFrame(frame, "")
                      self.html.SetRelatedStatusBar(0)
                      self.box.Add(self.html, 1, wx.GROW)

                      self.SetSizer(self.box)
                      self.SetAutoLayout(True)

                      self.already_loaded = None
              #--------------------------------------------------------
              def FirstLoad(self):
                      if not self.already_loaded:
                              self.already_loaded = 1
                              self.OnShowDefault(None)
              #--------------------------------------------------------
              def ShowTitle(self, title=''):
                      self.infoline.Clear()
                      self.infoline.WriteText(title)
              #--------------------------------------------------------
              def OnShowDefault(self, event):
                      name = os.path.join(self.docdir, 'index.html')
                      if os.access (name, os.F_OK):
                              self.html.LoadPage(name)
                      else:
                              _log.error("cannot load local document %s", name)
                              self.html.LoadPage('https://www.gnumed.de/documentation/')
              #--------------------------------------------------------
              def OnLoadFile(self, event):
                      dlg = wx.FileDialog(self, wildcard = '*.htm*', style=wx.FD_OPEN)
                      if dlg.ShowModal():
                              path = dlg.GetPath()
                              self.html.LoadPage(path)
                      dlg.DestroyLater()
              #--------------------------------------------------------
              def OnBack(self, event):
                      self.html.HistoryBack()
              #--------------------------------------------------------
              def OnForward(self, event):
                      self.html.HistoryForward()
              #--------------------------------------------------------
              def OnViewSource(self, event):
                      return 1
                      # FIXME:
                      #from wxPython.lib.dialogs import wx.ScrolledMessageDialog
                      source = self.html.GetParser().GetSource()
                      dlg = wx.ScrolledMessageDialog(self, source, _('HTML Source'))
                      dlg.ShowModal()
                      dlg.DestroyLater()
              #--------------------------------------------------------
              def OnPrint(self, event):
                      self.printer.PrintFile(self.html.GetOpenedPage())

  Panel() Panel(parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, style=TAB_TRAVERSAL, name=PanelNameStr)

  A panel is a window on which controls are placed.

  ### Ancestors

  - wx._core.Panel
  - wx._core.Window
  - wx._core.WindowBase
  - wx._core.EvtHandler
  - wx._core.Object
  - wx._core.Trackable
  - sip.wrapper
  - sip.simplewrapper

  ### Methods

  `def FirstLoad(self)`
    Expand source code

        def FirstLoad(self):
                if not self.already_loaded:
                        self.already_loaded = 1
                        self.OnShowDefault(None)

  `def OnBack(self, event)`
    Expand source code

        def OnBack(self, event):
                self.html.HistoryBack()

  `def OnForward(self, event)`
    Expand source code

        def OnForward(self, event):
                self.html.HistoryForward()

  `def OnLoadFile(self, event)`
    Expand source code

        def OnLoadFile(self, event):
                dlg = wx.FileDialog(self, wildcard = '*.htm*', style=wx.FD_OPEN)
                if dlg.ShowModal():
                        path = dlg.GetPath()
                        self.html.LoadPage(path)
                dlg.DestroyLater()

  `def OnPrint(self, event)`
    Expand source code

        def OnPrint(self, event):
                self.printer.PrintFile(self.html.GetOpenedPage())

  `def OnShowDefault(self, event)`
    Expand source code

        def OnShowDefault(self, event):
                name = os.path.join(self.docdir, 'index.html')
                if os.access (name, os.F_OK):
                        self.html.LoadPage(name)
                else:
                        _log.error("cannot load local document %s", name)
                        self.html.LoadPage('https://www.gnumed.de/documentation/')

  `def OnViewSource(self, event)`
    Expand source code

        def OnViewSource(self, event):
                return 1
                # FIXME:
                #from wxPython.lib.dialogs import wx.ScrolledMessageDialog
                source = self.html.GetParser().GetSource()
                dlg = wx.ScrolledMessageDialog(self, source, _('HTML Source'))
                dlg.ShowModal()
                dlg.DestroyLater()

  `def ShowTitle(self, title='')`
    Expand source code

        def ShowTitle(self, title=''):
                self.infoline.Clear()
                self.infoline.WriteText(title)

`class ManualHtmlWindow (parent, id)`
  Expand source code

      class ManualHtmlWindow(wx.html.HtmlWindow):
              def __init__(self, parent, id):
                      wx.html.HtmlWindow.__init__(self, parent, id)
                      self.parent = parent

              def OnSetTitle(self, title=''):
                      self.parent.ShowTitle(title)

  HtmlWindow() HtmlWindow(parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize, style=HW_DEFAULT_STYLE, name="htmlWindow")

  wxHtmlWindow is probably the only class you will directly use unless you want to do something special (like adding new tag handlers or MIME filters).

  ### Ancestors

  - wx._html.HtmlWindow
  - wx._core.ScrolledWindow
  - wx._core._ScrolledWindowBase
  - wx._core.Panel
  - wx._core.Window
  - wx._core.WindowBase
  - wx._core.EvtHandler
  - wx._core.Object
  - wx._core.Trackable
  - wx._html.HtmlWindowInterface
  - sip.wrapper
  - sip.simplewrapper

  ### Methods

  `def OnSetTitle(self, title='')`
    Expand source code

        def OnSetTitle(self, title=''):
                self.parent.ShowTitle(title)

    OnSetTitle(title)

    Called on parsing tag.</p></div> </dd> </dl> </dd> <dt id="Gnumed.wxpython.gui.gmManual.gmManual"><code class="flex name class"> <span>class <span class="ident">gmManual</span></span> </code></dt> <dd> <details class="source"> <summary> <span>Expand source code</span> </summary> <pre><code class="python">class gmManual (gmPlugin.cNotebookPlugin): """Plugin to encapsulate the manual window.""" tab_name = _('Manual') #-------------------------------------------------------- def name (self): return gmManual.tab_name #-------------------------------------------------------- def GetWidget (self, parent): #self._widget = ManualHtmlPanel (parent, ...) self._widget = wx.Panel(parent, -1) return self._widget #-------------------------------------------------------- def MenuInfo (self): return ('help', _('User &manual (local)')) #-------------------------------------------------------- def receive_focus(self): self._widget.FirstLoad() return True #-------------------------------------------------------- def can_receive_focus(self): return True #-------------------------------------------------------- #def populate_toolbar (self, tb, widget): #tool1 = tb.AddTool( # ID_MANUALCONTENTS, # images_for_gnumed_browser16_16.getcontentsBitmap(), # shortHelpString=_("GNUmed manual contents"), # isToggle=False #) #wx.EVT_TOOL (tb, ID_MANUALCONTENTS, widget.OnShowDefault) # tool1 = tb.AddTool( # ID_MANUALOPENFILE, # images_for_gnumed_browser16_16.getfileopenBitmap(), # shortHelpString="Open File", # isToggle=True # ) # wx.EVT_TOOL (tb, ID_MANUALOPENFILE, widget.OnLoadFile) #tool1 = tb.AddTool( # ID_MANUALBACK, # images_for_gnumed_browser16_16.get1leftarrowBitmap(), # shortHelpString=_("Back"), # isToggle=False #) #wx.EVT_TOOL (tb, ID_MANUALBACK, widget.OnBack) #tool1 = tb.AddTool( # ID_MANUALFORWARD, # images_for_gnumed_browser16_16.get1rightarrowBitmap(), # shortHelpString=_("Forward"), # isToggle=False #) #wx.EVT_TOOL (tb, ID_MANUALFORWARD, widget.OnForward) # #tool1 = tb.AddTool( # # ID_MANUALRELOAD, # # images_for_gnumed_browser16_16.getreloadBitmap(), # # shortHelpString=_("Reload"), # # isToggle=True # #) # #tb.AddSeparator() # #tool1 = tb.AddTool( # # ID_MANUALHOME, # # images_for_gnumed_browser16_16.getgohomeBitmap(), # # shortHelpString=_("Home"), # # isToggle=True # #) # #wx.EVT_TOOL (tb, ID_MANUALHOME, widget.OnShowDefault) # #tb.AddSeparator() # #tool1 = tb.AddTool( # # ID_MANUALBABELFISH, # # images_for_gnumed_browser16_16.getbabelfishBitmap(), # # shortHelpString=_("Translate text"), # # isToggle=False # #) # #wx.EVT_TOOL (tb, ID_MANUALBABELFISH, widget.OnBabelFish ) # #tb.AddSeparator() # #tool1 = tb.AddTool( # # ID_MANUALBOOKMARKS, # # images_for_gnumed_browser16_16.getbookmarkBitmap(), # # shortHelpString=_("Bookmarks"), # # isToggle=True # #) # #wx.EVT_TOOL (tb, ID_MANUALBOOKMARKS, widget.OnBookmarks) # #tool1 = tb.AddTool( # # ID_MANUALADDBOOKMARK, # # images_for_gnumed_browser16_16.getbookmark_addBitmap(), # # shortHelpString=_("Add Bookmark"), # # isToggle=True # #) # #wx.EVT_TOOL (tb, ID_MANUALADDBOOKMARK, widget.OnAddBookmark) # tool1 = tb.AddTool( # ID_VIEWSOURCE, # images_for_gnumed_browser16_16.getviewsourceBitmap(), # shortHelpString="View Source", # isToggle=True # ) # wx.EVT_TOOL (tb, ID_VIEWSOURCE, widget.OnViewSource) #tool1 = tb.AddTool( # ID_MANUALPRINTER, # images_for_gnumed_browser16_16.getprinterBitmap(), # shortHelpString = _("Print manual page"), # isToggle=False #) #wx.EVT_TOOL (tb, ID_MANUALPRINTER, widget.OnPrint) </code></pre> </details> <div class="desc"><p>Plugin to encapsulate the manual window.</p></div> <h3>Ancestors</h3> <ul class="hlist"> <li><a title="Gnumed.wxpython.gmPlugin.cNotebookPlugin" href="gmPlugin.html#Gnumed.wxpython.gmPlugin.cNotebookPlugin">cNotebookPlugin</a></li> </ul> <h3>Class variables</h3> <dl> <dt id="Gnumed.wxpython.gui.gmManual.gmManual.tab_name"><code class="name">var <span class="ident">tab_name</span></code></dt> <dd> <div class="desc"></div> </dd> </dl> <h3>Methods</h3> <dl> <dt id="Gnumed.wxpython.gui.gmManual.gmManual.GetWidget"><code class="name flex"> <span>def <span class="ident">GetWidget</span></span>(<span>self, parent)</span> </code></dt> <dd> <details class="source"> <summary> <span>Expand source code</span> </summary> <pre><code class="python">def GetWidget (self, parent): #self._widget = ManualHtmlPanel (parent, ...) self._widget = wx.Panel(parent, -1) return self._widget</code></pre> </details> <div class="desc"></div> </dd> <dt id="Gnumed.wxpython.gui.gmManual.gmManual.name"><code class="name flex"> <span>def <span class="ident">name</span></span>(<span>self)</span> </code></dt> <dd> <details class="source"> <summary> <span>Expand source code</span> </summary> <pre><code class="python">def name (self): return gmManual.tab_name</code></pre> </details> <div class="desc"></div> </dd> </dl> <h3>Inherited members</h3> <ul class="hlist"> <li><code><b><a title="Gnumed.wxpython.gmPlugin.cNotebookPlugin" href="gmPlugin.html#Gnumed.wxpython.gmPlugin.cNotebookPlugin">cNotebookPlugin</a></b></code>: <ul class="hlist"> <li><code><a title="Gnumed.wxpython.gmPlugin.cNotebookPlugin.MenuInfo" href="gmPlugin.html#Gnumed.wxpython.gmPlugin.cNotebookPlugin.MenuInfo">MenuInfo</a></code></li> <li><code><a title="Gnumed.wxpython.gmPlugin.cNotebookPlugin.Raise" href="gmPlugin.html#Gnumed.wxpython.gmPlugin.cNotebookPlugin.Raise">Raise</a></code></li> <li><code><a title="Gnumed.wxpython.gmPlugin.cNotebookPlugin.can_receive_focus" href="gmPlugin.html#Gnumed.wxpython.gmPlugin.cNotebookPlugin.can_receive_focus">can_receive_focus</a></code></li> <li><code><a title="Gnumed.wxpython.gmPlugin.cNotebookPlugin.receive_focus" href="gmPlugin.html#Gnumed.wxpython.gmPlugin.cNotebookPlugin.receive_focus">receive_focus</a></code></li> <li><code><a title="Gnumed.wxpython.gmPlugin.cNotebookPlugin.register" href="gmPlugin.html#Gnumed.wxpython.gmPlugin.cNotebookPlugin.register">register</a></code></li> <li><code><a title="Gnumed.wxpython.gmPlugin.cNotebookPlugin.unregister" href="gmPlugin.html#Gnumed.wxpython.gmPlugin.cNotebookPlugin.unregister">unregister</a></code></li> </ul> </li> </ul> </dd> </dl> </section> </article> <nav id="sidebar"> <div class="toc"> <ul></ul> </div> <ul id="index"> <li><h3>Super-module</h3> <ul> <li><code><a title="Gnumed.wxpython.gui" href="http://www.gnumed.de/downloads/docs/api/wxpython/gui/index.html">Gnumed.wxpython.gui</a></code></li> </ul> </li> <li><h3><a href="gmManual.html#header-classes">Classes</a></h3> <ul> <li> <h4><code><a title="Gnumed.wxpython.gui.gmManual.ManualHtmlPanel" href="gmManual.html#Gnumed.wxpython.gui.gmManual.ManualHtmlPanel">ManualHtmlPanel</a></code></h4> <ul class="two-column"> <li><code><a title="Gnumed.wxpython.gui.gmManual.ManualHtmlPanel.FirstLoad" href="gmManual.html#Gnumed.wxpython.gui.gmManual.ManualHtmlPanel.FirstLoad">FirstLoad</a></code></li> <li><code><a title="Gnumed.wxpython.gui.gmManual.ManualHtmlPanel.OnBack" href="gmManual.html#Gnumed.wxpython.gui.gmManual.ManualHtmlPanel.OnBack">OnBack</a></code></li> <li><code><a title="Gnumed.wxpython.gui.gmManual.ManualHtmlPanel.OnForward" href="gmManual.html#Gnumed.wxpython.gui.gmManual.ManualHtmlPanel.OnForward">OnForward</a></code></li> <li><code><a title="Gnumed.wxpython.gui.gmManual.ManualHtmlPanel.OnLoadFile" href="gmManual.html#Gnumed.wxpython.gui.gmManual.ManualHtmlPanel.OnLoadFile">OnLoadFile</a></code></li> <li><code><a title="Gnumed.wxpython.gui.gmManual.ManualHtmlPanel.OnPrint" href="gmManual.html#Gnumed.wxpython.gui.gmManual.ManualHtmlPanel.OnPrint">OnPrint</a></code></li> <li><code><a title="Gnumed.wxpython.gui.gmManual.ManualHtmlPanel.OnShowDefault" href="gmManual.html#Gnumed.wxpython.gui.gmManual.ManualHtmlPanel.OnShowDefault">OnShowDefault</a></code></li> <li><code><a title="Gnumed.wxpython.gui.gmManual.ManualHtmlPanel.OnViewSource" href="gmManual.html#Gnumed.wxpython.gui.gmManual.ManualHtmlPanel.OnViewSource">OnViewSource</a></code></li> <li><code><a title="Gnumed.wxpython.gui.gmManual.ManualHtmlPanel.ShowTitle" href="gmManual.html#Gnumed.wxpython.gui.gmManual.ManualHtmlPanel.ShowTitle">ShowTitle</a></code></li> </ul> </li> <li> <h4><code><a title="Gnumed.wxpython.gui.gmManual.ManualHtmlWindow" href="gmManual.html#Gnumed.wxpython.gui.gmManual.ManualHtmlWindow">ManualHtmlWindow</a></code></h4> <ul class=""> <li><code><a title="Gnumed.wxpython.gui.gmManual.ManualHtmlWindow.OnSetTitle" href="gmManual.html#Gnumed.wxpython.gui.gmManual.ManualHtmlWindow.OnSetTitle">OnSetTitle</a></code></li> </ul> </li> <li> <h4><code><a title="Gnumed.wxpython.gui.gmManual.gmManual" href="gmManual.html#Gnumed.wxpython.gui.gmManual.gmManual">gmManual</a></code></h4> <ul class=""> <li><code><a title="Gnumed.wxpython.gui.gmManual.gmManual.GetWidget" href="gmManual.html#Gnumed.wxpython.gui.gmManual.gmManual.GetWidget">GetWidget</a></code></li> <li><code><a title="Gnumed.wxpython.gui.gmManual.gmManual.name" href="gmManual.html#Gnumed.wxpython.gui.gmManual.gmManual.name">name</a></code></li> <li><code><a title="Gnumed.wxpython.gui.gmManual.gmManual.tab_name" href="gmManual.html#Gnumed.wxpython.gui.gmManual.gmManual.tab_name">tab_name</a></code></li> </ul> </li> </ul> </li> </ul> </nav> </main> <footer id="footer"> <p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.11.6</a>.</p> </footer> </body> </html>