Merge lp:~pawciobiel/lxkeymap/index_error_issues into lp:lxkeymap

Proposed by pawciobiel
Status: Merged
Merged at revision: 18
Proposed branch: lp:~pawciobiel/lxkeymap/index_error_issues
Merge into: lp:lxkeymap
Diff against target: 96 lines (+34/-20)
1 file modified
bin/lxkeymap (+34/-20)
To merge this branch: bzr merge lp:~pawciobiel/lxkeymap/index_error_issues
Reviewer Review Type Date Requested Status
Leszek Lesner (community) Approve
Review via email: mp+102514@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
Leszek Lesner (leszek-lesner) wrote :

Merged in Revision 18

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/lxkeymap'
2--- bin/lxkeymap 2012-02-05 14:08:14 +0000
3+++ bin/lxkeymap 2012-04-18 13:18:19 +0000
4@@ -137,10 +137,7 @@
5 active_group = state['group']
6
7 self.layout_current = server.get_layouts()#[active_group] # We handle now multiple layouts
8- try:
9- self.variant_current = server.get_variants()#[active_group]
10- except IndexError:
11- self.variant_current = ""
12+ self.variant_current = server.get_variants()#[active_group]
13
14 # Get options here
15 self.options_current = server.get_options()
16@@ -148,16 +145,7 @@
17
18 engine.stop_listen(xklavier.XKLL_TRACK_KEYBOARD_STATE)
19
20- #Init ConfigParser
21- self.config = ConfigParser.RawConfigParser()
22- if not os.path.exists(homedir+'/.config/lxkeymap.cfg'):
23- self.config.add_section('Global')
24- self.config.set('Global', 'Layout', self.layout_current[0])
25- self.config.set('Global', 'Variant', self.variant_current[0])
26- self.config.set('Global', 'Option', self.options_current[0])
27- with open(homedir+'/.config/lxkeymap.cfg', 'wb') as configfile:
28- self.config.write(configfile)
29- self.config.readfp(open(homedir+'/.config/lxkeymap.cfg'))
30+ self.init_config_parser()
31
32 # Create a TreeStore with one string column to use as the model
33 self.treestore_profiles = gtk.TreeStore(str)
34@@ -277,6 +265,30 @@
35 else:
36 self.status.set_text(_("Current Keymap: %s") % (self.layout_current[0]))
37
38+ def init_config_parser(self):
39+ """Initialize configuration"""
40+ self.config = ConfigParser.RawConfigParser()
41+ if not os.path.exists(homedir+'/.config/lxkeymap.cfg'):
42+ self.config.add_section('Global')
43+ try:
44+ self.config.set('Global', 'Layout', self.layout_current[0])
45+ except:
46+ self.config.set('Global', 'Layout', "")
47+
48+ try:
49+ self.config.set('Global', 'Variant', self.variant_current[0])
50+ except IndexError:
51+ self.config.set('Global', 'Variant', "")
52+
53+ try:
54+ self.config.set('Global', 'Option', self.options_current[0])
55+ except IndexError:
56+ self.config.set('Global', 'Option', "")
57+
58+ with open(homedir+'/.config/lxkeymap.cfg', 'wb') as configfile:
59+ self.config.write(configfile)
60+ self.config.readfp(open(homedir+'/.config/lxkeymap.cfg'))
61+
62 def print_option(self, c_reg, item, parent):
63 #print ('\t %s (%s)' % (item.get_description(), item.get_name())) #DEBUG
64 if item.get_name() in self.options_current:
65@@ -468,23 +480,25 @@
66 except:
67 pass
68 self.config.set(self.section, 'Layout',(self.country_selected).lower())
69- self.config.set(self.section, 'Variant',self.variant_current[-1])
70+ try:
71+ self.config.set(self.section, 'Variant',self.variant_current[-1])
72+ except IndexError:
73+ self.config.set(self.section, 'Variant', '')
74 if len(self.options_current) > 0:
75 print self.options_current # DEBUG
76 self.config.set(self.section, 'Option', self.options_current[-1])
77 else:
78- self.options_current = ['']
79- self.config.set(self.section, 'Option', self.options_current[-1])
80+ self.config.set(self.section, 'Option', '')
81 with open(homedir+'/.config/lxkeymap.cfg', 'wb') as configfile:
82 self.config.write(configfile)
83
84 def loadFromConfig(self):
85+ layout_saved = []
86+ variant_saved = []
87+ options_saved = []
88 if os.path.exists(homedir+'/.config/lxkeymap.cfg'):
89 config = ConfigParser.RawConfigParser()
90 config.read(homedir+'/.config/lxkeymap.cfg')
91- layout_saved = []
92- variant_saved = []
93- options_saved = []
94 for i in config.sections():
95 layout_saved.append(config.get(i, 'Layout'))
96 variant_saved.append(config.get(i, 'Variant'))

Subscribers

People subscribed via source and target branches

to all changes: