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

+ 1 new game

* improved tile binding
* bugs fixes


git-svn-id: https://pysolfc.svn.sourceforge.net/svnroot/pysolfc/PySolFC/trunk@92 39dd0a4e-7c14-0410-91b3-c4f2d318f732
This commit is contained in:
skomoroh 2006-11-10 22:27:54 +00:00
parent 017379ea05
commit 356f3808e8
9 changed files with 228 additions and 88 deletions

View file

@ -5,7 +5,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PySol 0.0.1\n"
"POT-Creation-Date: Thu Nov 9 17:36:05 2006\n"
"POT-Creation-Date: Fri Nov 10 23:00:51 2006\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -945,6 +945,9 @@ msgstr ""
msgid "Exiled Kings"
msgstr ""
msgid "Exit"
msgstr ""
msgid "Express"
msgstr ""

View file

@ -14,7 +14,7 @@ msgid ""
msgstr ""
"#-#-#-#-# pysol-1.pot (PACKAGE VERSION) #-#-#-#-#\n"
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: Thu Nov 9 17:36:57 2006\n"
"POT-Creation-Date: Fri Nov 10 23:01:45 2006\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -24,7 +24,7 @@ msgstr ""
"Generated-By: pygettext.py 1.5\n"
"#-#-#-#-# pysol-2.pot (PACKAGE VERSION) #-#-#-#-#\n"
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2006-11-09 17:36+0300\n"
"POT-Creation-Date: 2006-11-10 23:01+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -68,8 +68,8 @@ msgstr ""
msgid "&Next number"
msgstr ""
#: pysollib/actions.py:314 pysollib/app.py:892 pysollib/app.py:1155
#: pysollib/app.py:1167 pysollib/game.py:929 pysollib/game.py:1864
#: pysollib/actions.py:314 pysollib/app.py:878 pysollib/app.py:1161
#: pysollib/app.py:1173 pysollib/game.py:929 pysollib/game.py:1864
#: pysollib/main.py:379 pysollib/main.py:387 pysollib/tk/colorsdialog.py:122
#: pysollib/tk/edittextdialog.py:82 pysollib/tk/fontsdialog.py:143
#: pysollib/tk/fontsdialog.py:205 pysollib/tk/gameinfodialog.py:155
@ -77,7 +77,7 @@ msgstr ""
#: pysollib/tk/playeroptionsdialog.py:160 pysollib/tk/selectcardset.py:241
#: pysollib/tk/selectcardset.py:397 pysollib/tk/selecttile.py:159
#: pysollib/tk/soundoptionsdialog.py:170 pysollib/tk/soundoptionsdialog.py:211
#: pysollib/tk/timeoutsdialog.py:92 pysollib/tk/tkhtml.py:499
#: pysollib/tk/timeoutsdialog.py:92 pysollib/tk/tkhtml.py:500
#: pysollib/tk/tkstats.py:288 pysollib/tk/tkstats.py:512
#: pysollib/tk/tkstats.py:579 pysollib/tk/tkstats.py:594
#: pysollib/tk/tkstats.py:636 pysollib/tk/tkstats.py:708
@ -86,7 +86,7 @@ msgstr ""
msgid "&OK"
msgstr ""
#: pysollib/actions.py:314 pysollib/app.py:893 pysollib/app.py:1167
#: pysollib/actions.py:314 pysollib/app.py:879 pysollib/app.py:1173
#: pysollib/game.py:929 pysollib/game.py:1314 pysollib/game.py:1329
#: pysollib/game.py:1336 pysollib/game.py:1342 pysollib/tk/colorsdialog.py:122
#: pysollib/tk/edittextdialog.py:82 pysollib/tk/fontsdialog.py:143
@ -244,28 +244,28 @@ msgstr ""
msgid "Unknown"
msgstr ""
#: pysollib/app.py:894 pysollib/game.py:1314 pysollib/game.py:1329
#: pysollib/app.py:880 pysollib/game.py:1314 pysollib/game.py:1329
#: pysollib/game.py:1336 pysollib/game.py:1342 pysollib/tk/menubar.py:363
msgid "&New game"
msgstr ""
#: pysollib/app.py:1017
#: pysollib/app.py:1023
msgid "Loading %s %s..."
msgstr ""
#: pysollib/app.py:1052
#: pysollib/app.py:1058
msgid " load error"
msgstr ""
#: pysollib/app.py:1053
#: pysollib/app.py:1059
msgid "Error while loading "
msgstr ""
#: pysollib/app.py:1147
#: pysollib/app.py:1153
msgid "Incompatible "
msgstr ""
#: pysollib/app.py:1149
#: pysollib/app.py:1155
msgid ""
"The currently selected %s %s\n"
"is not compatible with the game\n"
@ -274,7 +274,7 @@ msgid ""
"Please select a %s type %s.\n"
msgstr ""
#: pysollib/app.py:1165
#: pysollib/app.py:1171
msgid "Please select a %s type %s"
msgstr ""
@ -1227,13 +1227,13 @@ msgstr ""
msgid " Help"
msgstr ""
#: pysollib/main.py:68 pysollib/main.py:287
msgid " installation error"
#: pysollib/main.py:67 pysollib/main.py:287
msgid "%s installation error"
msgstr ""
#: pysollib/main.py:69
#: pysollib/main.py:68
msgid ""
"No %ss were found !!!\n"
"No cardsets were found !!!\n"
"\n"
"Main data directory is:\n"
"%s\n"
@ -1241,17 +1241,17 @@ msgid ""
"Please check your %s installation.\n"
msgstr ""
#: pysollib/main.py:76 pysollib/main.py:295 pysollib/tk/menubar.py:382
#: pysollib/main.py:75 pysollib/main.py:295 pysollib/tk/menubar.py:382
msgid "&Quit"
msgstr ""
#: pysollib/main.py:100
#: pysollib/main.py:99
msgid ""
"%s: %s\n"
"try %s --help for more information"
msgstr ""
#: pysollib/main.py:147
#: pysollib/main.py:146
msgid ""
"Usage: %s [OPTIONS] [FILE]\n"
" -g --game=GAMENAME start game GAMENAME\n"
@ -1260,6 +1260,7 @@ msgid ""
" --fg --foreground=COLOR foreground color\n"
" --bg --background=COLOR background color\n"
" --fn --font=FONT default font\n"
" --theme=THEME specify theme (for Tile binding)\n"
" --sound-mod=MOD\n"
" --nosound disable sound support\n"
" --noplugins disable load plugins\n"
@ -1293,7 +1294,7 @@ msgid ""
msgstr ""
#: pysollib/main.py:374 pysollib/main.py:382
msgid " installation problem"
msgid "%s installation problem"
msgstr ""
#: pysollib/main.py:375
@ -1311,7 +1312,7 @@ msgid ""
msgstr ""
#: pysollib/main.py:390
msgid "Welcome to "
msgid "Welcome to %s"
msgstr ""
#: pysollib/resource.py:192

