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

* some bugs fixes

* cleanup code


git-svn-id: https://pysolfc.svn.sourceforge.net/svnroot/pysolfc/PySolFC/trunk@121 39dd0a4e-7c14-0410-91b3-c4f2d318f732
This commit is contained in:
skomoroh 2006-12-15 22:40:35 +00:00
parent 10f10ecb9c
commit f9711c85af
20 changed files with 54 additions and 285 deletions

View file

@ -5,7 +5,7 @@
##
include pysol.py setup.py setup.cfg MANIFEST.in Makefile COPYING README
#recursive-include pysollib *.py
include pysollib/*.py pysollib/macosx/*.py
include pysollib/*.py pysollib/macosx/*.py pysollib/tksettings/*.py
include pysollib/tk/*.py pysollib/tile/*.py pysollib/pysolgtk/*.py
include pysollib/games/*.py pysollib/games/special/*.py
include pysollib/games/ultra/*.py pysollib/games/mahjongg/*.py

View file

@ -56,6 +56,7 @@ from game import Game
from gamedb import GI, GAME_DB, loadGame
from settings import TOP_SIZE, TOP_TITLE, TOOLKIT
from settings import DEBUG
from tksettings import TkSettings
# Toolkit imports
from pysoltk import wm_withdraw, loadImage
@ -671,11 +672,9 @@ class Application:
# create the canvas
self.scrolled_canvas = MfxScrolledCanvas(self.top)
self.canvas = self.scrolled_canvas.canvas
if WIN_SYSTEM == 'win32':
self.scrolled_canvas.grid(row=1, column=1, sticky='nsew',
padx=1, pady=1)
else:
self.scrolled_canvas.grid(row=1, column=1, sticky='nsew')
padx, pady = TkSettings.canvas_padding
self.scrolled_canvas.grid(row=1, column=1, sticky='nsew',
padx=padx, pady=pady)
self.top.grid_columnconfigure(1, weight=1)
self.top.grid_rowconfigure(1, weight=1)
self.setTile(self.tabletile_index, force=True)

View file

@ -42,7 +42,7 @@ import Tkinter
# PySol imports
from mfxutil import EnvError
from settings import PACKAGE, PACKAGE_URL, TOOLKIT, VERSION, FC_VERSION
from pysoltk import make_help_toplevel, wm_map, wm_set_icon
from pysoltk import make_help_toplevel, wm_map
from pysoltk import MfxMessageDialog
from pysoltk import HTMLViewer
from gamedb import GAME_DB
@ -155,10 +155,6 @@ def help_html(app, document, dir_, top=None):
else:
#maximized = 0
top.wm_minsize(400, 200)
try:
wm_set_icon(top, app.dataloader.findIcon())
except:
pass
viewer = HTMLViewer(top, app, help_html_index)
viewer.display(doc)
#wm_map(top, maximized=maximized)

View file

@ -73,26 +73,28 @@ def init():
settings.TOOLKIT = 'tk'
settings.USE_TILE = True
sys.argv.remove('--tile')
elif settings.TOOLKIT == 'tk' and settings.USE_TILE == 'auto':
# check tile
if settings.TOOLKIT == 'tk':
import Tkinter
from Tkinter import TclError
root = Tkinter.Tk()
#
# TkAqua displays the console automatically in application
# bundles, so we hide it here.
from macosx.appSupport import hideTkConsole
#
hideTkConsole(root)
root.withdraw()
settings.USE_TILE = False
try:
root.tk.call('package', 'require', 'tile', '0.7.8')
except TclError:
pass
else:
settings.USE_TILE = True
settings.WIN_SYSTEM = root.tk.call('tk', 'windowingsystem')
if settings.WIN_SYSTEM == 'aqua':
# TkAqua displays the console automatically in application
# bundles, so we hide it here.
from macosx.appSupport import hideTkConsole
hideTkConsole(root)
#
root.withdraw()
if settings.USE_TILE == 'auto':
# check tile
settings.USE_TILE = False
try:
root.tk.call('package', 'require', 'tile', '0.7.8')
except TclError:
pass
else:
settings.USE_TILE = True
# "can't invoke event <<ThemeChanged>>: application has been destroyed"
#root.destroy()
Tkinter._default_root = None

View file

@ -51,9 +51,6 @@ def wm_deiconify(window):
def wm_map(window, maximized=None):
window.show()
def wm_set_icon(window, icon):
pass
def makeToplevel(parent, title=None, class_=None, gtkclass=gtk.Window):
window = gtkclass()
if not hasattr(window, 'table'):

View file

@ -51,7 +51,7 @@ from pysollib.actions import PysolMenubarActions
# toolkit imports
from tkconst import EVENT_HANDLED, EVENT_PROPAGATE, CURSOR_WATCH, COMPOUNDS
from tkutil import bind, after_idle, load_theme
from tkutil import bind, after_idle
from selectgame import SelectGameDialog, SelectGameDialogWithPreview
from soundoptionsdialog import SoundOptionsDialog
from selectcardset import SelectCardsetDialogWithPreview

View file

@ -41,7 +41,7 @@ import Tile as Tkinter
# Toolkit imports
from tkconst import EVENT_HANDLED, EVENT_PROPAGATE
from tkutil import makeToplevel, setTransient, wm_set_icon
from tkutil import makeToplevel, setTransient
# /***********************************************************************
@ -72,10 +72,6 @@ class PysolProgressBar:
else:
self.progress.pack(expand='yes', fill='x')
self.frame.pack(expand='yes', fill='both')
if app:
try:
wm_set_icon(self.top, app.dataloader.findIcon())
except: pass
if 1:
setTransient(self.top, None, relx=0.5, rely=0.5)
else:

View file

@ -239,9 +239,6 @@ class MfxTreeInCanvas(MfxScrolledCanvas):
self.font = None
self.linestyle = "gray50"
self.linecolor = "black"
if WIN_SYSTEM == "win32":
self.linestyle = "" # Tk bug ?
self.linecolor = "gray50"
def __init__(self, parent, rootnodes, **kw):
kw['bd'] = 0

View file

@ -36,7 +36,6 @@
__all__ = ['wm_withdraw',
'wm_deiconify',
'wm_map',
'wm_set_icon',
'wm_get_geometry',
#'setTransient',
#'makeToplevel',
@ -53,8 +52,6 @@ __all__ = ['wm_withdraw',
'createImage',
'shadowImage',
'get_text_width',
#'init_tile',
#'load_theme',
]
# imports
@ -91,17 +88,6 @@ def wm_map(window, maximized=0):
else:
wm_deiconify(window)
def wm_set_icon(window, filename):
if not filename:
return
if WIN_SYSTEM == 'win32':
##window.tk.call('wm', 'iconbitmap', root._w, '-default', '@'+filename)
pass
elif WIN_SYSTEM == 'x11':
##window.wm_iconbitmap("@"+filename)
##window.wm_iconmask("@"+filename)
pass
__wm_get_geometry_re = re.compile(r"^(\d+)x(\d+)\+([\-]?\d+)\+([\-]?\d+)$")
def wm_get_geometry(window):
@ -383,64 +369,4 @@ def get_text_width(text, font, root=None):
return Font(root=root, font=font).measure(text)
# /***********************************************************************
# //
# ************************************************************************/
def init_tile(app, top, theme):
if WIN_SYSTEM == 'x11':
f = os.path.join(app.dataloader.dir, 'tcl', 'menu8.4.tcl')
if os.path.exists(f):
top.tk.call('source', f)
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):
if os.path.exists(os.path.join(d, t, 'pkgIndex.tcl')):
try:
top.tk.call('package', 'require', 'tile::theme::'+t)
#print 'load theme:', t
except:
traceback.print_exc()
pass
#
load_theme(app, top, theme)
def load_theme(app, top, theme):
# set theme
style = Tkinter.Style(top)
all_themes = style.theme_names()
if theme not in all_themes:
print >> sys.stderr, 'WARNING: invalid theme name:', theme
theme = 'default'
if theme:
style.theme_use(theme)
if WIN_SYSTEM == 'x11':
color = style.lookup('.', 'background')
if color:
top.tk_setPalette(color)
color = style.lookup('.', 'background', 'active')
if color:
top.option_add('*Menu.activeBackground', color)
elif WIN_SYSTEM == 'win32':
if theme not in ('winnative', 'xpnative'):
color = style.lookup('.', 'background')
if color:
top.tk_setPalette(color)
##top.option_add('*Menu.foreground', 'black')
top.option_add('*Menu.activeBackground', '#08246b')
top.option_add('*Menu.activeForeground', 'white')
if theme == 'winnative':
style.configure('Toolbutton', padding=2)
font = app.opt.fonts['default']
if font:
style.configure('.', font=font)
else:
font = style.lookup('.', 'font')
if font:
top.option_add('*font', font)

