Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2013-12-14 13:32:51 (GMT)
committer Walter Bender <walter@sugarlabs.org>2013-12-14 13:32:51 (GMT)
commita50e4629e180366808ee4cb6af5952b5cf4ebf00 (patch)
tree029c59f3d67aa9c9d68512bc1e759410972ecc84
parent5317f51328cbd890e2f24de7cfc1a61ea7ad016c (diff)
more clean up of lang and tutorials
-rw-r--r--NEWS1
-rw-r--r--data/en/tutorials/Tutorial_07_gtk_basic_form.py6
-rw-r--r--data/en/tutorials/Tutorial_08_gtk_button_form.py14
-rw-r--r--data/en/tutorials/Tutorial_09_gtk_entry.py17
-rw-r--r--data/en/tutorials/Tutorial_10_gtk_dialog_button.py29
-rw-r--r--pippy_app.py74
6 files changed, 45 insertions, 96 deletions
diff --git a/NEWS b/NEWS
index b23acd3..c0d9653 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,7 @@ ENHANCEMENTS:
* Show/Hide terminal widget (svineet)
* Added new examples (math/pi, math/stern-brocot)
* Added i18n support for examples (Jorge Alberto Gómez López)
+* Added tutorials (Jorge Alberto Gómez López)
BUG FIXES:
* Reenable copy/paste (Ignacio Rodriguez)
diff --git a/data/en/tutorials/Tutorial_07_gtk_basic_form.py b/data/en/tutorials/Tutorial_07_gtk_basic_form.py
index bcff13c..add05d4 100644
--- a/data/en/tutorials/Tutorial_07_gtk_basic_form.py
+++ b/data/en/tutorials/Tutorial_07_gtk_basic_form.py
@@ -1,12 +1,12 @@
from gi.repository import Gtk
class PyApp(Gtk.Window):
+
def __init__(self):
super(PyApp, self).__init__()
- self.set_title("Hello World!!")
- self.connect("destroy", Gtk.main_quit)
+ self.set_title('Hello World!!')
+ self.connect('destroy', Gtk.main_quit)
self.set_size_request(250, 150)
- self.set_position(Gtk.WIN_POS_CENTER)
self.show()
PyApp()
diff --git a/data/en/tutorials/Tutorial_08_gtk_button_form.py b/data/en/tutorials/Tutorial_08_gtk_button_form.py
index 8a496ae..6f7f8e7 100644
--- a/data/en/tutorials/Tutorial_08_gtk_button_form.py
+++ b/data/en/tutorials/Tutorial_08_gtk_button_form.py
@@ -2,17 +2,21 @@ from gi.repository import Gtk
class PyApp(Gtk.Window):
def __init__(self):
+
super(PyApp, self).__init__()
- self.set_title("Button")
+ self.set_title('Button')
self.set_size_request(250, 200)
- self.set_position(Gtk.WIN_POS_CENTER)
- btn1 = Gtk.Button("Button")
+ def button_cb(widget):
+ print 'click'
+
+ button = Gtk.Button('Button')
fixed = Gtk.Fixed()
- fixed.put(btn1, 20, 30)
+ fixed.put(button, 20, 30)
+ button.connect('clicked', button_cb)
- self.connect("destroy", Gtk.main_quit)
+ self.connect('destroy', Gtk.main_quit)
self.add(fixed)
self.show_all()
diff --git a/data/en/tutorials/Tutorial_09_gtk_entry.py b/data/en/tutorials/Tutorial_09_gtk_entry.py
index 40873bf..5be537d 100644
--- a/data/en/tutorials/Tutorial_09_gtk_entry.py
+++ b/data/en/tutorials/Tutorial_09_gtk_entry.py
@@ -1,19 +1,28 @@
from gi.repository import Gtk
+from gi.repository import Gdk
class PyApp(Gtk.Window):
+
def __init__(self):
super(PyApp, self).__init__()
- self.set_title("Hello World!!")
- self.connect("destroy", Gtk.main_quit)
+ self.set_title('Text Entry')
self.set_size_request(250, 150)
- self.set_position(Gtk.WIN_POS_CENTER)
+ def entry_cb(widget, event):
+ if Gdk.keyval_name(event.keyval) == 'Return':
+ print widget.get_text()
+
entry = Gtk.Entry()
+ entry.show()
fixed = Gtk.Fixed()
+ fixed.show()
fixed.put(entry, 20, 30)
- self.connect("destroy", Gtk.main_quit)
self.add(fixed)
self.show()
+ entry.connect('key_press_event', entry_cb)
+
+ self.connect('destroy', Gtk.main_quit)
+
PyApp()
Gtk.main()
diff --git a/data/en/tutorials/Tutorial_10_gtk_dialog_button.py b/data/en/tutorials/Tutorial_10_gtk_dialog_button.py
deleted file mode 100644
index 6bdd198..0000000
--- a/data/en/tutorials/Tutorial_10_gtk_dialog_button.py
+++ /dev/null
@@ -1,29 +0,0 @@
-from gi.repository import Gtk
-
-class PyApp(Gtk.Window):
- def __init__(self):
- super(PyApp, self).__init__()
- self.set_size_request(300, 150)
- self.set_position(Gtk.WIN_POS_CENTER)
- self.connect("destroy", Gtk.main_quit)
- self.set_title("Click button")
-
-
- button = Gtk.Button("Click me!!!")
- button.set_size_request(80, 30)
- button.connect("clicked", self.on_clicked)
-
- fix = Gtk.Fixed()
- fix.put(button, 20, 20)
-
- self.add(fix)
- self.show_all()
-
- def on_clicked(self, widget):
- about = Gtk.AboutDialog()
- about.set_comments("Hello there!!!")
- about.run()
- about.destroy()
-
-PyApp()
-Gtk.main()
diff --git a/pippy_app.py b/pippy_app.py
index 36905a8..759814b 100644
--- a/pippy_app.py
+++ b/pippy_app.py
@@ -55,7 +55,6 @@ import groupthink.gtk_tools
from FileDialog import FileDialog
-_default_lang = '%s.%s' % locale.getdefaultlocale()
text_buffer = None
# magic prefix to use utf-8 source encoding
PYTHON_PREFIX = """#!/usr/bin/python
@@ -201,32 +200,29 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
self.paths = []
- root = os.path.join(get_bundle_path(), 'data')
+ data_path = os.path.join(get_bundle_path(), 'data')
- # get preferred language and default one
- logging.debug(_default_lang)
-
- self.pref_lang = self.get_languages()[0].split('_')[0]
- if len(_default_lang) == 0 or _default_lang.split('.')[0] == 'None':
- self.default_lang = 'en'
+ # get default language from locale
+ locale_lang = locale.getdefaultlocale()[0]
+ if locale_lang is None:
+ lang = 'en'
else:
- self.default_lang = _default_lang.split('_')[0]
-
- logging.debug(self.pref_lang)
- logging.debug(self.default_lang)
+ lang = locale_lang.split('_')[0]
+ logging.debug(locale.getdefaultlocale())
+ logging.debug(lang)
# construct the path for both
- self.lang_path = os.path.join(root, self.pref_lang)
- self.default_path = os.path.join(root, self.default_lang)
+ lang_path = os.path.join(data_path, lang)
+ en_lang_path = os.path.join(data_path, 'en')
# get all folders in lang examples
self.all_folders = []
- if os.path.exists(self.lang_path):
- for d in sorted(os.listdir(self.lang_path)):
+ if os.path.exists(lang_path):
+ for d in sorted(os.listdir(lang_path)):
self.all_folders.append(d)
- # get all folders in english examples
- for d in sorted(os.listdir(self.default_path)):
+ # get all folders in English examples
+ for d in sorted(os.listdir(en_lang_path)):
# check if folder isn't already in list
if d not in self.all_folders:
self.all_folders.append(d)
@@ -234,15 +230,15 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
for folder in self.all_folders:
direntry = {}
# check if dir exists in pref language, if exists, add it
- if os.path.exists(os.path.join(self.lang_path, folder)):
+ if os.path.exists(os.path.join(lang_path, folder)):
direntry = {
"name": _(folder.capitalize()),
- "path": os.path.join(self.lang_path, folder) + "/"}
- # if not try to see if it's in default english path
- elif os.path.exists(os.path.join(self.default_path, folder)):
+ "path": os.path.join(lang_path, folder) + "/"}
+ # if not try to see if it's in default English path
+ elif os.path.exists(os.path.join(en_lang_path, folder)):
direntry = {
"name": _(folder.capitalize()),
- "path": os.path.join(self.default_path, folder) + "/"}
+ "path": os.path.join(en_lang_path, folder) + "/"}
self.paths.append([direntry['name'], direntry['path']])
# Adding local examples
@@ -330,38 +326,6 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
def after_init(self):
self.outbox.hide()
- def get_languages(self):
- path = os.path.join(os.environ.get('HOME', ''), '.i18n')
- if not os.access(path, os.R_OK):
- logging.debug('Could not access ~/.i18n')
- print _default_lang
- fd = open(path, 'w')
- fd.write('LANG="%s"\n' % _default_lang)
- fd.write('LANGUAGE="%s"\n' % _default_lang)
- fd.close()
- return [_default_lang]
-
- fd = open(path, 'r')
- lines = fd.readlines()
- fd.close()
-
- langlist = None
- lang = 'en'
-
- for line in lines:
- if line.startswith('LANGUAGE='):
- lang = line[9:].replace('"', '')
- lang = lang.strip()
- langlist = lang.split(':')
- elif line.startswith('LANG='):
- lang = line[5:].replace('"', '')
-
- # There might be cases where .i18n may not contain a LANGUAGE field
- if langlist is None:
- return [lang]
- else:
- return langlist
-
def _toggle_output_cb(self, button):
shown = button.get_active()
if shown: