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