Package Gnumed :: Package wxpython :: Package gui :: Module gmManual |
[frames] | no frames]

# Source Code for Module Gnumed.wxpython.gui.gmManual

      1  # -*- coding: utf-8 -*-
      2  # a simple wrapper for the Manual class
      3
      4  """GNUMed manuals in a HTML browser window
      5
      6  A very basic HTML browser with back/forward history buttons
      7  with  the main pourpose of browsing the gnumed manuals
      8  The manuals should reside where the manual_path points to.
      9
     10  @copyright: GPL v2 or later
     11  @thanks: this code has been heavily "borrowed" from
     12                   Robin Dunn's extraordinary wxPython sample
     13  """
     14  #===========================================================
     15  # $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/client/wxpython/gui/gmManual.py,v $
     16  # $Id: gmManual.py,v 1.49 2009-07-17 09:27:38 ncq Exp $
     17  __version__ = "$Revision: 1.49 $"
     18  __author__ = "H.Herb, I.Haywood, H.Berger, K.Hilbert"
     19
     20  import os, sys, os.path, logging
     21
     22  import wx
     23  import wx.html
     24
     25  from Gnumed.pycommon import gmTools
     26  from Gnumed.wxpython import gmPlugin, images_for_gnumed_browser16_16, images_gnuMedGP_Toolbar
     27
     28  _log = logging.getLogger('gm.ui')
     29  _log.info(__version__)
     30
     31  ID_MANUALCONTENTS = wx.NewId()
     32  ID_MANUALBACK = wx.NewId()
     33  ID_MANUALFORWARD = wx.NewId()
     34  ID_MANUALHOME = wx.NewId()
     35  ID_MANUALBABELFISH = wx.NewId()
     36  ID_MANUALPRINTER  = wx.NewId()
     37  ID_MANUALOPENFILE = wx.NewId()
     38  ID_MANUALBOOKMARKS = wx.NewId()
     39  ID_MANUALADDBOOKMARK = wx.NewId()
     40  ID_MANUALVIEWSOURCE = wx.NewId()
     41  ID_MANUALRELOAD = wx.NewId()
     42  ID_VIEWSOURCE  = wx.NewId()
     43  #===========================================================
     44 -class ManualHtmlWindow(wx.html.HtmlWindow):
     45 -        def __init__(self, parent, id):
     46                  wx.html.HtmlWindow.__init__(self, parent, id)
     47                  self.parent = parent
     48
     49 -        def OnSetTitle(self, title=''):
     50                  self.parent.ShowTitle(title)
     51  #===========================================================
     52 -class ManualHtmlPanel(wx.Panel):
     53 -        def __init__(self, parent, frame):
     54                  wx.Panel.__init__(self, parent, -1)
     55                  self.frame = frame
     56
     57                  # get base directory for manuals from broker
     58                  paths = gmTools.gmPaths(app_name = 'gnumed', wx = wx)
     59                  candidates = [
     60                          os.path.join(paths.local_base_dir, 'doc', 'user-manual'),
     61                          '/usr/share/doc/gnumed/user-manual/',
     62                          os.path.join(paths.system_app_data_dir, 'doc', 'user-manual')
     63                  ]
     64                  for self.docdir in candidates:
     65                          if os.access(self.docdir, os.R_OK):
     66                                  _log.info('found Manual path [%s]', self.docdir)
     67                                  break
     68
     69                  self.box = wx.BoxSizer(wx.VERTICAL)
     70
     71                  infobox = wx.BoxSizer(wx.HORIZONTAL)
     72                  n = wx.NewId()
     73                  self.infoline = wx.TextCtrl(self, n, style=wx.TE_READONLY)
     74                  self.infoline.SetBackgroundColour(wx.LIGHT_GREY)
     75                  infobox.Add(self.infoline, 1, wx.GROW|wx.ALL)
     76                  self.box.Add(infobox, 0, wx.GROW)
     77
     78                  self.html = ManualHtmlWindow(self, -1)
     79                  self.html.SetRelatedFrame(frame, "")
     80                  self.html.SetRelatedStatusBar(0)
     81                  self.box.Add(self.html, 1, wx.GROW)
     82
     83                  self.SetSizer(self.box)
     84                  self.SetAutoLayout(True)
     85
     86                  self.already_loaded = None
     87          #--------------------------------------------------------
     88 -        def FirstLoad(self):
     89                  if not self.already_loaded:
     90                          self.already_loaded = 1
     91                          self.OnShowDefault(None)
     92          #--------------------------------------------------------
     93 -        def ShowTitle(self, title=''):
     94                  self.infoline.Clear()
     95                  self.infoline.WriteText(title)
     96          #--------------------------------------------------------
     97 -        def OnShowDefault(self, event):
     98                  name = os.path.join(self.docdir, 'index.html')
     99                  if os.access (name, os.F_OK):
    100                          self.html.LoadPage(name)
    101                  else:
    102                          _log.error("cannot load local document %s", name)
    103                          self.html.LoadPage('http://wiki.gnumed.de/bin/view/Gnumed/GnumedManual?template=viewprint')
    104          #--------------------------------------------------------
    105 -        def OnLoadFile(self, event):
    106                  dlg = wx.FileDialog(self, wildcard = '*.htm*', style=wx.FD_OPEN)
    107                  if dlg.ShowModal():
    108                          path = dlg.GetPath()
    109                          self.html.LoadPage(path)
    110                  dlg.DestroyLater()
    111          #--------------------------------------------------------
    112 -        def OnBack(self, event):
    113                  self.html.HistoryBack()
    114          #--------------------------------------------------------
    115 -        def OnForward(self, event):
    116                  self.html.HistoryForward()
    117          #--------------------------------------------------------
    118 -        def OnViewSource(self, event):
    119                  return 1
    120                  # FIXME:
    121                  #from wxPython.lib.dialogs import wx.ScrolledMessageDialog
    122                  source = self.html.GetParser().GetSource()
    123                  dlg = wx.ScrolledMessageDialog(self, source, _('HTML Source'))
    124                  dlg.ShowModal()
    125                  dlg.DestroyLater()
    126          #--------------------------------------------------------
    127 -        def OnPrint(self, event):
    128                  self.printer.PrintFile(self.html.GetOpenedPage())
    129  #===========================================================
    130 -class gmManual (gmPlugin.cNotebookPlugin):
    131          """Plugin to encapsulate the manual window."""
    132
    133          tab_name = _('Manual')
    134          #--------------------------------------------------------
    135 -        def name (self):
    136                  return gmManual.tab_name
    137          #--------------------------------------------------------
    138 -        def GetWidget (self, parent):
    139                  #self._widget = ManualHtmlPanel (parent, ...)
    140                  self._widget = wx.Panel(parent, -1)
    141                  return self._widget
    142          #--------------------------------------------------------
    143 -        def MenuInfo (self):
    144                  return ('help', _('User &manual (local)'))
    145          #--------------------------------------------------------
    146 -        def receive_focus(self):
    147                  self._widget.FirstLoad()
    148                  return True
    149          #--------------------------------------------------------
    150 -        def can_receive_focus(self):
    151                  return True
    152          #--------------------------------------------------------
    153          #def populate_toolbar (self, tb, widget):
    154                  #tool1 = tb.AddTool(
    155                  #       ID_MANUALCONTENTS,
    156                  #       images_for_gnumed_browser16_16.getcontentsBitmap(),
    157                  #       shortHelpString=_("GNUmed manual contents"),
    158                  #       isToggle=False
    159                  #)
    160                  #wx.EVT_TOOL (tb, ID_MANUALCONTENTS, widget.OnShowDefault)
    161
    162  #               tool1 = tb.AddTool(
    163  #                       ID_MANUALOPENFILE,
    164  #                       images_for_gnumed_browser16_16.getfileopenBitmap(),
    165  #                       shortHelpString="Open File",
    166  #                       isToggle=True
    167  #               )
    168  #               wx.EVT_TOOL (tb, ID_MANUALOPENFILE, widget.OnLoadFile)
    169
    170                  #tool1 = tb.AddTool(
    171                  #       ID_MANUALBACK,
    172                  #       images_for_gnumed_browser16_16.get1leftarrowBitmap(),
    173                  #       shortHelpString=_("Back"),
    174                  #       isToggle=False
    175                  #)
    176                  #wx.EVT_TOOL (tb, ID_MANUALBACK, widget.OnBack)
    177
    178                  #tool1 = tb.AddTool(
    179                  #       ID_MANUALFORWARD,
    180                  #       images_for_gnumed_browser16_16.get1rightarrowBitmap(),
    181                  #       shortHelpString=_("Forward"),
    182                  #       isToggle=False
    183                  #)
    184                  #wx.EVT_TOOL (tb, ID_MANUALFORWARD, widget.OnForward)
    185
    186  #               #tool1 = tb.AddTool(
    187  #               #       ID_MANUALRELOAD,
    188  #               #       images_for_gnumed_browser16_16.getreloadBitmap(),
    189  #               #       shortHelpString=_("Reload"),
    190  #               #       isToggle=True
    191  #               #)
    192
    193  #               #tb.AddSeparator()
    194
    195  #               #tool1 = tb.AddTool(
    196  #               #       ID_MANUALHOME,
    197  #               #       images_for_gnumed_browser16_16.getgohomeBitmap(),
    198  #               #       shortHelpString=_("Home"),
    199  #               #       isToggle=True
    200  #               #)
    201  #               #wx.EVT_TOOL (tb, ID_MANUALHOME, widget.OnShowDefault)
    202
    203  #               #tb.AddSeparator()
    204
    205  #               #tool1 = tb.AddTool(
    206  #               #       ID_MANUALBABELFISH,
    207  #               #       images_for_gnumed_browser16_16.getbabelfishBitmap(),
    208  #               #       shortHelpString=_("Translate text"),
    209  #               #       isToggle=False
    210  #               #)
    211  #               #wx.EVT_TOOL (tb, ID_MANUALBABELFISH, widget.OnBabelFish )
    212
    213  #               #tb.AddSeparator()
    214
    215  #               #tool1 = tb.AddTool(
    216  #               #       ID_MANUALBOOKMARKS,
    217  #               #       images_for_gnumed_browser16_16.getbookmarkBitmap(),
    218  #               #       shortHelpString=_("Bookmarks"),
    219  #               #       isToggle=True
    220  #               #)
    221  #               #wx.EVT_TOOL (tb, ID_MANUALBOOKMARKS, widget.OnBookmarks)
    222
    223  #               #tool1 = tb.AddTool(
    224  #               #       ID_MANUALADDBOOKMARK,
    225  #               #       images_for_gnumed_browser16_16.getbookmark_addBitmap(),
    226  #               #       shortHelpString=_("Add Bookmark"),
    227  #               #       isToggle=True
    228  #               #)
    229  #               #wx.EVT_TOOL (tb, ID_MANUALADDBOOKMARK, widget.OnAddBookmark)
    230
    231  #               tool1 = tb.AddTool(
    232  #                       ID_VIEWSOURCE,
    233  #                       images_for_gnumed_browser16_16.getviewsourceBitmap(),
    234  #                       shortHelpString="View Source",
    235  #                       isToggle=True
    236  #               )
    237  #               wx.EVT_TOOL (tb, ID_VIEWSOURCE, widget.OnViewSource)
    238
    239                  #tool1 = tb.AddTool(
    240                  #       ID_MANUALPRINTER,
    241                  #       images_for_gnumed_browser16_16.getprinterBitmap(),
    242                  #       shortHelpString = _("Print manual page"),
    243                  #       isToggle=False
    244                  #)
    245                  #wx.EVT_TOOL (tb, ID_MANUALPRINTER, widget.OnPrint)
    246  #===========================================================
    247