1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
#-*- coding:utf-8 -*-
# Pybik -- A 3 dimensional magic cube game.
# Copyright © 2009, 2011-2012 B. Clausius <barcc@gmx.de>
#
# 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 3 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. If not, see <http://www.gnu.org/licenses/>.
# Ported from GNUbik
# Original filename: menus.c
# Original copyright and license: 2003, 2004 John Darrington, GPL3+
import gtk
from gtk import gdk
from . import config
from .confstore import confstore, SELECTIONMODE_QUAD, SELECTIONMODE_EXT
_preferences_dialog = None
def preferences_dialog(application):
global _preferences_dialog
if _preferences_dialog is None:
_preferences_dialog = PreferencesDialog(application)
_preferences_dialog.run()
class PreferencesDialog (object):
def __init__(self, application):
self.dialog = application.ui_xml.get_object('dialog_preferences')
self.dialog.connect("response", self.on_dialog_preferences_response, application)
self.dialog.connect("delete-event", lambda *a: True)
self.application = application
self.permit_callbacks = False
self.button_size = application.ui_xml.get_object('button_size')
self.button_size.set_value(confstore.dimension)
self.button_size.connect("changed", self.on_size_changed)
self.hscale_animspeed = application.ui_xml.get_object('hscale_animspeed')
self.hscale_animspeed.set_value(confstore.frameQty)
self.hscale_animspeed.connect("value-changed", self.on_hscale_animspeed_value_changed)
self.button_lighting = application.ui_xml.get_object('button_lighting')
self.button_lighting.set_active(confstore.lighting)
self.button_lighting.connect("toggled", self.on_button_lighting_toggled)
self.button_mousemode_quad = application.ui_xml.get_object('radiobutton_quad')
self.button_mousemode_ext = application.ui_xml.get_object('radiobutton_ext')
self.set_selection_mode(confstore.selection_mode)
self.button_mousemode_quad.connect("toggled", self.on_button_mousemode_toggled, SELECTIONMODE_QUAD)
self.button_mousemode_ext.connect("toggled", self.on_button_mousemode_toggled, SELECTIONMODE_EXT)
for name in ['image_mousemode_quad', 'image_mousemode_ext']:
image = application.ui_xml.get_object(name)
pixbuf = image.get_pixbuf().scale_simple(64, 64, gdk.INTERP_BILINEAR)
image.set_from_pixbuf(pixbuf)
self.permit_callbacks = True
confstore.callbacks.append(self.on_confstore_changed)
def run(self):
self.dialog.show_all()
def set_selection_mode(self, mode):
if confstore.selection_mode == SELECTIONMODE_QUAD:
self.button_mousemode_quad.set_active(True)
elif confstore.selection_mode == SELECTIONMODE_EXT:
self.button_mousemode_ext.set_active(True)
def on_confstore_changed(self, key, *unused_subkeys):
self.permit_callbacks = False
if key == 'dimension':
self.button_size.set_value(confstore.dimension)
elif key == 'frameQty':
self.hscale_animspeed.set_value(confstore.frameQty)
elif key == 'lighting':
self.button_lighting.set_active(confstore.lighting)
elif key == 'selection_mode':
self.set_selection_mode(confstore.selection_mode)
self.permit_callbacks = True
def on_dialog_preferences_response(self, unused_dialog, response, application):
if (confstore.dimension != application.current_movement.current_cube_state.dimension
and response == 0):
dialog = gtk.MessageDialog(application.window,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO,
_("The Dimension of the cube has changed.\nStart cube with new settings?"))
def on_response(dialog, response, application):
if response == gtk.RESPONSE_YES:
application.request_new_game(None, confstore.dimension)
dialog.destroy()
dialog.connect("response", on_response, application)
dialog.show_all()
self.dialog.hide()
def on_size_changed(self, editable):
if self.permit_callbacks:
str_ = editable.get_chars(0, -1)
confstore.dimension = int(str_ or 1)
def on_hscale_animspeed_value_changed(self, widget):
if self.permit_callbacks:
confstore.frameQty = int(widget.get_value())
def on_button_lighting_toggled(self, toggle_button):
if self.permit_callbacks:
confstore.lighting = toggle_button.get_active()
def on_button_mousemode_toggled(self, button, mode):
if button.get_active():
confstore.selection_mode = mode
def show_about(toplevel):
about = gtk.AboutDialog()
about.set_transient_for(toplevel)
about.set_name(config.get_appname())
about.set_version(config.VERSION)
about.set_copyright(config.COPYRIGHT)
about.set_license('\n\n'.join(config.get_license()))
about.set_wrap_license(True)
about.set_comments(config.get_description())
about.set_authors(config.AUTHORS)
about.set_website(config.WEBSITE)
about.set_website_label(config.get_website_label())
about.set_logo_icon_name("pybik")
#about.set_translator_credits(_("translator-credits"))
about.connect("response", lambda d, r: d.destroy())
about.show()
|