diff pytouhou/options.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 b2269b9c6119
children 0768122da817
line wrap: on
line diff
--- a/pytouhou/options.py
+++ b/pytouhou/options.py
@@ -15,7 +15,7 @@
 import os
 from ConfigParser import RawConfigParser, NoOptionError
 
-from pytouhou.utils.xdg import load_config_paths
+from pytouhou.utils.xdg import load_config_paths, save_config_path
 
 
 class Options(object):
@@ -23,6 +23,7 @@ class Options(object):
         load_paths = list(reversed([os.path.join(directory, '%s.cfg' % name)
                                     for directory
                                     in load_config_paths(name)]))
+        self.save_path = os.path.join(save_config_path(name), '%s.cfg' % name)
 
         self.config = RawConfigParser(defaults)
         self.paths = self.config.read(load_paths)
@@ -34,6 +35,18 @@ class Options(object):
         except NoOptionError:
             return None
 
+    def set(self, option, value):
+        if value is not None:
+            self.config.set(self.section, option, value)
+        else:
+            self.config.remove_option(self.section, option)
+
+        defaults = self.config._defaults
+        self.config._defaults = None
+        with open(self.save_path, 'w') as save_file:
+            self.config.write(save_file)
+        self.config._defaults = defaults
+
 
 def patch_argument_parser():
     from argparse import ArgumentParser, _ActionsContainer
@@ -105,6 +118,7 @@ def parse_arguments(defaults):
     parser.add_argument('-p', '--path', metavar='DIRECTORY', help='Game directory path.')
     parser.add_argument('--debug', action='store_true', help='Set unlimited continues, and perhaps other debug features.')
     parser.add_argument('--verbosity', metavar='VERBOSITY', choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], help='Select the wanted logging level.')
+    parser.add_argument('--no-menu', action='store_true', help='Disable the menu.')
 
     game_group = parser.add_argument_group('Game options')
     game_group.add_argument('-s', '--stage', metavar='STAGE', type=int, help='Stage, 1 to 7 (Extra), nothing means story mode.')