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

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

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