3 # xkmap -- Simple GUI for 'setxkbmap'
5 # Using pygtk / glade / libglade to build GUI.
7 # Copyright (C) 2006-2007 Michael Towers
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #-------------------------------------------------------------------
24 # Version 1.2 // 27th March 2007
26 # Set this for your system (probably one of these is OK)
27 base_lst
= "/usr/share/X11/xkb/rules/base.lst"
28 #base_lst = "/etc/X11/xkb/rules/base.lst"
29 #base_lst = "/usr/lib/X11/xkb/rules/base.lst"
31 #-------------------------------------------------------------------
45 def __init__ (self
, i_xkbset
):
46 self
.i_xkbset
= i_xkbset
49 self
.wTree
= gtk
.glade
.XML("/usr/share/xkmap.glade")
51 # Create a dictionay of connections, then autoconnect
52 dic
= { "on_window1_destroy" : gtk
.main_quit
,
53 "on_btCancel_clicked" : gtk
.main_quit
,
54 "on_btApply_clicked" : self
.change
,
55 "on_btOK_clicked" : self
.changeq
,
56 "on_cbModel_changed" : self
.model
,
57 "on_cbLayout_changed" : self
.layout
,
58 "on_cbVariant_changed": self
.variant
60 self
.wTree
.signal_autoconnect(dic
)
64 cellm
= gtk
.CellRendererText()
65 self
.modelModel
= gtk
.ListStore(str)
66 self
.cbModel
= self
.wTree
.get_widget("cbModel")
67 self
.cbModel
.set_model(self
.modelModel
)
68 self
.cbModel
.pack_start(cellm
, True)
69 self
.cbModel
.set_attributes(cellm
, text
=0)
72 for item
in self
.i_xkbset
.models
: # item list is a list of strings
73 self
.modelModel
.append([item
])
74 if item
.split(None , 1)[0] == self
.i_xkbset
.model
:
77 self
.cbModel
.set_active(self
.iModel
)
80 celll
= gtk
.CellRendererText()
81 self
.modelLayout
= gtk
.ListStore(str)
82 self
.cbLayout
= self
.wTree
.get_widget("cbLayout")
83 self
.cbLayout
.set_model(self
.modelLayout
)
84 self
.cbLayout
.pack_start(celll
, True)
85 self
.cbLayout
.set_attributes(celll
, text
=0)
88 for item
in self
.i_xkbset
.layouts
: # item list is a list of strings
89 self
.modelLayout
.append([item
])
90 if item
.split(None , 1)[0] == self
.i_xkbset
.layout
:
93 self
.cbLayout
.set_active(self
.iLayout
)
95 # Variant -- this depends on the chosen Layout!
96 cellv
= gtk
.CellRendererText()
97 self
.modelVariant
= gtk
.ListStore(str)
98 self
.cbVariant
= self
.wTree
.get_widget("cbVariant")
99 self
.cbVariant
.set_model(self
.modelVariant
)
100 self
.cbVariant
.pack_start(cellv
, True)
101 self
.cbVariant
.set_attributes(cellv
, text
=0)
105 def showVariants (self
):
106 self
.modelVariant
.clear ()
107 layout
= self
.i_xkbset
.layouts
[self
.iLayout
].split ()[0]
108 self
.variants
= self
.i_xkbset
.allVariants
[layout
]
111 for item
in self
.variants
: # item list is a list of strings
112 self
.modelVariant
.append([item
])
113 if item
.split(None , 1)[0] == self
.i_xkbset
.variant
:
116 self
.cbVariant
.set_active(self
.iVariant
)
119 def change (self
, widget
):
122 def changeq (self
, widget
):
126 def model (self
, widget
):
127 i
= self
.cbModel
.get_active()
130 self
.i_xkbset
.model
= self
.i_xkbset
.models
[i
].split(None , 1)[0]
132 def layout (self
, widget
):
133 i
= self
.cbLayout
.get_active()
134 if i
!= self
.iLayout
:
136 self
.i_xkbset
.layout
= self
.i_xkbset
.layouts
[i
].split(None , 1)[0]
140 def variant (self
, widget
):
141 i
= self
.cbVariant
.get_active()
142 if (i
!= self
.iVariant
) or (widget
== None):
144 self
.i_xkbset
.variant
= self
.variants
[i
].split(None , 1)[0]
154 self
.configfile
= os
.path
.expanduser("~/.xkmap")
158 self
.variant
= "Standard"
159 if os
.path
.isfile (self
.configfile
):
160 f
= open (self
.configfile
)
161 self
.model
, self
.layout
, self
.variant
= f
.readline ().strip ().split ("|")
166 while blf
.readline().strip() != "! model": pass
170 line
= blf
.readline().strip()
171 if not line
: continue
172 if line
== "! layout": break
173 self
.models
.append (line
)
177 line
= blf
.readline().strip()
178 if not line
: continue
179 if line
== "! variant": break
180 self
.layouts
.append (line
)
182 self
.allVariants
= {}
184 line
= blf
.readline().strip()
185 if not line
: continue
186 if line
== "! option": break
187 parts
= line
.split (None, 2)
188 line
= parts
[0] + " - " + parts
[2]
189 layout
= parts
[1].rstrip (":")
190 if not self
.allVariants
.has_key (layout
):
191 self
.allVariants
[layout
] = [ "Standard" ]
192 self
.allVariants
[layout
].append (line
)
204 print "setxkbmap -rules xorg -model %s -layout %s -variant %s" % (m
, l
, v
)
205 os
.system ("setxkbmap -rules xorg -model %s -layout %s -variant %s" % (m
, l
, v
))
207 f
= open (self
.configfile
, "w")
208 f
.write ("%s|%s|%s\n" % (self
.model
, self
.layout
, self
.variant
))
211 if __name__
== "__main__":
213 i_gui
= gui (i_xkbset
)