# You should have received a copy of the GNU General Public License # along with Typing Turtle. If not, see <http://www.gnu.org/licenses/>. import sys import keyboard from gi.repository import Gtk # window = Gtk.Window(Gtk.WindowType.TOPLEVEL) Removed above line to because of GtkDeprecation of positional arguments window = Gtk.Window(type=Gtk.WindowType.TOPLEVEL) window.set_title("keyboard widget") window.connect("destroy", lambda w: Gtk.main_quit()) window.show_all() window.realize() image = keyboard.KeyboardImages(800, 400) k = keyboard.KeyboardWidget(image, window, poll_keys=True) try: k.load_letter_map(sys.argv[1]) except: pass k.set_layout(keyboard.get_layout()) savebtn = Gtk.Button() savebtn.add(Gtk.Label(label='Save Keys')) savebtn.connect('clicked', lambda w: k.save_letter_map(sys.argv[1])) quitbtn = Gtk.Button() quitbtn.add(Gtk.Label(label='Quit')) quitbtn.connect('clicked', lambda w: Gtk.main_quit())
def __init__(self, activity): gtk.VBox.__init__(self) self.activity = activity # Build background. self.titlescene = TitleScene() # Build lessons list. self.lessonbox = gtk.HBox() #nexticon = sugar.graphics.icon.Icon(icon_name='go-next') #self.nextlessonbtn.add(nexticon) nextlabel = gtk.Label() nextlabel.set_markup("<span size='8000'>" + _('Next') + "</span>") self.nextlessonbtn = gtk.Button() self.nextlessonbtn.add(nextlabel) self.nextlessonbtn.connect('clicked', self.next_lesson_clicked_cb) #previcon = sugar.graphics.icon.Icon(icon_name='go-previous') #self.prevlessonbtn.add(previcon) prevlabel = gtk.Label() prevlabel.set_markup("<span size='8000'>" + _('Previous') + "</span>") self.prevlessonbtn = gtk.Button() self.prevlessonbtn.add(prevlabel) self.prevlessonbtn.connect('clicked', self.prev_lesson_clicked_cb) lessonlabel = gtk.Label() lessonlabel.set_markup("<span size='12000'>" + _('Start Lesson') + "</span>") lessonbtn = gtk.Button() lessonbtn.add(lessonlabel) lessonbtn.connect('clicked', self.lesson_clicked_cb) lessonbtn.modify_bg(gtk.STATE_NORMAL, self.get_colormap().alloc_color('#60b060')) # Load lessons for this language. bundle_path = sugar.activity.activity.get_bundle_path() code = locale.getlocale(locale.LC_ALL)[0] path = bundle_path + '/lessons/' + code self.load_lessons(path) # Fallback to en_US lessons if none found. if not len(self.lessons): self.load_lessons(bundle_path + '/lessons/en_US') # We cannot run without lessons/ if not len(self.lessons): sys.exit(1) # Sort by the 'order' field. self.lessons.sort(lambda x, y: x.get('order', 0) - y.get('order', 0)) # Load all the keyboard images. self.keyboard_images = keyboard.KeyboardImages() self.keyboard_images.load_images() navbox = gtk.HBox() navbox.set_spacing(10) navbox.pack_start(self.prevlessonbtn, True) navbox.pack_start(lessonbtn, True) navbox.pack_start(self.nextlessonbtn, True) lessonbox = gtk.VBox() lessonbox.set_spacing(10) lessonbox.pack_start(navbox, False) lessonbox.pack_start(self.lessonbox) self.pack_start(self.titlescene, False, True, 10) self.pack_start(lessonbox, True) self.show_next_lesson()
def __init__(self, activity): GObject.GObject.__init__(self) self.activity = activity # Build background. self.titlescene = titlescene.TitleScene() # Build lessons list. self.lessonbox = Gtk.HBox() #nexticon = sugar3.graphics.icon.Icon(icon_name='go-next') #self.nextlessonbtn.add(nexticon) nextlabel = Gtk.Label() nextlabel.set_markup("<span size='large'>" + _('Next') + "</span>") self.nextlessonbtn = Gtk.Button() self.nextlessonbtn.add(nextlabel) self.nextlessonbtn.connect('clicked', self.next_lesson_clicked_cb) #previcon = sugar3.graphics.icon.Icon(icon_name='go-previous') #self.prevlessonbtn.add(previcon) prevlabel = Gtk.Label() prevlabel.set_markup("<span size='large'>" + _('Previous') + "</span>") self.prevlessonbtn = Gtk.Button() self.prevlessonbtn.add(prevlabel) self.prevlessonbtn.connect('clicked', self.prev_lesson_clicked_cb) lessonlabel = Gtk.Label() lessonlabel.set_markup("<span size='x-large' weight='bold'>" + _('Start Lesson') + "</span>") lessonbtn = Gtk.Button() lessonbtn.add(lessonlabel) lessonbtn.connect('clicked', self.lesson_clicked_cb) lessonbtn.modify_bg(Gtk.StateType.NORMAL, Gdk.Color.parse('#60b060')[1]) # Load lessons for this language. code = locale.getdefaultlocale()[0] or 'en_US' lessons_path = os.path.join(sugar3.activity.activity.get_bundle_path(), 'lessons') lessons_file = os.path.join(lessons_path, code + '.lessons') if os.path.isfile(lessons_file): self.load_lessons(lessons_file) else: code = code[0:2] lessons_file = os.path.join(lessons_path, code + '.lessons') if os.path.isfile(lessons_file): self.load_lessons(lessons_file) else: # Fallback to en_US lessons if none found. self.load_lessons('lessons/en_US.lessons') # We cannot run without lessons. if not len(self.lessons): logging.error('There is no lessons and we ' 'cannot run without them.') sys.exit(1) # Sort by the 'order' field. self.lessons.sort(lambda x, y: x.get('order', 0) - y.get('order', 0)) # Load all the keyboard images. width = int(Gdk.Screen.width()) height = int(Gdk.Screen.height() * 0.3) self.keyboard_images = keyboard.KeyboardImages(width, height) self.keyboard_images.load_images() navbox = Gtk.HBox() navbox.set_spacing(10) navbox.pack_start(self.prevlessonbtn, True, True, 0) navbox.pack_start(lessonbtn, True, True, 0) navbox.pack_start(self.nextlessonbtn, True, True, 0) lessonbox = Gtk.VBox() lessonbox.set_spacing(10) lessonbox.pack_start(navbox, False, True, 0) lessonbox.pack_start(self.lessonbox, True, True, 0) self.pack_start(self.titlescene, False, True, 10) self.pack_start(lessonbox, True, True, 0) self.show_next_lesson()