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

+ new variable: settings.WIN_SYSTEM - tk windowing system (set up in init.py)

* replaced os.name on WIN_SYSTEM for gui-specific code


git-svn-id: https://pysolfc.svn.sourceforge.net/svnroot/pysolfc/PySolFC/trunk@112 39dd0a4e-7c14-0410-91b3-c4f2d318f732
This commit is contained in:
skomoroh 2006-12-13 01:51:41 +00:00
parent 38e83e0bdc
commit 9a3c5b784d
19 changed files with 96 additions and 157 deletions

View file

@ -45,7 +45,7 @@ from mfxutil import getusername, gethomedir, getprefdir, EnvError
from mfxutil import latin1_to_ascii from mfxutil import latin1_to_ascii
from util import Timer from util import Timer
from util import CARDSET, IMAGE_EXTENSIONS from util import CARDSET, IMAGE_EXTENSIONS
from settings import PACKAGE, PACKAGE_URL, VERSION, VERSION_TUPLE from settings import PACKAGE, PACKAGE_URL, VERSION, VERSION_TUPLE, WIN_SYSTEM
from resource import CSI, CardsetConfig, Cardset, CardsetManager from resource import CSI, CardsetConfig, Cardset, CardsetManager
from resource import Tile, TileManager from resource import Tile, TileManager
from resource import Sample, SampleManager from resource import Sample, SampleManager
@ -108,13 +108,17 @@ class Options:
self.shade_filled_stacks = True self.shade_filled_stacks = True
self.demo_logo = True self.demo_logo = True
self.tile_theme = 'default' self.tile_theme = 'default'
if os.name == 'nt': if WIN_SYSTEM == 'win32':
self.tile_theme = 'winnative' self.tile_theme = 'winnative'
elif WIN_SYSTEM == 'x11':
self.tile_theme = 'step'
else: # aqua
self.tile_theme = 'aqua'
self.toolbar = 1 # 0 == hide, 1,2,3,4 == top, bottom, lef, right self.toolbar = 1 # 0 == hide, 1,2,3,4 == top, bottom, lef, right
##self.toolbar_style = 'default' ##self.toolbar_style = 'default'
self.toolbar_style = 'crystal'
if os.name == 'posix':
self.toolbar_style = 'bluecurve' self.toolbar_style = 'bluecurve'
if WIN_SYSTEM == 'win32':
self.toolbar_style = 'crystal'
self.toolbar_relief = 'flat' self.toolbar_relief = 'flat'
self.toolbar_compound = 'none' # icons only self.toolbar_compound = 'none' # icons only
self.toolbar_size = 0 self.toolbar_size = 0
@ -164,11 +168,11 @@ class Options:
"canvas_large" : ("helvetica", 16), "canvas_large" : ("helvetica", 16),
"canvas_small" : ("helvetica", 10), "canvas_small" : ("helvetica", 10),
} }
if os.name == 'posix': if WIN_SYSTEM == 'win32':
self.fonts["sans"] = ("helvetica", 12)
if os.name == 'nt':
self.fonts["sans"] = ("times new roman", 12) self.fonts["sans"] = ("times new roman", 12)
self.fonts["fixed"] = ("courier new", 10) self.fonts["fixed"] = ("courier new", 10)
elif WIN_SYSTEM == 'x11':
self.fonts["sans"] = ("helvetica", 12)
# colors # colors
self.colors = { self.colors = {
'table': '#008200', 'table': '#008200',
@ -665,7 +669,7 @@ class Application:
# create the canvas # create the canvas
self.scrolled_canvas = MfxScrolledCanvas(self.top) self.scrolled_canvas = MfxScrolledCanvas(self.top)
self.canvas = self.scrolled_canvas.canvas self.canvas = self.scrolled_canvas.canvas
if os.name == 'nt': if WIN_SYSTEM == 'win32':
self.scrolled_canvas.grid(row=1, column=1, sticky='nsew', self.scrolled_canvas.grid(row=1, column=1, sticky='nsew',
padx=1, pady=1) padx=1, pady=1)
else: else:
@ -865,10 +869,10 @@ class Application:
"joker11_100_774", "joker11_100_774",
"joker10_100",): "joker10_100",):
self.gimages.logos.append(self.dataloader.findImage(f, dir)) self.gimages.logos.append(self.dataloader.findImage(f, dir))
if os.name == 'posix': if WIN_SYSTEM == 'win32':
dir = os.path.join('images', 'dialog', 'bluecurve')
else:
dir = os.path.join('images', 'dialog', 'default') dir = os.path.join('images', 'dialog', 'default')
else:
dir = os.path.join('images', 'dialog', 'bluecurve')
for f in ('error', 'info', 'question', 'warning'): for f in ('error', 'info', 'question', 'warning'):
fn = self.dataloader.findImage(f, dir) fn = self.dataloader.findImage(f, dir)
im = loadImage(fn) im = loadImage(fn)

View file

@ -399,8 +399,8 @@ class GameInfo(Struct):
ncards = decks * (len(suits) * len(ranks) + len(trumps)) ncards = decks * (len(suits) * len(ranks) + len(trumps))
game_flags = game_type & ~1023 game_flags = game_type & ~1023
game_type = game_type & 1023 game_type = game_type & 1023
if os.name == "mac": #if os.name == "mac":
name = latin1_to_ascii(name) # name = latin1_to_ascii(name)
name = to_unicode(name) name = to_unicode(name)
if not short_name: if not short_name:
short_name = name short_name = name