View file

@ -5,8 +5,8 @@
msgid ""
msgstr ""
"Project-Id-Version: PySol 0.0.1\n"
"POT-Creation-Date: Thu Nov 9 17:36:05 2006\n"
"PO-Revision-Date: 2006-11-09 17:59+0300\n"
"POT-Creation-Date: Fri Nov 10 23:00:51 2006\n"
"PO-Revision-Date: 2006-11-10 13:20+0300\n"
"Last-Translator: Скоморох <skomoroh@gmail.com>\n"
"Language-Team: Russian <ru@li.org>\n"
"MIME-Version: 1.0\n"
@ -954,6 +954,9 @@ msgstr "Оправдание"
msgid "Exiled Kings"
msgstr "Изгнанные короли"
msgid "Exit"
msgstr "Выход"
msgid "Express"
msgstr "Экспресс"

View file

@ -5,8 +5,8 @@
msgid ""
msgstr ""
"Project-Id-Version: PySol 0.0.1\n"
"POT-Creation-Date: Thu Nov 9 17:36:57 2006\n"
"PO-Revision-Date: 2006-11-06 09:53+0300\n"
"POT-Creation-Date: Fri Nov 10 23:01:45 2006\n"
"PO-Revision-Date: 2006-11-10 23:18+0300\n"
"Last-Translator: Скоморох <skomoroh@gmail.com>\n"
"Language-Team: Russian <ru@li.org>\n"
"MIME-Version: 1.0\n"
@ -53,8 +53,8 @@ msgstr ""
msgid "&Next number"
msgstr "&Следующий номер"
#: pysollib/actions.py:314 pysollib/app.py:892 pysollib/app.py:1155
#: pysollib/app.py:1167 pysollib/game.py:929 pysollib/game.py:1864
#: pysollib/actions.py:314 pysollib/app.py:878 pysollib/app.py:1161
#: pysollib/app.py:1173 pysollib/game.py:929 pysollib/game.py:1864
#: pysollib/main.py:379 pysollib/main.py:387 pysollib/tk/colorsdialog.py:122
#: pysollib/tk/edittextdialog.py:82 pysollib/tk/fontsdialog.py:143
#: pysollib/tk/fontsdialog.py:205 pysollib/tk/gameinfodialog.py:155
@ -62,7 +62,7 @@ msgstr "&Следующий номер"
#: pysollib/tk/playeroptionsdialog.py:160 pysollib/tk/selectcardset.py:241
#: pysollib/tk/selectcardset.py:397 pysollib/tk/selecttile.py:159
#: pysollib/tk/soundoptionsdialog.py:170 pysollib/tk/soundoptionsdialog.py:211
#: pysollib/tk/timeoutsdialog.py:92 pysollib/tk/tkhtml.py:499
#: pysollib/tk/timeoutsdialog.py:92 pysollib/tk/tkhtml.py:500
#: pysollib/tk/tkstats.py:288 pysollib/tk/tkstats.py:512
#: pysollib/tk/tkstats.py:579 pysollib/tk/tkstats.py:594
#: pysollib/tk/tkstats.py:636 pysollib/tk/tkstats.py:708
@ -71,7 +71,7 @@ msgstr "&Следующий номер"
msgid "&OK"
msgstr "&ОК"
#: pysollib/actions.py:314 pysollib/app.py:893 pysollib/app.py:1167
#: pysollib/actions.py:314 pysollib/app.py:879 pysollib/app.py:1173
#: pysollib/game.py:929 pysollib/game.py:1314 pysollib/game.py:1329
#: pysollib/game.py:1336 pysollib/game.py:1342 pysollib/tk/colorsdialog.py:122
#: pysollib/tk/edittextdialog.py:82 pysollib/tk/fontsdialog.py:143
@ -241,28 +241,28 @@ msgstr "Настроить таймауты"
msgid "Unknown"
msgstr "Неизвестный"
#: pysollib/app.py:894 pysollib/game.py:1314 pysollib/game.py:1329
#: pysollib/app.py:880 pysollib/game.py:1314 pysollib/game.py:1329
#: pysollib/game.py:1336 pysollib/game.py:1342 pysollib/tk/menubar.py:363
msgid "&New game"
msgstr "&Новая игра"
#: pysollib/app.py:1017
#: pysollib/app.py:1023
msgid "Loading %s %s..."
msgstr "Загружается %s %s..."
#: pysollib/app.py:1052
#: pysollib/app.py:1058
msgid " load error"
msgstr " ошибка при загрузке"
#: pysollib/app.py:1053
#: pysollib/app.py:1059
msgid "Error while loading "
msgstr "Ошибка при загрузке"
#: pysollib/app.py:1147
#: pysollib/app.py:1153
msgid "Incompatible "
msgstr "Несовместимый "
#: pysollib/app.py:1149
#: pysollib/app.py:1155
msgid ""
"The currently selected %s %s\n"
"is not compatible with the game\n"
@ -276,7 +276,7 @@ msgstr ""
"\n"
"Необходимо выбрать %s типа %s.\n"
#: pysollib/app.py:1165
#: pysollib/app.py:1171
msgid "Please select a %s type %s"
msgstr "Выберите %s типа %s"
@ -1331,25 +1331,31 @@ msgstr "Не найден файл помощи\n"
msgid " Help"
msgstr " Помощь"
#: pysollib/main.py:68 pysollib/main.py:287
msgid " installation error"
msgstr " проблема с установкой"
#: pysollib/main.py:67 pysollib/main.py:287
msgid "%s installation error"
msgstr "%s проблема с установкой"
#: pysollib/main.py:69
#: pysollib/main.py:68
msgid ""
"No %ss were found !!!\n"
"No cardsets were found !!!\n"
"\n"
"Main data directory is:\n"
"%s\n"
"\n"
"Please check your %s installation.\n"
msgstr ""
"Не найдены наборы карт!!!\n"
"\n"
"Основной каталог:\n"
"%s\n"
"\n"
"Пожалуйста проверьте установку %s.\n"
#: pysollib/main.py:76 pysollib/main.py:295 pysollib/tk/menubar.py:382
#: pysollib/main.py:75 pysollib/main.py:295 pysollib/tk/menubar.py:382
msgid "&Quit"
msgstr "В&ыход"
#: pysollib/main.py:100
#: pysollib/main.py:99
msgid ""
"%s: %s\n"
"try %s --help for more information"
@ -1357,7 +1363,7 @@ msgstr ""
"%s: %s\n"
"попробуйте %s --help для получения более подробной информации"
#: pysollib/main.py:147
#: pysollib/main.py:146
msgid ""
"Usage: %s [OPTIONS] [FILE]\n"
" -g --game=GAMENAME start game GAMENAME\n"
@ -1366,6 +1372,7 @@ msgid ""
" --fg --foreground=COLOR foreground color\n"
" --bg --background=COLOR background color\n"
" --fn --font=FONT default font\n"
" --theme=THEME specify theme (for Tile binding)\n"
" --sound-mod=MOD\n"
" --nosound disable sound support\n"
" --noplugins disable load plugins\n"
@ -1381,13 +1388,14 @@ msgstr ""
" --fg --foreground=COLOR цвет текста\n"
" --bg --background=COLOR цвет фона\n"
" --fn --font=FONT шрифт по умолчанию\n"
" --theme=THEME установить тему (for Tile binding)\n"
" --sound-mod=MOD\n"
" --nosound отключить звук\n"
" --noplugins отключить загрузку плагинов\n"
" -h --help показать это сообщение и выйти\n"
"\n"
" FILE - имя файла сохранённой игры\n"
" MOD - one of following: pss(default), pygame, oss, win\n"
" MOD - одно из следующих значений: pss(default), pygame, oss, win\n"
#: pysollib/main.py:165
msgid ""
@ -1415,10 +1423,17 @@ msgid ""
"\n"
"Please check your %s installation.\n"
msgstr ""
"\n"
"Не найдены игры!!!\n"
"\n"
"Основной каталог с данными:\n"
"%s\n"
"\n"
"Пожалуйста проверьте установку %s.\n"
#: pysollib/main.py:374 pysollib/main.py:382
msgid " installation problem"
msgstr ""
msgid "%s installation problem"
msgstr "%s проблема с установкой"
#: pysollib/main.py:375
msgid ""
@ -1426,6 +1441,9 @@ msgid ""
"\n"
"Sounds and background music will be disabled."
msgstr ""
"Ваш дистрибутив Python собран без поддержки нитей.\n"
"\n"
"Звук и фоновая музыка будут недоступны."
#: pysollib/main.py:383
msgid ""
@ -1433,13 +1451,13 @@ msgid ""
"\n"
"Sounds and background music will be disabled."
msgstr ""
"Модуль pysolsoundserver не найден\n"
"Модуль pysolsoundserver не найден.\n"
"\n"
"Звук и фоновая музыка будут недоступны"
"Звук и фоновая музыка будут недоступны."
#: pysollib/main.py:390
msgid "Welcome to "
msgstr "Добро пожаловать в "
msgid "Welcome to %s"
msgstr "Добро пожаловать в %s"
#: pysollib/resource.py:192
msgid "French type (52 cards)"

