From d89f589b82448b9b417b3b1d1bce6d9da3687ca1 Mon Sep 17 00:00:00 2001 From: skomoroh Date: Fri, 6 Oct 2006 21:22:09 +0000 Subject: [PATCH] + improved tile support git-svn-id: file:///home/shlomif/Backup/svn-dumps/PySolFC/svnsync-repos/pysolfc/PySolFC/trunk@79 efabe8c0-fbe8-4139-b769-b5e6d273206e --- MANIFEST.in | 1 + pysollib/main.py | 14 +++++++++----- pysollib/tile/tkutil.py | 37 ++++++++++++++++++++++++++++++------- pysollib/tile/tkwrap.py | 12 ++++++------ pysollib/tile/toolbar.py | 6 +++++- 5 files changed, 51 insertions(+), 19 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 479e3134..da71a05a 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -17,6 +17,7 @@ include scripts/all_games.py scripts/cardset_viewer.py include docs/* graft data/html graft data/html-src +graft data/themes ## ## data - images ## diff --git a/pysollib/main.py b/pysollib/main.py index fe7fe883..908e31a8 100644 --- a/pysollib/main.py +++ b/pysollib/main.py @@ -213,9 +213,6 @@ def pysol_init(app, args): app.debug = int(opts['debug']) except: print >> sys.stderr, 'invalid argument for debug' - if opts['tile-theme']: - import settings - settings.TILE_THEME = opts['tile-theme'] # init games database import games @@ -245,8 +242,15 @@ def pysol_init(app, args): app.top_bg = top.cget("bg") app.top_palette = [None, None] # [fg, bg] app.top_cursor = top.cget("cursor") - - # print some debug info + if USE_TILE: + import settings + if opts['tile-theme']: + settings.TILE_THEME = opts['tile-theme'] + from pysoltk import load_theme + try: + load_theme(app, top, settings.TILE_THEME) + except Exception, err: + print >> sys.stderr, 'ERROR: set theme:', err # load options app.loadOptions() diff --git a/pysollib/tile/tkutil.py b/pysollib/tile/tkutil.py index 48224b27..ace112bc 100644 --- a/pysollib/tile/tkutil.py +++ b/pysollib/tile/tkutil.py @@ -52,6 +52,7 @@ __all__ = ['wm_withdraw', #'fillImage', 'createImage', 'get_text_width', + 'load_theme', ] # imports @@ -174,14 +175,9 @@ def make_help_toplevel(app, title=None): # Create an independent Toplevel window. parent = app.top window = Tkinter.Tk(className=PACKAGE) - window.tk.call('package', 'require', 'tile') from pysollib.settings import TILE_THEME if TILE_THEME: - ##window.tk.call('style', 'theme', 'use', TILE_THEME) - style = Tkinter.Style(window) - style.theme_use(TILE_THEME) - bg = window.tk.call('style', 'lookup', TILE_THEME, '-background') - window.tk_setPalette(bg) + load_theme(app, window, TILE_THEME) font = parent.option_get('font', '') if font: window.option_add('*font', font) @@ -195,7 +191,6 @@ def make_help_toplevel(app, title=None): if os.name == "posix": window.option_add('*Scrollbar.elementBorderWidth', '1', 60) window.option_add('*Scrollbar.borderWidth', '1', 60) - if title: window.wm_title(title) window.wm_iconname(title) @@ -409,3 +404,31 @@ def createImage(width, height, fill, outline=None): def get_text_width(text, font, root=None): return Font(root=root, font=font).measure(text) + +# /*********************************************************************** +# // +# ************************************************************************/ + +def load_theme(app, top, theme): + top.tk.call("package", "require", "tile") + # load available themes + d = os.path.join(app.dataloader.dir, 'themes') + if os.path.isdir(d): + top.tk.call('lappend', 'auto_path', d) + for t in os.listdir(d): + #top.tk.call('tile::setTheme', t) + try: + top.tk.call('package', 'require', 'tile::theme::'+t) + ##print 'load theme:', t + except: + traceback.print_exc() + pass + # set theme + if theme: + top.tk.call('style', 'theme', 'use', theme) + bg = top.tk.call('style', 'lookup', '.', '-background') + top.tk_setPalette(bg) + bg = top.tk.call('style', 'lookup', '.', '-background', 'active') + top.option_add('*Menu.activeBackground', bg) + + diff --git a/pysollib/tile/tkwrap.py b/pysollib/tile/tkwrap.py index 692f63d3..1ffdfc19 100644 --- a/pysollib/tile/tkwrap.py +++ b/pysollib/tile/tkwrap.py @@ -85,12 +85,12 @@ StringVar = Tkinter.StringVar class MfxRoot(Tkinter.Tk): def __init__(self, **kw): apply(Tkinter.Tk.__init__, (self,), kw) - self.tk.call("package", "require", "tile") - from pysollib.settings import TILE_THEME - if TILE_THEME: - ##self.tk.call('style', 'theme', 'use', TILE_THEME) - style = Tkinter.Style(self) - style.theme_use(TILE_THEME) +## self.tk.call("package", "require", "tile") +## from pysollib.settings import TILE_THEME +## if TILE_THEME: +## ##self.tk.call('style', 'theme', 'use', TILE_THEME) +## style = Tkinter.Style(self) +## style.theme_use(TILE_THEME) self.app = None # for interruptible sleep #self.sleep_var = Tkinter.IntVar(self) diff --git a/pysollib/tile/toolbar.py b/pysollib/tile/toolbar.py index 468a4461..c2f61553 100644 --- a/pysollib/tile/toolbar.py +++ b/pysollib/tile/toolbar.py @@ -38,6 +38,7 @@ __all__ = ['PysolToolbar'] #, 'TOOLBAR_BUTTONS'] # imports import os, sys, types import traceback +import Tkinter as Tk import Tile as Tkinter try: # PIL @@ -223,7 +224,8 @@ class PysolToolbar(PysolToolbarActions): self.label_pady = 4 self.button_pad = 2 # - self.frame = Tkinter.Frame(top, class_='Toolbar') + #self.frame = Tkinter.Frame(top, class_='Toolbar') + self.frame = Tk.Frame(top) # for l, f, t in ( (n_("New"), self.mNewGame, _("New game")), @@ -273,6 +275,7 @@ class PysolToolbar(PysolToolbarActions): if os.name == 'posix': #self.frame.config(bd=0, highlightthickness=1) #~self.frame.config(bd=1, relief=self.frame_relief, highlightthickness=0) + self.frame.config(bd=1, relief='raised', highlightthickness=0) pass elif os.name == "nt": self.frame.config(bd=2, relief=self.frame_relief, padx=2, pady=2) @@ -536,6 +539,7 @@ class PysolToolbar(PysolToolbarActions): return 1 def setRelief(self, relief): + return True if self.button_relief == relief: return False self._setRelief(relief)