Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSayamindu Dasgupta <sayamindu@gmail.com>2009-07-03 12:07:03 (GMT)
committer Sayamindu Dasgupta <sayamindu@gmail.com>2009-07-03 12:07:03 (GMT)
commit4df895df23b3b34f618c9b5f9f61d3f95832ae26 (patch)
treec12f69f471584dc1b899c951dda90a475b0662fd
parent8235cd38bf3d65f1f26db7236bb05568d56605ba (diff)
Add some sample code
-rw-r--r--samples/get_country_variants.py20
-rw-r--r--samples/get_current_config.py33
-rw-r--r--samples/get_language_variants.py20
-rw-r--r--samples/get_layout_variants.py18
-rw-r--r--samples/get_models.py15
-rw-r--r--samples/get_options.py18
6 files changed, 124 insertions, 0 deletions
diff --git a/samples/get_country_variants.py b/samples/get_country_variants.py
new file mode 100644
index 0000000..bb50117
--- /dev/null
+++ b/samples/get_country_variants.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+
+import xklavier
+import gtk
+
+def print_variant(c_reg, item, subitem):
+ print ('\t %s (%s)' % (item.get_description(), item.get_name()))
+ if subitem:
+ print ('\t\t %s (%s)' % (subitem.get_description(), subitem.get_name()))
+
+def print_country(c_reg, item):
+ print ('\n%s (%s)' % (item.get_description(), item.get_name()))
+ c_reg.foreach_country_variant(item.get_name(), print_variant)
+
+display = gtk.gdk.display_get_default()
+engine = xklavier.Engine(display)
+configreg = xklavier.ConfigRegistry(engine)
+
+configreg.load(False)
+configreg.foreach_country(print_country)
diff --git a/samples/get_current_config.py b/samples/get_current_config.py
new file mode 100644
index 0000000..b4fdc0b
--- /dev/null
+++ b/samples/get_current_config.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+import xklavier
+import gtk
+
+display = gtk.gdk.display_get_default()
+engine = xklavier.Engine(display)
+
+crec = xklavier.ConfigRec()
+crec.get_from_server(engine)
+
+print "Layouts:"
+for layout in crec.get_layouts():
+ print "\t%s" % layout
+
+print "Variants:"
+for variant in crec.get_variants():
+ print "\t%s" % variant
+
+print "Options:"
+for option in crec.get_options():
+ print "\t%s" % option
+
+print "Model:"
+print "\t%s" % crec.get_model()
+
+engine.start_listen(xklavier.XKLL_TRACK_KEYBOARD_STATE)
+state = engine.get_current_state()
+engine.stop_listen()
+
+active_group = state['group']
+print "Active group:"
+print "\t%s(%s)" % (crec.get_layouts()[active_group], \
+ crec.get_variants()[active_group])
diff --git a/samples/get_language_variants.py b/samples/get_language_variants.py
new file mode 100644
index 0000000..6cfbda7
--- /dev/null
+++ b/samples/get_language_variants.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+
+import xklavier
+import gtk
+
+def print_variant(c_reg, item, subitem):
+ print ('\t %s (%s)' % (item.get_description(), item.get_name()))
+ if subitem:
+ print ('\t\t %s (%s)' % (subitem.get_description(), subitem.get_name()))
+
+def print_language(c_reg, item):
+ print ('\n%s (%s)' % (item.get_description(), item.get_name()))
+ c_reg.foreach_language_variant(item.get_name(), print_variant)
+
+display = gtk.gdk.display_get_default()
+engine = xklavier.Engine(display)
+configreg = xklavier.ConfigRegistry(engine)
+
+configreg.load(False)
+configreg.foreach_language(print_language)
diff --git a/samples/get_layout_variants.py b/samples/get_layout_variants.py
new file mode 100644
index 0000000..7490da4
--- /dev/null
+++ b/samples/get_layout_variants.py
@@ -0,0 +1,18 @@
+#!/usr/bin/env python
+
+import xklavier
+import gtk
+
+def print_variant(c_reg, item):
+ print ('\t %s (%s)' % (item.get_description(), item.get_name()))
+
+def print_layout(c_reg, item):
+ print ('\n%s (%s)' % (item.get_description(), item.get_name()))
+ c_reg.foreach_layout_variant(item.get_name(), print_variant)
+
+display = gtk.gdk.display_get_default()
+engine = xklavier.Engine(display)
+configreg = xklavier.ConfigRegistry(engine)
+
+configreg.load(False)
+configreg.foreach_layout(print_layout)
diff --git a/samples/get_models.py b/samples/get_models.py
new file mode 100644
index 0000000..aaf4372
--- /dev/null
+++ b/samples/get_models.py
@@ -0,0 +1,15 @@
+#!/usr/bin/env python
+
+import xklavier
+import gtk
+
+def print_model(c_reg, item):
+ print ('\n%s (%s)' % (item.get_description(), item.get_name()))
+ #c_reg.foreach_layout_variant(item.get_name(), print_variant)
+
+display = gtk.gdk.display_get_default()
+engine = xklavier.Engine(display)
+configreg = xklavier.ConfigRegistry(engine)
+
+configreg.load(False)
+configreg.foreach_model(print_model)
diff --git a/samples/get_options.py b/samples/get_options.py
new file mode 100644
index 0000000..e072cf3
--- /dev/null
+++ b/samples/get_options.py
@@ -0,0 +1,18 @@
+#!/usr/bin/env python
+
+import xklavier
+import gtk
+
+def print_option(c_reg, item):
+ print ('\t %s (%s)' % (item.get_description(), item.get_name()))
+
+def print_option_group(c_reg, item):
+ print ('\n%s (%s)' % (item.get_description(), item.get_name()))
+ c_reg.foreach_option(item.get_name(), print_option)
+
+display = gtk.gdk.display_get_default()
+engine = xklavier.Engine(display)
+configreg = xklavier.ConfigRegistry(engine)
+
+configreg.load(False)
+configreg.foreach_option_group(print_option_group)