View file

@ -61,7 +61,6 @@ def init():
except: except:
settings.DEBUG = 1 settings.DEBUG = 1
print 'PySol debugging: set DEBUG to', settings.DEBUG print 'PySol debugging: set DEBUG to', settings.DEBUG
## init toolkit ## init toolkit
if '--gtk' in sys.argv: if '--gtk' in sys.argv:
settings.TOOLKIT = 'gtk' settings.TOOLKIT = 'gtk'
@ -93,6 +92,7 @@ def init():
pass pass
else: else:
settings.USE_TILE = True settings.USE_TILE = True
settings.WIN_SYSTEM = root.tk.call('tk', 'windowingsystem')
#root.destroy() #root.destroy()
Tkinter._default_root = None Tkinter._default_root = None

View file

@ -32,6 +32,9 @@ VERSION = '4.82'
FC_VERSION = '0.9.5' FC_VERSION = '0.9.5'
VERSION_TUPLE = (4, 82) VERSION_TUPLE = (4, 82)
# Tk windowing system (auto determine in init.py)
WIN_SYSTEM = 'x11' # win32, x11, aqua, classic
# toolkit # toolkit
TOOLKIT = 'tk' # or 'gtk' TOOLKIT = 'tk' # or 'gtk'
USE_TILE = 'auto' # or True or False USE_TILE = 'auto' # or True or False

View file

@ -1,5 +1,5 @@
import sys from pysollib.settings import WIN_SYSTEM
import Tkinter import Tkinter
from Tkconstants import * from Tkconstants import *
@ -325,7 +325,7 @@ class Scrollbar(Widget, Tkinter.Scrollbar):
# from http://tkinter.unpythonic.net/wiki/PyLocateTile : # from http://tkinter.unpythonic.net/wiki/PyLocateTile :
# standard Tk scrollbars work on OS X, but Tile ones look weird # standard Tk scrollbars work on OS X, but Tile ones look weird
if sys.platform == "darwin": if WIN_SYSTEM == "aqua":
Scrollbar = Tkinter.Scrollbar Scrollbar = Tkinter.Scrollbar

View file