View file

@ -47,9 +47,9 @@ from tkFont import Font
# PySol imports
from pysollib.mfxutil import destruct, Struct
from pysollib.settings import PACKAGE, VERSION, WIN_SYSTEM
from pysollib.settings import PACKAGE, VERSION
from pysollib.macosx.appSupport import setupApp
from tkutil import after_idle, init_tile, wm_set_icon
from tkutil import after_idle
from tkconst import EVENT_HANDLED, EVENT_PROPAGATE
# /***********************************************************************
@ -99,68 +99,6 @@ class MfxRoot(Tkinter.Tk):
def connectApp(self, app):
self.app = app
def initToolkit(self, app, fg=None, bg=None, font=None):
setupApp(app)
sw, sh, sd = self.winfo_screenwidth(), self.winfo_screenheight(), self.winfo_screendepth()
self.wm_group(self)
self.wm_title(PACKAGE + ' ' + VERSION)
self.wm_iconname(PACKAGE + ' ' + VERSION)
if sw < 640 or sh < 480:
self.wm_minsize(400, 300)
else:
self.wm_minsize(540, 380)
##self.self.wm_maxsize(9999, 9999) # unlimited
self.wm_protocol('WM_DELETE_WINDOW', self.wmDeleteWindow)
prog = sys.executable
if prog and os.path.isfile(prog):
argv0 = os.path.normpath(sys.argv[0])
prog = os.path.abspath(prog)
if os.path.isfile(argv0):
wm_command = prog + " " + os.path.abspath(argv0)
self.wm_command(wm_command)
if 1:
# set expected window size to assist the layout of the window manager
self.config(width=min(800,sw-64), height=min(600,sh-64))
try:
wm_set_icon(self, app.dataloader.findIcon())
except: pass
# font
if font:
self.option_add('*font', font)
elif WIN_SYSTEM == 'x11':
self.option_add('*font', 'Helvetica 12', 50)
font = self.option_get('font', '')
try:
f = Font(self, font)
except:
print >> sys.stderr, 'invalid font name:', font
pass
else:
if font:
fa = f.actual()
app.opt.fonts['default'] = (fa['family'],
fa['size'],
fa['slant'],
fa['weight'])
else:
app.opt.fonts['default'] = None
# theme
try:
init_tile(app, self, app.opt.tile_theme)
except TclError:
raise
except Exception, err:
print >> sys.stderr, 'ERROR: set theme:', err
##self.option_add('*Toolbar.relief', 'groove')
##self.option_add('*Toolbar.relief', 'raised')
##self.option_add('*Toolbar.borderWidth', 1)
##self.option_add('*Toolbar.Button.Pad', 2)
##self.option_add('*Toolbar.Button.default', 'disabled')
##self.option_add('*Toolbar*takeFocus', 0)
# sometimes an update() is needed under Windows, whereas
# under Unix an update_idletasks() would be enough...
def busyUpdate(self):

