annotate pytouhou/menu.py @ 770:f6c287745a67

Rust: Add a libtouhou Python wrapper using pyo3
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 30 Aug 2022 18:23:55 +0200
parents d1f0bb0b7a17
children
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
572
7f113f15300b Include the Glade file in the main package on install.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 570
diff changeset
18 from gi.repository import Gtk, Gdk, GLib
568
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20 import sys
572
7f113f15300b Include the Glade file in the main package on install.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 570
diff changeset
21 import os
568
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22 import re
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 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
25
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26
615
d1f0bb0b7a17 Don’t inherit explicitely from object, we are not on Python 2.7 anymore. :)
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
27 class Handler:
568
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 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
29 self.config = config
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 self.args = args
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32 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
33 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
34 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
35 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
36
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 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
38
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39 # Game widgets
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 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
41 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
42 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
43 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
44
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 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
46 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
47 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
48
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 # Options widgets
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50 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
51 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
52
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 # OpenGL backend
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54 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
55 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
56 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
57 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
58
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59 # SDL backend
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60 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
61
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62 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
63 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
64 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
65 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
66
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
67 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
68 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
69 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
70 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
71
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 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
73 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
74
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
75 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
76 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
77 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
78 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
79 else:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80 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
81 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
82
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
83 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
84 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
85 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
86 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
87
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88 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
89 window.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 Gtk.main_quit()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
91 print('Play!')
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
93 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
94 Gtk.main_quit(*args)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
95 sys.exit(0)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
96
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
97
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
98 # Main menu
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 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
101 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
102 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
103 self.on_quit()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
104
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
105 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
106 self.difficulty_box.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
107 self.character_box.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
108 self.stage_box.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
109
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
110 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
111 self.args.stage = None
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.start_window.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
114 self.game_window.show()
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 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
117 self.difficulty_box.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
118 self.character_box.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
119 self.stage_box.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
120
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
121 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
122 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
123
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
124 self.start_window.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
125 self.game_window.show()
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 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
128 self.difficulty_box.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
129 self.character_box.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
130 self.stage_box.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
131
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
132 self.start_window.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
133 self.game_window.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 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
136 self.start_window.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
137 self.options_window.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
138
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
139 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
140 self.start_window.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
141 self.replay_filechooserdialog.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
142
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
143 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
144 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
145
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
146 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
147 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
148 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
149
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
150
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
151 # Game menu
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 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
154 self.game_window.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
155 self.start_window.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
156
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
157 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
158 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
159
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
160 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
161 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
162 self.game_window.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
163 self.start_window.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
164 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
165 self.on_quit()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
166
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
167 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
168 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
169 difficulty = int(active)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
170 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
171 self.args.rank = difficulty
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
172
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
173 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
174 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
175 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
176 self.args.character = character
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
177
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
178 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
179 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
180 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
181
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
182 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
183 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
184 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
185 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
186
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
187
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
188 # Replay dialog
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 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
191 self.replay_filechooserdialog.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
192 self.start_window.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
193
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
194 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
195
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
196 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
197 try:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
198 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
199 except (IOError, TypeError):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
200 return
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
201 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
202
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
203 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
204 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
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_file_activated(self, window):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
207 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
208 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
209
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
210 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
211 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
212 self.replay_filechooserdialog.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
213 self.start_window.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
214 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
215 self.on_quit()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
216
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
217
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
218 # Options menu
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 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
221 self.options_window.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
222 self.start_window.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
223
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
224 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
225 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
226 self.options_window.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
227 self.start_window.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
228 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
229 self.on_quit()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
230
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
231 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
232 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
233 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
234
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
235 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
236 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
237 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
238 backends = active.split()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
239 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
240 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
241 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
242 grid.hide()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
243 else:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
244 grid.show()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
245
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
246 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
247 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
248 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
249
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
250 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
251 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
252 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
253 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
254 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
255
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
256 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
257 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
258 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
259 if inconsistent:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
260 active = False
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
261 inconsistent = False
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
262 elif active:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
263 active = True
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
264 else:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
265 inconsistent = True
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
266 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
267 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
268 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
269
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
270 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
271 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
272 try:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
273 int(text)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
274 except ValueError:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
275 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
276 else:
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
277 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
278
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
279 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
280 active = checkbutton.get_active()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
281 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
282
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
283 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
284 active = checkbutton.get_active()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
285 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
286
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
287 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
288 active = checkbutton.get_active()
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
289 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
290
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
291
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
292 def menu(config, args):
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
293 assert Gtk
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
294 handler = Handler(config, args)
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
295
e7a4731a278b Add a GTK+ main menu, mimicking the original EoSD one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
296 builder = Gtk.Builder()
572
7f113f15300b Include the Glade file in the main package on install.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 570
diff changeset
297 try:
7f113f15300b Include the Glade file in the main package on install.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 570
diff changeset
298 builder.add_from_file(os.path.join(os.path.dirname(__file__), 'data', 'menu.glade'))
7f113f15300b Include the Glade file in the main package on install.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 570
diff changeset
299 except GLib.GError:
7f113f15300b Include the Glade file in the main package on install.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 570
diff changeset
300 builder.add_from_file(os.path.join('data', 'menu.glade'))
568
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()