1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00

Implementation of createBottom in kivy.

A first set of Python 3 adaptations.
Added a choice of cardsets to android build.
Added new scripts to tarball (MAKEFILE.in)
This commit is contained in:
lb@lb520 2018-03-12 20:35:42 +01:00
parent 1394c0df8f
commit 91ef11b7ac
23 changed files with 278 additions and 132 deletions

View file

@ -18,6 +18,7 @@ graft data/themes
recursive-exclude data/themes *.py recursive-exclude data/themes *.py
include scripts/build.bat scripts/create_iss.py scripts/mahjongg_utils.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/pygettext.py scripts/all_games.py scripts/cardset_viewer.py
include scripts/cardconv scripts/cardsetsgiftobmp
include android/*.py include android/*.py
include android/mk* include android/mk*
include android/debian/* include android/debian/*

46
android/mkcards Executable file
View file

@ -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'

View file

@ -1,6 +1,8 @@
#!/bin/bash #!/bin/bash
rm -rf tmp/* rm -rf tmp
python3 -m pythonforandroid.toolchain clean_dists python3 -m pythonforandroid.toolchain clean_dists
python3 -m pythonforandroid.toolchain clean_builds python3 -m pythonforandroid.toolchain clean_builds
rm -f *.apk rm -f *.apk
rm -rf PySolFC-Cardsets-2.0

View file

@ -1,7 +1,10 @@
#!/bin/bash #!/bin/bash
rm -rf tmp/* rm -rf tmp
rm -f *.apk 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/packages
rm -rf ~/.local/share/python-for-android/build rm -rf ~/.local/share/python-for-android/build
rm -rf ~/.local/share/python-for-android/dists rm -rf ~/.local/share/python-for-android/dists

View file

@ -13,9 +13,18 @@ echo '### install p4a'
#python3 -m pip install -q --user "./p4a/${p4aversion}.zip" #python3 -m pip install -q --user "./p4a/${p4aversion}.zip"
p4aversion='0.5.3' 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 ] if [ -d ./packages ]
then then
@ -40,5 +49,18 @@ mv ${HOME}/.local/tmp/src tmp/src
rm -rf tmp/src/android rm -rf tmp/src/android
rm -rf tmp/src/src rm -rf tmp/src/src
cp -a main.py tmp/src/main.py 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' echo '### end init'

Binary file not shown.

View file

@ -114,7 +114,7 @@ class Images:
imagedir = self.d.findDir(cs_type, d) imagedir = self.d.findDir(cs_type, d)
except Exception: except Exception:
pass pass
if not USE_PIL or imagedir is None: if (not USE_PIL and TOOLKIT is not 'kivy') or imagedir is None:
# load image # load image
img = self.__loadCard(filename+self.cs.ext, check_w, check_h) img = self.__loadCard(filename+self.cs.ext, check_w, check_h)
if USE_PIL: if USE_PIL:
@ -260,6 +260,8 @@ class Images:
return self._bottom[0] return self._bottom[0]
def getBlankBottom(self): def getBlankBottom(self):
if TOOLKIT is 'kivy':
return self._bottom[0]
return self._blank_bottom return self._blank_bottom
def getSuitBottom(self, suit=-1): def getSuitBottom(self, suit=-1):

View file

@ -21,11 +21,7 @@
from __future__ import division from __future__ import division
# import os
# print ('KIVY_HOME: '+os.environ['KIVY_HOME'])
import logging import logging
# import time
import math import math
import traceback import traceback
@ -34,15 +30,10 @@ from kivy.graphics import Rectangle
from kivy.graphics import Line from kivy.graphics import Line
from kivy.graphics import Triangle from kivy.graphics import Triangle
# from kivy.uix.treeview import TreeView
# from kivy.uix.actionbar import ActionBar
from kivy.utils import platform from kivy.utils import platform
# from kivy.event import EventDispatcher
from kivy.properties import StringProperty from kivy.properties import StringProperty
from kivy.base import EventLoop from kivy.base import EventLoop
# from kivy.base import EventLoopBase
from kivy.base import stopTouchApp from kivy.base import stopTouchApp
from kivy.app import App from kivy.app import App
from kivy.animation import Animation from kivy.animation import Animation
@ -50,13 +41,11 @@ from kivy.core.audio import SoundLoader
from kivy.clock import Clock from kivy.clock import Clock
from kivy.uix.image import Image as KivyImage from kivy.uix.image import Image as KivyImage
# from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.boxlayout import BoxLayout from kivy.uix.boxlayout import BoxLayout
from kivy.uix.widget import Widget from kivy.uix.widget import Widget
from kivy.uix.button import Button from kivy.uix.button import Button
from kivy.uix.behaviors import ButtonBehavior from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.label import Label from kivy.uix.label import Label
# from kivy.uix.relativelayout import RelativeLayout
from kivy.uix.scrollview import ScrollView from kivy.uix.scrollview import ScrollView
from kivy.uix.actionbar import ActionView from kivy.uix.actionbar import ActionView
@ -294,6 +283,7 @@ class LText(Widget):
def __init__(self, canvas, x, y, **kwargs): def __init__(self, canvas, x, y, **kwargs):
super(LText, self).__init__(**kwargs) super(LText, self).__init__(**kwargs)
# super(LText, self).__init__()
if 'text' not in kwargs: if 'text' not in kwargs:
kwargs['text'] = 'X' kwargs['text'] = 'X'
@ -317,6 +307,7 @@ class LText(Widget):
# print('LText: text = %s' % (self.text)) # print('LText: text = %s' % (self.text))
self.label = Label(font=font, font_size=fontsize, **kwargs) self.label = Label(font=font, font_size=fontsize, **kwargs)
# self.label = Label(font=font, font_size=fontsize)
self.label.texture_update() self.label.texture_update()
self.coreSize = self.label.texture_size self.coreSize = self.label.texture_size
self.corePos = (x, y) self.corePos = (x, y)
@ -1082,6 +1073,7 @@ class LMenuBar(BoxLayout):
class LMenu(ActionView): class LMenu(ActionView):
def __init__(self, prev, **kw): def __init__(self, prev, **kw):
print('prev = %s, kw = %s' % (prev, kw))
super(LMenu, self).__init__(**kw) super(LMenu, self).__init__(**kw)
self.ap = ap = ActionPrevious( self.ap = ap = ActionPrevious(
with_previous=prev, size_hint=(.01, 1), **kw) with_previous=prev, size_hint=(.01, 1), **kw)
@ -1143,6 +1135,7 @@ class LMenuItem(ActionButton):
def __init__(self, menu, **kw): def __init__(self, menu, **kw):
super(LMenuItem, self).__init__(**kw) super(LMenuItem, self).__init__(**kw)
# super(LMenuItem, self).__init__()
self.bar = None self.bar = None
self.submenu = None self.submenu = None
self.menu = menu self.menu = menu
@ -1422,13 +1415,8 @@ class LMainWindow(BoxLayout, LTkBase):
background_normal='atlas:' background_normal='atlas:'
'//data/images/defaulttheme/action_item', '//data/images/defaulttheme/action_item',
border=(0, 0, 0, 0)) border=(0, 0, 0, 0))
self.topLine1 = Label( self.topLine1 = Label(size_hint=(1.0, 0.01))
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.add_widget(self.topLine) self.add_widget(self.topLine)
self.add_widget(self.menuArea) self.add_widget(self.menuArea)
self.add_widget(self.topLine1) self.add_widget(self.topLine1)

View file

@ -22,7 +22,7 @@
# ---------------------------------------------------------------------------# # ---------------------------------------------------------------------------#
# Toolkit imports # Toolkit imports
from tkwidget import MfxDialog from pysollib.pysoltk import MfxDialog
__all__ = ['ColorsDialog'] __all__ = ['ColorsDialog']

View file

@ -22,7 +22,7 @@
# ---------------------------------------------------------------------------# # ---------------------------------------------------------------------------#
# Toolkit imports # Toolkit imports
from tkwidget import MfxDialog from pysollib.pysoltk import MfxDialog
__all__ = ['EditTextDialog'] __all__ = ['EditTextDialog']

View file

@ -22,7 +22,7 @@
# ---------------------------------------------------------------------------# # ---------------------------------------------------------------------------#
# Toolkit imports # Toolkit imports
from tkwidget import MfxDialog from pysollib.pysoltk import MfxDialog
__all__ = ['FontsDialog'] __all__ = ['FontsDialog']

View file

@ -27,7 +27,7 @@
# from pysollib.gamedb import GI # from pysollib.gamedb import GI
# Toolkit imports # Toolkit imports
from tkwidget import MfxDialog from pysollib.pysoltk import MfxDialog
__all__ = ['GameInfoDialog'] __all__ = ['GameInfoDialog']

View file

@ -31,21 +31,12 @@ import re
# import traceback # import traceback
# PySol imports # PySol imports
# from pysollib.mygettext import _, n_
from pysollib.mygettext import _ from pysollib.mygettext import _
# from pysollib.mfxutil import Struct, kwdefault
from pysollib.mfxutil import Struct from pysollib.mfxutil import Struct
# from pysollib.mfxutil import Image
from pysollib.util import CARDSET from pysollib.util import CARDSET
# from pysollib.settings import TITLE, WIN_SYSTEM
from pysollib.settings import TITLE from pysollib.settings import TITLE
# from pysollib.settings import TOP_TITLE
from pysollib.settings import SELECT_GAME_MENU 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.gamedb import GI
# from pysollib.pysoltk import MfxMenu
# from pysollib.pysoltk import SelectCardsetDialogWithPreview
# toolkit imports # toolkit imports
from pysollib.kivy.tkconst import EVENT_HANDLED, EVENT_PROPAGATE, CURSOR_WATCH 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.tkutil import after_idle
from pysollib.kivy.selectcardset import SelectCardsetDialogWithPreview from pysollib.kivy.selectcardset import SelectCardsetDialogWithPreview
from selectgame import SelectGameDialog from pysollib.kivy.selectgame import SelectGameDialog
from findcarddialog import connect_game_find_card_dialog from pysollib.pysoltk import connect_game_find_card_dialog
from findcarddialog import destroy_find_card_dialog
from solverdialog import connect_game_solver_dialog from pysollib.kivy.findcarddialog import destroy_find_card_dialog
from tkconst import TOOLBAR_BUTTONS from pysollib.kivy.solverdialog import connect_game_solver_dialog
from pysollib.kivy.tkconst import TOOLBAR_BUTTONS
# Kivy # 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 BooleanProperty
from kivy.properties import NumericProperty from kivy.properties import NumericProperty
from kivy.properties import StringProperty from kivy.properties import StringProperty
from kivy.event import EventDispatcher from kivy.event import EventDispatcher
from LApp import LMenu from pysollib.kivy.LApp import LMenu
from LApp import LTreeNode from pysollib.kivy.LApp import LTreeNode
from LApp import LMenuItem from pysollib.kivy.LApp import LMenuItem
from LApp import LTopLevel from pysollib.kivy.LApp import LTopLevel
from LApp import LScrollView from pysollib.kivy.LApp import LScrollView
from LApp import LTreeRoot from pysollib.kivy.LApp import LTreeRoot
__all__ = ['PysolMenubarTk'] __all__ = ['PysolMenubarTk']
@ -1112,9 +1094,6 @@ class EmulTkMenu(object):
def __init__(self, master, **kw): def __init__(self, master, **kw):
# tearoff = 0
# self.n = kw["tearoff"] = int(kw.get("tearoff", tearoff))
self.name = kw["name"] self.name = kw["name"]
self.n = 0 self.n = 0
self._w = None self._w = None
@ -1126,10 +1105,7 @@ class EmulTkMenu(object):
else: else:
self.name = "<>" self.name = "<>"
# print('self._w = %s' % self._w)
def labeltoname(self, label): def labeltoname(self, label):
# print label, type(label)
name = re.sub(r"[^0-9a-zA-Z]", "", label).lower() name = re.sub(r"[^0-9a-zA-Z]", "", label).lower()
label = _(label) label = _(label)
underline = label.find('&') underline = label.find('&')
@ -1138,19 +1114,14 @@ class EmulTkMenu(object):
return name, label, underline return name, label, underline
def add_cascade(self, cnf={}, **kw): def add_cascade(self, cnf={}, **kw):
# print('add_cascade: %s, %s' % (cnf, kw))
self.add('cascade', cnf or kw) self.add('cascade', cnf or kw)
pass pass
def add(self, itemType, cnf={}): def add(self, itemType, cnf={}):
label = cnf.get("label") label = cnf.get("label")
# print('add: label=%s' % label)
if label: if label:
name = cnf.get('name') name = cnf.get('name')
if name: if name:
# LB ?????
# del cnf['name'] # TclError: unknown option "-name"
# else:
name, label, underline = self.labeltoname(label) name, label, underline = self.labeltoname(label)
cnf["underline"] = cnf.get("underline", underline) cnf["underline"] = cnf.get("underline", underline)
cnf["label"] = label cnf["label"] = label
@ -1158,9 +1129,6 @@ class EmulTkMenu(object):
path = str(self._w) + "." + name path = str(self._w) + "." + name
self.addPath(path, self, self.n, cnf.get("menu")) self.addPath(path, self, self.n, cnf.get("menu"))
# Tkinter.Menu.add(self, itemType, cnf)
# self.n = self.n + 1
def cget(self, key): def cget(self, key):
return key return key

View file

@ -22,7 +22,7 @@
# ---------------------------------------------------------------------------# # ---------------------------------------------------------------------------#
# Toolkit imports # Toolkit imports
from tkwidget import MfxDialog from pysollib.pysoltk import MfxDialog
__all__ = ['PlayerOptionsDialog'] __all__ = ['PlayerOptionsDialog']

View file

@ -27,13 +27,10 @@
# PySol imports # PySol imports
from pysollib.mygettext import _ from pysollib.mygettext import _
# from pysollib.resource import CSI
from pysollib.mfxutil import kwdefault from pysollib.mfxutil import kwdefault
# Toolkit imports # Toolkit imports
from tkwidget import MfxDialog from pysollib.pysoltk import MfxDialog
# from tkcanvas import MfxCanvas, MfxCanvasImage
# from tkutil import loadImage
# ************************************************************************ # ************************************************************************
# * Dialog # * Dialog

View file

@ -23,43 +23,29 @@
# imports # imports
# import os # import os
from UserList import UserList from six.moves import UserList
# PySol imports # PySol imports
# from pysollib.mygettext import _, n_
from pysollib.mygettext import _ from pysollib.mygettext import _
# from pysollib.mfxutil import destruct, Struct, KwStruct
# from pysollib.mfxutil import format_time
from pysollib.gamedb import GI from pysollib.gamedb import GI
# from pysollib.help import help_html
# from pysollib.resource import CSI
# Toolkit imports # Toolkit imports
# from tkutil import unbind_destroy from pysollib.kivy.selecttree import SelectDialogTreeLeaf, SelectDialogTreeNode
# from tkwidget import MfxDialog, MfxScrolledCanvas from pysollib.kivy.selecttree import SelectDialogTreeData
from selecttree import SelectDialogTreeLeaf, SelectDialogTreeNode from pysollib.kivy.LApp import LScrollView
from selecttree import SelectDialogTreeData # , SelectDialogTreeCanvas from pysollib.kivy.LApp import LTopLevel
from pysollib.kivy.LApp import LTreeNode
from pysollib.kivy.LApp import LTreeRoot
# Kivy imports # 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 kivy.clock import Clock
from LApp import LScrollView
from LApp import LTopLevel
from LApp import LTreeNode
from LApp import LTreeRoot
# ************************************************************************ # ************************************************************************
# * Nodes # * Nodes
# ************************************************************************ # ************************************************************************
class SelectGameLeaf(SelectDialogTreeLeaf): class SelectGameLeaf(SelectDialogTreeLeaf):
pass pass

View file

@ -25,8 +25,7 @@
# import tkFont # import tkFont
# Toolkit imports # Toolkit imports
# from pysollib.mygettext import _, n_ from pysollib.kivy.tktree import MfxTreeLeaf, MfxTreeNode, MfxTreeInCanvas
from tktree import MfxTreeLeaf, MfxTreeNode, MfxTreeInCanvas
__all__ = ['SelectDialogTreeData'] __all__ = ['SelectDialogTreeData']

View file

@ -442,7 +442,8 @@ class MfxCanvasText(object):
class MfxCanvas(Widget): class MfxCanvas(Widget):
def __init__(self, wmain, *args, **kw): 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) # self.tags = {} # bei basisklasse widget (ev. nur vorläufig)

View file

@ -23,7 +23,8 @@
# imports # imports
import os import os
import htmllib # import htmllib
import pysollib.htmllib2 as htmllib
import formatter import formatter
# PySol imports # PySol imports
@ -38,9 +39,6 @@ from pysollib.pysoltk import MfxMessageDialog
from kivy.uix.boxlayout import BoxLayout from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label from kivy.uix.label import Label
from kivy.uix.button import Button 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:") REMOTE_PROTOCOLS = ("ftp:", "gopher:", "http:", "mailto:", "news:", "telnet:")

View file

@ -25,14 +25,14 @@
# import os # import os
# Toolkit imports # Toolkit imports
# from tkutil import bind from pysollib.pysoltk import MfxScrolledCanvas
from tkwidget import MfxScrolledCanvas
# ************************************************************************ # ************************************************************************
# * # *
# ************************************************************************ # ************************************************************************
class MfxTreeBaseNode: class MfxTreeBaseNode:
def __init__(self, tree, parent_node, text, key): def __init__(self, tree, parent_node, text, key):
self.tree = tree self.tree = tree

View file

@ -26,7 +26,6 @@
# emulated. # emulated.
from __future__ import division from __future__ import division
''' '''
__all__ = ['wm_withdraw', __all__ = ['wm_withdraw',
'wm_map', 'wm_map',
@ -51,18 +50,19 @@ __all__ = ['wm_withdraw',
''' '''
# imports # imports
import os
import logging import logging
from array import array from array import array
# PySol imports # Toolkit imports
# from pysollib.mfxutil import Image
from pysollib.kivy.LApp import LTopLevel0 from pysollib.kivy.LApp import LTopLevel0
from pysollib.kivy.LApp import LImage from pysollib.kivy.LApp import LImage
# Kivy imports # Kivy imports
from kivy.core.text import Label as CoreLabel 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.graphics.texture import Texture
from kivy.clock import Clock
# ************************************************************************ # ************************************************************************
# * window manager util # * window manager util
@ -76,6 +76,7 @@ def wm_withdraw(window):
def wm_map(window, maximized=0): def wm_map(window, maximized=0):
return return
# ************************************************************************ # ************************************************************************
# * window util # * window util
# ************************************************************************ # ************************************************************************
@ -112,11 +113,11 @@ def make_help_toplevel(app, title=None):
# init_root_window(window, app) # init_root_window(window, app)
return window return window
# ************************************************************************ # ************************************************************************
# * bind wrapper - Tkinter doesn't properly delete all bindings # * bind wrapper - Tkinter doesn't properly delete all bindings
# ************************************************************************ # ************************************************************************
__mfx_bindings = {} __mfx_bindings = {}
__mfx_wm_protocols = ("WM_DELETE_WINDOW", "WM_TAKE_FOCUS", "WM_SAVE_YOURSELF") __mfx_wm_protocols = ("WM_DELETE_WINDOW", "WM_TAKE_FOCUS", "WM_SAVE_YOURSELF")
@ -196,6 +197,7 @@ def unbind_destroy(widget):
widget.bindings = [] widget.bindings = []
pass pass
# ************************************************************************ # ************************************************************************
# * timer wrapper - Tkinter doesn't properly delete all commands # * 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 kw["texture"] = data
# ob das geht ?? - kommt das vor ? # ob das geht ?? - kommt das vor ?
# yy = self.yy # yy = self.yy
''' '''
if 'source' in kw: if 'source' in kw:
logging.info ("makeImage: " + kw["source"]) logging.info ("makeImage: " + kw["source"])
@ -264,8 +265,8 @@ def copyImage(image, x, y, width, height):
def fillTexture(texture, fill, outline=None, owidth=1): def fillTexture(texture, fill, outline=None, owidth=1):
logging.info("fillImage: t=%s, f=%s o=%s, w=%s" % # logging.info("fillImage: t=%s, f=%s o=%s, w=%s" %
(texture, fill, outline, owidth)) # (texture, fill, outline, owidth))
# O.K. Kivy # O.K. Kivy
if not fill and not outline: if not fill and not outline:
@ -275,7 +276,7 @@ def fillTexture(texture, fill, outline=None, owidth=1):
height = texture.height height = texture.height
ox = round(owidth) ox = round(owidth)
ow = int(ox) # muss int sein! ow = int(ox) # muss int sein!
if width <= 2 * ow or height <= 2 * ow: if width <= 2 * ow or height <= 2 * ow:
fill = fill or outline fill = fill or outline
outline = None outline = None
@ -315,7 +316,12 @@ def fillTexture(texture, fill, outline=None, owidth=1):
if len(outline) >= 8: if len(outline) >= 8:
ou3 = int(outline[6:8], 16) 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, ) * \ l2 = (ou0, ou1, ou2, ou3, ) * ow + (fi0, fi1, fi2, fi3, ) * \
(width - 2 * ow) + (ou0, ou1, ou2, ou3, ) * ow (width - 2 * ow) + (ou0, ou1, ou2, ou3, ) * ow
f = (l1, ) * ow + (l2, ) * (height - 2 * ow) + (l1, ) * 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) arr = array('B', f)
texture.blit_buffer(arr, colorfmt='rgba', bufferfmt='ubyte') texture.blit_buffer(arr, colorfmt='rgba', bufferfmt='ubyte')
logging.info("fillImage: filled")
def createImage(width, height, fill, outline=None, outwidth=1): def createImage(width, height, fill, outline=None, outwidth=1):
@ -338,14 +342,15 @@ def createImage(width, height, fill, outline=None, outwidth=1):
# fill = '#00cc00' # fill = '#00cc00'
# if (outline==None): # if (outline==None):
# outline = '#ff00ff' # outline = '#ff00ff'
if (fill is None and (outline is None or outline == '')):
outline = '#fff000' # if (fill is None and (outline is None or outline == '')):
outwidth = 1 # outline = '#fff000'
# outwidth = 1
texture = Texture.create(size=(width, height), colorfmt='rgba') texture = Texture.create(size=(width, height), colorfmt='rgba')
fillTexture(texture, fill, outline, outwidth) fillTexture(texture, fill, outline, outwidth)
image = LImage(texture=texture) image = LImage(texture=texture)
logging.info("createImage: LImage create %s" % image) # logging.info("createImage: LImage create %s" % image)
return image return image
@ -364,17 +369,142 @@ def markImage(image):
return None 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): def createBottom(image, color='white', backfile=None):
logging.info("createBottom: ") backfilebase = None
# TBD. if backfile is not None:
# y = self.yy backfilebase = os.path.basename(backfile)
if not hasattr(image, '_pil_image'): logging.info("createBottom: %s | %s" % (color, backfilebase))
return None # print('createBottom:',image)
# obviously not used. # th = 1 # thickness
return None # 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 im = image._pil_image
th = 1 # thickness th = 1 # thickness
@ -399,6 +529,7 @@ def createBottom(image, color='white', backfile=None):
return PIL_Image(image=out) return PIL_Image(image=out)
''' '''
# ************************************************************************ # ************************************************************************
# * font utils # * font utils
# ************************************************************************ # ************************************************************************

View file

@ -71,7 +71,7 @@ class AbstractToolbarButton:
if E402Fix: if E402Fix:
from LApp import LImage from pysollib.kivy.LApp import LImage
# from LApp import LMainWindow # from LApp import LMainWindow
from kivy.uix.boxlayout import BoxLayout from kivy.uix.boxlayout import BoxLayout
# from kivy.uix.button import Button # from kivy.uix.button import Button
@ -85,6 +85,7 @@ if E402Fix:
class MyButton(ButtonBehavior, KivyImage): class MyButton(ButtonBehavior, KivyImage):
def __init__(self, **kwargs): def __init__(self, **kwargs):
super(MyButton, self).__init__(**kwargs) super(MyButton, self).__init__(**kwargs)
# super(MyButton, self).__init__()
self.src = None self.src = None
if ('image' in kwargs): if ('image' in kwargs):
self.src = kwargs['image'].source self.src = kwargs['image'].source
@ -106,6 +107,7 @@ class MyButton(ButtonBehavior, KivyImage):
class MyCheckButton(ButtonBehavior, KivyImage): class MyCheckButton(ButtonBehavior, KivyImage):
def __init__(self, **kwargs): def __init__(self, **kwargs):
super(MyCheckButton, self).__init__(**kwargs) super(MyCheckButton, self).__init__(**kwargs)
# super(MyCheckButton, self).__init__()
self.src = None self.src = None
if ('image' in kwargs): if ('image' in kwargs):
self.src = kwargs['image'].source self.src = kwargs['image'].source

View file

@ -131,7 +131,7 @@ def getusername():
def getprefdir(package): def getprefdir(package):
if (TOOLKIT == 'kivy'): if (TOOLKIT == 'kivy'):
from kivy.LApp import get_platform from pysollib.kivy.LApp import get_platform
plat = get_platform() plat = get_platform()
if plat == 'android': if plat == 'android':
os.environ['HOME'] = '/sdcard' os.environ['HOME'] = '/sdcard'