From 3ce24a088bb74370991ba90c3234a12a849ee57f Mon Sep 17 00:00:00 2001 From: skomoroh Date: Fri, 25 Aug 2006 21:27:33 +0000 Subject: [PATCH] * little reorganization: move some func. from pysollib/actions.py to pysollib/tk/menubar.py * bug fixes git-svn-id: file:///home/shlomif/Backup/svn-dumps/PySolFC/svnsync-repos/pysolfc/PySolFC/trunk@57 efabe8c0-fbe8-4139-b769-b5e6d273206e --- MANIFEST.in | 5 +- pysollib/actions.py | 130 +---------------------------------- pysollib/pysolgtk/menubar.py | 36 +++++++--- pysollib/pysolgtk/tkwrap.py | 48 ------------- pysollib/tk/menubar.py | 128 +++++++++++++++++++++++++++++++++- pysollib/tk/selecttile.py | 2 +- setup.py | 2 + 7 files changed, 161 insertions(+), 190 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 9f12a899..2298846d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -4,7 +4,7 @@ ## include pysol setup.py setup.cfg MANIFEST.in Makefile COPYING README #recursive-include pysollib *.py -include pysollib/*.py pysollib/tk/*.py +include pysollib/*.py pysollib/tk/*.py pysollib/pysolgtk/*.py include pysollib/games/*.py pysollib/games/special/*.py include pysollib/games/ultra/*.py pysollib/games/mahjongg/*.py include docs/* @@ -28,7 +28,8 @@ graft data/cardset-tuxedo graft data/cardset-vienna-2k graft data/html graft data/html-src -graft data/images +#graft data/images +recursive-include data/images *.gif *.png #graft data/music #graft data/plugins graft data/sound diff --git a/pysollib/actions.py b/pysollib/actions.py index 2fd02925..282c1e2a 100644 --- a/pysollib/actions.py +++ b/pysollib/actions.py @@ -56,7 +56,6 @@ from pysoltk import GameInfoDialog from pysoltk import EVENT_HANDLED, EVENT_PROPAGATE from pysoltk import MfxMessageDialog, MfxSimpleEntry from pysoltk import MfxExceptionDialog -from pysoltk import MfxRadioMenuItem, MfxCheckMenuItem, StringVar from pysoltk import PlayerOptionsDialog #from pysoltk import HintOptionsDialog from pysoltk import TimeoutsDialog @@ -64,7 +63,7 @@ from pysoltk import ColorsDialog from pysoltk import FontsDialog from pysoltk import EditTextDialog from pysoltk import TOOLBAR_BUTTONS -from pysoltk import create_find_card_dialog, connect_game_find_card_dialog, destroy_find_card_dialog +from pysoltk import create_find_card_dialog from help import help_about, help_html gettext = _ @@ -98,106 +97,9 @@ class PysolMenubarActions: rules = 0, pause = 0, ) - # structure to convert menu-options to Toolkit variables - self.tkopt = Struct( - gameid = MfxRadioMenuItem(self), - gameid_popular = MfxRadioMenuItem(self), - comment = MfxCheckMenuItem(self), - autofaceup = MfxCheckMenuItem(self), - autodrop = MfxCheckMenuItem(self), - autodeal = MfxCheckMenuItem(self), - quickplay = MfxCheckMenuItem(self), - undo = MfxCheckMenuItem(self), - bookmarks = MfxCheckMenuItem(self), - hint = MfxCheckMenuItem(self), - highlight_piles = MfxCheckMenuItem(self), - highlight_cards = MfxCheckMenuItem(self), - highlight_samerank = MfxCheckMenuItem(self), - highlight_not_matching = MfxCheckMenuItem(self), - mahjongg_show_removed = MfxCheckMenuItem(self), - shisen_show_hint = MfxCheckMenuItem(self), - sound = MfxCheckMenuItem(self), - cardback = MfxRadioMenuItem(self), - tabletile = MfxRadioMenuItem(self), - animations = MfxRadioMenuItem(self), - shadow = MfxCheckMenuItem(self), - shade = MfxCheckMenuItem(self), - shade_filled_stacks = MfxCheckMenuItem(self), - shrink_face_down = MfxCheckMenuItem(self), - toolbar = MfxRadioMenuItem(self), - toolbar_style = StringVar(), - toolbar_relief = StringVar(), - toolbar_compound = StringVar(), - toolbar_size = MfxRadioMenuItem(self), - statusbar = MfxCheckMenuItem(self), - num_cards = MfxCheckMenuItem(self), - helpbar = MfxCheckMenuItem(self), - save_games_geometry = MfxCheckMenuItem(self), - splashscreen = MfxCheckMenuItem(self), - demo_logo = MfxCheckMenuItem(self), - sticky_mouse = MfxCheckMenuItem(self), - mouse_undo = MfxCheckMenuItem(self), - negative_bottom = MfxCheckMenuItem(self), - pause = MfxCheckMenuItem(self), - toolbar_vars = {}, - ) - - for w in TOOLBAR_BUTTONS: - self.tkopt.toolbar_vars[w] = MfxCheckMenuItem(self) - def connectGame(self, game): self.game = game - if game is None: - return - assert self.app is game.app - tkopt, opt = self.tkopt, self.app.opt - # set state of the menu items - tkopt.gameid.set(game.id) - tkopt.gameid_popular.set(game.id) - tkopt.comment.set(bool(game.gsaveinfo.comment)) - tkopt.autofaceup.set(opt.autofaceup) - tkopt.autodrop.set(opt.autodrop) - tkopt.autodeal.set(opt.autodeal) - tkopt.quickplay.set(opt.quickplay) - tkopt.undo.set(opt.undo) - tkopt.hint.set(opt.hint) - tkopt.bookmarks.set(opt.bookmarks) - tkopt.highlight_piles.set(opt.highlight_piles) - tkopt.highlight_cards.set(opt.highlight_cards) - tkopt.highlight_samerank.set(opt.highlight_samerank) - tkopt.highlight_not_matching.set(opt.highlight_not_matching) - tkopt.shrink_face_down.set(opt.shrink_face_down) - tkopt.shade_filled_stacks.set(opt.shade_filled_stacks) - tkopt.mahjongg_show_removed.set(opt.mahjongg_show_removed) - tkopt.shisen_show_hint.set(opt.shisen_show_hint) - tkopt.sound.set(opt.sound) - tkopt.cardback.set(self.app.cardset.backindex) - tkopt.tabletile.set(self.app.tabletile_index) - tkopt.animations.set(opt.animations) - tkopt.shadow.set(opt.shadow) - tkopt.shade.set(opt.shade) - tkopt.toolbar.set(opt.toolbar) - tkopt.toolbar_style.set(opt.toolbar_style) - tkopt.toolbar_relief.set(opt.toolbar_relief) - tkopt.toolbar_compound.set(opt.toolbar_compound) - tkopt.toolbar_size.set(opt.toolbar_size) - tkopt.toolbar_relief.set(opt.toolbar_relief) - tkopt.statusbar.set(opt.statusbar) - tkopt.num_cards.set(opt.num_cards) - tkopt.helpbar.set(opt.helpbar) - tkopt.save_games_geometry.set(opt.save_games_geometry) - tkopt.demo_logo.set(opt.demo_logo) - tkopt.splashscreen.set(opt.splashscreen) - tkopt.sticky_mouse.set(opt.sticky_mouse) - tkopt.mouse_undo.set(opt.mouse_undo) - tkopt.negative_bottom.set(opt.negative_bottom) - for w in TOOLBAR_BUTTONS: - tkopt.toolbar_vars[w].set(opt.toolbar_vars[w]) - if game.canFindCard(): - connect_game_find_card_dialog(game) - else: - destroy_find_card_dialog() # will get called after connectGame() def updateRecentGamesMenu(self, gameids): @@ -328,9 +230,6 @@ class PysolMenubarActions: self.setToolbarState(ms.autodrop, "autodrop") self.setToolbarState(ms.pause, "pause") self.setToolbarState(ms.rules, "rules") - # - self.tkopt.comment.set(bool(self.game.gsaveinfo.comment)) - self.tkopt.pause.set(self.game.pause) # update menu items and toolbar def updateMenus(self): @@ -368,9 +267,6 @@ class PysolMenubarActions: return if self.changed(): if not self.game.areYouSure(_("Select game")): - # restore radiobutton settings - self.tkopt.gameid.set(self.game.id) - self.tkopt.gameid_popular.set(self.game.id) return self.game.endGame() self.game.quitGame(id, random=random) @@ -626,15 +522,9 @@ class PysolMenubarActions: if fd: fd.close() d = MfxMessageDialog(self.top, title=PACKAGE+_(" Info"), bitmap="info", text=_("Comments were appended to\n\n") + fn) - self.tkopt.comment.set(bool(game.gsaveinfo.comment)) + self._setCommentMenu(bool(game.gsaveinfo.comment)) - def mPause(self, *args): - if not self.game.pause: - if self._cancelDrag(): return - self.game.doPause() - self.tkopt.pause.set(self.game.pause) - # # Game menu - statistics # @@ -804,20 +694,6 @@ class PysolMenubarActions: self.game.updateStatus(player=self.app.opt.player) self.game.updateStatus(stats=self.app.stats.getStats(self.app.opt.player, self.game.id)) -## def mOptIrregularPiles(self, *args): -## if self._cancelDrag(): return -## self.app.opt.irregular_piles = self.tkopt.irregular_piles.get() - - def _mOptTableTile(self, i): - if self.app.setTile(i): - self.tkopt.tabletile.set(i) - - def _mOptTableColor(self, color): - tile = self.app.tabletile_manager.get(0) - tile.color = color - if self.app.setTile(0): - self.tkopt.tabletile.set(0) - def mOptColors(self, *args): if self._cancelDrag(break_pause=False): return d = ColorsDialog(self.top, _("Set colors"), self.app) @@ -836,7 +712,7 @@ class PysolMenubarActions: # if (text_color != self.app.opt.colors['text'] or use_default_text_color != self.app.opt.use_default_text_color): - self.app.setTile(self.tkopt.tabletile.get(), 1) + self.app.setTile(self.app.opt.tabletile_index) def mOptFonts(self, *args): if self._cancelDrag(break_pause=False): return diff --git a/pysollib/pysolgtk/menubar.py b/pysollib/pysolgtk/menubar.py index f833c920..e7dfb021 100644 --- a/pysollib/pysolgtk/menubar.py +++ b/pysollib/pysolgtk/menubar.py @@ -47,8 +47,8 @@ from tkutil import color_tk2gtk, color_gtk2tk from soundoptionsdialog import SoundOptionsDialog from selectcardset import SelectCardsetDialogWithPreview from selecttile import SelectTileDialogWithPreview - from selectgame import SelectGameDialogWithPreview +from findcarddialog import connect_game_find_card_dialog, destroy_find_card_dialog gettext = _ @@ -76,6 +76,19 @@ class PysolMenubar(PysolMenubarActions): 0, 0); menubar.show() + def connectGame(self, game): + self.game = game + if game is None: + return + assert self.app is game.app +## tkopt, opt = self.tkopt, self.app.opt +## tkopt.gameid.set(game.id) +## tkopt.gameid_popular.set(game.id) +## tkopt.comment.set(bool(game.gsaveinfo.comment)) + if game.canFindCard(): + connect_game_find_card_dialog(game) + else: + destroy_find_card_dialog() # # create menubar @@ -759,6 +772,10 @@ class PysolMenubar(PysolMenubarActions): self.game.endGame() self.game.quitGame(d.gameid, random=d.random) + def mPause(self, *args): + if not self.game.pause: + if self._cancelDrag(): return + self.game.doPause() def mOptSoundDialog(self, *args): if self._cancelDrag(break_pause=False): return @@ -776,15 +793,11 @@ class PysolMenubar(PysolMenubarActions): key=key) if d.status == 0 and d.button in (0, 1): if type(d.key) is str: - self._mOptTableColor(d.key) + tile = self.app.tabletile_manager.get(0) + tile.color = d.key + self.app.setTile(0) elif d.key > 0 and d.key != self.app.tabletile_index: - self._mOptTableTile(d.key) -## if type(d.key) is str: -## tile = self.app.tabletile_manager.get(0) -## tile.color = d.color -## self.app.setTile(0) -## elif d.key > 0 and d.key != self.app.tabletile_index: -## self.app.setTile(i) + self.app.setTile(d.key) def mSelectCardsetDialog(self, *event): @@ -845,3 +858,8 @@ class PysolMenubar(PysolMenubarActions): def updateAll(self, *event): self.app.canvas.updateAll() + + def _setCommentMenu(self, v): + # FIXME + pass + diff --git a/pysollib/pysolgtk/tkwrap.py b/pysollib/pysolgtk/tkwrap.py index b4fb77c7..3b8ef444 100644 --- a/pysollib/pysolgtk/tkwrap.py +++ b/pysollib/pysolgtk/tkwrap.py @@ -54,54 +54,6 @@ def make_help_toplevel(parent, title=None, class_=None): return makeToplevel(parent, title=title, class_=class_, gtkclass=_MfxToplevel) -class MfxCheckMenuItem: - def __init__(self, menubar, path=None): - self.menubar = menubar - self.path = path - self.value = None - def get(self): - ##print 'MfxCheckMenuItem.get:', self.path - if self.path is None: return 0 - w = self.menubar.menus.get_widget(self.path) - return w.active - def set(self, value): - ##print 'MfxCheckMenuItem.set:', value, self.path - if self.path is None: return - if not value or value == 'false': value = 0 - assert type(value) is types.IntType and 0 <= value <= 1 - self.value = value - w = self.menubar.menus.get_widget(self.path) - w.set_active(value) - #print self.path, value, w, w.active - - -class MfxRadioMenuItem(MfxCheckMenuItem): - def get(self): - ##print 'MfxRadioMenuItem.get:', self.path, self.value - if self.path is None: return 0 - w = self.menubar.menus.get_widget(self.path) - #from pprint import pprint - #pprint(dir(w)) - #print 'widget:', w - #print w.active - #print w.__dict__ - return self.value - def set(self, value): - ##print 'MfxRadioMenuItem.set:', value, self.path - if self.path is None: return - if not value or value == 'false': value = 0 - assert type(value) is types.IntType and 0 <= value - self.value = value - #w = self.menubar.menus.get_widget(self.path) - #w.set_active(value) - #print self.path, value #, w, w.active - - -class StringVar: - def set(self, v): - pass - - # /*********************************************************************** # // A toplevel window. # ************************************************************************/ diff --git a/pysollib/tk/menubar.py b/pysollib/tk/menubar.py index 6b49aa47..b063cff6 100644 --- a/pysollib/tk/menubar.py +++ b/pysollib/tk/menubar.py @@ -56,6 +56,8 @@ from selectgame import SelectGameDialog, SelectGameDialogWithPreview from soundoptionsdialog import SoundOptionsDialog from selectcardset import SelectCardsetDialogWithPreview from selecttile import SelectTileDialogWithPreview +from findcarddialog import connect_game_find_card_dialog, destroy_find_card_dialog +from tkwrap import MfxRadioMenuItem, MfxCheckMenuItem, StringVar #from toolbar import TOOLBAR_BUTTONS from tkconst import TOOLBAR_BUTTONS @@ -197,6 +199,8 @@ class MfxMenu(MfxMenubar): class PysolMenubar(PysolMenubarActions): def __init__(self, app, top, progress=None): PysolMenubarActions.__init__(self, app, top) + self._createTkOpt() + self._setOptions() # init columnbreak self.__cb_max = int(self.top.winfo_screenheight()/23) ## sh = self.top.winfo_screenheight() @@ -217,6 +221,110 @@ class PysolMenubar(PysolMenubarActions): self.updateBackgroundImagesMenu() self.top.config(menu=self.__menubar) + def _createTkOpt(self): + # structure to convert menu-options to Toolkit variables + self.tkopt = Struct( + gameid = MfxRadioMenuItem(self), + gameid_popular = MfxRadioMenuItem(self), + comment = MfxCheckMenuItem(self), + autofaceup = MfxCheckMenuItem(self), + autodrop = MfxCheckMenuItem(self), + autodeal = MfxCheckMenuItem(self), + quickplay = MfxCheckMenuItem(self), + undo = MfxCheckMenuItem(self), + bookmarks = MfxCheckMenuItem(self), + hint = MfxCheckMenuItem(self), + highlight_piles = MfxCheckMenuItem(self), + highlight_cards = MfxCheckMenuItem(self), + highlight_samerank = MfxCheckMenuItem(self), + highlight_not_matching = MfxCheckMenuItem(self), + mahjongg_show_removed = MfxCheckMenuItem(self), + shisen_show_hint = MfxCheckMenuItem(self), + sound = MfxCheckMenuItem(self), + cardback = MfxRadioMenuItem(self), + tabletile = MfxRadioMenuItem(self), + animations = MfxRadioMenuItem(self), + shadow = MfxCheckMenuItem(self), + shade = MfxCheckMenuItem(self), + shade_filled_stacks = MfxCheckMenuItem(self), + shrink_face_down = MfxCheckMenuItem(self), + toolbar = MfxRadioMenuItem(self), + toolbar_style = StringVar(), + toolbar_relief = StringVar(), + toolbar_compound = StringVar(), + toolbar_size = MfxRadioMenuItem(self), + statusbar = MfxCheckMenuItem(self), + num_cards = MfxCheckMenuItem(self), + helpbar = MfxCheckMenuItem(self), + save_games_geometry = MfxCheckMenuItem(self), + splashscreen = MfxCheckMenuItem(self), + demo_logo = MfxCheckMenuItem(self), + sticky_mouse = MfxCheckMenuItem(self), + mouse_undo = MfxCheckMenuItem(self), + negative_bottom = MfxCheckMenuItem(self), + pause = MfxCheckMenuItem(self), + toolbar_vars = {}, + ) + for w in TOOLBAR_BUTTONS: + self.tkopt.toolbar_vars[w] = MfxCheckMenuItem(self) + + def _setOptions(self): + tkopt, opt = self.tkopt, self.app.opt + # set state of the menu items + tkopt.autofaceup.set(opt.autofaceup) + tkopt.autodrop.set(opt.autodrop) + tkopt.autodeal.set(opt.autodeal) + tkopt.quickplay.set(opt.quickplay) + tkopt.undo.set(opt.undo) + tkopt.hint.set(opt.hint) + tkopt.bookmarks.set(opt.bookmarks) + tkopt.highlight_piles.set(opt.highlight_piles) + tkopt.highlight_cards.set(opt.highlight_cards) + tkopt.highlight_samerank.set(opt.highlight_samerank) + tkopt.highlight_not_matching.set(opt.highlight_not_matching) + tkopt.shrink_face_down.set(opt.shrink_face_down) + tkopt.shade_filled_stacks.set(opt.shade_filled_stacks) + tkopt.mahjongg_show_removed.set(opt.mahjongg_show_removed) + tkopt.shisen_show_hint.set(opt.shisen_show_hint) + tkopt.sound.set(opt.sound) + tkopt.cardback.set(self.app.cardset.backindex) + tkopt.tabletile.set(self.app.tabletile_index) + tkopt.animations.set(opt.animations) + tkopt.shadow.set(opt.shadow) + tkopt.shade.set(opt.shade) + tkopt.toolbar.set(opt.toolbar) + tkopt.toolbar_style.set(opt.toolbar_style) + tkopt.toolbar_relief.set(opt.toolbar_relief) + tkopt.toolbar_compound.set(opt.toolbar_compound) + tkopt.toolbar_size.set(opt.toolbar_size) + tkopt.toolbar_relief.set(opt.toolbar_relief) + tkopt.statusbar.set(opt.statusbar) + tkopt.num_cards.set(opt.num_cards) + tkopt.helpbar.set(opt.helpbar) + tkopt.save_games_geometry.set(opt.save_games_geometry) + tkopt.demo_logo.set(opt.demo_logo) + tkopt.splashscreen.set(opt.splashscreen) + tkopt.sticky_mouse.set(opt.sticky_mouse) + tkopt.mouse_undo.set(opt.mouse_undo) + tkopt.negative_bottom.set(opt.negative_bottom) + for w in TOOLBAR_BUTTONS: + tkopt.toolbar_vars[w].set(opt.toolbar_vars[w]) + + def connectGame(self, game): + self.game = game + if game is None: + return + assert self.app is game.app + tkopt, opt = self.tkopt, self.app.opt + tkopt.gameid.set(game.id) + tkopt.gameid_popular.set(game.id) + tkopt.comment.set(bool(game.gsaveinfo.comment)) + tkopt.pause.set(self.game.pause) + if game.canFindCard(): + connect_game_find_card_dialog(game) + else: + destroy_find_card_dialog() + # create a GTK-like path def _addPath(self, path, menu, index, submenu): if not self.__menupath.has_key(path): @@ -828,6 +936,9 @@ class PysolMenubar(PysolMenubarActions): w = getattr(self.app.toolbar, path + "_button") w["state"] = s + def _setCommentMenu(self, v): + self.tkopt.comment.set(v) + # # menu actions @@ -895,6 +1006,12 @@ class PysolMenubar(PysolMenubarActions): self.game.saveGame(filename) self.updateMenus() + def mPause(self, *args): + if not self.game.pause: + if self._cancelDrag(): return + self.game.doPause() + self.tkopt.pause.set(self.game.pause) + def mOptSoundDialog(self, *args): if self._cancelDrag(break_pause=False): return d = SoundOptionsDialog(self.top, _("Sound settings"), self.app) @@ -1050,7 +1167,8 @@ class PysolMenubar(PysolMenubarActions): n = self.app.tabletile_manager.len() if n >= 2: i = (self.tkopt.tabletile.get() + 1) % n - self._mOptTableTile(i) + if self.app.setTile(i): + self.tkopt.tabletile.set(i) def mSelectTileDialog(self, *event): if self._cancelDrag(break_pause=False): return @@ -1063,9 +1181,13 @@ class PysolMenubar(PysolMenubarActions): key=key) if d.status == 0 and d.button in (0, 1): if type(d.key) is str: - self._mOptTableColor(d.key) + tile = self.app.tabletile_manager.get(0) + tile.color = d.key + if self.app.setTile(0): + self.tkopt.tabletile.set(0) elif d.key > 0 and d.key != self.app.tabletile_index: - self._mOptTableTile(d.key) + if self.app.setTile(d.key): + self.tkopt.tabletile.set(d.key) def mOptToolbar(self, *event): ##if self._cancelDrag(break_pause=False): return diff --git a/pysollib/tk/selecttile.py b/pysollib/tk/selecttile.py index 1ebfde57..ef2a9093 100644 --- a/pysollib/tk/selecttile.py +++ b/pysollib/tk/selecttile.py @@ -190,7 +190,7 @@ class SelectTileDialogWithPreview(MfxDialog): return canvas = self.preview.canvas canvas.deleteAllItems() - if type(key) in str: + if type(key) is str: # solid color canvas.config(bg=key) canvas.setTile(None) diff --git a/setup.py b/setup.py index 0cb1bf94..bca3e377 100644 --- a/setup.py +++ b/setup.py @@ -56,6 +56,7 @@ kw = { 'scripts' : ['pysol'], 'packages' : ['pysollib', 'pysollib.tk', + 'pysollib.pysolgtk', 'pysollib.games', 'pysollib.games.special', 'pysollib.games.ultra', @@ -66,5 +67,6 @@ kw = { if os.name == 'nt': kw['windows'] = [{'script': 'pysol', 'icon_resources': [(1, "data/pysol.ico")], }] + kw['packages'].remove('pysollib.pysolgtk') setup(**kw)