View file

@ -40,7 +40,7 @@ import os, sys, Tkinter
# Toolkit imports
from tkconst import EVENT_HANDLED, EVENT_PROPAGATE
from tkutil import makeToplevel, setTransient, wm_set_icon
from tkutil import makeToplevel, setTransient
# /***********************************************************************
@ -75,10 +75,6 @@ class PysolProgressBar:
self.f2 = Tkinter.Label(self.frame, image=images[1])
self.f2.grid_configure(column=2, row=0, sticky="ew", ipadx=8, ipady=4)
self.top.config(cursor="watch")
if app:
try:
wm_set_icon(self.top, app.dataloader.findIcon())
except: pass
self.pack()
if 1:
setTransient(self.top, None, relx=0.5, rely=0.5)

View file

@ -331,7 +331,7 @@ class CanvasFormatter(PysolStatsFormatter):
def pstats(self, y, args, gameid=None):
x = 1
t1, t2, t3, t4, t5, t6, t7 = args
self.gamenumber = None
self.gameid = gameid
if gameid is None: # header
self.gameid = 'header'
for var, text, anchor, tab in (
@ -342,6 +342,7 @@ class CanvasFormatter(PysolStatsFormatter):
('time', t5, 'ne', self._tabs[5]),
('moves', t6, 'ne', self._tabs[6]),
('percent', t7, 'ne', self._tabs[7]), ):
self.gamenumber = None
if gameid is None: # header
self.gamenumber=var
id = self.canvas.create_text(x, y, text=text, anchor=anchor,
@ -477,6 +478,7 @@ class AllGames_StatsDialog(MfxDialog):
self.player = player
self.title = title
self.sort_by = 'name'
self.selected_game = None
#
kwdefault(kw, width=self.CHAR_W*64, height=lines*self.CHAR_H)
kw = self.initKw(kw)
@ -535,7 +537,7 @@ class AllGames_StatsDialog(MfxDialog):
id = self.canvas.find_withtag(Tkinter.CURRENT)
if not id:
return
##print id, self.nodes.get(id[0])
##print 'singleClick:', id, self.nodes.get(id[0])
gameid, gamenumber = self.nodes.get(id[0], (None, None))
if gameid == 'header':
if self.sort_by == gamenumber: return

View file

@ -36,7 +36,6 @@
__all__ = ['wm_withdraw',
'wm_deiconify',
'wm_map',
'wm_set_icon',
'wm_get_geometry',
#'setTransient',
#'makeToplevel',
@ -89,17 +88,6 @@ def wm_map(window, maximized=0):
else:
wm_deiconify(window)
def wm_set_icon(window, filename):
if not filename:
return
if WIN_SYSTEM == 'win32':
pass
##window.wm_iconbitmap(default="@"+filename)
elif WIN_SYSTEM == "x11":
pass
##window.wm_iconbitmap("@" + filename)
##window.wm_iconmask("@" + filename)
__wm_get_geometry_re = re.compile(r"^(\d+)x(\d+)\+([\-]?\d+)\+([\-]?\d+)$")
def wm_get_geometry(window):

View file

@ -49,7 +49,7 @@ from tkFont import Font
from pysollib.mfxutil import destruct, Struct
from pysollib.settings import PACKAGE, VERSION, WIN_SYSTEM
from pysollib.macosx.appSupport import setupApp
from tkutil import after_idle, wm_set_icon
from tkutil import after_idle
from tkconst import EVENT_HANDLED, EVENT_PROPAGATE
@ -100,81 +100,6 @@ class MfxRoot(Tkinter.Tk):
def connectApp(self, app):
self.app = app
def initToolkit(self, app, fg=None, bg=None, font=None, theme=None):
setupApp(app)
sw, sh, sd = self.winfo_screenwidth(), self.winfo_screenheight(), self.winfo_screendepth()
self.wm_group(self)
self.wm_title(PACKAGE + ' ' + VERSION)
self.wm_iconname(PACKAGE + ' ' + VERSION)
if sw < 640 or sh < 480:
self.wm_minsize(400, 300)
else:
self.wm_minsize(520, 360)
##self.self.wm_maxsize(9999, 9999) # unlimited
self.wm_protocol('WM_DELETE_WINDOW', self.wmDeleteWindow)
prog = sys.executable
if prog and os.path.isfile(prog):
argv0 = os.path.normpath(sys.argv[0])
prog = os.path.abspath(prog)
if os.path.isfile(argv0):
wm_command = prog + " " + os.path.abspath(argv0)
self.wm_command(wm_command)
if 1:
# set expected window size to assist the layout of the window manager
self.config(width=min(800,sw-64), height=min(600,sh-64))
try:
wm_set_icon(self, app.dataloader.findIcon())
except: pass
# set global color scheme
if not fg and not bg:
if WIN_SYSTEM == 'x11': # Unix/X11
pass
else:
if bg:
self.tk_setPalette(bg)
app.top_palette[1] = bg
app.top_bg = bg
if fg:
self.option_add('*foreground', fg)
app.top_palette[0] = fg
#
if WIN_SYSTEM == 'x11': # Unix/X11
self.option_add('*Entry.background', 'white', 60)
self.option_add('*Entry.foreground', 'black', 60)
self.option_add('*Listbox.background', 'white', 60)
self.option_add('*Listbox.foreground', 'black', 60)
##self.option_add('*borderWidth', '1', 50)
##self.option_add('*Button.borderWidth', '1', 50)
self.option_add('*Scrollbar.elementBorderWidth', '1', 60)
self.option_add('*Scrollbar.borderWidth', '1', 60)
self.option_add('*Menu.borderWidth', '1', 60)
#self.option_add('*Button.HighlightBackground', '#595d59')
#self.option_add('*Button.HighlightThickness', '1')
# font
if font:
self.option_add('*font', font)
elif WIN_SYSTEM == 'x11':
self.option_add('*font', 'Helvetica 12', 50)
font = self.option_get('font', '')
try:
f = Font(self, font)
except:
print >> sys.stderr, 'invalid font name:', font
pass
else:
if font:
fa = f.actual()
app.opt.fonts['default'] = (fa['family'],
fa['size'],
fa['slant'],
fa['weight'])
else:
app.opt.fonts['default'] = None
# sometimes an update() is needed under Windows, whereas
# under Unix an update_idletasks() would be enough...
def busyUpdate(self):

View file

@ -47,7 +47,7 @@ except ImportError:
# PySol imports
from pysollib.mfxutil import destruct
from pysollib.util import IMAGE_EXTENSIONS
from pysollib.settings import PACKAGE, WIN_SYSTEM
from pysollib.settings import PACKAGE
from pysollib.actions import PysolToolbarActions
from pysollib.tksettings import TkSettings

View file

@ -31,8 +31,9 @@ from common import baseInitRootWindow, BaseTkSettings
class initRootWindow(baseInitRootWindow):
def __init__(self, root, app):
baseInitRootWindow.__init__(self, root, app)
#setupApp(app)
hideTkConsole(root)
if TOOLKIT == 'tk':
#setupApp(app)
hideTkConsole(root)
if TOOLKIT == 'gtk':
pass
elif USE_TILE:

View file

@ -24,7 +24,6 @@ import sys, os, traceback
from pysollib.settings import PACKAGE, VERSION
from pysollib.settings import TOOLKIT, USE_TILE
from pysollib.tile import Tile
from pysollib.pysoltk import wm_set_icon
def init_tile(app, top, theme):
@ -57,9 +56,9 @@ class baseInitRootWindow:
#root.wm_group(root)
root.wm_title(PACKAGE + ' ' + VERSION)
root.wm_iconname(PACKAGE + ' ' + VERSION)
try:
wm_set_icon(root, app.dataloader.findIcon())
except: pass
root.wm_protocol('WM_DELETE_WINDOW', root.wmDeleteWindow)
# set minsize
sw, sh, sd = (root.winfo_screenwidth(),
root.winfo_screenheight(),
@ -79,6 +78,7 @@ class baseInitRootWindow:
pass
class BaseTkSettings:
canvas_padding = (0, 0)
toolbar_button_padding = (2, 2)
toolbar_label_padding = (4, 4)
if USE_TILE:

View file

@ -24,7 +24,7 @@ import sys, os
from pysollib.settings import TOOLKIT, USE_TILE
from pysollib.tile import Tile
from common import baseInitRootWindow
from common import baseInitRootWindow, BaseTkSettings
class initRootWindow(baseInitRootWindow):
@ -34,13 +34,14 @@ class initRootWindow(baseInitRootWindow):
pass
elif USE_TILE:
theme = app.opt.tile_theme
style = Tile.Style(root)
if theme not in ('winnative', 'xpnative'):
color = style.lookup('.', 'background')
if color:
top.tk_setPalette(color)
##top.option_add('*Menu.foreground', 'black')
top.option_add('*Menu.activeBackground', '#08246b')
top.option_add('*Menu.activeForeground', 'white')
root.tk_setPalette(color)
##root.option_add('*Menu.foreground', 'black')
root.option_add('*Menu.activeBackground', '#08246b')
root.option_add('*Menu.activeForeground', 'white')
if theme == 'winnative':
style.configure('Toolbutton', padding=2)
else:
@ -49,9 +50,9 @@ class initRootWindow(baseInitRootWindow):
class TkSettings(BaseTkSettings):
canvas_padding = (1, 1)
toolbar_relief = 'groove'
toolbar_borderwidth = 2
if USE_TILE:
toolbar_button_padding = (2, 0)
toolbar_label_padding = (6, 6)

View file

@ -35,6 +35,10 @@ class initRootWindow(baseInitRootWindow):
def __init__(self, root, app):
baseInitRootWindow.__init__(self, root, app)
## if TOOLKIT == 'tk':
## window.wm_iconbitmap("@"+filename)
## window.wm_iconmask("@"+filename)
##root.self.wm_maxsize(9999, 9999) # unlimited
if TOOLKIT == 'gtk':
pass

View file

@ -66,6 +66,7 @@ kw = {
'scripts' : ['pysol.py'],
'packages' : ['pysollib',
'pysollib.macosx',
'pysollib.tksettings',
'pysollib.tk',
'pysollib.tile',
'pysollib.pysolgtk',