1#!/usr/bin/env python 2# -*- mode: python; coding: utf-8; -*- 3# ---------------------------------------------------------------------------## 4# 5# Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer 6# Copyright (C) 2003 Mt. Hood Playing Card Co. 7# Copyright (C) 2005-2009 Skomoroh 8# 9# This program is free software: you can redistribute it and/or modify 10# it under the terms of the GNU General Public License as published by 11# the Free Software Foundation, either version 3 of the License, or 12# (at your option) any later version. 13# 14# This program is distributed in the hope that it will be useful, 15# but WITHOUT ANY WARRANTY; without even the implied warranty of 16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17# GNU General Public License for more details. 18# 19# You should have received a copy of the GNU General Public License 20# along with this program. If not, see <http://www.gnu.org/licenses/>. 21# 22# ---------------------------------------------------------------------------## 23 24import os 25import sys 26 27from pysollib.mfxutil import Struct 28from pysollib.mygettext import _ 29from pysollib.ui.tktile.tkhtml import Base_HTMLViewer 30 31from six.moves import tkinter 32from six.moves import tkinter_ttk as ttk 33 34from .statusbar import HtmlStatusbar 35from .tkwidget import MfxMessageDialog 36 37if __name__ == '__main__': 38 d = os.path.abspath(os.path.join(sys.path[0], '..', '..')) 39 sys.path.append(d) 40 import gettext 41 gettext.install('pysol', d, unicode=True) 42 43# ************************************************************************ 44# * 45# ************************************************************************ 46 47 48class HTMLViewer(Base_HTMLViewer): 49 symbols_fn = {} # filenames, loaded in Application.loadImages3 50 symbols_img = {} 51 52 def _calc_MfxMessageDialog(self): 53 return MfxMessageDialog 54 55 def __init__(self, parent, app=None, home=None): 56 self.parent = parent 57 self.app = app 58 self.home = home 59 self.url = None 60 self.history = Struct( 61 list=[], 62 index=0, 63 ) 64 self.visited_urls = [] 65 # need to keep a reference because of garbage collection 66 self.images = {} 67 self.defcursor = parent["cursor"] 68 # self.defcursor = 'xterm' 69 self.handcursor = "hand2" 70 71 frame = ttk.Frame(parent, width=640, height=440) 72 frame.pack(expand=True, fill='both') 73 frame.grid_propagate(False) 74 75 # create buttons 76 button_width = 8 77 self.homeButton = ttk.Button(frame, text=_("Index"), 78 width=button_width, 79 command=self.goHome) 80 self.homeButton.grid(row=0, column=0, sticky='w') 81 self.backButton = ttk.Button(frame, text=_("Back"), 82 width=button_width, 83 command=self.goBack) 84 self.backButton.grid(row=0, column=1, sticky='w') 85 self.forwardButton = ttk.Button(frame, text=_("Forward"), 86 width=button_width, 87 command=self.goForward) 88 self.forwardButton.grid(row=0, column=2, sticky='w') 89 self.closeButton = ttk.Button(frame, text=_("Close"), 90 width=button_width, 91 command=self.destroy) 92 self.closeButton.grid(row=0, column=3, sticky='e') 93 94 # create text widget 95 text_frame = ttk.Frame(frame) 96 text_frame.grid(row=1, column=0, columnspan=4, 97 sticky='nsew', padx=1, pady=1) 98 vbar = ttk.Scrollbar(text_frame) 99 vbar.pack(side='right', fill='y') 100 self.text = tkinter.Text(text_frame, 101 fg='black', bg='white', 102 bd=1, relief='sunken', 103 cursor=self.defcursor, 104 wrap='word', padx=10) 105 self.text.pack(side='left', fill='both', expand=True) 106 self.text["yscrollcommand"] = vbar.set 107 vbar["command"] = self.text.yview 108 109 # statusbar 110 self.statusbar = HtmlStatusbar(frame, row=2, column=0, columnspan=4) 111 112 frame.columnconfigure(2, weight=1) 113 frame.rowconfigure(1, weight=1) 114 115 # load images 116 for name, fn in self.symbols_fn.items(): 117 self.symbols_img[name] = self.getImage(fn) 118 119 self.initBindings() 120 121 122# ************************************************************************ 123# * 124# ************************************************************************ 125 126 127def tkhtml_main(args): 128 try: 129 url = args[1] 130 except Exception: 131 url = os.path.join(os.pardir, os.pardir, "data", "html", "index.html") 132 top = tkinter.Tk() 133 top.tk.call("package", "require", "tile") 134 top.wm_minsize(400, 200) 135 viewer = HTMLViewer(top) 136 viewer.app = None 137 viewer.display(url) 138 top.mainloop() 139 return 0 140 141 142if __name__ == "__main__": 143 sys.exit(tkhtml_main(sys.argv)) 144