Package nMOLDYN :: Package GUI :: Package HTMLReader :: Module tkwidget |
[hide private]
[frames] | no frames]

# Source Code for Module nMOLDYN.GUI.HTMLReader.tkwidget

      1  ## vim:ts=4:et:nowrap
      2  ##
      3  ##---------------------------------------------------------------------------##
      4  ##
      5  ## PySol -- a Python Solitaire game
      6  ##
      7  ## Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
      8  ## Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
      9  ## Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
     10  ## Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
     11  ## Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
     12  ## Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
     13  ## All Rights Reserved.
     14  ##
     15  ## This program is free software; you can redistribute it and/or modify
     16  ## it under the terms of the GNU General Public License as published by
     17  ## the Free Software Foundation; either version 2 of the License, or
     18  ## (at your option) any later version.
     19  ##
     20  ## This program is distributed in the hope that it will be useful,
     21  ## but WITHOUT ANY WARRANTY; without even the implied warranty of
     22  ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     23  ## GNU General Public License for more details.
     24  ##
     25  ## You should have received a copy of the GNU General Public License
     26  ## along with this program; see the file COPYING.
     27  ## If not, write to the Free Software Foundation, Inc.,
     28  ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
     29  ##
     30  ## Markus F.X.J. Oberhumer
     31  ## <markus@oberhumer.com>
     32  ## http://www.oberhumer.com/pysol
     33  ##
     34  ##---------------------------------------------------------------------------##
     35
     36
     37  # imports
     38  import os, sys, re, string, types, Tkinter
     39  import traceback
     40
     41  # PySol imports
     42  from mfxutil import destruct, kwdefault, KwStruct
     43  from mfxutil import win32api
     44
     45  # Toolkit imports
     46  from tkconst import tkversion
     47  from tkconst import EVENT_HANDLED, EVENT_PROPAGATE
     48  from tkutil import getFont
     49  from tkutil import after, after_idle, after_cancel
     50  from tkutil import bind, unbind_destroy, makeImage
     51  from tkutil import makeToplevel, setTransient
     52
     53
     54  # /***********************************************************************
     55  # // abstract base class for the dialogs in this module
     56  # ************************************************************************/
     57
     58 -class _ToplevelDialog:
     59      img = None
     60 -    def __init__(self, parent, title="", resizable=0, default=-1):
     61          self.parent = parent
     62          self.status = 0
     63          self.button = default
     64          self.timer = None
     65          self.top = makeToplevel(parent, title=title)
     66          self.top.wm_resizable(resizable, resizable)
     67          bind(self.top, "WM_DELETE_WINDOW", self.wmDeleteWindow)
     68          if self.img is None:
     69              _ToplevelDialog.img = (makeImage(dither=0, data="""
     70  R0lGODlhIAAgAPICAH8AAH9/f7+/v/8AAP///wAAAAAAAAAAACH5BAEAAAIALAAAAAAgACAAAAPZ
     71  KLos8PC1SRccOGNYO9AgCHTNE57ZQwoA6mZAB7z0AFRA/QLBBISEFyEECDAAIYISpSSEAAwAqKkM
     72  UQkgQGABCF011xAgEBAAUFfMFQUICACu69UFCAgAL7nyBSADaHI0AGQANHI0AGQAL3oELwBkAC6N
     73  Si4AZAAoVxhXKABkAgAhVxpXIQBkAQIAIFchVyAAqQIAIU0oTSEAZAsAIQQvBCEAqQwAOi4AqQEM
     74  AMgoAKkTAM8gAKkVD9UPyx0BAMgAywErARAoEOMrC2QREeMB6w3w9AHyFfUrCQA7"""),
     75  makeImage(dither=0, data="""
     76  R0lGODlhIAAgAPIDAAAAAAAA/39/f7+/v////wAAAAAAAAAAACH5BAEAAAMALAAAAAAgACAAAAPU
     77  OLo88vC1SRccJOsBa32DJo7D4zHCMK7jIJyDwA5BHQws4AksYds9AEXQI/xqRUBDMCgOfoPiAMAQ
     78  FK8sgEAhGGC/mgFAMBBcjzUsQDAQfI9YAOR7xAIg3yMWAPkesQAQA1hHVwMADwMCWEdXABADAgNX
     79  R0UDABAKAj1oNiwAEAwAYEUAEQ0ApCsAERQAA6oEAwARHgAAA18DtxEwArcAAysDwBECMAoQwAMa
     80  AMYPyAwRABoAxtEVAgAaAA/YyAAZAA/fyAAEAA/lyLcP68gQ78gPMAkAOw=="""),
     81  makeImage(dither=0, data="""
     82  R0lGODlhIAAgAPIDAAAAAAAA/39/f7+/v////wAAAAAAAAAAACH5BAEAAAMALAAAAAAgACAAAAPp
     83  OLo88vC1SRccJOsBa32DJo7D4zHCMK7jIJyDwM4j4AnsEOz8wAIUAWsQGGR4gQEL0BAMWDsRkjUA
     84  MAQzZAY5AwgUgsEMSRggZwOAYCCgDXYDApJGAAgGArpmwNMDIHoZPIEAEIEEOwOBABCHO4cAEAOH
     85  hwMADwMCegM7A3oAEAMCA3RIdAMAEAoCdEh0ABAMADQDOwM0ABENAJQrABEUAAO9BAMAER4AAAOB
     86  A8oRMALKAAMrA9MRAjAKENMDGgDZD9sMEQAaANnkFQIAGgAP69sAGQAP8tsABAAP+NvKD/xtgyBw
     87  2wMYCQAAOw=="""), makeImage(dither=0, data="""
     88  R0lGODlhIAAgAPIDAAAAAH9/AH9/f7+/v///AAAAAAAAAAAAACH5BAEAAAMALAAAAAAgACAAAAPu
     89  OLq88S3KqQIhA9Atw70DIHDkEHwXIAglFaDXAKytFMAXsNZNgF8DwIq3CPwugBVxEDheBoAVMfAZ
     90  AK6DD2DFC6Cu4M8AsKoFUOArCrBqBWBpAGoAWJUCsDgMsCIFcHEwAwArHAE4AWABOAArGwE/A2AD
     91  OAMAKxQBR2BHACsTAU4BAAFHAwArEgFOAwADTgArEQFOFwC1AwArDQG1vhcAKwwBvgNXA04DACsL
     92  Ab5ptQArCgG/abUDACsDAb8DVwO+ACsDAb/nFwArAgHovwMA6wMB7k4DAOsCCgFx/f79+QQwCEiw
     93  oEEBEQ4qJKggAQA7"""))
     94
     95 -    def mainloop(self, focus=None, timeout=0):
     96          bind(self.top, "<Escape>", self.mCancel)
     97          if focus is not None:
     98              focus.focus()
     99          setTransient(self.top, self.parent)
    100          try:
    101              self.top.grab_set()
    102          except Tkinter.TclError:
    103              pass
    104          if timeout > 0:
    105              self.timer = after(self.top, timeout, self.mTimeout)
    106          try: self.top.mainloop()
    107          except SystemExit: pass
    108          self.destroy()
    109
    110 -    def destroy(self):
    111          after_cancel(self.timer)
    112          unbind_destroy(self.top)
    113          try:
    114              self.top.wm_withdraw()
    115          except:
    116              if traceback: traceback.print_exc()
    117              pass
    118          try:
    119              self.top.destroy()
    120          except:
    121              if traceback: traceback.print_exc()
    122              pass
    123          destruct(self.top)
    124          if self.parent:
    125              try:
    126                  ##self.parent.update_idletasks()
    127                  # FIXME: why do we need this under Windows ?
    128                  if hasattr(self.parent, "busyUpdate"):
    129                      self.parent.busyUpdate()
    130                  else:
    131                      self.parent.update()
    132              except:
    133                  if traceback: traceback.print_exc()
    134                  pass
    135          self.top = None
    136          self.parent = None
    137
    138 -    def getDefaultFont(self):
    139          return getFont("default")
    140
    141 -    def wmDeleteWindow(self, *event):
    142          self.status = 1
    143          raise SystemExit
    144          ##return EVENT_HANDLED
    145
    146 -    def mCancel(self, *event):
    147          self.status = 1
    148          raise SystemExit
    149
    150 -    def mTimeout(self, *event):
    151          self.status = 2
    152          raise SystemExit
    153
    154
    155  # /***********************************************************************
    156  # // replacement for the tk_dialog script
    157  # ************************************************************************/
    158
    159 -class MfxDialog(_ToplevelDialog):
    160 -    def __init__(self, parent, title, **kw):
    161          kw = self.initKw(kw)
    162          _ToplevelDialog.__init__(self, parent, title, kw.resizable, kw.default)
    163          top_frame, bottom_frame = self.createFrames(kw)
    164          self.createBitmaps(top_frame, kw)
    165          #
    166          self.button = kw.default
    167          msg = Tkinter.Label(top_frame, text=kw.text, justify=kw.justify,
    168                              width=kw.width, font=kw.font)
    169          msg.pack(fill=Tkinter.BOTH, expand=1, padx=kw.padx, pady=kw.pady)
    170          #
    171          focus = self.createButtons(bottom_frame, kw)
    172          self.mainloop(focus, kw.timeout)
    173
    174 -    def initKw(self, kw):
    175          kw = KwStruct(kw,
    176              timeout=0, resizable=0,
    177              text="", justify="center",
    178              strings=("OK",), default=0,
    179              width=0,
    180              font=self.getDefaultFont(),
    181              buttonfont=self.getDefaultFont(),
    182              padx=20, pady=20,
    183              bitmap=None, bitmap_side="left", bitmap_padx=10, bitmap_pady=20,
    184              image=None, image_side="left", image_padx=10, image_pady=20,
    185          )
    186          # default to separator if more than one button
    187          sw = 2 * (len(kw.strings) > 1)
    188          kwdefault(kw.__dict__, separatorwidth=sw)
    189          return kw
    190
    191 -    def createFrames(self, kw):
    192          bottom_frame = Tkinter.Frame(self.top)
    193          bottom_frame.pack(side=Tkinter.BOTTOM, fill=Tkinter.BOTH, ipady=3)
    194          if kw.separatorwidth > 0:
    195              separator = Tkinter.Frame(self.top, relief="sunken",
    196                      height=kw.separatorwidth, width=kw.separatorwidth,
    197                      borderwidth=kw.separatorwidth / 2)
    198              separator.pack(side=Tkinter.BOTTOM, fill=Tkinter.X)
    199          top_frame = Tkinter.Frame(self.top)
    200          top_frame.pack(side=Tkinter.TOP, fill=Tkinter.BOTH, expand=1)
    201          return top_frame, bottom_frame
    202
    203 -    def createBitmaps(self, frame, kw):
    204          bm = ["error", "info", "questhead", "warning"]
    205          if kw.bitmap in bm:
    206              b = Tkinter.Label(frame, image=self.img[bm.index(kw.bitmap)])
    207              b.pack(side=kw.bitmap_side, padx=kw.bitmap_padx, pady=kw.bitmap_pady)
    208          elif kw.bitmap:
    209              b = Tkinter.Label(frame, bitmap=kw.bitmap)
    210              b.pack(side=kw.bitmap_side, padx=kw.bitmap_padx, pady=kw.bitmap_pady)
    211          elif kw.image:
    212              b = Tkinter.Label(frame, image=kw.image)
    213              b.pack(side=kw.image_side, padx=kw.image_padx, pady=kw.image_pady)
    214
    215 -    def createButtons(self, frame, kw):
    216          button = column = -1
    217          padx, pady = kw.get("buttonpadx", 10), kw.get("buttonpady", 10)
    218          focus = None
    219          max_len = 6
    220          for s in kw.strings:
    221              if type(s) is types.TupleType:
    222                  s = s[0]
    223              if s:
    224                  s = re.sub(r"[\s\.\,]", "", s)
    225                  max_len = max(max_len, len(s))
    226          for s in kw.strings:
    227              xbutton = button = button + 1
    228              if type(s) is types.TupleType:
    229                  assert len(s) == 2
    230                  button = int(s[1])
    231                  s = s[0]
    232              if s is None:
    233                  continue
    234              if button < 0:
    235                  b = Tkinter.Button(frame, text=s, font=kw.buttonfont, state="disabled")
    236                  button = xbutton
    237              else:
    238                  b = Tkinter.Button(frame, text=s, font=kw.buttonfont, default="normal",
    239                                     command=(lambda self=self, button=button: self.mDone(button)))
    240                  if button == kw.default:
    241                      focus = b
    242                      focus.config(default="active")
    243              l = len(s)
    244              if 1 and l < max_len:
    245                  l = l + (max_len - l) / 2
    246                  b.config(width=l)
    247              column = column + 1
    248              b.grid_configure(column=column, row=0, sticky="ew", padx=padx, pady=pady)
    249              b.grid_columnconfigure(column)
    250          if focus is not None:
    251              l = (lambda event=None, self=self, button=kw.default: self.mDone(button))
    252              bind(self.top, "<Return>", l)
    253              bind(self.top, "<KP_Enter>", l)
    254          return focus
    255
    256 -    def mDone(self, button):
    257          self.button = button
    258          raise SystemExit
    259
    260
    261  # /***********************************************************************
    262  # //
    263  # ************************************************************************/
    264
    265 -class MfxExceptionDialog(MfxDialog):
    266 -    def __init__(self, parent, ex, title="Error", **kw):
    267          kw = KwStruct(kw, bitmap="error")
    268          text = str(kw.get("text", ""))
    269          if text and text[-1] != "\n":
    270              text = text + "\n"
    271          text = text + "\n"
    272          if isinstance(ex, EnvironmentError) and ex.filename is not None:
    273              t = "[Errno %s] %s:\n%s" % (ex.errno, ex.strerror, repr(ex.filename))
    274          else:
    275              t = str(ex)
    276          kw.text = text + t
    277          apply(MfxDialog.__init__, (self, parent, title), kw.getKw())
    278
    279
    280  # /***********************************************************************
    281  # //
    282  # ************************************************************************/
    283
    284 -class MfxSimpleSlider(MfxDialog):
    285 -    def __init__(self, parent, title,
    286                   label, value, from_, to, resolution, **kw):
    287          kw = self.initKw(kw)
    288          _ToplevelDialog.__init__(self, parent, title, kw.resizable, kw.default)
    289          top_frame, bottom_frame = self.createFrames(kw)
    290          self.createBitmaps(top_frame, kw)
    291          #
    292          self.value = value
    293          self.var = Tkinter.DoubleVar()
    294          self.var.set(value)
    295          slider = Tkinter.Scale(top_frame, from_=from_, to=to,
    296                                 resolution=resolution, orient=Tkinter.HORIZONTAL,
    297                                 length="3i", label=label, variable=self.var, takefocus=0)
    298          slider.pack(side=Tkinter.TOP, padx=kw.padx, pady=kw.pady)
    299          #
    300          focus = self.createButtons(bottom_frame, kw)
    301          self.mainloop(focus, kw.timeout)
    302
    303 -    def initKw(self, kw):
    304          kw = KwStruct(kw,
    305              strings=("OK", "Cancel"), default=0,
    306              separatorwidth = 0,
    307          )
    308          return MfxDialog.initKw(self, kw)
    309
    310 -    def mDone(self, button):
    311          self.button = button
    312          self.value = self.var.get()
    313          raise SystemExit
    314
    315
    316  # /***********************************************************************
    317  # //
    318  # ************************************************************************/
    319
    320 -class MfxSimpleEntry(MfxSimpleSlider):
    321 -    def __init__(self, parent, title, label, value, **kw):
    322          kw = self.initKw(kw)
    323          _ToplevelDialog.__init__(self, parent, title, kw.resizable, kw.default)
    324          top_frame, bottom_frame = self.createFrames(kw)
    325          self.createBitmaps(top_frame, kw)
    326          #
    327          self.value = value
    328          if label:
    329              label = Tkinter.Label(top_frame, text=label, takefocus=0)
    330              label.pack(pady=5)
    331          w = kw.get("e_width", 0)    # width in characters
    332          self.var = Tkinter.Entry(top_frame, exportselection=1, width=w)
    333          self.var.insert(0, value)
    334          self.var.pack(side=Tkinter.TOP, padx=kw.padx, pady=kw.pady)
    335          #
    336          focus = self.createButtons(bottom_frame, kw)
    337          focus = self.var
    338          self.mainloop(focus, kw.timeout)
    339
    340
    341  # /***********************************************************************
    342  # // a simple tooltip
    343  # ************************************************************************/
    344
    345 -class MfxTooltip:
    346 -    def __init__(self, widget):
    347          # private vars
    348          self.widget = widget
    349          self.text = None
    350          self.timer = None
    351          self.tooltip = None
    352          self.label = None
    353          self.bindings = []
    354          self.bindings.append(self.widget.bind("<Enter>", self._enter))
    355          self.bindings.append(self.widget.bind("<Leave>", self._leave))
    356          self.bindings.append(self.widget.bind("<ButtonPress>", self._leave))
    357          # user overrideable settings
    358          self.time = 1000                    # milliseconds
    359          self.relief = Tkinter.SOLID
    360          self.justify = Tkinter.LEFT
    361          self.fg = "#000000"
    362          self.bg = "#ffffe0"
    363          self.xoffset = 20
    364          self.yoffset = 1
    365
    366 -    def setText(self, text):
    367          self.text = text
    368
    369 -    def _unbind(self):
    370          if self.bindings and self.widget:
    371              self.widget.unbind("<Enter>", self.bindings[0])
    372              self.widget.unbind("<Leave>", self.bindings[1])
    373              self.widget.unbind("<ButtonPress>", self.bindings[2])
    374              self.bindings = []
    375
    376 -    def destroy(self):
    377          self._unbind()
    378          self._leave()
    379
    380 -    def _enter(self, *event):
    381          after_cancel(self.timer)
    382          self.timer = after(self.widget, self.time, self._showTip)
    383
    384 -    def _leave(self, *event):
    385          after_cancel(self.timer)
    386          self.timer = None
    387          if self.tooltip:
    388              self.label.destroy()
    389              destruct(self.label)
    390              self.label = None
    391              self.tooltip.destroy()
    392              destruct(self.tooltip)
    393              self.tooltip = None
    394
    395 -    def _showTip(self):
    396          if self.tooltip or not self.text:
    397              return
    398          c = self.widget.__class__
    399          if c in (Tkinter.Button,):
    400              if self.widget["state"] == Tkinter.DISABLED:
    401                  return
    402          x = self.widget.winfo_rootx()
    403          y = self.widget.winfo_rooty() + self.widget.winfo_height()
    404          x = x + self.xoffset
    405          y = y + self.yoffset
    406          self.tooltip = Tkinter.Toplevel()
    407          self.tooltip.wm_iconify()
    408          self.tooltip.wm_overrideredirect(1)
    409          self.tooltip.wm_protocol("WM_DELETE_WINDOW", self.destroy)
    410          self.label = Tkinter.Label(self.tooltip, text=self.text,
    411                           relief=self.relief, justify=self.justify,
    412                           fg=self.fg, bg=self.bg, bd=1, takefocus=0)
    413          self.label.pack(ipadx=1, ipady=1)
    414          self.tooltip.wm_geometry("%+d%+d" % (x, y))
    415          self.tooltip.wm_deiconify()
    416          ##self.tooltip.tkraise()
    417
    418
    419  # /***********************************************************************
    420  # // A canvas widget with scrollbars and some useful bindings.
    421  # ************************************************************************/
    422
    423 -class MfxScrolledCanvas:
    424 -    def __init__(self, parent, hbar=2, vbar=2, **kw):
    425          bg = kw.get("bg", parent.cget("bg"))
    426          kwdefault(kw, bg=bg, highlightthickness=0,
    427                    xscrollincrement=16, yscrollincrement=16)
    428          self.parent = parent
    429          self.createFrame(kw)
    430          self.canvas = None
    431          self.hbar = None
    432          self.hbar_mode = hbar
    433          self.vbar = None
    434          self.vbar_mode = vbar
    435          self.hbar_show = 0
    436          self.vbar_show = 0
    437          self.resize_pending = 0
    438          self.timer = None
    439          self.createCanvas(kw)
    440          self.frame.grid_rowconfigure(0, weight=1)
    441          self.frame.grid_columnconfigure(0, weight=1)
    442          if hbar:
    443              if hbar == 3:
    444                  w = 21
    445                  if win32api:
    446                      w = win32api.GetSystemMetrics(3)        # SM_CYHSCROLL
    447                  self.frame.grid_rowconfigure(1, minsize=w)
    448              self.createHbar(bg)
    449              if not vbar:
    450                  bind(self.hbar, "<Map>", self._mapBar)
    451              self.bindHbar()
    452          if vbar:
    453              if vbar == 3:
    454                  w = 21
    455                  if win32api:
    456                      w = win32api.GetSystemMetrics(2)        # SM_CXVSCROLL
    457                  self.frame.grid_columnconfigure(1, minsize=w)
    458              self.createVbar(bg)
    459              bind(self.vbar, "<Map>", self._mapBar)
    460              self.bindVbar()
    461          ###self.canvas.focus_set()
    462
    463      #
    464      #
    465      #
    466
    467 -    def destroy(self):
    468          after_cancel(self.timer)
    469          self.timer = None
    470          self.unbind_all()
    471          self.canvas.destroy()
    472          self.frame.destroy()
    473
    474 -    def pack(self, **kw):
    475          apply(self.frame.pack, (), kw)
    476
    477      #
    478      #
    479      #
    480
    481 -    def unbind_all(self):
    482          unbind_destroy(self.hbar)
    483          unbind_destroy(self.vbar)
    484          unbind_destroy(self.canvas)
    485          unbind_destroy(self.frame)
    486
    487 -    def createFrame(self, kw):
    488          width = kw.get("width")
    489          height = kw.get("height")
    490          self.frame = Tkinter.Frame(self.parent, width=width, height=height, bg=None)
    491 -    def createCanvas(self, kw):
    492          self.canvas = apply(Tkinter.Canvas, (self.frame,), kw)
    493          self.canvas.grid(row=0, column=0, sticky="news")
    494 -    def createHbar(self, bg):
    495          self.hbar = Tkinter.Scrollbar(self.frame, name="hbar", bg=bg, takefocus=0, orient="horizontal")
    496          self.canvas["xscrollcommand"] = self._setHbar
    497          self.hbar["command"] = self.canvas.xview
    498 -    def createVbar(self, bg):
    499          self.vbar = Tkinter.Scrollbar(self.frame, name="vbar", bg=bg, takefocus=0)
    500          self.canvas["yscrollcommand"] = self._setVbar
    501          self.vbar["command"] = self.canvas.yview
    502 -    def bindHbar(self, w=None):
    503          if w is None:
    504              w = self.canvas
    505          bind(w, "<KeyPress-Left>", self.unit_left)
    506          bind(w, "<KeyPress-Right>", self.unit_right)
    507 -    def bindVbar(self, w=None):
    508          if w is None:
    509              w = self.canvas
    510          bind(w, "<KeyPress-Prior>", self.page_up)
    511          bind(w, "<KeyPress-Next>", self.page_down)
    512          bind(w, "<KeyPress-Up>", self.unit_up)
    513          bind(w, "<KeyPress-Down>", self.unit_down)
    514          bind(w, "<KeyPress-Begin>", self.scroll_top)
    515          bind(w, "<KeyPress-Home>", self.scroll_top)
    516          bind(w, "<KeyPress-End>", self.scroll_bottom)
    517
    518 -    def _mapBar(self, event):
    519          # see: autoscroll.tcl, http://mini.net/cgi-bin/wikit/950.html
    520          top = event.widget.winfo_toplevel()
    521          g = top.wm_geometry()
    522          if self.resize_pending:
    523              self.resize_pending = 0
    524              self.canvas.update_idletasks()
    525          top.wm_geometry(g)
    526
    527 -    def _setHbar(self, *args):
    528          apply(self.hbar.set, args)
    529          self.showHbar()
    530 -    def _setVbar(self, *args):
    531          apply(self.vbar.set, args)
    532          self.showVbar()
    533
    534 -    def showHbar(self, show=-1):
    535          if not self.hbar:
    536              return 0
    537          if show < 0:
    538              show = self.hbar_mode
    539          if show > 1:
    540              if not self.canvas.winfo_ismapped():
    541                  return 0
    542              view = self.canvas.xview()
    543              show = abs(view[0]) > 0.0001 or abs(view[1] - 1.0) > 0.0001
    544          if show == self.hbar_show:
    545              return 0
    546          if show:
    547              self.hbar.grid(row=1, column=0, sticky="we")
    548          else:
    549              self.hbar.grid_forget()
    550          self.hbar_show = show
    551          return 1
    552
    553 -    def showVbar(self, show=-1):
    554          if not self.vbar:
    555              return 0
    556          if show < 0:
    557              show = self.vbar_mode
    558          if show > 1:
    559              if not self.canvas.winfo_ismapped():
    560                  return 0
    561              view = self.canvas.yview()
    562              show = abs(view[0]) > 0.0001 or abs(view[1] - 1.0) > 0.0001
    563          if show == self.vbar_show:
    564              return 0
    565          if show:
    566              self.vbar.grid(row=0, column=1, sticky="ns")
    567          else:
    568              self.vbar.grid_forget()
    569          self.vbar_show = show
    570          return 1
    571
    572 -    def page_up(self, *event):
    573          self.canvas.yview_scroll(-1, "page")
    574          return "break"
    575 -    def page_down(self, *event):
    576          self.canvas.yview_scroll(1, "page")
    577          return "break"
    578 -    def unit_up(self, *event):
    579          self.canvas.yview_scroll(-1, "unit")
    580          return "break"
    581 -    def unit_down(self, *event):
    582          self.canvas.yview_scroll(1, "unit")
    583          return "break"
    584 -    def page_left(self, *event):
    585          self.canvas.xview_scroll(-1, "page")
    586          return "break"
    587 -    def page_right(self, *event):
    588          self.canvas.xview_scroll(1, "page")
    589          return "break"
    590 -    def unit_left(self, *event):
    591          self.canvas.xview_scroll(-1, "unit")
    592          return "break"
    593 -    def unit_right(self, *event):
    594          self.canvas.xview_scroll(1, "unit")
    595          return "break"
    596 -    def scroll_top(self, *event):
    597          self.canvas.yview_moveto(0)
    598          return "break"
    599 -    def scroll_bottom(self, *event):
    600          self.canvas.yview_moveto(1)
    601          return "break"
    602
    603
    604  # /***********************************************************************
    605  # //
    606  # ************************************************************************/
    607
    608
    609 -def tkwidget_main(args):
    610      from tkutil import wm_withdraw
    611      tk = Tkinter.Tk()
    612      wm_withdraw(tk)
    613      tk.update()
    614      if 1:
    615          d = MfxDialog(tk, "title", text="This is an info dialog",
    616                        bitmap="info", default=0, strings=("OK",))
    617          print d.status, d.button
    618      if 1:
    619          d = MfxSimpleSlider(tk, "title", "label", 1.0, 0.2, 9.9, 0.1)
    620          print d.status, d.value
    621      if 1:
    622          d = MfxSimpleEntry(tk, "title", "label", "value")
    623          print d.status, d.value
    624      return 0
    625
    626  if __name__ == "__main__":
    627      import sys
    628      sys.exit(tkwidget_main(sys.argv))
    629