View file

@ -938,6 +938,106 @@ class Cheops(Pyramid):
return abs(card1.rank-card2.rank) in (0,1)
# /***********************************************************************
# // Exit
# ************************************************************************/
class Exit_RowStack(Elevens_RowStack):
def acceptsCards(self, from_stack, cards):
#if self.basicIsBlocked():
# return 0
if from_stack is self or not self.cards or len(cards) != 1:
return False
c1 = self.cards[-1]
c2 = cards[0]
#if not c1.face_up or not c2.face_up:
# return False
return self.game._checkPair(c1, c2)
def moveMove(self, ncards, to_stack, frames=-1, shadow=-1):
self._dropPairMove(ncards, to_stack, frames=-1, shadow=shadow)
class Exit(Game):
def createGame(self):
# create layout
l, s = Layout(self), self.s
# set window
h1 = l.YS+5*l.YOFFSET
self.setSize(l.XM+7*l.XS, l.YM+2*h1+l.YS)
# create stacks
y = l.YM
for i in (0, 1):
x = l.XM
for j in range(5):
stack = Exit_RowStack(x, y, self, base_rank=NO_RANK,
max_move=1, max_accept=1, dir=0)
s.rows.append(stack)
stack.CARD_YOFFSET = l.YOFFSET
x += l.XS
y += h1
x, y = self.width-l.XS, l.YM
stack = Exit_RowStack(x, y, self, base_rank=NO_RANK,
max_move=1, max_accept=1, dir=0)
s.reserves.append(stack)
stack.CARD_YOFFSET = l.YOFFSET
x, y = self.width-l.XS, self.height-l.YS
s.foundations.append(AbstractFoundationStack(x, y, self, suit=ANY_SUIT,
max_accept=0, max_move=0, max_cards=52))
l.createText(s.foundations[0], "n")
x, y = l.XM, self.height-l.YS
s.talon = InitialDealTalonStack(x, y, self)
# define stack-groups
l.defaultStackGroups()
def _checkPair(self, c1, c2):
if c1.rank + c2.rank == 9: # A-10, 2-9, 3-8, 4-7, 5-6
return True
if c1.rank == JACK and c2.rank == JACK:
return True
if c1.rank + c2.rank == 23: # Q-K
return True
return False
def _shuffleHook(self, cards):
swap_index = None
for i in range(10):
jack_indexes = []
for j in range(5):
k = i*5+j
c = cards[k]
if c.rank == JACK:
jack_indexes.append(k)
if len(jack_indexes) == 3:
swap_index = jack_indexes[1]
if len(jack_indexes) >= 2:
break
if not swap_index is None:
i = -1
if cards[-1].rank == JACK: # paranoia
i = -2
cards[swap_index], cards[i] = cards[i], cards[swap_index]
cards.reverse()
return cards
def startGame(self):
self.startDealSample()
for i in range(10):
for j in range(5):
self.s.talon.dealRow(rows=[self.s.rows[i]], frames=4)
self.s.talon.dealRow(rows=self.s.reserves, frames=4)
self.s.talon.dealRow(rows=self.s.reserves, frames=4)
## def getAutoStacks(self, event=None):
## return ((), (), self.sg.dropstacks)
def shallHighlightMatch(self, stack1, card1, stack2, card2):
return self._checkPair(card1, card2)
# register the game
registerGame(GameInfo(38, Pyramid, "Pyramid",
@ -969,4 +1069,6 @@ registerGame(GameInfo(658, Apophis, "Apophis",
GI.GT_PAIRING_TYPE, 1, 2, GI.SL_MOSTLY_LUCK))
registerGame(GameInfo(659, Cheops, "Cheops",
GI.GT_PAIRING_TYPE, 1, 0, GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(674, Exit, "Exit",
GI.GT_PAIRING_TYPE, 1, 0, GI.SL_MOSTLY_SKILL))

View file

@ -41,7 +41,7 @@ import getopt
# PySol imports
from mfxutil import destruct, EnvError
from util import CARDSET, DataLoader
from util import DataLoader
from resource import Tile
from gamedb import GI
from app import Application
@ -64,16 +64,16 @@ from pysoltk import PysolProgressBar
def fatal_no_cardsets(app):
app.wm_withdraw()
d = MfxMessageDialog(app.top, title=PACKAGE + _(" installation error"),
text=_('''No %ss were found !!!
d = MfxMessageDialog(app.top, title=_("%s installation error") % PACKAGE,
text=_('''No cardsets were found !!!
Main data directory is:
%s
Please check your %s installation.
''') % (CARDSET, app.dataloader.dir, PACKAGE),
''') % (app.dataloader.dir, PACKAGE),
bitmap="error", strings=(_("&Quit"),))
##raise Exception, "no "+CARDSET+"s found !"
##raise Exception, "no cardsets found !"
# /***********************************************************************
@ -150,6 +150,7 @@ def parse_option(argv):
--fg --foreground=COLOR foreground color
--bg --background=COLOR background color
--fn --font=FONT default font
--theme=THEME specify theme (for Tile binding)
--sound-mod=MOD
--nosound disable sound support
--noplugins disable load plugins
@ -283,7 +284,7 @@ def pysol_init(app, args):
# check games
if len(app.gdb.getGamesIdSortedByName()) == 0:
app.wm_withdraw()
d = MfxMessageDialog(top, title=PACKAGE + _(" installation error"),
d = MfxMessageDialog(top, title=_("%s installation error") % PACKAGE,
text=_('''
No games were found !!!
@ -331,7 +332,7 @@ Please check your %s installation.
if not app.audio.CAN_PLAY_SOUND:
app.opt.sound = 0
if not opts["nosound"] and not opts['sound-mod'] and pysolsoundserver and not app.audio.connected:
print >> sys.stderr, PACKAGE + ": could not connect to pysolsoundserver, sound disabled."
print >> sys.stderr, "%s: could not connect to pysolsoundserver, sound disabled." % PACKAGE
warn_pysolsoundserver = 1
app.audio.updateSettings()
# start up the background music
@ -363,14 +364,14 @@ Please check your %s installation.
if thread is None:
warn_thread = 1
if thread is None:
print >> sys.stderr, PACKAGE+": Python thread module not found, sound disabled."
print >> sys.stderr, "%s: Python thread module not found, sound disabled." % PACKAGE
else:
print >> sys.stderr, PACKAGE+": pysolsoundserver module not found, sound disabled."
print >> sys.stderr, "%s: pysolsoundserver module not found, sound disabled." % PACKAGE
sys.stdout.flush()
if not opts["nosound"]:
if warn_thread:
top.update()
d = MfxMessageDialog(top, title=PACKAGE + _(" installation problem"),
d = MfxMessageDialog(top, title=_("%s installation problem") % PACKAGE,
text=_('''\
Your Python installation is compiled without thread support.
@ -378,7 +379,7 @@ Sounds and background music will be disabled.'''),
bitmap="warning", strings=(_("&OK"),))
elif warn_pysolsoundserver:
top.update()
d = MfxMessageDialog(top, title=PACKAGE + _(" installation problem"),
d = MfxMessageDialog(top, title=_("%s installation problem") % PACKAGE,
text=_('''\
The pysolsoundserver module was not found.
@ -386,7 +387,7 @@ Sounds and background music will be disabled.'''),
bitmap="warning", strings=(_("&OK"),))
# create the progress bar
title = _("Welcome to ") + PACKAGE
title = _("Welcome to %s") % PACKAGE
color = app.opt.colors['table']
if app.tabletile_index > 0:
color = "#008200"
@ -425,4 +426,3 @@ def main(args=None):
return r
# let's go - enter the mainloop
app.mainloop()
return 0

View file

@ -67,6 +67,7 @@ class _MfxToplevel(gtk.Window):
#self.add(self.vbox)
self.table = gtk.Table(3, 6, False)
self.add(self.table)
self.connect('destroy', self.mainquit)
self.table.show()
self.realize()
@ -112,7 +113,7 @@ class _MfxToplevel(gtk.Window):
def mainloop(self):
gtk.main() # the global function
def mainquit(self):
def mainquit(self, *args):
gtk.main_quit() # the global function
def screenshot(self, filename):

View file

@ -27,8 +27,10 @@ TclError = Tkinter.TclError
_flatten = Tkinter._flatten
class Style:
def __init__(self, master):
class Style(Tkinter.Misc):
def __init__(self, master=None):
if master is None:
master = Tkinter._default_root
self.tk = master.tk
def default(self, style, **kw):
@ -82,15 +84,6 @@ class Style:
"""Sets the current theme to themeName, and refreshes all widgets."""
return self.tk.call("style", "theme", "use", theme)
def _options(self, cnf):
"""Internal function."""
res = ()
for k, v in cnf.items():
if v is not None:
if k[-1] == '_': k = k[:-1]
res = res + ('-'+k, str(v))
return res
def configure(self, style, **kw):
"""Sets the default value of the specified option(s)
in style."""
@ -98,6 +91,22 @@ class Style:
return self.tk.call("style", "configure", style, *opts)
config = configure
def lookup(self, style, option, state=None, default=None):
"""Returns the value specified for -option in style
style in state state, using the standard lookup
rules for element options. state is a list of
state names; if omitted, it defaults to all bits
off (the ``normal'' state). If the default argu-
ment is present, it is used as a fallback value in
case no specification for -option is found."""
opts = []
if state:
opts = [state]
if default:
opts.append(default)
return self.tk.call("style", "lookup", style, "-"+option, *opts)
class Widget(Tkinter.Widget, Style):
def __init__(self, master, widgetName=None, cnf={}, kw={}, extra=()):

View file

@ -421,6 +421,7 @@ def load_theme(app, top, theme):
top.tk.call('source', f)
#
top.tk.call("package", "require", "tile")
style = Tkinter.Style(top)
# load available themes
d = os.path.join(app.dataloader.dir, 'themes')
if os.path.isdir(d):
@ -434,26 +435,28 @@ def load_theme(app, top, theme):
traceback.print_exc()
pass
# set theme
all_themes = top.tk.call('style', 'theme', 'names')
all_themes = style.theme_names()
if theme not in all_themes:
print >> sys.stderr, 'WARNING: invalid theme name:', theme
theme = 'default'
if theme:
top.tk.call('style', 'theme', 'use', theme)
if theme not in ('winnative',):
bg = top.tk.call('style', 'lookup', '.', '-background')
top.tk_setPalette(bg)
bg = top.tk.call('style', 'lookup', '.', '-background', 'active')
top.option_add('*Menu.activeBackground', bg)
style.theme_use(theme)
if theme not in ('winnative', 'xpnative'):
color = style.lookup('.', 'background')
if color:
top.tk_setPalette(color)
color = style.lookup('.', 'background', 'active')
if color:
top.option_add('*Menu.activeBackground', color)
if theme == 'winnative':
top.tk.call('style', 'configure', 'Toolbutton', '-padding', '1 1')
style.configure('Toolbutton', padding=1)
#if 'xpnative' in all_themes:
# theme = 'xpnative'
font = app.opt.fonts['default']
if font:
top.tk.call('style', 'configure', '.', '-font', font)
style.configure('.', font=font)
else:
font = top.tk.call('style', 'lookup', '.', '-font')
font = style.lookup('.', 'font')
if font:
top.option_add('*font', font)