## vim:ts=4:et:nowrap ## ##---------------------------------------------------------------------------## ## ## PySol -- a Python Solitaire game ## ## Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer ## Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer ## Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. ## If not, write to the Free Software Foundation, Inc., ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ## ## Markus F.X.J. Oberhumer ## ## http://wildsau.idv.uni-linz.ac.at/mfx/pysol.html ## ##---------------------------------------------------------------------------## # imports import math, os, re, string, sys import gtk from gtk import gdk TRUE, FALSE = True, False # PySol imports from pysollib.gamedb import GI from pysollib.actions import PysolMenubarActions # toolkit imports from tkutil import setTransient from tkutil import color_tk2gtk, color_gtk2tk from selectcardset import SelectCardsetDialogWithPreview from selectcardset import SelectCardsetByTypeDialogWithPreview # /*********************************************************************** # // - create menubar # // - update menubar # // - menu actions # ************************************************************************/ class PysolMenubar(PysolMenubarActions): def __init__(self, app, top, progress=None): PysolMenubarActions.__init__(self, app, top) self.menus = None self.menu_items = None # create menus menubar, accel = self.createMenus() # additional key bindings ### FIXME ###self.accel.add("Space", None, None, None, None) # delete the old menubar # set the menubar ##~ accel.attach(self.top) top.add_accel_group(accel) w = menubar.get_widget('
') self.top.vbox.pack_start(w, expand=FALSE, fill=FALSE) self.top.vbox.reorder_child(w, 0) self.__menubar = menubar self.__accel = accel self.menus = menubar # # create menubar # def m(self, *args): ##print args pass def _initItemFactory(self): self.menu_items = ( ("/_File", None, None, 0, ""), ("/File/", None, None, 0, ""), ("/File/_New Game", "N", self.mNewGame, 0, ""), ("/File/Select _game", None, None, 0, ""), ) # # /File/Select game # mi, radio = [], "" games = self.app.gdb.getGamesIdSortedByName() i = 0 path = "/File/Select game" columnbreak = 25 n = 0 mm = [] t1 = t2 = None for id in games: if t1 is None: t1 = self.app.getGameMenuitemName(id)[:3] if n == columnbreak: t2 = self.app.getGameMenuitemName(id)[:3] pp = '%s/%s-%s' % (path, t1, t2) mi.append((pp, None, None, 0, '')) for m in mm: p = '%s/%s' % (pp, m[0]) mi.append((p, None, self.mSelectGame, m[1], radio)) if radio[0] == '<': radio = re.sub('_', '', p) n = 0 mm = [] t1 = t2 mm.append((self.app.getGameMenuitemName(id), id)) n += 1 t2 = self.app.getGameMenuitemName(id)[:3] pp = '%s/%s-%s' % (path, t1, t2) mi.append((pp, None, None, 0, '')) for m in mm: p = '%s/%s' % (pp, m[0]) mi.append((p, None, self.mSelectGame, m[1], radio)) self.menu_items = self.menu_items + tuple(mi) self.tkopt.gameid.path = radio # # # self.menu_items = self.menu_items + ( ("/File/Select game by number...", None, self.mSelectGameById, 0, ""), ("/File/", None, None, 0, ""), ("/File/_Open", "O", self.m, 0, ""), ("/File/_Save", "S", self.mSave, 0, ""), ("/File/Save _as...", None, self.m, 0, ""), ("/File/", None, None, 0, ""), ("/File/_Quit", "Q", self.mQuit, 0, ""), ("/_Edit", None, None, 0, ""), ("/Edit/", None, None, 0, ""), ("/Edit/_Undo", "Z", self.mUndo, 0, ""), ("/Edit/_Redo", "R", self.mRedo, 0, ""), ("/Edit/Redo _all", None, self.mRedoAll, 0, ""), ("/Edit/", None, None, 0, ""), ("/Edit/Restart _game", "G", self.mRestart, 0, ""), ("/_Game", None, None, 0, ""), ("/Game/", None, None, 0, ""), ("/Game/_Deal cards", "D", self.mDeal, 0, ""), ("/Game/_Auto drop", "A", self.mDrop, 0, ""), ("/Game/", None, None, 0, ""), ("/Game/S_tatus...", "T", self.mStatus, 0, ""), ("/_Assist", None, None, 0, ""), ("/Assist/", None, None, 0, ""), ("/Assist/_Hint", "H", self.mHint, 0, ""), ("/Assist/Highlight _piles", "Shift", self.mHighlightPiles, 0, ""), ("/Assist/", None, None, 0, ""), ("/Assist/_Demo", "D", self.mDemo, 0, ""), ("/Assist/Demo (all games)", "", self.mMixedDemo, 0, ""), ("/_Options", None, None, 0, ""), ("/Options/", None, None, 0, ""), ("/Options/_Confirm", None, self.mOptConfirm, 0, ""), ("/Options/Auto_play", "P", self.mOptAutoDrop, 0, ""), ("/Options/_Automatic _face up", "F", self.mOptAutoFaceUp, 0, ""), ("/Options/Highlight _matching cards", None, self.mOptEnableHighlightCards, 0, ""), ("/Options/", None, None, 0, ""), ) mi, radio = [], "" path = "/Options/Cards_et" mi.append((path, None, None, 0, "")) for i in range(self.app.cardset_manager.len()): columnbreak = i > 0 and (i % 25) == 0 p = path + '/' + self.app.cardset_manager.get(i).name mi.append((p, None, self.mOptCardset, i, radio)) if radio[0] == '<': radio = re.sub('_', '', p) self.menu_items = self.menu_items + tuple(mi) ## self.tkopt.cardset.path = radio self.menu_items = self.menu_items + ( ("/Options/Table color...", None, self.mOptTableColor, 0, ""), ) mi, radio = [], "" path = "/Options/_Animations" mi.append((path, None, None, 0, "")) i = 0 for k in ("_None", "_Fast", "_Timer based"): p = path + '/' + k mi.append((p, None, self.mOptAnimations, i, radio)) if radio[0] == '<': radio = re.sub('_', '', p) i = i + 1 self.menu_items = self.menu_items + tuple(mi) self.tkopt.animations.path = radio self.menu_items = self.menu_items + ( ("/Options/Card shadow", None, self.mOptShadow, 0, ""), ("/Options/Shade legal moves", None, self.mOptShade, 0, ""), ("/Options/", None, None, 0, ""), ("/Options/_Hint options...", None, self.mOptHintOptions, 0, ""), ("/Options/_Demo options...", None, self.mOptDemoOptions, 0, ""), ("/_Help", None, None, 0, ""), ("/Help/", None, None, 0, ""), ("/Help/_Contents", "F1", self.mHelp, 0, ""), ("/Help/_Rules", None, self.mHelpRules, 0, ""), ("/Help/", None, None, 0, ""), ("/Help/_About PySol...", None, self.mHelpAbout, 0, ""), ) def createMenus(self): if not self.menu_items: self._initItemFactory() accel = gtk.AccelGroup() item_factory = gtk.ItemFactory(gtk.MenuBar, '
', accel) item_factory.create_items(self.menu_items) return item_factory, accel # # menu updates # def setMenuState(self, state, path): return w = self.__menubar.get_widget(path) w.set_sensitive(state) def setToolbarState(self, state, path): ##~ w = getattr(self.app.toolbar, path + "_button") ##~ w.set_sensitive(state) pass # # menu actions # def mOpen(self, *args): pass def mSaveAs(self, *event): pass def mOptCardset(self, *args): pass def mOptTableColor(self, *args): win = gtk.ColorSelectionDialog("Select table color") win.help_button.destroy() win.set_position(gtk.WIN_POS_MOUSE) win.colorsel.set_current_color(gdk.color_parse(self.app.opt.table_color)) ##win.colorsel.set_update_policy(UPDATE_CONTINUOUS) def delete_event(widget, *event): widget.destroy() def ok_button_clicked(_button, self=self, win=win): c = win.colorsel.get_current_color() c = '#%02x%02x%02x' % (c.red/256, c.green/256, c.blue/256) win.destroy() self.app.opt.table_color = c self.game.canvas.config(bg=self.app.opt.table_color) self.top.config(bg=self.app.opt.table_color) win.connect("delete_event", delete_event) win.ok_button.connect("clicked", ok_button_clicked) win.cancel_button.connect("clicked", win.destroy) setTransient(win, self.top) win.show() def mOptConfirm(self, *args): pass def mOptHintOptions(self, *args): pass def mOptDemoOptions(self, *args): pass def updateFavoriteGamesMenu(self, *args): pass ## def mSelectGame(self, gameid, menuitem): ## if menuitem.get_active(): ## self._mSelectGame(gameid)