mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
Kivy/Android
- added navigation buttons to html display - fixed line formatting in html displays - title line formatting as centered and multiline if needed - html text rendering revised to circumvent hardware limits - screen rotation lock changes - balkenbreite
This commit is contained in:
parent
301d461875
commit
23657469c4
4 changed files with 104 additions and 83 deletions
|
@ -1075,11 +1075,17 @@ class LTopLine(ButtonBehavior, Label, LBase):
|
|||
self.rect = Rectangle(pos=self.pos, size=self.size)
|
||||
self.bind(pos=self.update_rect)
|
||||
self.bind(size=self.update_rect)
|
||||
self.maxlines = 0
|
||||
self.halign = 'center'
|
||||
self.valign = 'center'
|
||||
|
||||
def update_rect(self, *args):
|
||||
self.rect.pos = self.pos
|
||||
self.rect.size = self.size
|
||||
|
||||
def on_size(self, o, s):
|
||||
self.text_size = s
|
||||
|
||||
def on_press(self):
|
||||
print('press')
|
||||
|
||||
|
@ -1089,18 +1095,23 @@ class LTopLine(ButtonBehavior, Label, LBase):
|
|||
# =============================================================================
|
||||
|
||||
|
||||
class LTopLevel0(BoxLayout, LBase):
|
||||
def __init__(self, top, title=None, **kw):
|
||||
self.main = top
|
||||
super(LTopLevel0, self).__init__(
|
||||
orientation="vertical", **kw)
|
||||
|
||||
class LTopLevelBase(BoxLayout, LBase):
|
||||
def __init__(self, title='', **kw):
|
||||
super(LTopLevelBase, self).__init__(orientation="vertical", **kw)
|
||||
self.title = title
|
||||
self.titleline = LTopLine(text=title, size_hint=[1.0, 0.15])
|
||||
self.content = LTopLevelContent(orientation="vertical", **kw)
|
||||
self.add_widget(self.titleline)
|
||||
self.add_widget(self.content)
|
||||
|
||||
# =============================================================================
|
||||
|
||||
|
||||
class LTopLevel0(LTopLevelBase, LBase):
|
||||
def __init__(self, top, title='', **kw):
|
||||
super(LTopLevel0, self).__init__(title=title, **kw)
|
||||
|
||||
self.main = top
|
||||
self.titleline.bind(on_press=self.onClick)
|
||||
self.main.pushWork(self.title, self)
|
||||
|
||||
|
@ -1111,16 +1122,10 @@ class LTopLevel0(BoxLayout, LBase):
|
|||
# =============================================================================
|
||||
|
||||
|
||||
class LTopLevel(BoxLayout, LBase):
|
||||
def __init__(self, parent, title=None, **kw):
|
||||
class LTopLevel(LTopLevelBase, LBase):
|
||||
def __init__(self, parent, title='', **kw):
|
||||
super(LTopLevel, self).__init__(title=title, **kw)
|
||||
self.mainwindow = parent
|
||||
super(LTopLevel, self).__init__(
|
||||
orientation="vertical", **kw)
|
||||
|
||||
self.titleline = LTopLine(text=title, size_hint=(1.0, 0.10))
|
||||
self.content = LTopLevelContent(orientation="vertical", **kw)
|
||||
self.add_widget(self.titleline)
|
||||
self.add_widget(self.content)
|
||||
|
||||
def processAndroidBack(self):
|
||||
ret = False
|
||||
|
@ -1935,13 +1940,13 @@ class LApp(App):
|
|||
# für hintrgrund und resume. Diese funktioneren gemäss logcat
|
||||
# einwandfrei. Daher versuchen wir ... um den graphik context
|
||||
# wieder zu aktivieren/auszurichten:
|
||||
Clock.schedule_once(lambda dt: Window.update_viewport(), 3.0)
|
||||
Clock.schedule_once(lambda dt: Window.update_viewport(), 0.2)
|
||||
# fazit: schwarzer screen trotzdem gelegentlich wieder beobachtet.
|
||||
Clock.schedule_once(lambda dt: self.mainWindow.rebuildContainer(), 4.0)
|
||||
Clock.schedule_once(lambda dt: self.mainWindow.rebuildContainer(), 0.4)
|
||||
|
||||
# Pause modus abschalten nach resume:
|
||||
if app.game.pause:
|
||||
Clock.schedule_once(self.makeEndPauseCmd(app), 5.0)
|
||||
Clock.schedule_once(self.makeEndPauseCmd(app), 2.0)
|
||||
|
||||
def makeEndPauseCmd(self, app):
|
||||
def endPauseCmd(dt):
|
||||
|
|
|
@ -252,8 +252,7 @@ class MainMenuDialog(LMenuDialog):
|
|||
super(MainMenuDialog, self).__init__(
|
||||
menubar, parent, title, app, **kw)
|
||||
|
||||
print('MainMenuDialog starting')
|
||||
AndroidScreenRotation.unlock(toaster=False)
|
||||
# print('MainMenuDialog starting')
|
||||
|
||||
def buildTree(self, tv, node):
|
||||
rg = tv.add_node(
|
||||
|
@ -1429,6 +1428,10 @@ class PysolMenubarTk:
|
|||
if self.progress:
|
||||
self.progress.update(step=1)
|
||||
|
||||
def unlockScreenRotation(self, obj, val):
|
||||
AndroidScreenRotation.unlock(toaster=False)
|
||||
print('unlock screen rotation')
|
||||
|
||||
def _createTkOpt(self):
|
||||
opt = self.app.opt
|
||||
|
||||
|
@ -1538,7 +1541,7 @@ class PysolMenubarTk:
|
|||
# num_cards=BooleanVar(),
|
||||
# helpbar=BooleanVar(),
|
||||
# game
|
||||
gameid=LNumWrap(self, "gameid"),
|
||||
gameid=LNumWrap(self, "gameid", self.unlockScreenRotation),
|
||||
gameid_popular=LNumWrap(self, "gameid_popular"),
|
||||
)
|
||||
for w in TOOLBAR_BUTTONS:
|
||||
|
@ -2131,7 +2134,6 @@ class PysolMenubarTk:
|
|||
return
|
||||
self.game.doPause()
|
||||
self.tkopt.pause.value = self.game.pause
|
||||
AndroidScreenRotation.unlock(toaster=False)
|
||||
|
||||
def mOptLanguage(self, *args):
|
||||
if self._cancelDrag(break_pause=False):
|
||||
|
|
|
@ -312,14 +312,59 @@ class HTMLText(LScrollView, LPopCommander):
|
|||
def __init__(self, **kw):
|
||||
super(HTMLText, self).__init__(**kw)
|
||||
|
||||
self.label = HTMLLabel(text='', markup=True)
|
||||
self.viewer = kw['viewer']
|
||||
# self.scroll_timeout = 250
|
||||
# self.scroll_distance = 20
|
||||
self.do_scroll_x = False
|
||||
|
||||
self.multiLabel = True
|
||||
if self.multiLabel:
|
||||
self.label = BoxLayout(orientation='vertical', size_hint=(1, None))
|
||||
else:
|
||||
self.label = HTMLLabel(text='', markup=True)
|
||||
self.label.bind(on_ref_press=self.viewer.refpress)
|
||||
self.tags = {}
|
||||
self.textbuffer = ''
|
||||
self.add_widget(self.label)
|
||||
|
||||
def applyBuffer(self):
|
||||
# print('applybuffer:')
|
||||
self.label.text = self.textbuffer
|
||||
if self.multiLabel:
|
||||
splittedText = self.textbuffer.split('\n')
|
||||
self.textbuffer = ''
|
||||
self.label.clear_widgets()
|
||||
|
||||
def add_label(si, ei):
|
||||
lt = '\n'.join(splittedText[si:ei])
|
||||
if lt == '':
|
||||
lt = ' '
|
||||
label = HTMLLabel(text=lt, markup=True)
|
||||
label.bind(on_ref_press=self.viewer.refpress)
|
||||
label.bind(size=self.on_size)
|
||||
self.label.add_widget(label)
|
||||
|
||||
index = 0
|
||||
sindex = 0
|
||||
limit = 1000
|
||||
summe = 0
|
||||
for k in splittedText:
|
||||
l = len(k) # noqa
|
||||
s = summe + l
|
||||
index += 1
|
||||
if s > limit:
|
||||
add_label(sindex, index)
|
||||
sindex = index
|
||||
summe = l
|
||||
else:
|
||||
summe = s
|
||||
add_label(sindex, index)
|
||||
else:
|
||||
self.label.text = self.textbuffer
|
||||
|
||||
def on_size(self, o, s):
|
||||
y = 0
|
||||
for c in self.label.children:
|
||||
y += c.size[1]
|
||||
self.label.size[1] = y
|
||||
|
||||
def config(self, **kw):
|
||||
# print('config: %s' % kw)
|
||||
|
@ -419,86 +464,54 @@ class HTMLViewer:
|
|||
pc = self.make_pop_command(parent, self.title)
|
||||
cc = self.make_close_command(parent, self.title)
|
||||
|
||||
# neuen Dialog aufbauen.
|
||||
# create new dialog.
|
||||
|
||||
window = LTopLevel(app.top, self.title, size_hint=(1.8, 1.0))
|
||||
window = LTopLevel(app.top, self.title, size_hint=(2.0, 1.0))
|
||||
window.titleline.bind(on_press=cc)
|
||||
self.parent.pushWork(self.title, window)
|
||||
self.window = window
|
||||
self.running = True
|
||||
|
||||
content = BoxLayout(orientation='vertical')
|
||||
# buttonline =
|
||||
# BoxLayout(orientation='horizontal', size_hint=(1.0, 0.1))
|
||||
|
||||
# create buttons
|
||||
self.homeButton = HTMLButton(text=_("Index"), on_release=self.goHome)
|
||||
# create button line
|
||||
|
||||
buttonline = BoxLayout(
|
||||
orientation='horizontal', size_hint=(None, 0.07))
|
||||
|
||||
self.backButton = HTMLButton(text=_("Back"), on_release=self.goBack)
|
||||
self.homeButton = HTMLButton(text=_("Index"), on_release=self.goHome)
|
||||
self.forwardButton = HTMLButton(
|
||||
text=_("Forward"), on_release=self.goForward)
|
||||
self.closeButton = HTMLButton(text=_("Close"), on_release=self.goHome)
|
||||
# self.closeButton = HTMLButton(text=_("Close"), on_release=cc)
|
||||
# -> use title bar as usual.
|
||||
|
||||
'''
|
||||
buttonline.add_widget(self.homeButton)
|
||||
buttonline.add_widget(self.backButton)
|
||||
buttonline.add_widget(self.homeButton)
|
||||
buttonline.add_widget(self.forwardButton)
|
||||
buttonline.add_widget(self.closeButton)
|
||||
content.add_widget(buttonline)
|
||||
'''
|
||||
|
||||
'''
|
||||
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')
|
||||
'''
|
||||
# buttonline.add_widget(self.closeButton)
|
||||
self.buttonline = buttonline
|
||||
|
||||
# create text widget
|
||||
|
||||
self.text = HTMLText(
|
||||
pop_command=pc, text="hallo", size_hint=(1.0, 1.0))
|
||||
self.text.label.bind(on_ref_press=self.refpress)
|
||||
pop_command=pc, text="hallo", size_hint=(None, 1.0), viewer=self)
|
||||
|
||||
# add content: first text, buttonline at bottom.
|
||||
|
||||
content.add_widget(self.text)
|
||||
'''
|
||||
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
|
||||
'''
|
||||
|
||||
content.add_widget(buttonline)
|
||||
self.window.content.add_widget(content)
|
||||
self.window.bind(size=self.on_size)
|
||||
|
||||
# statusbar
|
||||
# self.statusbar = HtmlStatusbar(parent, row=2, column=0, columnspan=4)
|
||||
|
||||
# parent.columnconfigure(2, weight=1)
|
||||
# parent.rowconfigure(1, weight=1)
|
||||
|
||||
# load images
|
||||
# load images ?
|
||||
for name, fn in self.symbols_fn.items():
|
||||
self.symbols_img[name] = self.getImage(fn)
|
||||
|
||||
def on_size(self, o, s):
|
||||
self.text.size = s
|
||||
self.buttonline.size = s
|
||||
|
||||
def _yview(self, *args):
|
||||
self.text.yview(*args)
|
||||
return 'break'
|
||||
|
@ -573,9 +586,11 @@ class HTMLViewer:
|
|||
# render the whole text into a label ... and Android does not
|
||||
# allow local files be displayed in the local browser. The
|
||||
# simplest way is to take it from the original web site.
|
||||
'''
|
||||
if get_platform() == 'android':
|
||||
if os.path.basename(url) == 'license.html':
|
||||
url = 'https://www.gnu.org/licenses/gpl-3.0-standalone.html'
|
||||
'''
|
||||
|
||||
# ftp: and http: would work if we use urllib, but this widget is
|
||||
# far too limited to display anything but our documentation...
|
||||
|
@ -653,7 +668,6 @@ class HTMLViewer:
|
|||
self.parent.wm_iconname(parser.title)
|
||||
self.defcursor, self.handcursor = old_c1, old_c2
|
||||
self.text.config(cursor=self.defcursor)
|
||||
# self.frame.config(cursor=self.defcursor)
|
||||
|
||||
def addHistory(self, url, xview=0, yview=0):
|
||||
if url not in self.visited_urls:
|
||||
|
|
|
@ -7,7 +7,7 @@ use_bzip2 = 1
|
|||
[flake8]
|
||||
extend-ignore = H101,H104,H201,H237,H301,H306,H403,H404,H405,
|
||||
# remove some most ugly flakes (proposal)
|
||||
# E231,E302
|
||||
# E231,E302,E741
|
||||
|
||||
[sdist]
|
||||
force_manifest = 1
|
||||
|
|
Loading…
Add table
Reference in a new issue