diff options
author | Joe Lee <joe@jotaro.com> | 2008-03-11 05:18:54 (GMT) |
---|---|---|
committer | Joe Lee <joe@jotaro.com> | 2008-03-11 05:18:54 (GMT) |
commit | 0044b6872ca1cd38e96c81d7f3ce21c5689b7f0c (patch) | |
tree | f95248f4cb71f17a128bb7903b07342fd4265def /sugarless.py |
Initial import
Diffstat (limited to 'sugarless.py')
-rwxr-xr-x | sugarless.py | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/sugarless.py b/sugarless.py new file mode 100755 index 0000000..4fa460f --- /dev/null +++ b/sugarless.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python +# +# Copyright (C) 2007, Joseph C. Lee +# +# 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; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +# A stub file for running the application on a sugarless GTK, when the Activity +# framework is not available. + +import pygtk +pygtk.require('2.0') +import gtk + +import implodegame + +class ImplodeWindow(gtk.Window): + def __init__(self): + super(ImplodeWindow, self).__init__(gtk.WINDOW_TOPLEVEL) + self.set_geometry_hints(None, min_width=640, min_height=480) + self.set_title("Implode") + + self.connect("delete_event", self._delete_event_cb) + + toolbar = gtk.Toolbar() + self.game = implodegame.ImplodeGame() + + def add_button(id, func): + button = gtk.ToolButton(id) + toolbar.add(button) + + def callback(source): + func() + button.connect('clicked', callback) + + return button + + add_button(gtk.STOCK_NEW, self.game.new_game) + add_button(gtk.STOCK_MEDIA_PREVIOUS, self.game.replay_game) + add_button(gtk.STOCK_UNDO, self.game.undo) + add_button(gtk.STOCK_REDO, self.game.redo) + + toolbar.add(gtk.SeparatorToolItem()) + + radio_buttons = [] + def add_radio_button(label, func): + button = gtk.RadioToolButton() + button.set_label(label) + toolbar.add(button) + radio_buttons.append(button) + + def callback(source): + if source.get_active(): + func() + button.connect('clicked', callback) + + return button + + add_radio_button('easy', self._easy_clicked) + add_radio_button('medium', self._medium_clicked) + add_radio_button('hard', self._hard_clicked) + for button in radio_buttons[1:]: + button.set_group(radio_buttons[0]) + + main_box = gtk.VBox(False, 0) + main_box.pack_start(toolbar, False) + main_box.pack_start(self.game, True, True, 0) + self.add(main_box) + + self.show_all() + + def _delete_event_cb(self, window, event): + gtk.main_quit() + return False + + def _easy_clicked(self): + print "Easy" + + def _medium_clicked(self): + print "Medium" + + def _hard_clicked(self): + print "Hard" + + +def main(): + w = ImplodeWindow() + gtk.main() + +if __name__ == "__main__": + main() |