annotate pytouhou/menu.py @ 568:e7a4731a278b

Add a GTK+ main menu, mimicking the original EoSD one.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 01 Jul 2014 23:18:15 +0200
parents
children f0252cf111d8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
568
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 # -*- encoding: utf-8 -*-
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2 ##
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 ## Copyright (C) 2014 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 ##
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 ## This program is free software; you can redistribute it and/or modify
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 ## it under the terms of the GNU General Public License as published
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 ## by the Free Software Foundation; version 3 only.
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 ##
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 ## This program is distributed in the hope that it will be useful,
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 ## GNU General Public License for more details.
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 ##
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 from pytouhou.utils.helpers import get_logger
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 logger = get_logger(__name__)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18 try:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 from gi.repository import Gtk, Gdk
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20 except ImportError:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 logger.error('GTK+ unavailable, disabling the GUI menu.')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22 raise
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 import sys
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 import re
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 GL_VERSION_REGEX = re.compile(r'^\d\.\d$')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 class Handler(object):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 def __init__(self, config, args):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32 self.config = config
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33 self.args = args
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 def init_gtk(self, builder):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36 self.start_window = builder.get_object('start_window')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 self.game_window = builder.get_object('game_window')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38 self.options_window = builder.get_object('options_window')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 self.replay_filechooserdialog = builder.get_object('replay_filechooserdialog')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42 # Game widgets
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43 self.difficulty_box = builder.get_object('difficulty_box')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 self.character_box = builder.get_object('character_box')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 self.stage_box = builder.get_object('stage_box')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46 self.boss_rush_checkbutton = builder.get_object('boss_rush_checkbutton')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48 self.difficulty_comboboxtext = builder.get_object('difficulty_comboboxtext')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 self.character_comboboxtext = builder.get_object('character_comboboxtext')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50 self.stage_comboboxtext = builder.get_object('stage_comboboxtext')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52 # Options widgets
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 self.path_filechooserbutton = builder.get_object('path_filechooserbutton')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54 self.backend_comboboxtext = builder.get_object('backend_comboboxtext')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
56 # OpenGL backend
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57 self.opengl_grid = builder.get_object('opengl_grid')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58 self.flavor_comboboxtext = builder.get_object('flavor_comboboxtext')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59 self.version_entry = builder.get_object('version_entry')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60 self.double_buffer_checkbutton = builder.get_object('double_buffer_checkbutton')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62 # SDL backend
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63 self.sdl_grid = builder.get_object('sdl_grid')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65 self.fps_entry = builder.get_object('fps_entry')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66 self.no_background_checkbutton = builder.get_object('no_background_checkbutton')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
67 self.no_particles_checkbutton = builder.get_object('no_particles_checkbutton')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68 self.no_sound_checkbutton = builder.get_object('no_sound_checkbutton')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
69
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70 self.difficulty_comboboxtext.set_active_id(str(self.args.rank))
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71 self.character_comboboxtext.set_active_id(str(self.args.character))
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 self.stage_comboboxtext.set_active_id(str(self.args.stage))
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 self.boss_rush_checkbutton.set_active(self.args.boss_rush)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
75 self.path_filechooserbutton.set_filename(self.args.path)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76 self.backend_comboboxtext.set_active_id(' '.join(self.args.backend))
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
78 self.flavor_comboboxtext.set_active_id(self.args.gl_flavor)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
79 self.version_entry.set_text(str(self.args.gl_version))
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80 if self.args.double_buffer is None:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
81 self.double_buffer_checkbutton.set_inconsistent(True)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
82 else:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
83 self.double_buffer_checkbutton.set_inconsistent(False)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84 self.double_buffer_checkbutton.set_active(self.args.double_buffer)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
86 self.fps_entry.set_text(str(self.args.fps_limit))
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87 self.no_background_checkbutton.set_active(self.args.no_background)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88 self.no_particles_checkbutton.set_active(self.args.no_particles)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
89 self.no_sound_checkbutton.set_active(self.args.no_sound)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
91 def hide_and_play(self, window):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92 window.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
93 Gtk.main_quit()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
94 print('Play!')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
95
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
96 def on_quit(self, *args):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
97 Gtk.main_quit(*args)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
98 sys.exit(0)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
100
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
101 # Main menu
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
102
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
103 def on_start_window_key_press_event(self, window, event_key):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
104 if (event_key.keyval == Gdk.KEY_Escape or
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
105 event_key.state == Gdk.ModifierType.CONTROL_MASK and event_key.keyval == Gdk.KEY_q):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
106 self.on_quit()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
107
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
108 def on_start_button_clicked(self, _):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
109 self.difficulty_box.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
110 self.character_box.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
111 self.stage_box.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
112
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
113 self.stage_comboboxtext.set_active_id(None)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
114 self.args.stage = None
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
115
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
116 self.start_window.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
117 self.game_window.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
118
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
119 def on_extra_start_button_clicked(self, _):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
120 self.difficulty_box.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
121 self.character_box.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
122 self.stage_box.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
123
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
124 self.difficulty_comboboxtext.set_active_id('4')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
125 self.stage_comboboxtext.set_active_id('7')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
126
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
127 self.start_window.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
128 self.game_window.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
129
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
130 def on_practice_start_button_clicked(self, _):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
131 self.difficulty_box.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
132 self.character_box.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
133 self.stage_box.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
134
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
135 self.start_window.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
136 self.game_window.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
137
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
138 def on_options_button_clicked(self, _):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
139 self.start_window.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
140 self.options_window.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
141
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
142 def on_replay_button_clicked(self, _):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
143 self.start_window.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
144 self.replay_filechooserdialog.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
145
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
146 def on_inactive_button_clicked(self, _):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
147 raise NotImplementedError('Menu not implemented')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
148
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
149 on_netplay_start_button_clicked = on_inactive_button_clicked
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
150 on_score_button_clicked = on_inactive_button_clicked
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
151 on_music_room_button_clicked = on_inactive_button_clicked
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
152
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
153
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
154 # Game menu
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
155
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
156 def on_game_back_button_clicked(self, _):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
157 self.game_window.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
158 self.start_window.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
159
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
160 def on_play_button_clicked(self, _):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
161 self.hide_and_play(self.game_window)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
162
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
163 def on_game_window_key_press_event(self, window, event_key):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
164 if event_key.keyval == Gdk.KEY_Escape:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
165 self.game_window.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
166 self.start_window.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
167 elif event_key.state == Gdk.ModifierType.CONTROL_MASK and event_key.keyval == Gdk.KEY_q:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
168 self.on_quit()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
169
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
170 def on_difficulty_comboboxtext_changed(self, item):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
171 active = item.get_active_id()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
172 difficulty = int(active)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
173 self.config.set('rank', active if difficulty < 4 else None)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
174 self.args.rank = difficulty
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
175
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
176 def on_character_comboboxtext_changed(self, item):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
177 character = int(item.get_active_id())
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
178 self.config.set('character', character)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
179 self.args.character = character
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
180
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
181 def on_stage_comboboxtext_changed(self, item):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
182 stage = item.get_active_id()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
183 self.args.stage = int(stage) if stage is not None else None
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
184
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
185 def on_boss_rush_checkbutton_toggled(self, boss_rush_checkbutton):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
186 active = boss_rush_checkbutton.get_active()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
187 self.config.set('boss-rush', active)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
188 self.args.boss_rush = active
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
189
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
190
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
191 # Replay dialog
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
192
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
193 def on_replay_filechooserdialog_close(self, _):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
194 self.replay_filechooserdialog.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
195 self.start_window.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
196
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
197 on_replay_cancel_button_clicked = on_replay_filechooserdialog_close
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
198
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
199 def on_replay_open_button_clicked(self, button):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
200 try:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
201 open(self.args.replay, 'rb').close()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
202 except (IOError, TypeError):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
203 return
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
204 self.hide_and_play(self.replay_filechooserdialog)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
205
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
206 def on_replay_filechooserdialog_selection_changed(self, dialog):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
207 self.args.replay = dialog.get_filename()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
208
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
209 def on_replay_filechooserdialog_file_activated(self, window):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
210 self.args.replay = window.get_filename()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
211 self.hide_and_play(self.replay_filechooserdialog)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
212
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
213 def on_replay_filechooserdialog_key_press_event(self, window, event_key):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
214 if event_key.keyval == Gdk.KEY_Escape:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
215 self.replay_filechooserdialog.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
216 self.start_window.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
217 elif event_key.state == Gdk.ModifierType.CONTROL_MASK and event_key.keyval == Gdk.KEY_q:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
218 self.on_quit()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
219
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
220
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
221 # Options menu
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
222
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
223 def on_options_back_button_clicked(self, _):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
224 self.options_window.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
225 self.start_window.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
226
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
227 def on_options_window_key_press_event(self, window, event_key):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
228 if event_key.keyval == Gdk.KEY_Escape:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
229 self.options_window.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
230 self.start_window.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
231 elif event_key.state == Gdk.ModifierType.CONTROL_MASK and event_key.keyval == Gdk.KEY_q:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
232 self.on_quit()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
233
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
234 def on_path_filechooserbutton_file_set(self, path_filechooserbutton):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
235 path = path_filechooserbutton.get_filename()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
236 self.config.set('path', path)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
237
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
238 def on_backend_comboboxtext_changed(self, backend_comboboxtext):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
239 active = backend_comboboxtext.get_active_id()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
240 self.config.set('backend', active)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
241 backends = active.split()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
242 new_grids = [getattr(self, backend + '_grid') for backend in backends]
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
243 for grid in [self.opengl_grid, self.sdl_grid]:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
244 if grid not in new_grids:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
245 grid.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
246 else:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
247 grid.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
248
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
249 def on_flavor_comboboxtext_changed(self, flavor_comboboxtext):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
250 active = flavor_comboboxtext.get_active_id()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
251 self.config.set('gl-flavor', active)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
252
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
253 def on_version_entry_changed(self, version_entry):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
254 text = version_entry.get_text()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
255 if not GL_VERSION_REGEX.match(text):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
256 raise ValueError('ā€œ%sā€ is not <digit>.<digit>' % text)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
257 self.config.set('gl-version', text)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
258
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
259 def on_double_buffer_checkbutton_clicked(self, double_buffer_checkbutton):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
260 inconsistent = double_buffer_checkbutton.get_inconsistent()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
261 active = double_buffer_checkbutton.get_active()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
262 if inconsistent:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
263 active = False
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
264 inconsistent = False
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
265 elif active:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
266 active = True
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
267 else:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
268 inconsistent = True
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
269 double_buffer_checkbutton.set_active(active)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
270 double_buffer_checkbutton.set_inconsistent(inconsistent)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
271 self.config.set('double-buffer', None if inconsistent else active)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
272
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
273 def on_fps_entry_changed(self, fps_entry):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
274 text = fps_entry.get_text()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
275 try:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
276 int(text)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
277 except ValueError:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
278 raise ValueError('ā€œ%sā€ is not integer' % text)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
279 else:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
280 self.config.set('fps-limit', text)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
281
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
282 def on_no_background_checkbutton_toggled(self, checkbutton):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
283 active = checkbutton.get_active()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
284 self.config.set('no-background', not active)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
285
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
286 def on_no_particles_checkbutton_toggled(self, checkbutton):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
287 active = checkbutton.get_active()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
288 self.config.set('no-particles', active)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
289
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
290 def on_no_sound_checkbutton_toggled(self, checkbutton):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
291 active = checkbutton.get_active()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
292 self.config.set('no-sound', active)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
293
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
294
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
295 def menu(config, args):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
296 assert Gtk
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
297 handler = Handler(config, args)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
298
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
299 builder = Gtk.Builder()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
300 builder.add_from_file('data/menu.glade')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
301 builder.connect_signals(handler)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
302
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
303 handler.init_gtk(builder)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
304
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
305 Gtk.main()