diff --git a/MANIFEST.in b/MANIFEST.in index 990c264f..b818a85d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -18,6 +18,7 @@ graft data/themes recursive-exclude data/themes *.py include scripts/build.bat scripts/create_iss.py scripts/mahjongg_utils.py include scripts/pygettext.py scripts/all_games.py scripts/cardset_viewer.py +include scripts/cardconv scripts/cardsetsgiftobmp include android/*.py include android/mk* include android/debian/* diff --git a/android/mkcards b/android/mkcards new file mode 100755 index 00000000..b996897e --- /dev/null +++ b/android/mkcards @@ -0,0 +1,46 @@ +#!/bin/bash + +echo '### prepare cardsets' + +if [ ! -f ./PySolFC-Cardsets-2.0.tar.bz2 ] +then + echo '### downloading cardets' + # wget http://downloads.sourceforge.net/pysolfc/PySolFC-Cardsets-2.0.tar.bz2 + wget https://netix.dl.sourceforge.net/project/pysolfc/PySolFC-Cardsets/PySolFC-Cardsets-2.0/PySolFC-Cardsets-2.0.tar.bz2 +fi + +if [ -f ./PySolFC-Cardsets-2.0.tar.bz2 ] +then + if [ ! -d ./PySolFC-Cardsets-2.0 ] + then + echo '### extracting selected cardets' + tar -xjvf PySolFC-Cardsets-2.0.tar.bz2 \ +PySolFC-Cardsets-2.0/cardset-crystal-mahjongg \ +PySolFC-Cardsets-2.0/cardset-dashavatara-ganjifa \ +PySolFC-Cardsets-2.0/cardset-dondorf \ +PySolFC-Cardsets-2.0/cardset-hexadeck \ +PySolFC-Cardsets-2.0/cardset-kintengu \ +PySolFC-Cardsets-2.0/cardset-matrix \ +PySolFC-Cardsets-2.0/cardset-mughal-ganjifa \ +PySolFC-Cardsets-2.0/cardset-oxymoron \ +PySolFC-Cardsets-2.0/cardset-standard \ +PySolFC-Cardsets-2.0/cardset-vienna-2k \ +PySolFC-Cardsets-2.0/cardset-greywyvern + fi + + if [ -d ./PySolFC-Cardsets-2.0 ] + then + echo '### processing cardets' + cd PySolFC-Cardsets-2.0 + ../../scripts/cardsetsgiftobmp + for i in cardset-*-bmp + do + rm -rf `basename $i -bmp` + done + cd .. + fi +else + echo '### error downloading cardsets' +fi + +echo '### end cardsets' diff --git a/android/mkp4a.clean b/android/mkp4a.clean index 75ed2916..bc46fe42 100755 --- a/android/mkp4a.clean +++ b/android/mkp4a.clean @@ -1,6 +1,8 @@ #!/bin/bash -rm -rf tmp/* +rm -rf tmp python3 -m pythonforandroid.toolchain clean_dists python3 -m pythonforandroid.toolchain clean_builds rm -f *.apk +rm -rf PySolFC-Cardsets-2.0 + diff --git a/android/mkp4a.cleanall b/android/mkp4a.cleanall index 1de262e7..34ef7480 100755 --- a/android/mkp4a.cleanall +++ b/android/mkp4a.cleanall @@ -1,7 +1,10 @@ #!/bin/bash -rm -rf tmp/* +rm -rf tmp rm -f *.apk +rm -f *.bz2 +rm -f *.zip +rm -rf PySolFC-Cardsets-2.0 rm -rf ~/.local/share/python-for-android/packages rm -rf ~/.local/share/python-for-android/build rm -rf ~/.local/share/python-for-android/dists diff --git a/android/mkp4a.init b/android/mkp4a.init index 1d0bea9d..a31da717 100755 --- a/android/mkp4a.init +++ b/android/mkp4a.init @@ -13,9 +13,18 @@ echo '### install p4a' #python3 -m pip install -q --user "./p4a/${p4aversion}.zip" p4aversion='0.5.3' -python3 -m pip install -q --user "https://github.com/kivy/python-for-android/archive/${p4aversion}.zip" +if [ ! -f ./${p4aversion}.zip ] +then + wget "https://github.com/kivy/python-for-android/archive/${p4aversion}.zip" +fi +if [ -f ./${p4aversion}.zip ] +then + python3 -m pip install -q --user "./${p4aversion}.zip" +else + echo "### download of ${p4aversion}.zip failed" +fi -echo '### prepare recipes' +echo '### load prepared recipes if available' if [ -d ./packages ] then @@ -40,5 +49,18 @@ mv ${HOME}/.local/tmp/src tmp/src rm -rf tmp/src/android rm -rf tmp/src/src cp -a main.py tmp/src/main.py +mkdir -p tmp/src/data/images/cards/bottoms/trumps-only +echo "" > tmp/src/data/images/cards/bottoms/trumps-only/.keep + +if [ ! -d ./PySolFC-Cardsets-2.0 ] +then + ./mkcards +fi + +if [ -d ./PySolFC-Cardsets-2.0 ] +then + echo '### copying cardsets' + cp -a ./PySolFC-Cardsets-2.0/* ./tmp/src/data +fi echo '### end init' diff --git a/android/p4a/0.5.3p.zip b/android/p4a/0.5.3p.zip deleted file mode 100644 index 20cf297b..00000000 Binary files a/android/p4a/0.5.3p.zip and /dev/null differ diff --git a/pysollib/images.py b/pysollib/images.py index 47f257b6..dd623f9c 100644 --- a/pysollib/images.py +++ b/pysollib/images.py @@ -114,7 +114,7 @@ class Images: imagedir = self.d.findDir(cs_type, d) except Exception: pass - if not USE_PIL or imagedir is None: + if (not USE_PIL and TOOLKIT is not 'kivy') or imagedir is None: # load image img = self.__loadCard(filename+self.cs.ext, check_w, check_h) if USE_PIL: @@ -260,6 +260,8 @@ class Images: return self._bottom[0] def getBlankBottom(self): + if TOOLKIT is 'kivy': + return self._bottom[0] return self._blank_bottom def getSuitBottom(self, suit=-1): diff --git a/pysollib/kivy/LApp.py b/pysollib/kivy/LApp.py index 904f3671..c3879a01 100644 --- a/pysollib/kivy/LApp.py +++ b/pysollib/kivy/LApp.py @@ -21,11 +21,7 @@ from __future__ import division -# import os -# print ('KIVY_HOME: '+os.environ['KIVY_HOME']) - import logging -# import time import math import traceback @@ -34,15 +30,10 @@ from kivy.graphics import Rectangle from kivy.graphics import Line from kivy.graphics import Triangle -# from kivy.uix.treeview import TreeView -# from kivy.uix.actionbar import ActionBar from kivy.utils import platform -# from kivy.event import EventDispatcher - from kivy.properties import StringProperty from kivy.base import EventLoop -# from kivy.base import EventLoopBase from kivy.base import stopTouchApp from kivy.app import App from kivy.animation import Animation @@ -50,13 +41,11 @@ from kivy.core.audio import SoundLoader from kivy.clock import Clock from kivy.uix.image import Image as KivyImage -# from kivy.uix.anchorlayout import AnchorLayout from kivy.uix.boxlayout import BoxLayout from kivy.uix.widget import Widget from kivy.uix.button import Button from kivy.uix.behaviors import ButtonBehavior from kivy.uix.label import Label -# from kivy.uix.relativelayout import RelativeLayout from kivy.uix.scrollview import ScrollView from kivy.uix.actionbar import ActionView @@ -294,6 +283,7 @@ class LText(Widget): def __init__(self, canvas, x, y, **kwargs): super(LText, self).__init__(**kwargs) + # super(LText, self).__init__() if 'text' not in kwargs: kwargs['text'] = 'X' @@ -317,6 +307,7 @@ class LText(Widget): # print('LText: text = %s' % (self.text)) self.label = Label(font=font, font_size=fontsize, **kwargs) + # self.label = Label(font=font, font_size=fontsize) self.label.texture_update() self.coreSize = self.label.texture_size self.corePos = (x, y) @@ -1082,6 +1073,7 @@ class LMenuBar(BoxLayout): class LMenu(ActionView): def __init__(self, prev, **kw): + print('prev = %s, kw = %s' % (prev, kw)) super(LMenu, self).__init__(**kw) self.ap = ap = ActionPrevious( with_previous=prev, size_hint=(.01, 1), **kw) @@ -1143,6 +1135,7 @@ class LMenuItem(ActionButton): def __init__(self, menu, **kw): super(LMenuItem, self).__init__(**kw) + # super(LMenuItem, self).__init__() self.bar = None self.submenu = None self.menu = menu @@ -1422,13 +1415,8 @@ class LMainWindow(BoxLayout, LTkBase): background_normal='atlas:' '//data/images/defaulttheme/action_item', border=(0, 0, 0, 0)) - self.topLine1 = Label( - size_hint=(1.0, 0.01), - background_down='atlas:' - '//data/images/defaulttheme/action_item_down', - background_normal='atlas:' - '//data/images/defaulttheme/action_item', - border=(0, 0, 0, 0)) + self.topLine1 = Label(size_hint=(1.0, 0.01)) + self.add_widget(self.topLine) self.add_widget(self.menuArea) self.add_widget(self.topLine1) diff --git a/pysollib/kivy/colorsdialog.py b/pysollib/kivy/colorsdialog.py index 2399d2fa..a00d287f 100644 --- a/pysollib/kivy/colorsdialog.py +++ b/pysollib/kivy/colorsdialog.py @@ -22,7 +22,7 @@ # ---------------------------------------------------------------------------# # Toolkit imports -from tkwidget import MfxDialog +from pysollib.pysoltk import MfxDialog __all__ = ['ColorsDialog'] diff --git a/pysollib/kivy/edittextdialog.py b/pysollib/kivy/edittextdialog.py index 79090e31..dd7fff82 100644 --- a/pysollib/kivy/edittextdialog.py +++ b/pysollib/kivy/edittextdialog.py @@ -22,7 +22,7 @@ # ---------------------------------------------------------------------------# # Toolkit imports -from tkwidget import MfxDialog +from pysollib.pysoltk import MfxDialog __all__ = ['EditTextDialog'] diff --git a/pysollib/kivy/fontsdialog.py b/pysollib/kivy/fontsdialog.py index 9fc07bea..6e6b7802 100644 --- a/pysollib/kivy/fontsdialog.py +++ b/pysollib/kivy/fontsdialog.py @@ -22,7 +22,7 @@ # ---------------------------------------------------------------------------# # Toolkit imports -from tkwidget import MfxDialog +from pysollib.pysoltk import MfxDialog __all__ = ['FontsDialog'] diff --git a/pysollib/kivy/gameinfodialog.py b/pysollib/kivy/gameinfodialog.py index f670d123..09d7383a 100644 --- a/pysollib/kivy/gameinfodialog.py +++ b/pysollib/kivy/gameinfodialog.py @@ -27,7 +27,7 @@ # from pysollib.gamedb import GI # Toolkit imports -from tkwidget import MfxDialog +from pysollib.pysoltk import MfxDialog __all__ = ['GameInfoDialog'] diff --git a/pysollib/kivy/menubar.py b/pysollib/kivy/menubar.py index 90118ee3..4d2e4e48 100644 --- a/pysollib/kivy/menubar.py +++ b/pysollib/kivy/menubar.py @@ -31,21 +31,12 @@ import re # import traceback # PySol imports -# from pysollib.mygettext import _, n_ from pysollib.mygettext import _ -# from pysollib.mfxutil import Struct, kwdefault from pysollib.mfxutil import Struct -# from pysollib.mfxutil import Image from pysollib.util import CARDSET -# from pysollib.settings import TITLE, WIN_SYSTEM from pysollib.settings import TITLE -# from pysollib.settings import TOP_TITLE from pysollib.settings import SELECT_GAME_MENU -# from pysollib.settings import USE_FREECELL_SOLVER -# from pysollib.settings import DEBUG from pysollib.gamedb import GI -# from pysollib.pysoltk import MfxMenu -# from pysollib.pysoltk import SelectCardsetDialogWithPreview # toolkit imports from pysollib.kivy.tkconst import EVENT_HANDLED, EVENT_PROPAGATE, CURSOR_WATCH @@ -53,35 +44,26 @@ from pysollib.kivy.tkutil import bind from pysollib.kivy.tkutil import after_idle from pysollib.kivy.selectcardset import SelectCardsetDialogWithPreview -from selectgame import SelectGameDialog -from findcarddialog import connect_game_find_card_dialog -from findcarddialog import destroy_find_card_dialog -from solverdialog import connect_game_solver_dialog -from tkconst import TOOLBAR_BUTTONS +from pysollib.kivy.selectgame import SelectGameDialog +from pysollib.pysoltk import connect_game_find_card_dialog + +from pysollib.kivy.findcarddialog import destroy_find_card_dialog +from pysollib.kivy.solverdialog import connect_game_solver_dialog +from pysollib.kivy.tkconst import TOOLBAR_BUTTONS # Kivy - -# from kivy.uix.treeview import TreeView -# from kivy.uix.treeview import TreeViewLabel -# from kivy.uix.treeview import TreeViewNode -# from kivy.uix.label import Label -# from kivy.uix.button import Button -# from kivy.uix.behaviors import ButtonBehavior -# from kivy.uix.scrollview import ScrollView - -# from kivy.clock import Clock from kivy.properties import BooleanProperty from kivy.properties import NumericProperty from kivy.properties import StringProperty from kivy.event import EventDispatcher -from LApp import LMenu -from LApp import LTreeNode -from LApp import LMenuItem -from LApp import LTopLevel -from LApp import LScrollView -from LApp import LTreeRoot +from pysollib.kivy.LApp import LMenu +from pysollib.kivy.LApp import LTreeNode +from pysollib.kivy.LApp import LMenuItem +from pysollib.kivy.LApp import LTopLevel +from pysollib.kivy.LApp import LScrollView +from pysollib.kivy.LApp import LTreeRoot __all__ = ['PysolMenubarTk'] @@ -1112,9 +1094,6 @@ class EmulTkMenu(object): def __init__(self, master, **kw): - # tearoff = 0 - # self.n = kw["tearoff"] = int(kw.get("tearoff", tearoff)) - self.name = kw["name"] self.n = 0 self._w = None @@ -1126,10 +1105,7 @@ class EmulTkMenu(object): else: self.name = "<>" - # print('self._w = %s' % self._w) - def labeltoname(self, label): - # print label, type(label) name = re.sub(r"[^0-9a-zA-Z]", "", label).lower() label = _(label) underline = label.find('&') @@ -1138,19 +1114,14 @@ class EmulTkMenu(object): return name, label, underline def add_cascade(self, cnf={}, **kw): - # print('add_cascade: %s, %s' % (cnf, kw)) self.add('cascade', cnf or kw) pass def add(self, itemType, cnf={}): label = cnf.get("label") - # print('add: label=%s' % label) if label: name = cnf.get('name') if name: - # LB ????? - # del cnf['name'] # TclError: unknown option "-name" - # else: name, label, underline = self.labeltoname(label) cnf["underline"] = cnf.get("underline", underline) cnf["label"] = label @@ -1158,9 +1129,6 @@ class EmulTkMenu(object): path = str(self._w) + "." + name self.addPath(path, self, self.n, cnf.get("menu")) - # Tkinter.Menu.add(self, itemType, cnf) - # self.n = self.n + 1 - def cget(self, key): return key diff --git a/pysollib/kivy/playeroptionsdialog.py b/pysollib/kivy/playeroptionsdialog.py index d3b5f9a1..19b4d52c 100644 --- a/pysollib/kivy/playeroptionsdialog.py +++ b/pysollib/kivy/playeroptionsdialog.py @@ -22,7 +22,7 @@ # ---------------------------------------------------------------------------# # Toolkit imports -from tkwidget import MfxDialog +from pysollib.pysoltk import MfxDialog __all__ = ['PlayerOptionsDialog'] diff --git a/pysollib/kivy/selectcardset.py b/pysollib/kivy/selectcardset.py index 49841d52..86ab3b17 100644 --- a/pysollib/kivy/selectcardset.py +++ b/pysollib/kivy/selectcardset.py @@ -27,13 +27,10 @@ # PySol imports from pysollib.mygettext import _ -# from pysollib.resource import CSI from pysollib.mfxutil import kwdefault # Toolkit imports -from tkwidget import MfxDialog -# from tkcanvas import MfxCanvas, MfxCanvasImage -# from tkutil import loadImage +from pysollib.pysoltk import MfxDialog # ************************************************************************ # * Dialog diff --git a/pysollib/kivy/selectgame.py b/pysollib/kivy/selectgame.py index 967b75bd..61dbee6b 100644 --- a/pysollib/kivy/selectgame.py +++ b/pysollib/kivy/selectgame.py @@ -23,43 +23,29 @@ # imports # import os -from UserList import UserList +from six.moves import UserList # PySol imports -# from pysollib.mygettext import _, n_ from pysollib.mygettext import _ -# from pysollib.mfxutil import destruct, Struct, KwStruct -# from pysollib.mfxutil import format_time from pysollib.gamedb import GI -# from pysollib.help import help_html -# from pysollib.resource import CSI # Toolkit imports -# from tkutil import unbind_destroy -# from tkwidget import MfxDialog, MfxScrolledCanvas -from selecttree import SelectDialogTreeLeaf, SelectDialogTreeNode -from selecttree import SelectDialogTreeData # , SelectDialogTreeCanvas +from pysollib.kivy.selecttree import SelectDialogTreeLeaf, SelectDialogTreeNode +from pysollib.kivy.selecttree import SelectDialogTreeData +from pysollib.kivy.LApp import LScrollView +from pysollib.kivy.LApp import LTopLevel +from pysollib.kivy.LApp import LTreeNode +from pysollib.kivy.LApp import LTreeRoot # Kivy imports -# from kivy.uix.treeview import TreeView -# from kivy.uix.treeview import TreeViewLabel -# from kivy.uix.treeview import TreeViewNode -# from kivy.uix.label import Label -# from kivy.uix.button import Button -# from kivy.uix.behaviors import ButtonBehavior -# from kivy.uix.scrollview import ScrollView from kivy.clock import Clock -from LApp import LScrollView -from LApp import LTopLevel -from LApp import LTreeNode -from LApp import LTreeRoot - # ************************************************************************ # * Nodes # ************************************************************************ + class SelectGameLeaf(SelectDialogTreeLeaf): pass diff --git a/pysollib/kivy/selecttree.py b/pysollib/kivy/selecttree.py index aec81c96..b6bf3aa3 100644 --- a/pysollib/kivy/selecttree.py +++ b/pysollib/kivy/selecttree.py @@ -25,8 +25,7 @@ # import tkFont # Toolkit imports -# from pysollib.mygettext import _, n_ -from tktree import MfxTreeLeaf, MfxTreeNode, MfxTreeInCanvas +from pysollib.kivy.tktree import MfxTreeLeaf, MfxTreeNode, MfxTreeInCanvas __all__ = ['SelectDialogTreeData'] diff --git a/pysollib/kivy/tkcanvas.py b/pysollib/kivy/tkcanvas.py index 9c4b6e02..afcfbf49 100644 --- a/pysollib/kivy/tkcanvas.py +++ b/pysollib/kivy/tkcanvas.py @@ -442,7 +442,8 @@ class MfxCanvasText(object): class MfxCanvas(Widget): def __init__(self, wmain, *args, **kw): - super(MfxCanvas, self).__init__(**kw) + # super(MfxCanvas, self).__init__(**kw) + super(MfxCanvas, self).__init__() # self.tags = {} # bei basisklasse widget (ev. nur vorläufig) diff --git a/pysollib/kivy/tkhtml.py b/pysollib/kivy/tkhtml.py index 65a2c7b7..fc2e07fd 100644 --- a/pysollib/kivy/tkhtml.py +++ b/pysollib/kivy/tkhtml.py @@ -23,7 +23,8 @@ # imports import os -import htmllib +# import htmllib +import pysollib.htmllib2 as htmllib import formatter # PySol imports @@ -38,9 +39,6 @@ from pysollib.pysoltk import MfxMessageDialog from kivy.uix.boxlayout import BoxLayout from kivy.uix.label import Label from kivy.uix.button import Button -# from kivy.uix.behaviors import ButtonBehavior -# from kivy.uix.scrollview import ScrollView -# from kivy.clock import Clock REMOTE_PROTOCOLS = ("ftp:", "gopher:", "http:", "mailto:", "news:", "telnet:") diff --git a/pysollib/kivy/tktree.py b/pysollib/kivy/tktree.py index 94cfdcfd..b16f50b9 100644 --- a/pysollib/kivy/tktree.py +++ b/pysollib/kivy/tktree.py @@ -25,14 +25,14 @@ # import os # Toolkit imports -# from tkutil import bind -from tkwidget import MfxScrolledCanvas +from pysollib.pysoltk import MfxScrolledCanvas # ************************************************************************ # * # ************************************************************************ + class MfxTreeBaseNode: def __init__(self, tree, parent_node, text, key): self.tree = tree diff --git a/pysollib/kivy/tkutil.py b/pysollib/kivy/tkutil.py index 724cd674..5621f7b5 100644 --- a/pysollib/kivy/tkutil.py +++ b/pysollib/kivy/tkutil.py @@ -26,7 +26,6 @@ # emulated. from __future__ import division - ''' __all__ = ['wm_withdraw', 'wm_map', @@ -51,18 +50,19 @@ __all__ = ['wm_withdraw', ''' # imports +import os import logging from array import array -# PySol imports -# from pysollib.mfxutil import Image +# Toolkit imports from pysollib.kivy.LApp import LTopLevel0 from pysollib.kivy.LApp import LImage # Kivy imports from kivy.core.text import Label as CoreLabel -from kivy.clock import Clock +from kivy.core.image import Image as CoreImage from kivy.graphics.texture import Texture +from kivy.clock import Clock # ************************************************************************ # * window manager util @@ -76,6 +76,7 @@ def wm_withdraw(window): def wm_map(window, maximized=0): return + # ************************************************************************ # * window util # ************************************************************************ @@ -112,11 +113,11 @@ def make_help_toplevel(app, title=None): # init_root_window(window, app) return window + # ************************************************************************ # * bind wrapper - Tkinter doesn't properly delete all bindings # ************************************************************************ - __mfx_bindings = {} __mfx_wm_protocols = ("WM_DELETE_WINDOW", "WM_TAKE_FOCUS", "WM_SAVE_YOURSELF") @@ -196,6 +197,7 @@ def unbind_destroy(widget): widget.bindings = [] pass + # ************************************************************************ # * timer wrapper - Tkinter doesn't properly delete all commands # ************************************************************************ @@ -241,7 +243,6 @@ def makeImage(file=None, data=None, dither=None, alpha=None): kw["texture"] = data # ob das geht ?? - kommt das vor ? # yy = self.yy - ''' if 'source' in kw: logging.info ("makeImage: " + kw["source"]) @@ -264,8 +265,8 @@ def copyImage(image, x, y, width, height): def fillTexture(texture, fill, outline=None, owidth=1): - logging.info("fillImage: t=%s, f=%s o=%s, w=%s" % - (texture, fill, outline, owidth)) + # logging.info("fillImage: t=%s, f=%s o=%s, w=%s" % + # (texture, fill, outline, owidth)) # O.K. Kivy if not fill and not outline: @@ -275,7 +276,7 @@ def fillTexture(texture, fill, outline=None, owidth=1): height = texture.height ox = round(owidth) - ow = int(ox) # muss int sein! + ow = int(ox) # muss int sein! if width <= 2 * ow or height <= 2 * ow: fill = fill or outline outline = None @@ -315,7 +316,12 @@ def fillTexture(texture, fill, outline=None, owidth=1): if len(outline) >= 8: ou3 = int(outline[6:8], 16) - l1 = (ou0, ou1, ou2, ou3, ) * width + l1 = ( + ou0, + ou1, + ou2, + ou3, + ) * width l2 = (ou0, ou1, ou2, ou3, ) * ow + (fi0, fi1, fi2, fi3, ) * \ (width - 2 * ow) + (ou0, ou1, ou2, ou3, ) * ow f = (l1, ) * ow + (l2, ) * (height - 2 * ow) + (l1, ) * ow @@ -325,8 +331,6 @@ def fillTexture(texture, fill, outline=None, owidth=1): arr = array('B', f) texture.blit_buffer(arr, colorfmt='rgba', bufferfmt='ubyte') - logging.info("fillImage: filled") - def createImage(width, height, fill, outline=None, outwidth=1): @@ -338,14 +342,15 @@ def createImage(width, height, fill, outline=None, outwidth=1): # fill = '#00cc00' # if (outline==None): # outline = '#ff00ff' - if (fill is None and (outline is None or outline == '')): - outline = '#fff000' - outwidth = 1 + + # if (fill is None and (outline is None or outline == '')): + # outline = '#fff000' + # outwidth = 1 texture = Texture.create(size=(width, height), colorfmt='rgba') fillTexture(texture, fill, outline, outwidth) image = LImage(texture=texture) - logging.info("createImage: LImage create %s" % image) + # logging.info("createImage: LImage create %s" % image) return image @@ -364,17 +369,142 @@ def markImage(image): return None +def _createImageMask(texture, color): + + col = 0 + if (color is 'black'): + col = 0 + if (color is 'white'): + col = 255 + + g = texture.pixels + arr = array('B', g) + + for mx in range(int(len(arr) / 4)): + m = 4 * mx + if arr[m + 3] < 128: + arr[m + 3] = 0 + arr[m] = arr[m + 1] = arr[m + 2] = 0 + else: + arr[m + 3] = 32 + arr[m] = arr[m + 1] = arr[m + 2] = col + + mask = Texture.create(size=texture.size, colorfmt='rgba') + mask.blit_buffer(arr, colorfmt='rgba', bufferfmt='ubyte') + return mask + + +def _scaleTextureToSize(texture, size): + + width = size[0] + height = size[1] + + g = texture.pixels + ag = array('B', g) + gw, gh = texture.size + + # print('size:',width,height) + # print('texture size:',gw,gh) + + bb = array('B', [0 for x in range(width * height * 4)]) + # print ('bb length: ',len(bb)) + # print ('gg length: ',gw*gh*4) + + scalex = width / gw + scaley = height / gh + + # scale, x und y offset bestimmen. + + scale = scaley + if (scalex < scaley): + scale = scalex + + offx = (width - gw * scale) / 2 + offy = (height - gh * scale) / 2 + + # print ('scale: ',scalex,'/',scaley,' -> ',scale) + # print ('offs: ',offx,'/',offy) + + for bi in range(height): + bline = bi * width + if (bi >= offy) and (bi < (height - offy)): + # transfer + ai = gh - int((bi - offy) / scale) - 1 + aline = ai * gw + for bk in range(width): + bpos = (bline + bk) * 4 + if (bk >= offx) and (bk < (width - offx)): + # transfer + ak = gw - int((bk - offx) / scale) - 1 + apos = (aline + ak) * 4 + bb[bpos] = ag[apos] + bb[bpos + 1] = ag[apos + 1] + bb[bpos + 2] = ag[apos + 2] + bb[bpos + 3] = ag[apos + 3] + else: + # transparent + bb[bpos + 3] = 0 + else: + # transparent + for bk in range(width): + bb[(bline + bk) * 4 + 3] = 0 + + stext = Texture.create(size=(width, height), colorfmt='rgba') + stext.blit_buffer(bb, colorfmt='rgba', bufferfmt='ubyte') + return stext + + +def _pasteTextureTo(texture, totexture): + + g = texture.pixels + ag = array('B', g) + gw, gh = texture.size + + t = totexture.pixels + at = array('B', t) + tw, th = totexture.size + + if (tw != gw) or (th != gh): + return + + for i in range(int(len(ag) / 4)): + i4 = i * 4 + if ag[i4 + 3] > 128: + at[i4] = ag[i4] + at[i4 + 1] = ag[i4 + 1] + at[i4 + 2] = ag[i4 + 2] + at[i4 + 3] = ag[i4 + 3] + + stext = Texture.create(size=(tw, th), colorfmt='rgba') + stext.blit_buffer(at, colorfmt='rgba', bufferfmt='ubyte') + return stext + + def createBottom(image, color='white', backfile=None): - logging.info("createBottom: ") - # TBD. - # y = self.yy + backfilebase = None + if backfile is not None: + backfilebase = os.path.basename(backfile) - if not hasattr(image, '_pil_image'): - return None + logging.info("createBottom: %s | %s" % (color, backfilebase)) + # print('createBottom:',image) - # obviously not used. - return None + # th = 1 # thickness + # size = (w - th * 2, h - th * 2) + # original: zeichnet noch eine outline um die karte - können wir nicht. + + tmp0 = _createImageMask(image.texture, color) + if backfile: + tmp1 = CoreImage(backfile) + txtre = _scaleTextureToSize(tmp1.texture, image.texture.size) + tmp = _pasteTextureTo(txtre, tmp0) + else: + tmp = tmp0 + + img = LImage(texture=tmp) + img.size[0] = image.getWidth() + img.size[1] = image.getHeight() + return img ''' im = image._pil_image th = 1 # thickness @@ -399,6 +529,7 @@ def createBottom(image, color='white', backfile=None): return PIL_Image(image=out) ''' + # ************************************************************************ # * font utils # ************************************************************************ diff --git a/pysollib/kivy/toolbar.py b/pysollib/kivy/toolbar.py index 692f6b43..3106b160 100644 --- a/pysollib/kivy/toolbar.py +++ b/pysollib/kivy/toolbar.py @@ -71,7 +71,7 @@ class AbstractToolbarButton: if E402Fix: - from LApp import LImage + from pysollib.kivy.LApp import LImage # from LApp import LMainWindow from kivy.uix.boxlayout import BoxLayout # from kivy.uix.button import Button @@ -85,6 +85,7 @@ if E402Fix: class MyButton(ButtonBehavior, KivyImage): def __init__(self, **kwargs): super(MyButton, self).__init__(**kwargs) + # super(MyButton, self).__init__() self.src = None if ('image' in kwargs): self.src = kwargs['image'].source @@ -106,6 +107,7 @@ class MyButton(ButtonBehavior, KivyImage): class MyCheckButton(ButtonBehavior, KivyImage): def __init__(self, **kwargs): super(MyCheckButton, self).__init__(**kwargs) + # super(MyCheckButton, self).__init__() self.src = None if ('image' in kwargs): self.src = kwargs['image'].source diff --git a/pysollib/mfxutil.py b/pysollib/mfxutil.py index 67bbf07b..440da557 100644 --- a/pysollib/mfxutil.py +++ b/pysollib/mfxutil.py @@ -131,7 +131,7 @@ def getusername(): def getprefdir(package): if (TOOLKIT == 'kivy'): - from kivy.LApp import get_platform + from pysollib.kivy.LApp import get_platform plat = get_platform() if plat == 'android': os.environ['HOME'] = '/sdcard'