def getLocalePrefs(self): ''' Locale prefs @return: gtk.Box ''' self.optionFrame.set_label(_("Locale Preferences")) box = gtk.VBox(False) box.set_border_width(3) box.pack_start(gtk.Label(_('Locale:')), False, False, 10) l = manager.LocaleManager() model = gtk.ListStore(str, str) for key in l.getAvailableLocales(): desc = l.getLocaleDescription(key) model.append([_(desc), key]) cell = gtk.CellRendererText() combo = gtk.ComboBox(model) combo.pack_start(cell) combo.add_attribute(cell, 'text', 0) box.pack_start(combo, False, False, 0) button = gtk.Button(_("Save")) button.connect("clicked", self.saveLocalePrefs_cb, combo) bbox = gtk.HButtonBox() bbox.add(button) box.pack_start(bbox, False, False, 10) o = manager.OptionManager() opt = o.get_default_option(LOCALE_OPTION, None) if not opt: combo.set_active_iter(model.get_iter_first()) else: i = model.get_iter_first() while i: val = model.get_value(i, 1) if val == opt: combo.set_active_iter(i) i = model.iter_next(i) return box
def saveLocalePrefs_cb(self, widget, combo): ''' Save Locale Prefs @param widget: Widget that activated this callback @param combo: Combo box ''' model = combo.get_model() iter = combo.get_active_iter() opt = model.get_value(iter, 1) o = manager.OptionManager() o.set_option(LOCALE_OPTION, opt) l = manager.LocaleManager() l.setLocale() s = _('Please restart the application for the changes to take effect.') self.info(s)
def createGameWindow(self, button=None): ''' Show the dialog to create a new game @param button: Widget that was clicked to activate this handler. ''' s = _("Create New Game") self.gamedialog = gtk.Dialog(title="%s" % s, flags=gtk.DIALOG_MODAL) self.gamedialog.vbox.set_spacing(10) self.gamedialog.vbox.set_border_width(5) self.gamedialog.vbox.set_homogeneous(False) main = gtk.VBox(False, 5) header = gtk.Label() header.set_markup("<b><big>%s:</big></b>" % s) main.pack_start(header) s = _("Game Name") self.createGameEntry = gtkutil.EntryWithLabel( label="%s: " % s, maxLength=constants.MAX_NAME_LENGTH) main.pack_start(self.createGameEntry) s = _("Options") main.pack_start(gtk.Label("%s:" % s)) centerOption = gtk.CheckButton(_("Center square is double word score")) centerOption.set_active(True) rankedOption = gtk.CheckButton(_("Official Game")) rankedOption.set_active(True) showCountOption = gtk.CheckButton(_("Show letter distribution")) showCountOption.set_active(True) finalLetterOption = gtk.CheckButton(_("Final letter redistribution")) finalLetterOption.set_active(True) longWordBonus = gtk.CheckButton(_("Long word bonus")) longWordBonus.set_active(False) noRepeatOption = gtk.CheckButton(_("Disallow words already on board")) noRepeatOption.set_active(False) timeBox = gtk.HBox(False, 2) limitBox = gtk.HBox(False, 2) moveTimeBox = gtk.HBox(False, 2) limitOption = gtk.CheckButton(_('Optional Overtime Limit')) untimedOption = gtk.RadioButton(None, _('Untimed')) timedOption = gtk.RadioButton(untimedOption, _('Timed Game')) moveTimeOption = gtk.RadioButton(untimedOption, _('Timed Moves')) a = gtk.Adjustment(value=25, lower=1, upper=100, step_incr=1, page_incr=1, page_size=1) timeControl = gtk.SpinButton(a, climb_rate=1, digits=0) timeBox.pack_start(timedOption, False, False, 0) timeBox.pack_start(timeControl, False, False, 5) timedOption.set_active(False) timedOption.connect( "toggled", lambda w, a, b: [x.set_sensitive(w.get_active()) for x in (a, b)], timeControl, limitBox) timedOption.connect("toggled", lambda w, a: a.set_active(w.get_active()), limitOption) timeControl.set_sensitive(False) a = gtk.Adjustment(value=1, lower=1, upper=100, step_incr=1, page_incr=1, page_size=1) limitControl = gtk.SpinButton(a, climb_rate=1, digits=0) limitBox.pack_start(limitOption, False, False, 20) limitBox.pack_start(limitControl, False, False, 5) limitOption.connect("toggled", lambda w, a: a.set_sensitive(w.get_active()), limitControl) limitBox.set_sensitive(False) self.tips.set_tip( rankedOption, _('If this game is Official, the outcome will be marked in your statistics' )) self.tips.set_tip( limitOption, _('If you set the optional overtime limit, a player will be allowed to go over the normal game time, but the player will be penalized 10 points for every overtime minute' )) self.tips.set_tip( timedOption, _('Select this option if you wish to limit the overall time each player has for the entire game' )) self.tips.set_tip( moveTimeOption, _('Select this option if you wish to limit the time a player has for each move' )) self.tips.set_tip( showCountOption, _('Select this option if you wish to show a count of the letters remaining in the bag during the game' )) self.tips.set_tip( finalLetterOption, _('Select this option if you wish for player who put the final tile to get points from the remaining players letters' )) self.tips.set_tip( longWordBonus, _('Select this option if you wish to reward long words with more points' )) self.tips.set_tip( noRepeatOption, _('Select this option if you wish to disallow repeating words')) a = gtk.Adjustment(value=3, lower=0, upper=100, step_incr=1, page_incr=1, page_size=1) moveTimeControl = gtk.SpinButton(a, climb_rate=.1, digits=1) moveTimeBox.pack_start(moveTimeOption, False, False, 0) moveTimeBox.pack_start(moveTimeControl, False, False, 5) moveTimeOption.connect("toggled", lambda w, a: a.set_sensitive(w.get_active()), moveTimeControl) moveTimeControl.set_sensitive(False) box = gtk.VBox(False, 5) box.pack_start(untimedOption, False, False, 0) box.pack_start(timeBox, False, False, 0) box.pack_start(limitBox, False, False, 0) box.pack_start(moveTimeBox, False, False, 0) exp = gtk.Expander(_('Timing Options')) exp.add(box) exp.set_spacing(10) main.pack_start(centerOption, False, False, 3) main.pack_start(rankedOption, False, False, 3) main.pack_start(showCountOption, False, False, 3) main.pack_start(finalLetterOption, False, False, 3) main.pack_start(longWordBonus, False, False, 3) main.pack_start(noRepeatOption, False, False, 3) box = gtk.HBox(False, 3) box.pack_start(gtk.Label(_('Rules:')), False, False, 3) model = gtk.ListStore(str, str) l = manager.LocaleManager() locales = l.getAvailableLocales() for locale in locales: model.append([_(l.getLocaleDescription(locale)), locale]) model.append([_('Swedish'), 'sv']) cell = gtk.CellRendererText() combo = gtk.ComboBox(model) combo.pack_start(cell) combo.add_attribute(cell, 'text', 0) cur = None for locale in locales: if l.locale == locale: cur = locale if cur is not None: i = model.get_iter_first() while i: if model.get_value(i, 1) == cur: combo.set_active_iter(i) break i = model.iter_next(i) else: combo.set_active(0) box.pack_start(combo, False, False, 0) main.pack_start(box, False, False, 3) okbutton = gtk.Button(_("Create")) cancelbutton = gtk.Button(_("Cancel")) self.gamedialog.vbox.pack_start(main, False, False, 0) self.gamedialog.vbox.pack_start(exp, False, False, 0) self.gamedialog.action_area.pack_start(okbutton) self.gamedialog.action_area.pack_start(cancelbutton) okbutton.connect("clicked", self.createGame, centerOption, rankedOption, showCountOption, finalLetterOption, longWordBonus, noRepeatOption, combo, timedOption, timeControl, limitOption, limitControl, moveTimeOption, moveTimeControl) cancelbutton.connect("clicked", lambda b: self.gamedialog.destroy()) self.gamedialog.show_all() self.gamedialog.run()
#!/usr/bin/env python from twisted.internet import gtk2reactor gtk2reactor.install() import warnings warnings.filterwarnings("ignore") from pyscrabble import constants import gettext gettext.install(constants.LOCALE_DOMAIN, constants.LOCALE_DIR) from pyscrabble import manager l = manager.LocaleManager() from pyscrabble import dist from pyscrabble import gtkconstants from pyscrabble import gtkutil from twisted.internet import reactor from pyscrabble.gui.login import LoginWindow import gtk if __name__ == '__main__': dist.ensure_config_dir(dist.CONFIG_DIR) gtk.rc_parse_string(gtkconstants.DEFAULT_THEME) gtkutil.setupStockItems() o = manager.OptionManager() def callback(): LoginWindow()