@ -44,7 +44,7 @@ import tkFileDialog
# PySol imports # PySol imports
from pysollib.mfxutil import destruct, Struct, kwdefault from pysollib.mfxutil import destruct, Struct, kwdefault
from pysollib.util import CARDSET from pysollib.util import CARDSET
from pysollib.settings import PACKAGE from pysollib.settings import PACKAGE, WIN_SYSTEM
from pysollib.settings import TOP_TITLE from pysollib.settings import TOP_TITLE
from pysollib.gamedb import GI from pysollib.gamedb import GI
from pysollib.actions import PysolMenubarActions from pysollib.actions import PysolMenubarActions
@ -340,7 +340,7 @@ class PysolMenubar(PysolMenubarActions):
def _createMenubar(self): def _createMenubar(self):
MfxMenubar.addPath = self._addPath MfxMenubar.addPath = self._addPath
kw = { "name": "menubar" } kw = { "name": "menubar" }
if 1 and os.name == "posix": if WIN_SYSTEM == "x11":
pass pass
##kw["relief"] = "groove" ##kw["relief"] = "groove"
kw["activeborderwidth"] = 1 kw["activeborderwidth"] = 1
@ -353,7 +353,7 @@ class PysolMenubar(PysolMenubarActions):
m = "Ctrl-" m = "Ctrl-"
if sys.platform == "darwin": m = "Cmd-" if sys.platform == "darwin": m = "Cmd-"
if self.top.tk.call("tk", "windowingsystem") == "aqua": if WIN_SYSTEM == "aqua":
applemenu=MfxMenu(self.__menubar, n_("apple")) applemenu=MfxMenu(self.__menubar, n_("apple"))
applemenu.add_command(label=_("&About ")+PACKAGE, command=self.mHelpAbout) applemenu.add_command(label=_("&About ")+PACKAGE, command=self.mHelpAbout)
@ -377,7 +377,7 @@ class PysolMenubar(PysolMenubarActions):
menu.add_command(label=n_("Save &as..."), command=self.mSaveAs) menu.add_command(label=n_("Save &as..."), command=self.mSaveAs)
menu.add_separator() menu.add_separator()
menu.add_command(label=n_("&Hold and quit"), command=self.mHoldAndQuit) menu.add_command(label=n_("&Hold and quit"), command=self.mHoldAndQuit)
if not self.top.tk.call("tk", "windowingsystem") == "aqua": if WIN_SYSTEM != "aqua":
menu.add_command(label=n_("&Quit"), command=self.mQuit, accelerator=m+"Q") menu.add_command(label=n_("&Quit"), command=self.mQuit, accelerator=m+"Q")
if self.progress: self.progress.update(step=1) if self.progress: self.progress.update(step=1)
@ -517,7 +517,7 @@ class PysolMenubar(PysolMenubarActions):
menu.add_command(label=n_("&Rules for this game"), command=self.mHelpRules, accelerator="F1") menu.add_command(label=n_("&Rules for this game"), command=self.mHelpRules, accelerator="F1")
menu.add_command(label=n_("&License terms"), command=self.mHelpLicense) menu.add_command(label=n_("&License terms"), command=self.mHelpLicense)
##menu.add_command(label=n_("What's &new ?"), command=self.mHelpNews) ##menu.add_command(label=n_("What's &new ?"), command=self.mHelpNews)
if not self.top.tk.call("tk", "windowingsystem") == "aqua": if WIN_SYSTEM != "aqua":
menu.add_separator() menu.add_separator()
menu.add_command(label=n_("&About ")+PACKAGE+"...", command=self.mHelpAbout) menu.add_command(label=n_("&About ")+PACKAGE+"...", command=self.mHelpAbout)
@ -1335,7 +1335,6 @@ the next time you restart """)+PACKAGE,
'xpnative': 'XP Native', 'xpnative': 'XP Native',
'aqua': 'Aqua', 'aqua': 'Aqua',
} }
for t in all_themes: for t in all_themes:
try: try:
n = tn[t] n = tn[t]

View file

@ -73,16 +73,6 @@ class MfxStatusbar:
columnspan=self._columnspan, sticky='ew') columnspan=self._columnspan, sticky='ew')
self.frame = Tkinter.Frame(self.top_frame) self.frame = Tkinter.Frame(self.top_frame)
self.frame.pack(side='left', expand=True, fill='both', padx=0, pady=1) self.frame.pack(side='left', expand=True, fill='both', padx=0, pady=1)
## if os.name == "mac":
## Tkinter.Label(self.frame, width=2).pack(side='right')
## if os.name == 'nt':
## #self.frame.config(relief='raised')
## #self.padx = 1
## pass
## if 0:
## self.frame.config(bd=0)
## self.label_relief = 'flat'
## self.padx = 0
# util # util
def _createLabel(self, name, side='left', def _createLabel(self, name, side='left',

View file

@ -40,6 +40,7 @@ import Tile as Tkinter
# Toolkit imports # Toolkit imports
from tkutil import bind from tkutil import bind
from tkwidget import MfxScrolledCanvas from tkwidget import MfxScrolledCanvas
from pysollib.settings import WIN_SYSTEM
# /*********************************************************************** # /***********************************************************************
@ -238,7 +239,7 @@ class MfxTreeInCanvas(MfxScrolledCanvas):
self.font = None self.font = None
self.linestyle = "gray50" self.linestyle = "gray50"
self.linecolor = "black" self.linecolor = "black"
if os.name == "nt": if WIN_SYSTEM == "win32":
self.linestyle = "" # Tk bug ? self.linestyle = "" # Tk bug ?
self.linecolor = "gray50" self.linecolor = "gray50"

View file

@ -71,7 +71,7 @@ except ImportError:
# Toolkit imports # Toolkit imports
from tkconst import tkversion from tkconst import tkversion
from pysollib.settings import PACKAGE from pysollib.settings import PACKAGE, WIN_SYSTEM
# /*********************************************************************** # /***********************************************************************
@ -82,20 +82,11 @@ def wm_withdraw(window):
window.wm_withdraw() window.wm_withdraw()
def wm_deiconify(window): def wm_deiconify(window):
need_fix = os.name == "nt" and tkversion < (8, 3, 0, 0)
if need_fix:
# FIXME: This is needed so the window pops up on top on Windows.
try:
window.wm_iconify()
window.update_idletasks()
except Tkinter.TclError:
# wm_iconify() may fail if the window is transient
pass
window.wm_deiconify() window.wm_deiconify()
def wm_map(window, maximized=0): def wm_map(window, maximized=0):
if window.wm_state() != "iconic": if window.wm_state() != "iconic":
if maximized and os.name == "nt": if maximized and WIN_SYSTEM == "win32":
window.wm_state("zoomed") window.wm_state("zoomed")
else: else:
wm_deiconify(window) wm_deiconify(window)
@ -103,10 +94,10 @@ def wm_map(window, maximized=0):
def wm_set_icon(window, filename): def wm_set_icon(window, filename):
if not filename: if not filename:
return return
if os.name == 'nt': if WIN_SYSTEM == 'win32':
##window.tk.call('wm', 'iconbitmap', root._w, '-default', '@'+filename) ##window.tk.call('wm', 'iconbitmap', root._w, '-default', '@'+filename)
pass pass
elif os.name == "posix": elif WIN_SYSTEM == 'x11':
##window.wm_iconbitmap("@"+filename) ##window.wm_iconbitmap("@"+filename)
##window.wm_iconmask("@"+filename) ##window.wm_iconmask("@"+filename)
pass pass
@ -139,24 +130,12 @@ def setTransient(window, parent, relx=None, rely=None, expose=1):
# remain invisible while we figure out the geometry # remain invisible while we figure out the geometry
window.wm_withdraw() window.wm_withdraw()
window.wm_group(parent) window.wm_group(parent)
need_fix = os.name == "nt" and tkversion < (8, 3, 0, 0)
if need_fix:
# FIXME: This is needed to avoid ugly frames on Windows.
window.wm_geometry("+%d+%d" % (-10000, -10000))
if expose and parent is not None:
# FIXME: This is needed so the window pops up on top on Windows.
window.wm_iconify()
if parent and parent.wm_state() != "withdrawn": if parent and parent.wm_state() != "withdrawn":
window.wm_transient(parent) window.wm_transient(parent)
# actualize geometry information # actualize geometry information
window.update_idletasks() window.update_idletasks()
# show # show
x, y = __getWidgetXY(window, parent, relx=relx, rely=rely) x, y = __getWidgetXY(window, parent, relx=relx, rely=rely)
if need_fix:
if expose:
wm_deiconify(window)
window.wm_geometry("+%d+%d" % (x, y))
else:
window.wm_geometry("+%d+%d" % (x, y)) window.wm_geometry("+%d+%d" % (x, y))
if expose: if expose:
window.wm_deiconify() window.wm_deiconify()
@ -193,7 +172,7 @@ def make_help_toplevel(app, title=None):
window.option_add('*foreground', fg) window.option_add('*foreground', fg)
window.option_add('*selectBackground', '#00008b', 50) window.option_add('*selectBackground', '#00008b', 50)
window.option_add('*selectForeground', 'white', 50) window.option_add('*selectForeground', 'white', 50)
if os.name == "posix": if WIN_SYSTEM == "x11":
window.option_add('*Scrollbar.elementBorderWidth', '1', 60) window.option_add('*Scrollbar.elementBorderWidth', '1', 60)
window.option_add('*Scrollbar.borderWidth', '1', 60) window.option_add('*Scrollbar.borderWidth', '1', 60)
if title: if title:
@ -216,7 +195,7 @@ def __getWidgetXY(widget, parent, relx=None, rely=None,
##print parent.wm_geometry() ##print parent.wm_geometry()
##print parent.winfo_geometry(), parent.winfo_x(), parent.winfo_y(), parent.winfo_rootx(), parent.winfo_rooty(), parent.winfo_vrootx(), parent.winfo_vrooty() ##print parent.winfo_geometry(), parent.winfo_x(), parent.winfo_y(), parent.winfo_rootx(), parent.winfo_rooty(), parent.winfo_vrootx(), parent.winfo_vrooty()
m_x = m_y = None m_x = m_y = None
if os.name == "nt": if WIN_SYSTEM == "win32":
try: try:
m_width, m_height, m_x, m_y = wm_get_geometry(parent) m_width, m_height, m_x, m_y = wm_get_geometry(parent)
except: except:
@ -426,7 +405,7 @@ def get_text_width(text, font, root=None):
# ************************************************************************/ # ************************************************************************/
def init_tile(app, top, theme): def init_tile(app, top, theme):
if os.name == 'posix': if WIN_SYSTEM == 'x11':
f = os.path.join(app.dataloader.dir, 'tcl', 'menu8.4.tcl') f = os.path.join(app.dataloader.dir, 'tcl', 'menu8.4.tcl')
if os.path.exists(f): if os.path.exists(f):
top.tk.call('source', f) top.tk.call('source', f)
@ -455,28 +434,23 @@ def load_theme(app, top, theme):
theme = 'default' theme = 'default'
if theme: if theme:
style.theme_use(theme) style.theme_use(theme)
if theme not in ('winnative', 'xpnative'): if WIN_SYSTEM == 'x11':
color = style.lookup('.', 'background') color = style.lookup('.', 'background')
if color: if color:
try:
top.tk_setPalette(color) top.tk_setPalette(color)
##top.option_add('*background', color)
pass
except:
traceback.print_exc()
pass
if os.name == 'posix':
color = style.lookup('.', 'background', 'active') color = style.lookup('.', 'background', 'active')
if color: if color:
top.option_add('*Menu.activeBackground', color) top.option_add('*Menu.activeBackground', color)
elif os.name == 'nt': 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.foreground', 'black')
top.option_add('*Menu.activeBackground', '#08246b') top.option_add('*Menu.activeBackground', '#08246b')
top.option_add('*Menu.activeForeground', 'white') top.option_add('*Menu.activeForeground', 'white')
if theme == 'winnative': if theme == 'winnative':
style.configure('Toolbutton', padding=2) style.configure('Toolbutton', padding=2)
#if 'xpnative' in all_themes:
# theme = 'xpnative'
font = app.opt.fonts['default'] font = app.opt.fonts['default']
if font: if font:
style.configure('.', font=font) style.configure('.', font=font)

View file

@ -50,6 +50,7 @@ import traceback
# PySol imports # PySol imports
from pysollib.mfxutil import destruct, kwdefault, KwStruct from pysollib.mfxutil import destruct, kwdefault, KwStruct
from pysollib.settings import WIN_SYSTEM
# Toolkit imports # Toolkit imports
from tkconst import EVENT_HANDLED, EVENT_PROPAGATE from tkconst import EVENT_HANDLED, EVENT_PROPAGATE
@ -194,7 +195,7 @@ class MfxDialog: # ex. _ToplevelDialog
s = s.replace('&', '') s = s.replace('&', '')
max_len = max(max_len, len(s)) max_len = max(max_len, len(s))
##print s, len(s) ##print s, len(s)
if max_len > 12 and os.name == 'posix': button_width = max_len if max_len > 12 and WIN_SYSTEM == 'x11': button_width = max_len
elif max_len > 9 : button_width = max_len+1 elif max_len > 9 : button_width = max_len+1
elif max_len > 6 : button_width = max_len+2 elif max_len > 6 : button_width = max_len+2
else : button_width = 8 else : button_width = 8
@ -560,7 +561,7 @@ class MfxScrolledCanvas:
bind(w, "<KeyPress-Home>", self.scroll_top) bind(w, "<KeyPress-Home>", self.scroll_top)
bind(w, "<KeyPress-End>", self.scroll_bottom) bind(w, "<KeyPress-End>", self.scroll_bottom)
# mousewheel support # mousewheel support
if os.name == 'posix': if WIN_SYSTEM == 'x11':
bind(w, '<4>', self.mouse_wheel_up) bind(w, '<4>', self.mouse_wheel_up)
bind(w, '<5>', self.mouse_wheel_down) bind(w, '<5>', self.mouse_wheel_down)
# don't work on Linux # don't work on Linux

View file

@ -47,7 +47,7 @@ from tkFont import Font
# PySol imports # PySol imports
from pysollib.mfxutil import destruct, Struct from pysollib.mfxutil import destruct, Struct
from pysollib.settings import PACKAGE, VERSION from pysollib.settings import PACKAGE, VERSION, WIN_SYSTEM
from pysollib.macosx.appSupport import setupApp from pysollib.macosx.appSupport import setupApp
from tkutil import after_idle, init_tile, wm_set_icon from tkutil import after_idle, init_tile, wm_set_icon
from tkconst import EVENT_HANDLED, EVENT_PROPAGATE from tkconst import EVENT_HANDLED, EVENT_PROPAGATE
@ -128,7 +128,7 @@ class MfxRoot(Tkinter.Tk):
# font # font
if font: if font:
self.option_add('*font', font) self.option_add('*font', font)
elif os.name == 'posix': elif WIN_SYSTEM == 'x11':
self.option_add('*font', 'Helvetica 12', 50) self.option_add('*font', 'Helvetica 12', 50)
font = self.option_get('font', '') font = self.option_get('font', '')
try: try:
@ -148,13 +148,6 @@ class MfxRoot(Tkinter.Tk):
# theme # theme
try: try:
windowingsystem = app.top.tk.call("tk", "windowingsystem")
if windowingsystem == "x11":
app.opt.tile_theme = "clam"
elif windowingsystem == "aqua":
app.opt.tile_theme = "aqua"
elif windowingsystem == "win32":
app.opt.tile_theme = "xpnative"
init_tile(app, self, app.opt.tile_theme) init_tile(app, self, app.opt.tile_theme)
except TclError: except TclError:
raise raise

View file

@ -49,7 +49,7 @@ except ImportError:
# PySol imports # PySol imports
from pysollib.mfxutil import destruct from pysollib.mfxutil import destruct
from pysollib.util import IMAGE_EXTENSIONS from pysollib.util import IMAGE_EXTENSIONS
from pysollib.settings import PACKAGE from pysollib.settings import PACKAGE, WIN_SYSTEM
from pysollib.actions import PysolToolbarActions from pysollib.actions import PysolToolbarActions
# Toolkit imports # Toolkit imports
@ -78,7 +78,7 @@ class AbstractToolbarButton:
self.visible = True self.visible = True
if orient == 'horizontal': if orient == 'horizontal':
padx, pady = 0, 2 padx, pady = 0, 2
if os.name == 'nt': if WIN_SYSTEM == 'win32':
padx, pady = 2, 2 padx, pady = 2, 2
self.grid(row=0, self.grid(row=0,
column=self.position, column=self.position,
@ -86,7 +86,7 @@ class AbstractToolbarButton:
sticky='nsew') sticky='nsew')
else: else:
padx, pady = 2, 0 padx, pady = 2, 0
if os.name == 'nt': if WIN_SYSTEM == 'win32':
padx, pady = 2, 2 padx, pady = 2, 2
self.grid(row=self.position, self.grid(row=self.position,
column=0, column=0,
@ -154,7 +154,7 @@ class ToolbarLabel(Tkinter.Message):
return return
self.visible = True self.visible = True
padx, pady = 4, 4 padx, pady = 4, 4
if os.name == 'nt': if WIN_SYSTEM == 'win32':
padx, pady = 6, 6 padx, pady = 6, 6
if orient == 'horizontal': if orient == 'horizontal':
self.grid(row=0, self.grid(row=0,
@ -232,9 +232,9 @@ class PysolToolbar(PysolToolbarActions):
# #
self.setCompound(compound, force=True) self.setCompound(compound, force=True)
# Change the look of the frame to match the platform look # Change the look of the frame to match the platform look
if os.name == 'posix': if WIN_SYSTEM == 'x11':
pass pass
elif os.name == "nt": elif WIN_SYSTEM == "win32":
self.frame.config(relief='groove') self.frame.config(relief='groove')
else: else:
pass pass

View file

@ -43,7 +43,7 @@ import Tkinter, tkColorChooser, tkFileDialog
# PySol imports # PySol imports
from pysollib.mfxutil import destruct, Struct, kwdefault from pysollib.mfxutil import destruct, Struct, kwdefault
from pysollib.util import CARDSET from pysollib.util import CARDSET
from pysollib.settings import PACKAGE from pysollib.settings import PACKAGE, WIN_SYSTEM
from pysollib.settings import TOP_TITLE from pysollib.settings import TOP_TITLE
from pysollib.gamedb import GI from pysollib.gamedb import GI
from pysollib.actions import PysolMenubarActions from pysollib.actions import PysolMenubarActions
@ -347,7 +347,7 @@ class PysolMenubar(PysolMenubarActions):
def _createMenubar(self): def _createMenubar(self):
MfxMenubar.addPath = self._addPath MfxMenubar.addPath = self._addPath
kw = { "name": "menubar" } kw = { "name": "menubar" }
if 1 and os.name == "posix": if WIN_SYSTEM == "x11":
pass pass
##kw["relief"] = "groove" ##kw["relief"] = "groove"
kw["activeborderwidth"] = 1 kw["activeborderwidth"] = 1
@ -360,7 +360,7 @@ class PysolMenubar(PysolMenubarActions):
m = "Ctrl-" m = "Ctrl-"
if sys.platform == "darwin": m = "Cmd-" if sys.platform == "darwin": m = "Cmd-"
if self.top.tk.call("tk", "windowingsystem") == "aqua": if WIN_SYSTEM == "aqua":
applemenu=MfxMenu(self.__menubar, n_("apple")) applemenu=MfxMenu(self.__menubar, n_("apple"))
applemenu.add_command(label=_("&About ")+PACKAGE, command=self.mHelpAbout) applemenu.add_command(label=_("&About ")+PACKAGE, command=self.mHelpAbout)
@ -384,7 +384,7 @@ class PysolMenubar(PysolMenubarActions):
menu.add_command(label=n_("Save &as..."), command=self.mSaveAs) menu.add_command(label=n_("Save &as..."), command=self.mSaveAs)
menu.add_separator() menu.add_separator()
menu.add_command(label=n_("&Hold and quit"), command=self.mHoldAndQuit) menu.add_command(label=n_("&Hold and quit"), command=self.mHoldAndQuit)
if not self.top.tk.call("tk", "windowingsystem") == "aqua": if WIN_SYSTEM != "aqua":
menu.add_command(label=n_("&Quit"), command=self.mQuit, accelerator=m+"Q") menu.add_command(label=n_("&Quit"), command=self.mQuit, accelerator=m+"Q")
if self.progress: self.progress.update(step=1) if self.progress: self.progress.update(step=1)
@ -522,7 +522,7 @@ class PysolMenubar(PysolMenubarActions):
menu.add_command(label=n_("&Rules for this game"), command=self.mHelpRules, accelerator="F1") menu.add_command(label=n_("&Rules for this game"), command=self.mHelpRules, accelerator="F1")
menu.add_command(label=n_("&License terms"), command=self.mHelpLicense) menu.add_command(label=n_("&License terms"), command=self.mHelpLicense)
##menu.add_command(label=n_("What's &new ?"), command=self.mHelpNews) ##menu.add_command(label=n_("What's &new ?"), command=self.mHelpNews)
if not self.top.tk.call("tk", "windowingsystem") == "aqua": if WIN_SYSTEM != "aqua":
menu.add_separator() menu.add_separator()
menu.add_command(label=n_("&About ")+PACKAGE+"...", command=self.mHelpAbout) menu.add_command(label=n_("&About ")+PACKAGE+"...", command=self.mHelpAbout)

View file

@ -49,6 +49,8 @@ if __name__ == '__main__':
# Toolkit imports # Toolkit imports
from tkwidget import MfxTooltip from tkwidget import MfxTooltip
from pysollib.settings import WIN_SYSTEM
# /*********************************************************************** # /***********************************************************************
# // # //
@ -73,7 +75,7 @@ class MfxStatusbar:
padx=1, pady=1) padx=1, pady=1)
#if os.name == "mac": #if os.name == "mac":
# Tkinter.Label(self.frame, width=2).pack(side='right') # Tkinter.Label(self.frame, width=2).pack(side='right')
if os.name == 'nt': if WIN_SYSTEM == 'win32':
self.frame.config(relief='raised') self.frame.config(relief='raised')
self.padx = 0 self.padx = 0
if 0: if 0:

View file

@ -40,6 +40,7 @@ import Tkinter
# Toolkit imports # Toolkit imports
from tkutil import bind from tkutil import bind
from tkwidget import MfxScrolledCanvas from tkwidget import MfxScrolledCanvas
from pysollib.settings import WIN_SYSTEM
# /*********************************************************************** # /***********************************************************************
@ -238,7 +239,7 @@ class MfxTreeInCanvas(MfxScrolledCanvas):
self.font = None self.font = None
self.linestyle = "gray50" self.linestyle = "gray50"
self.linecolor = "black" self.linecolor = "black"
if os.name == "nt": if WIN_SYSTEM == "win32":
self.linestyle = "" # Tk bug ? self.linestyle = "" # Tk bug ?
self.linecolor = "gray50" self.linecolor = "gray50"

View file

@ -69,7 +69,7 @@ except ImportError:
# Toolkit imports # Toolkit imports
from tkconst import tkversion from tkconst import tkversion
from pysollib.settings import PACKAGE from pysollib.settings import PACKAGE, WIN_SYSTEM
# /*********************************************************************** # /***********************************************************************
@ -80,20 +80,11 @@ def wm_withdraw(window):
window.wm_withdraw() window.wm_withdraw()
def wm_deiconify(window): def wm_deiconify(window):
need_fix = os.name == "nt" and tkversion < (8, 3, 0, 0)
if need_fix:
# FIXME: This is needed so the window pops up on top on Windows.
try:
window.wm_iconify()
window.update_idletasks()
except Tkinter.TclError:
# wm_iconify() may fail if the window is transient
pass
window.wm_deiconify() window.wm_deiconify()
def wm_map(window, maximized=0): def wm_map(window, maximized=0):
if window.wm_state() != "iconic": if window.wm_state() != "iconic":
if maximized and os.name == "nt": if maximized and WIN_SYSTEM == "win32":
window.wm_state("zoomed") window.wm_state("zoomed")
else: else:
wm_deiconify(window) wm_deiconify(window)
@ -101,12 +92,13 @@ def wm_map(window, maximized=0):
def wm_set_icon(window, filename): def wm_set_icon(window, filename):
if not filename: if not filename:
return return
if os.name == 'nt': if WIN_SYSTEM == 'win32':
window.wm_iconbitmap(default="@"+filename) pass
elif os.name == "posix": ##window.wm_iconbitmap(default="@"+filename)
elif WIN_SYSTEM == "x11":
pass
##window.wm_iconbitmap("@" + filename) ##window.wm_iconbitmap("@" + filename)
##window.wm_iconmask("@" + filename) ##window.wm_iconmask("@" + filename)
pass
__wm_get_geometry_re = re.compile(r"^(\d+)x(\d+)\+([\-]?\d+)\+([\-]?\d+)$") __wm_get_geometry_re = re.compile(r"^(\d+)x(\d+)\+([\-]?\d+)\+([\-]?\d+)$")
@ -136,24 +128,12 @@ def setTransient(window, parent, relx=None, rely=None, expose=1):
# remain invisible while we figure out the geometry # remain invisible while we figure out the geometry
window.wm_withdraw() window.wm_withdraw()
window.wm_group(parent) window.wm_group(parent)
need_fix = os.name == "nt" and tkversion < (8, 3, 0, 0)
if need_fix:
# FIXME: This is needed to avoid ugly frames on Windows.
window.wm_geometry("+%d+%d" % (-10000, -10000))
if expose and parent is not None:
# FIXME: This is needed so the window pops up on top on Windows.
window.wm_iconify()
if parent and parent.wm_state() != "withdrawn": if parent and parent.wm_state() != "withdrawn":
window.wm_transient(parent) window.wm_transient(parent)
# actualize geometry information # actualize geometry information
window.update_idletasks() window.update_idletasks()
# show # show
x, y = __getWidgetXY(window, parent, relx=relx, rely=rely) x, y = __getWidgetXY(window, parent, relx=relx, rely=rely)
if need_fix:
if expose:
wm_deiconify(window)
window.wm_geometry("+%d+%d" % (x, y))
else:
window.wm_geometry("+%d+%d" % (x, y)) window.wm_geometry("+%d+%d" % (x, y))
if expose: if expose:
window.wm_deiconify() window.wm_deiconify()
@ -188,7 +168,7 @@ def make_help_toplevel(app, title=None):
window.option_add('*foreground', fg) window.option_add('*foreground', fg)
window.option_add('*selectBackground', '#00008b', 50) window.option_add('*selectBackground', '#00008b', 50)
window.option_add('*selectForeground', 'white', 50) window.option_add('*selectForeground', 'white', 50)
if os.name == "posix": if WIN_SYSTEM == "x11":
window.option_add('*Scrollbar.elementBorderWidth', '1', 60) window.option_add('*Scrollbar.elementBorderWidth', '1', 60)
window.option_add('*Scrollbar.borderWidth', '1', 60) window.option_add('*Scrollbar.borderWidth', '1', 60)
@ -212,7 +192,7 @@ def __getWidgetXY(widget, parent, relx=None, rely=None,
##print parent.wm_geometry() ##print parent.wm_geometry()
##print parent.winfo_geometry(), parent.winfo_x(), parent.winfo_y(), parent.winfo_rootx(), parent.winfo_rooty(), parent.winfo_vrootx(), parent.winfo_vrooty() ##print parent.winfo_geometry(), parent.winfo_x(), parent.winfo_y(), parent.winfo_rootx(), parent.winfo_rooty(), parent.winfo_vrootx(), parent.winfo_vrooty()
m_x = m_y = None m_x = m_y = None
if os.name == "nt": if WIN_SYSTEM == "win32":
try: try:
m_width, m_height, m_x, m_y = wm_get_geometry(parent) m_width, m_height, m_x, m_y = wm_get_geometry(parent)
except: except:

View file

@ -49,6 +49,7 @@ import traceback
# PySol imports # PySol imports
from pysollib.mfxutil import destruct, kwdefault, KwStruct from pysollib.mfxutil import destruct, kwdefault, KwStruct
from pysollib.settings import WIN_SYSTEM
# Toolkit imports # Toolkit imports
from tkconst import EVENT_HANDLED, EVENT_PROPAGATE from tkconst import EVENT_HANDLED, EVENT_PROPAGATE
@ -206,7 +207,7 @@ class MfxDialog: # ex. _ToplevelDialog
s = s.replace('&', '') s = s.replace('&', '')
max_len = max(max_len, len(s)) max_len = max(max_len, len(s))
##print s, len(s) ##print s, len(s)
if max_len > 12 and os.name == 'posix': button_width = max_len if max_len > 12 and WIN_SYSTEM == 'x11': button_width = max_len
elif max_len > 9 : button_width = max_len+1 elif max_len > 9 : button_width = max_len+1
elif max_len > 6 : button_width = max_len+2 elif max_len > 6 : button_width = max_len+2
else : button_width = 8 else : button_width = 8
@ -564,7 +565,7 @@ class MfxScrolledCanvas:
bind(w, "<KeyPress-Home>", self.scroll_top) bind(w, "<KeyPress-Home>", self.scroll_top)
bind(w, "<KeyPress-End>", self.scroll_bottom) bind(w, "<KeyPress-End>", self.scroll_bottom)
# mousewheel support # mousewheel support
if os.name == 'posix': if WIN_SYSTEM == 'x11':
bind(w, '<4>', self.mouse_wheel_up) bind(w, '<4>', self.mouse_wheel_up)
bind(w, '<5>', self.mouse_wheel_down) bind(w, '<5>', self.mouse_wheel_down)
# don't work on Linux # don't work on Linux

View file

@ -127,18 +127,8 @@ class MfxRoot(Tkinter.Tk):
# set global color scheme # set global color scheme
if not fg and not bg: if not fg and not bg:
if os.name == 'posix': # Unix/X11 if WIN_SYSTEM == 'x11': # Unix/X11
pass pass
if os.name == 'mac':
color, priority = '#d9d9d9', '60'
classes = (
'Button', 'Canvas', 'Checkbutton', 'Entry',
'Frame', 'Label', 'Listbox', 'Menubutton', ### 'Menu',
'Message', 'Radiobutton', 'Scale', 'Scrollbar', 'Text',
)
for c in classes:
self.option_add('*' + c + '*background', color, priority)
self.option_add('*' + c + '*activeBackground', color, priority)
else: else:
if bg: if bg:
self.tk_setPalette(bg) self.tk_setPalette(bg)
@ -149,7 +139,7 @@ class MfxRoot(Tkinter.Tk):
app.top_palette[0] = fg app.top_palette[0] = fg
# #
if os.name == 'posix': # Unix/X11 if WIN_SYSTEM == 'x11': # Unix/X11
self.option_add('*Entry.background', 'white', 60) self.option_add('*Entry.background', 'white', 60)
self.option_add('*Entry.foreground', 'black', 60) self.option_add('*Entry.foreground', 'black', 60)
self.option_add('*Listbox.background', 'white', 60) self.option_add('*Listbox.background', 'white', 60)
@ -165,7 +155,7 @@ class MfxRoot(Tkinter.Tk):
# font # font
if font: if font:
self.option_add('*font', font) self.option_add('*font', font)
elif os.name == 'posix': elif WIN_SYSTEM == 'x11':
self.option_add('*font', 'Helvetica 12', 50) self.option_add('*font', 'Helvetica 12', 50)
font = self.option_get('font', '') font = self.option_get('font', '')
try: try:

View file

@ -47,7 +47,7 @@ except ImportError:
# PySol imports # PySol imports
from pysollib.mfxutil import destruct from pysollib.mfxutil import destruct
from pysollib.util import IMAGE_EXTENSIONS from pysollib.util import IMAGE_EXTENSIONS
from pysollib.settings import PACKAGE from pysollib.settings import PACKAGE, WIN_SYSTEM
from pysollib.actions import PysolToolbarActions from pysollib.actions import PysolToolbarActions
# Toolkit imports # Toolkit imports
@ -234,10 +234,10 @@ class PysolToolbar(PysolToolbarActions):
self.setCompound(compound, force=True) self.setCompound(compound, force=True)
# Change the look of the frame to match the platform look # Change the look of the frame to match the platform look
# (see also setRelief) # (see also setRelief)
if os.name == 'posix': if WIN_SYSTEM == 'x11':
#self.frame.config(bd=0, highlightthickness=1) #self.frame.config(bd=0, highlightthickness=1)
self.frame.config(bd=1, relief=self.frame_relief, highlightthickness=0) self.frame.config(bd=1, relief=self.frame_relief, highlightthickness=0)
elif os.name == "nt": elif WIN_SYSTEM == "win32":
self.frame.config(bd=2, relief=self.frame_relief, padx=2, pady=2) self.frame.config(bd=2, relief=self.frame_relief, padx=2, pady=2)
#self._createSeparator(width=4, side=Tkinter.LEFT, relief=Tkinter.FLAT) #self._createSeparator(width=4, side=Tkinter.LEFT, relief=Tkinter.FLAT)
#self._createSeparator(width=4, side=Tkinter.RIGHT, relief=Tkinter.FLAT) #self._createSeparator(width=4, side=Tkinter.RIGHT, relief=Tkinter.FLAT)
@ -284,12 +284,12 @@ class PysolToolbar(PysolToolbarActions):
if relief == 'raised': if relief == 'raised':
self.frame_relief = 'flat' self.frame_relief = 'flat'
self.separator_relief = 'flat' self.separator_relief = 'flat'
if os.name == 'nt': if WIN_SYSTEM == 'win32':
self.frame_relief = 'groove' self.frame_relief = 'groove'
else: else:
self.frame_relief = 'raised' self.frame_relief = 'raised'
self.separator_relief = 'sunken' #'raised' self.separator_relief = 'sunken' #'raised'
if os.name == 'nt': if WIN_SYSTEM == 'win32':
self.frame_relief = 'groove' self.frame_relief = 'groove'
self.separator_relief = 'groove' self.separator_relief = 'groove'
return relief return relief