mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
Fixed html link handling in kivy version
This commit is contained in:
parent
1f61a15ca0
commit
574178a16b
2 changed files with 51 additions and 21 deletions
|
@ -1046,30 +1046,43 @@ class OptionsMenuDialog(LMenuDialog):
|
||||||
self.menubar.tkopt.display_win_message,
|
self.menubar.tkopt.display_win_message,
|
||||||
self.menubar.mWinDialog)
|
self.menubar.mWinDialog)
|
||||||
|
|
||||||
|
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
|
|
||||||
|
|
||||||
class HelpMenuDialog(LMenuDialog):
|
class HelpMenuDialog(LMenuDialog):
|
||||||
|
|
||||||
def __init__(self, menubar, parent, title, app, **kw):
|
def __init__(self, menubar, parent, title, app, **kw):
|
||||||
kw['size_hint'] = (0.3, 1)
|
kw['size_hint'] = (0.3, 1)
|
||||||
kw['persist'] = True
|
kw['persist'] = True
|
||||||
super(HelpMenuDialog, self).__init__(
|
super(HelpMenuDialog, self).__init__(menubar, parent, title, app, **kw)
|
||||||
menubar, parent, title, app, **kw)
|
|
||||||
|
def make_help_command(self, command):
|
||||||
|
def help_command():
|
||||||
|
command()
|
||||||
|
self.closeWindow(0)
|
||||||
|
return help_command
|
||||||
|
|
||||||
def buildTree(self, tv, node):
|
def buildTree(self, tv, node):
|
||||||
tv.add_node(LTreeNode(
|
tv.add_node(
|
||||||
text='Contents', command=self.menubar.mHelp))
|
LTreeNode(
|
||||||
|
text='Contents',
|
||||||
tv.add_node(LTreeNode(
|
command=self.make_help_command(self.menubar.mHelp)))
|
||||||
text='How to play', command=self.menubar.mHelpHowToPlay))
|
tv.add_node(
|
||||||
tv.add_node(LTreeNode(
|
LTreeNode(
|
||||||
text='Rules for this game', command=self.menubar.mHelpRules))
|
text='How to play',
|
||||||
tv.add_node(LTreeNode(
|
command=self.make_help_command(self.menubar.mHelpHowToPlay)))
|
||||||
text='License terms', command=self.menubar.mHelpLicense))
|
tv.add_node(
|
||||||
|
LTreeNode(
|
||||||
tv.add_node(LTreeNode(
|
text='Rules for this game',
|
||||||
text='About' + TITLE + '...', command=self.menubar.mHelpAbout))
|
command=self.make_help_command(self.menubar.mHelpRules)))
|
||||||
|
tv.add_node(
|
||||||
|
LTreeNode(
|
||||||
|
text='License terms',
|
||||||
|
command=self.make_help_command(self.menubar.mHelpLicense)))
|
||||||
|
tv.add_node(
|
||||||
|
LTreeNode(
|
||||||
|
text='About' + TITLE + '...',
|
||||||
|
command=self.make_help_command(self.menubar.mHelpAbout)))
|
||||||
|
|
||||||
# tv.add_node(LTreeNode(
|
# tv.add_node(LTreeNode(
|
||||||
# text='AboutKivy ...',
|
# text='AboutKivy ...',
|
||||||
|
@ -1078,8 +1091,10 @@ class HelpMenuDialog(LMenuDialog):
|
||||||
def makeHtmlCommand(self, bar, htmlfile):
|
def makeHtmlCommand(self, bar, htmlfile):
|
||||||
def htmlCommand():
|
def htmlCommand():
|
||||||
bar.mHelpHtml(htmlfile)
|
bar.mHelpHtml(htmlfile)
|
||||||
|
|
||||||
return htmlCommand
|
return htmlCommand
|
||||||
|
|
||||||
|
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
# *
|
# *
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
# import htmllib
|
# import htmllib
|
||||||
import pysollib.htmllib2 as htmllib
|
import pysollib.htmllib2 as htmllib
|
||||||
import formatter
|
import formatter
|
||||||
|
@ -93,6 +94,7 @@ class tkHTMLWriter(formatter.NullWriter):
|
||||||
self.indent = ""
|
self.indent = ""
|
||||||
self.text.label.bind(on_ref_press=self.refpress)
|
self.text.label.bind(on_ref_press=self.refpress)
|
||||||
|
|
||||||
|
'''
|
||||||
def createCallback(self, href):
|
def createCallback(self, href):
|
||||||
class Functor:
|
class Functor:
|
||||||
def __init__(self, viewer, arg):
|
def __init__(self, viewer, arg):
|
||||||
|
@ -103,6 +105,7 @@ class tkHTMLWriter(formatter.NullWriter):
|
||||||
self.viewer.updateHistoryXYView()
|
self.viewer.updateHistoryXYView()
|
||||||
return self.viewer.display(self.arg)
|
return self.viewer.display(self.arg)
|
||||||
return Functor(self.viewer, href)
|
return Functor(self.viewer, href)
|
||||||
|
'''
|
||||||
|
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
print('writer: write %s' % data)
|
print('writer: write %s' % data)
|
||||||
|
@ -333,10 +336,19 @@ class HTMLViewer:
|
||||||
|
|
||||||
def make_pop_command(self, parent, title):
|
def make_pop_command(self, parent, title):
|
||||||
def pop_command(event):
|
def pop_command(event):
|
||||||
print('event = %s' % event)
|
if self.history.index > 1:
|
||||||
|
self.goBack(event)
|
||||||
|
return None
|
||||||
|
self.history.list = None
|
||||||
|
self.history.index = 0
|
||||||
parent.popWork(title)
|
parent.popWork(title)
|
||||||
return pop_command
|
return pop_command
|
||||||
|
|
||||||
|
def refpress(self, instance, value):
|
||||||
|
# print('writer: refpress %s, %s' % (instance, value))
|
||||||
|
self.updateHistoryXYView()
|
||||||
|
return self.display(value)
|
||||||
|
|
||||||
def __init__(self, parent, app=None, home=None):
|
def __init__(self, parent, app=None, home=None):
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.app = app
|
self.app = app
|
||||||
|
@ -414,8 +426,7 @@ class HTMLViewer:
|
||||||
# create text widget
|
# create text widget
|
||||||
|
|
||||||
self.text = HTMLText(text="hallo", size_hint=(1.0, 1.0))
|
self.text = HTMLText(text="hallo", size_hint=(1.0, 1.0))
|
||||||
# textouter = BoxLayout(size_hint=(1.0, 1.0))
|
self.text.label.bind(on_ref_press=self.refpress)
|
||||||
# textouter.add_widget(self.text)
|
|
||||||
content.add_widget(self.text)
|
content.add_widget(self.text)
|
||||||
'''
|
'''
|
||||||
text_frame = Tkinter.Frame(parent)
|
text_frame = Tkinter.Frame(parent)
|
||||||
|
@ -529,6 +540,9 @@ class HTMLViewer:
|
||||||
if url[-1:] == "/" or os.path.isdir(url):
|
if url[-1:] == "/" or os.path.isdir(url):
|
||||||
url = os.path.join(url, "index.html")
|
url = os.path.join(url, "index.html")
|
||||||
url = os.path.normpath(url)
|
url = os.path.normpath(url)
|
||||||
|
if sys.version_info > (3,):
|
||||||
|
import codecs
|
||||||
|
return codecs.open(url, encoding='utf-8'), url
|
||||||
return open(url, "rb"), url
|
return open(url, "rb"), url
|
||||||
|
|
||||||
def display(self, url, add=1, relpath=1, xview=0, yview=0):
|
def display(self, url, add=1, relpath=1, xview=0, yview=0):
|
||||||
|
@ -563,7 +577,9 @@ class HTMLViewer:
|
||||||
except Exception:
|
except Exception:
|
||||||
if file:
|
if file:
|
||||||
file.close()
|
file.close()
|
||||||
|
'''
|
||||||
self.errorDialog(_("Unable to service request:\n") + url)
|
self.errorDialog(_("Unable to service request:\n") + url)
|
||||||
|
'''
|
||||||
return
|
return
|
||||||
|
|
||||||
self.url = url
|
self.url = url
|
||||||
|
@ -591,10 +607,11 @@ class HTMLViewer:
|
||||||
self.text.config(state="normal")
|
self.text.config(state="normal")
|
||||||
self.text.delete("1.0", "end")
|
self.text.delete("1.0", "end")
|
||||||
# self.images = {}
|
# self.images = {}
|
||||||
|
self.text.textbuffer = ''
|
||||||
writer = tkHTMLWriter(self.text, self, self.app)
|
writer = tkHTMLWriter(self.text, self, self.app)
|
||||||
fmt = formatter.AbstractFormatter(writer)
|
fmt = formatter.AbstractFormatter(writer)
|
||||||
parser = tkHTMLParser(fmt)
|
parser = tkHTMLParser(fmt)
|
||||||
parser.feed(str(data))
|
parser.feed(data)
|
||||||
parser.close()
|
parser.close()
|
||||||
self.text.config(state="disabled")
|
self.text.config(state="disabled")
|
||||||
if 0.0 <= xview <= 1.0:
|
if 0.0 <= xview <= 1.0:
|
||||||
|
@ -623,8 +640,6 @@ class HTMLViewer:
|
||||||
def updateHistoryXYView(self):
|
def updateHistoryXYView(self):
|
||||||
if self.history.index > 0:
|
if self.history.index > 0:
|
||||||
url, xview, yview = self.history.list[self.history.index - 1]
|
url, xview, yview = self.history.list[self.history.index - 1]
|
||||||
xview = self.text.xview()[0]
|
|
||||||
yview = self.text.yview()[0]
|
|
||||||
self.history.list[self.history.index - 1] = (url, xview, yview)
|
self.history.list[self.history.index - 1] = (url, xview, yview)
|
||||||
|
|
||||||
def goBack(self, *event):
|
def goBack(self, *event):
|
||||||
|
|
Loading…
Add table
Reference in a new issue