diff --git a/pysollib/tile/timeoutsdialog.py b/pysollib/tile/timeoutsdialog.py index 86e9ae8f..8f696986 100644 --- a/pysollib/tile/timeoutsdialog.py +++ b/pysollib/tile/timeoutsdialog.py @@ -28,7 +28,7 @@ import Tkinter import ttk # PySol imports -from pysollib.mygettext import _, n_ +from pysollib.mygettext import _ from pysollib.mfxutil import KwStruct # Toolkit imports @@ -44,7 +44,7 @@ class TimeoutsDialog(MfxDialog): kw = self.initKw(kw) MfxDialog.__init__(self, parent, title, kw.resizable, kw.default) top_frame, bottom_frame = self.createFrames(kw) - #self.createBitmaps(top_frame, kw) + # self.createBitmaps(top_frame, kw) frame = ttk.Frame(top_frame) frame.pack(expand=True, fill='both', padx=5, pady=10) @@ -61,10 +61,11 @@ class TimeoutsDialog(MfxDialog): self.highlight_cards_sleep_var = Tkinter.DoubleVar() self.highlight_cards_sleep_var.set(app.opt.timeouts['highlight_cards']) self.highlight_samerank_sleep_var = Tkinter.DoubleVar() - self.highlight_samerank_sleep_var.set(app.opt.timeouts['highlight_samerank']) + self.highlight_samerank_sleep_var.set( + app.opt.timeouts['highlight_samerank']) # lframe = ttk.LabelFrame(frame, text=_('Set delays in seconds'), - padding=(10, 5)) + padding=(10, 5)) lframe.pack(expand=True, fill='both', padx=4) row = 0 for title, var in ( @@ -74,9 +75,10 @@ class TimeoutsDialog(MfxDialog): (_('Highlight piles:'), self.highlight_piles_sleep_var), (_('Highlight cards:'), self.highlight_cards_sleep_var), (_('Highlight same rank:'), self.highlight_samerank_sleep_var), - ): - ttk.Label(lframe, text=title, anchor='w' - ).grid(row=row, column=0, sticky='we') + ): + ttk.Label( + lframe, text=title, anchor='w').grid( + row=row, column=0, sticky='we') widget = PysolScale(lframe, from_=0.2, to=9.9, value=var.get(), resolution=0.1, orient='horizontal', length="3i", variable=var, takefocus=0) @@ -91,7 +93,8 @@ class TimeoutsDialog(MfxDialog): self.raise_card_timeout = self.raise_card_sleep_var.get() self.highlight_piles_timeout = self.highlight_piles_sleep_var.get() self.highlight_cards_timeout = self.highlight_cards_sleep_var.get() - self.highlight_samerank_timeout = self.highlight_samerank_sleep_var.get() + self.highlight_samerank_timeout = \ + self.highlight_samerank_sleep_var.get() def initKw(self, kw): kw = KwStruct(kw, @@ -99,7 +102,3 @@ class TimeoutsDialog(MfxDialog): padx=10, pady=10, ) return MfxDialog.initKw(self, kw) - - - - diff --git a/pysollib/tile/toolbar.py b/pysollib/tile/toolbar.py index 62397d78..0a7e8763 100644 --- a/pysollib/tile/toolbar.py +++ b/pysollib/tile/toolbar.py @@ -30,10 +30,9 @@ import ttk # PySol imports from pysollib.mygettext import _, n_ -from pysollib.mfxutil import destruct from pysollib.mfxutil import Image, ImageTk, ImageOps from pysollib.util import IMAGE_EXTENSIONS -from pysollib.settings import TITLE, WIN_SYSTEM +from pysollib.settings import TITLE from pysollib.winsystems import TkSettings # Toolkit imports @@ -72,7 +71,8 @@ class AbstractToolbarButton: sticky='nsew') def hide(self): - if not self.visible: return + if not self.visible: + return self.visible = False self.grid_forget() @@ -92,6 +92,7 @@ class ToolbarButton(AbstractToolbarButton, ttk.Button): AbstractToolbarButton.__init__(self, parent, toolbar, toolbar_name, position) + class ToolbarSeparator(ttk.Separator): def __init__(self, parent, toolbar, position, **kwargs): kwargs['orient'] = 'vertical' @@ -99,6 +100,7 @@ class ToolbarSeparator(ttk.Separator): self.toolbar = toolbar self.position = position self.visible = False + def show(self, orient, force=False): if self.visible and not force: return @@ -117,11 +119,14 @@ class ToolbarSeparator(ttk.Separator): column=0, padx=pady, pady=padx, sticky='nsew') + def hide(self): - if not self.visible: return + if not self.visible: + return self.visible = False self.grid_forget() + class ToolbarLabel(Tkinter.Message): def __init__(self, parent, toolbar, toolbar_name, position, **kwargs): Tkinter.Message.__init__(self, parent, **kwargs) @@ -129,6 +134,7 @@ class ToolbarLabel(Tkinter.Message): self.toolbar_name = toolbar_name self.position = position self.visible = False + def show(self, orient, force=False): if self.visible and not force: return @@ -144,8 +150,10 @@ class ToolbarLabel(Tkinter.Message): column=0, padx=padx, pady=pady, sticky='nsew') + def hide(self): - if not self.visible: return + if not self.visible: + return self.visible = False self.grid_forget() @@ -166,7 +174,7 @@ class PysolToolbarTk: self.dir = dir self.size = size self.compound = compound - self.orient='horizontal' + self.orient = 'horizontal' # self.frame = ttk.Frame(top, class_='Toolbar', relief=TkSettings.toolbar_relief, @@ -189,7 +197,7 @@ class PysolToolbarTk: (n_("Rules"), self.mHelpRules, _("Rules for this game")), (None, None, None), (n_("Quit"), self.mQuit, _("Quit ")+TITLE), - ): + ): if l is None: sep = self._createSeparator() sep.bind("<3>", self.rightclickHandler) @@ -202,14 +210,14 @@ class PysolToolbarTk: self.popup = MfxMenu(master=None, label=n_('Toolbar'), tearoff=0) createToolbarMenu(menubar, self.popup) - position=len(self._widgets) + position = len(self._widgets) self.frame.rowconfigure(position, weight=1) self.frame.columnconfigure(position, weight=1) # self._createLabel("player", label=n_('Player'), tooltip=_("Player options")) # - self.player_label.bind("<1>",self.mOptPlayerOptions) + self.player_label.bind("<1>", self.mOptPlayerOptions) self.frame.bind("<3>", self.rightclickHandler) # self.setCompound(compound, force=True) @@ -224,7 +232,6 @@ class PysolToolbarTk: else: # button widget = getattr(self, w+'_button') - position = widget.position if v: widget.show(orient=self.orient) else: @@ -234,7 +241,8 @@ class PysolToolbarTk: last_visible = None for w in self._widgets: if isinstance(w, ToolbarSeparator): - if prev_visible is None or isinstance(prev_visible, ToolbarSeparator): + if prev_visible is None or isinstance(prev_visible, + ToolbarSeparator): w.hide() else: w.show(orient=self.orient) @@ -257,7 +265,7 @@ class PysolToolbarTk: return image def _createSeparator(self): - position=len(self._widgets) + position = len(self._widgets) sep = ToolbarSeparator(self.frame, position=position, toolbar=self, @@ -272,8 +280,8 @@ class PysolToolbarTk: return None im = tkim._pil_image dis_im = ImageOps.grayscale(im) - ##color = '#ffffff' - ##factor = 0.6 + # color = '#ffffff' + # factor = 0.6 color = '#dedede' factor = 0.7 sh = Image.new(dis_im.mode, dis_im.size, color) @@ -297,12 +305,12 @@ class PysolToolbarTk: name = label.lower() position = len(self._widgets) kw = { - 'position' : position, - 'toolbar' : self, - 'toolbar_name' : name, - 'command' : command, - 'takefocus' : 0, - 'text' : _(label), + 'position': position, + 'toolbar': self, + 'toolbar_name': name, + 'command': command, + 'takefocus': 0, + 'text': _(label), } if check: @@ -320,7 +328,7 @@ class PysolToolbarTk: return button def _createLabel(self, name, label=None, tooltip=None): - aspect = (400, 300) [self.getSize() != 0] + aspect = (400, 300)[self.getSize() != 0] position = len(self._widgets)+1 label = ToolbarLabel(self.frame, position=position, @@ -345,7 +353,6 @@ class PysolToolbarTk: self.game.interruptSleep() return self.game.busy - # # public methods # @@ -389,10 +396,12 @@ class PysolToolbarTk: def destroy(self): for w in self._tooltips: - if w: w.destroy() + if w: + w.destroy() self._tooltips = [] for w in self._widgets: - if w: w.destroy() + if w: + w.destroy() self._widgets = [] def setCursor(self, cursor): @@ -418,7 +427,7 @@ class PysolToolbarTk: name = w.toolbar_name data.append((name, w)) l = self.player_label - aspect = (400, 300) [size != 0] + aspect = (400, 300)[size != 0] l.config(aspect=aspect) for name, w in data: self._setButtonImage(w, name) @@ -449,9 +458,11 @@ class PysolToolbarTk: # def rightclickHandler(self, event): - if self._busy(): return EVENT_HANDLED + if self._busy(): + return EVENT_HANDLED if self.popup: - ##print event.x, event.y, event.x_root, event.y_root, event.__dict__ + # print event.x, event.y, \ + # event.x_root, event.y_root, event.__dict__ self.popup.tk_popup(event.x_root, event.y_root) return EVENT_HANDLED @@ -461,4 +472,3 @@ class PysolToolbarTk: size = self.size comp = int(self.compound in ('top', 'bottom')) return int((size+comp) != 0) - diff --git a/pysollib/tile/wizarddialog.py b/pysollib/tile/wizarddialog.py index 20926918..f65031c7 100644 --- a/pysollib/tile/wizarddialog.py +++ b/pysollib/tile/wizarddialog.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- mode: python; coding: utf-8; -*- -# ---------------------------------------------------------------------------## +# --------------------------------------------------------------------------- # # Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer # Copyright (C) 2003 Mt. Hood Playing Card Co. @@ -19,17 +19,19 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -# ---------------------------------------------------------------------------## +# --------------------------------------------------------------------------- __all__ = ['WizardDialog'] # imports +import sys + import Tkinter import ttk # PySol imports -from pysollib.mygettext import _, n_ +from pysollib.mygettext import _ from pysollib.mfxutil import KwStruct from pysollib.wizardutil import WizardWidgets from pysollib.wizardpresets import presets @@ -38,11 +40,14 @@ from pysollib.wizardpresets import presets from tkwidget import MfxDialog from tkwidget import PysolScale, PysolCombo +if sys.version_info > (3,): + basestring = str # ************************************************************************ # * # ************************************************************************ + class WizardDialog(MfxDialog): def __init__(self, parent, title, app, **kw): kw = self.initKw(kw) @@ -75,7 +80,9 @@ class WizardDialog(MfxDialog): values.remove(default) values.sort() values.insert(0, default) - callback = lambda e, w=w: self.presetSelected(e, w) + + def callback(e, w=w): + self.presetSelected(e, w) cb = PysolCombo(frame, values=tuple(values), textvariable=w.variable, exportselection=False, @@ -104,7 +111,8 @@ class WizardDialog(MfxDialog): for mod, cbname in w.variable.trace_vinfo(): w.variable.trace_vdelete(mod, cbname) from_, to = w.values - ##s = Spinbox(frame, textvariable=w.variable, from_=from_, to=to) + # s = Spinbox( + # frame, textvariable=w.variable, from_=from_, to=to) s = PysolScale(frame, from_=from_, to=to, resolution=1, orient='horizontal', variable=w.variable) @@ -129,7 +137,6 @@ class WizardDialog(MfxDialog): focus = self.createButtons(bottom_frame, kw) self.mainloop(focus, kw.timeout) - def presetSelected(self, e, w): n = e.widget.get() n = w.translation_map[n] @@ -145,7 +152,6 @@ class WizardDialog(MfxDialog): v = _(v) w.variable.set(v) - def initKw(self, kw): kw = KwStruct(kw, strings=(_('&OK'), _('&Cancel')), @@ -153,6 +159,3 @@ class WizardDialog(MfxDialog): separator=False, ) return MfxDialog.initKw(self, kw) - - - diff --git a/tests/style/py-flake8.t b/tests/style/py-flake8.t index 28e03e7a..7c3fe0da 100644 --- a/tests/style/py-flake8.t +++ b/tests/style/py-flake8.t @@ -10,7 +10,7 @@ use String::ShellQuote qw/ shell_quote /; # my $cmd = shell_quote( 'flake8', '.' ); my $cmd = shell_quote( 'flake8', - grep { not($_ eq './pysollib/pysoltk.py') } glob('./pysollib/*.py ./pysollib/[cmp]*/*.py ./pysollib/tile/[a-s]*.py') ); + grep { not($_ eq './pysollib/pysoltk.py') } glob('./pysollib/*.py ./pysollib/[cmp]*/*.py ./pysollib/tile/{[a-s],ti,to,w}*.py') ); # TEST eq_or_diff( scalar(`$cmd`), '', "flake8 is happy with the code." );