From 101b7252a92565ab55ebc85e2ceb54962e575d45 Mon Sep 17 00:00:00 2001 From: skomoroh Date: Mon, 18 Dec 2006 23:09:00 +0000 Subject: [PATCH] * improved SingleGame_StatsDialog * improved Tile/Scale * other improvements git-svn-id: https://pysolfc.svn.sourceforge.net/svnroot/pysolfc/PySolFC/trunk@124 39dd0a4e-7c14-0410-91b3-c4f2d318f732 --- pysollib/games/calculation.py | 2 +- pysollib/games/spider.py | 3 ++ pysollib/tile/fontsdialog.py | 5 +-- pysollib/tile/selectcardset.py | 15 +++---- pysollib/tile/tkstats.py | 22 +++++----- pysollib/tile/tkwidget.py | 79 ++++++++++++++++++++++++++-------- pysollib/tksettings/aqua.py | 5 ++- 7 files changed, 88 insertions(+), 43 deletions(-) diff --git a/pysollib/games/calculation.py b/pysollib/games/calculation.py index d656ea91..bc45471d 100644 --- a/pysollib/games/calculation.py +++ b/pysollib/games/calculation.py @@ -162,7 +162,7 @@ class Calculation(Game): for i in range(4): s.rows.append(self.RowStack_Class(x, y, self)) x = x + l.XS - self.setRegion(s.rows, (-999, y, 999999, 999999)) + self.setRegion(s.rows, (-999, y-l.CH/2, 999999, 999999)) x = l.XM s.talon = WasteTalonStack(x, y, self, max_rounds=1) l.createText(s.talon, "n") diff --git a/pysollib/games/spider.py b/pysollib/games/spider.py index 6e030129..b21c3ac0 100644 --- a/pysollib/games/spider.py +++ b/pysollib/games/spider.py @@ -971,6 +971,9 @@ class York(RelaxedSpider): self.startDealSample() self.s.talon.dealRow(rows=self.s.rows[2:-2]) + shallHighlightMatch = Game._shallHighlightMatch_RKW + + class BigYork(York): def createGame(self): diff --git a/pysollib/tile/fontsdialog.py b/pysollib/tile/fontsdialog.py index 344572bb..4094e95c 100644 --- a/pysollib/tile/fontsdialog.py +++ b/pysollib/tile/fontsdialog.py @@ -106,9 +106,8 @@ class FontChooserDialog(MfxDialog): cb2.grid(row=3, column=0, columnspan=2, sticky='we') sc = PysolScale(frame, from_=6, to=40, resolution=1, - #label='Size', - orient='horizontal', - command=self.fontupdate, variable=self.size_var) + label=_('Size:'), orient='horizontal', + command=self.fontupdate, variable=self.size_var) sc.grid(row=4, column=0, columnspan=2, sticky='news') # font_families = list(tkFont.families()) diff --git a/pysollib/tile/selectcardset.py b/pysollib/tile/selectcardset.py index 2402e954..5a5e0b43 100644 --- a/pysollib/tile/selectcardset.py +++ b/pysollib/tile/selectcardset.py @@ -344,14 +344,13 @@ class CardsetInfoDialog(MfxDialog): from random import choice im = choice(images) f = os.path.join(cardset.dir, cardset.backname) - self.back_image = loadImage(file=f) - canvas = Tkinter.Canvas(info_frame, - width=2*im.width()+30, - height=im.height()+2) - canvas.create_image(10, 1, image=im, anchor='nw') - canvas.create_image(im.width()+20, 1, - image=self.back_image, anchor='nw') - canvas.grid(row=0, column=2, rowspan=row+1, sticky='ne') + self.back_image = loadImage(file=f) # store the image + l = Tkinter.Label(info_frame, image=im, padding=5) + l.grid(row=0, column=2, rowspan=row+1, sticky='ne') + l = Tkinter.Label(info_frame, image=self.back_image, + padding=(0,5,5,5)) # left margin = 0 + l.grid(row=0, column=3, rowspan=row+1, sticky='ne') + info_frame.columnconfigure(2, weight=1) info_frame.rowconfigure(row, weight=1) except: diff --git a/pysollib/tile/tkstats.py b/pysollib/tile/tkstats.py index 115e6a00..c473ab1b 100644 --- a/pysollib/tile/tkstats.py +++ b/pysollib/tile/tkstats.py @@ -136,18 +136,18 @@ class SingleGame_StatsDialog(MfxDialog): return pwon, plost def _createChartInit(self, text): - w, h = self.tab_x[-1]+20, self.tab_y[-1]+20 - c = Tkinter.Canvas(self.top_frame, width=w, height=h) - c.pack(side=Tkinter.TOP, fill=Tkinter.BOTH, expand=0, padx=20, pady=10) - self.canvas = c - ##self.fg = c.cget("insertbackground") - self.fg = c.option_get('foreground', '') or c.cget("insertbackground") + frame = Tkinter.LabelFrame(self.top_frame, text=text) + frame.pack(side='top', fill='both', expand=False, padx=20, pady=10) + style = Tkinter.Style(self.top_frame) + fg = style.lookup('.', 'foreground') or None # use default if fg == '' + bg = style.lookup('.', 'background') or None + self.fg = fg # - c.create_rectangle(2, 7, w, h, fill="", outline="#7f7f7f") - l = Tkinter.Label(c, text=text) - dy = int(self.font_metrics['ascent']) - 10 - dy = dy/2 - c.create_window(20, -dy, window=l, anchor="nw") + w, h = self.tab_x[-1]+20, self.tab_y[-1]+20 + c = Tkinter.Canvas(frame, width=w, height=h, + bg=bg, highlightthickness=0) + c.pack(fill='both', expand=True) + self.canvas = c def _createChartTexts(self, tx, ty, won, lost): c, tfont, fg = self.canvas, self.font, self.fg diff --git a/pysollib/tile/tkwidget.py b/pysollib/tile/tkwidget.py index 2f0785ab..8d42989d 100644 --- a/pysollib/tile/tkwidget.py +++ b/pysollib/tile/tkwidget.py @@ -75,6 +75,8 @@ class MfxDialog: # ex. _ToplevelDialog self.buttons = [] self.accel_keys = {} self.top = makeToplevel(parent, title=title) + self._frame = Tkinter.Frame(self.top) + self._frame.pack(expand=True, fill='both') self.top.wm_resizable(resizable, resizable) ##w, h = self.top.winfo_screenwidth(), self.top.winfo_screenheight() ##self.top.wm_maxsize(w-4, h-32) @@ -159,12 +161,12 @@ class MfxDialog: # ex. _ToplevelDialog return kw def createFrames(self, kw): - bottom_frame = Tkinter.Frame(self.top) + bottom_frame = Tkinter.Frame(self._frame) bottom_frame.pack(side='bottom', fill='both', expand=0, ipadx=3, ipady=3, padx=5) if kw.separatorwidth > 0: - separator = Tkinter.Separator(self.top) + separator = Tkinter.Separator(self._frame) separator.pack(side='bottom', fill='x', pady=kw.separatorwidth/2) - top_frame = Tkinter.Frame(self.top) + top_frame = Tkinter.Frame(self._frame) top_frame.pack(side='top', fill='both', expand=1) return top_frame, bottom_frame @@ -708,38 +710,77 @@ class StackDesc: # /*********************************************************************** -# // +# // Tile.Scale workaround (label and resolution) # ************************************************************************/ class MyPysolScale: def __init__(self, parent, **kw): if kw.has_key('resolution'): self.resolution = kw['resolution'] + del kw['resolution'] else: self.resolution = 1 + if kw.has_key('from_'): + kw['from_'] = kw['from_']/self.resolution + if kw.has_key('to'): + kw['to'] = kw['to']/self.resolution if kw.has_key('command'): self.command = kw['command'] else: self.command = None - self.frame = Tkinter.Frame(parent) - - self.label = Tkinter.Label(self.frame) - self.label.pack() - - kw['command'] = self._scale_command - self.scale = Tkinter.Scale(self.frame, **kw) - self.scale.pack(expand=True, fill='both') - + if kw.has_key('variable'): + self.variable = kw['variable'] + del kw['variable'] + else: + self.variable = None if kw.has_key('value'): - self.label.configure(text=self._round(kw['value'])) - elif kw.has_key('variable'): - self.label.configure(text=self._round(kw['variable'].get())) + value = kw['value'] + del kw['value'] + if self.variable: + self.variable.set(value) + else: + value = None + if self.variable: + value = self.variable.get() + if self.variable: + self.variable.trace('w', self._trace_var) + kw['command'] = self._scale_command + if kw.has_key('label'): + self.label_text = kw['label'] + del kw['label'] + else: + self.label_text = None + + # create widgets + side = 'left' # 'top' + self.frame = Tkinter.Frame(parent) + self.label = Tkinter.Label(self.frame, anchor='w', padding=(5,0)) + self.label.pack(side=side, expand=False, fill='x') + self.scale = Tkinter.Scale(self.frame, **kw) + self.scale.pack(side=side, expand=True, fill='both', pady=4) + + if not value is None: + if self.variable: + self.variable.set(self._round(value)) + self._set_text(self._round(value)) def _round(self, value): return int(float(value)/self.resolution)*self.resolution + def _trace_var(self, *args): + self.scale.set(float(self.variable.get())/self.resolution) + + def _set_text(self, v): + if self.label_text: + t = self.label_text+' '+str(v) + else: + t = str(v) + self.label.configure(text=t) + def _scale_command(self, value): - self.label.configure(text=self._round(value)) + v = self._round(float(value)*self.resolution) + self._set_text(v) + self.variable.set(v) if self.command: self.command(value) @@ -760,5 +801,5 @@ class TkinterScale(Tk.Scale): Tk.Scale.__init__(self, parent, **kw) -#PysolScale = MyPysolScale -PysolScale = TkinterScale +PysolScale = MyPysolScale +#PysolScale = TkinterScale diff --git a/pysollib/tksettings/aqua.py b/pysollib/tksettings/aqua.py index fdb78263..fcbb507a 100644 --- a/pysollib/tksettings/aqua.py +++ b/pysollib/tksettings/aqua.py @@ -37,8 +37,11 @@ class initRootWindow(baseInitRootWindow): if TOOLKIT == 'gtk': pass elif USE_TILE: + color = style.lookup('.', 'background') + if color: + root.tk_setPalette(color) # for non-Tile widgets pass - else: + else: # pure Tk #root.option_add(...) pass