Permalink
Browse files

Add support for student skins

  • Loading branch information...
1 parent 90ec2ac commit e5a57c77c983b40192df4161f1348dc6c71ed9f9 @eugeni committed Jul 5, 2011
Showing with 140 additions and 89 deletions.
  1. +108 −0 skins/DefaultSkinStudent.py
  2. +32 −89 student.py
View
@@ -0,0 +1,108 @@
+#!/usr/bin/python
+"""
+OpenClass default student skin.
+
+Copyright, (C) Eugeni Dodonov <eugeni@dodonov.net>, 2011
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, see <http://www.gnu.org/licenses/>.
+
+"""
+
+import gtk
+import pygtk
+import gobject
+from gtk import gdk
+
+from skins import Skin
+
+class DefaultSkinStudent(Skin):
+ def __init__(self, logger, gui):
+ """Initializes default openclass skin"""
+ Skin.__init__(self, logger, gui)
+ # Building student UI
+ gui.icon = gtk.StatusIcon()
+
+ menu = '''
+ <ui>
+ <menubar name="Menubar">
+ <menu action="Menu">
+ <menuitem action="Login"/>
+ <menuitem action="Teacher"/>
+ <separator/>
+ <menuitem action="RaiseHand"/>
+ <separator/>
+ <menuitem action="About"/>
+ <separator/>
+ <menuitem action="Quit"/>
+ </menu>
+ </menubar>
+ </ui>
+ '''
+ actions = [
+ ('Menu', None, 'Menu'),
+ ('Login', None, _('_Login'), None, _('Identify yourgui to the teacher'), gui.login),
+ ('Teacher', gtk.STOCK_PREFERENCES, _('_Teacher'), None, _('Select your teacher'), gui.choose_teacher),
+ ('RaiseHand', gtk.STOCK_INFO, _('_Call attention'), None, _('Raise your hand to call teacher attention'), gui.raise_hand),
+ ('About', gtk.STOCK_ABOUT, _('_About'), None, _('About OpenClass'), gui.on_about),
+ ('Quit', gtk.STOCK_QUIT, _('_Quit'), None, _('Quit class'), lambda *w: gui.quit(None, None))
+ ]
+ ag = gtk.ActionGroup('Actions')
+ ag.add_actions(actions)
+ gui.manager = gtk.UIManager()
+ gui.manager.insert_action_group(ag, 0)
+ gui.manager.add_ui_from_string(menu)
+ gui.menu = gui.manager.get_widget('/Menubar/Menu/About').props.parent
+ search = gui.manager.get_widget('/Menubar/Menu/Login')
+ search.get_children()[0].set_markup('<b>_Login...</b>')
+ search.get_children()[0].set_use_underline(True)
+ search.get_children()[0].set_use_markup(True)
+
+ gui.icon.set_visible(True)
+ gui.icon.connect('activate', gui.on_activate)
+ gui.icon.connect('popup-menu', gui.on_popup_menu)
+
+ # drawing
+ gui.projection_window = gtk.Window()
+ gui.projection_window.set_resizable(False)
+ #gui.projection_window.set_has_frame(False)
+ #gui.projection_window.set_decorated(False)
+ gui.projection_window.set_keep_above(True)
+ gui.projection_window.connect('delete-event', lambda *w: True)
+ gui.projection_window.visible = False
+ gui.projection_window.is_fullscreen = False
+ vbox = gtk.VBox()
+ gui.projection_window.add(vbox)
+ gui.gc = None
+ gui.drawing = gtk.DrawingArea()
+ gui.drawing.set_size_request(gui.screen.width, gui.screen.height)
+ vbox.pack_start(gui.drawing)
+ gui.projection_window.hide()
+
+ # attention
+ gui.attention_window = gtk.Window()
+ gui.attention_window.set_resizable(False)
+ gui.attention_window.set_has_frame(False)
+ gui.attention_window.set_decorated(False)
+ gui.attention_window.set_keep_above(True)
+ gui.attention_window.connect('delete-event', lambda *w: True)
+ gui.attention_window.visible = False
+
+ vbox = gtk.VBox()
+ gui.attention_window.add(vbox)
+ gui.attention_label = gtk.Label()
+ gui.attention_label.set_use_markup(True)
+ vbox.pack_start(gui.attention_label)
+
+ gui.attention_window.hide()
+
View
@@ -54,21 +54,21 @@
_ = str
traceback.print_exc()
-from openclass import network, system, protocol, screen, notification
-
-DEBUG=False
-
-# configuracoes globais
-commands = None
-iface_selected = 0
+from openclass import network, system, protocol, screen, notification, config
+import skins
+# variables
+CONFIGFILE = system.get_full_path(system.get_local_storage(), ".openclass-student.conf")
+SYSTEM_CONFIGFILE = system.get_full_path(system.get_system_storage(), "openclass-student.conf")
class Student:
selected_machines = 0
"""Teacher GUI main class"""
- def __init__(self, logger=None, max_missed_commands=30):
+ def __init__(self, logger, config):
"""Initializes the interface"""
# logger
self.logger = logger
+ # config
+ self.config = config
# colors
self.color_normal = gtk.gdk.color_parse("#99BFEA")
self.color_active = gtk.gdk.color_parse("#FFBBFF")
@@ -77,47 +77,13 @@ def __init__(self, logger=None, max_missed_commands=30):
# notification
self.notification = notification.Notification("OpenClass student")
- self.icon = gtk.StatusIcon()
-
- menu = '''
- <ui>
- <menubar name="Menubar">
- <menu action="Menu">
- <menuitem action="Login"/>
- <menuitem action="Teacher"/>
- <separator/>
- <menuitem action="RaiseHand"/>
- <separator/>
- <menuitem action="About"/>
- <separator/>
- <menuitem action="Quit"/>
- </menu>
- </menubar>
- </ui>
- '''
- actions = [
- ('Menu', None, 'Menu'),
- ('Login', None, _('_Login'), None, _('Identify yourself to the teacher'), self.login),
- ('Teacher', gtk.STOCK_PREFERENCES, _('_Teacher'), None, _('Select your teacher'), self.choose_teacher),
- ('RaiseHand', gtk.STOCK_INFO, _('_Call attention'), None, _('Raise your hand to call teacher attention'), self.raise_hand),
- ('About', gtk.STOCK_ABOUT, _('_About'), None, _('About OpenClass'), self.on_about),
- ('Quit', gtk.STOCK_QUIT, _('_Quit'), None, _('Quit class'), lambda *w: self.quit(None, None))
- ]
- ag = gtk.ActionGroup('Actions')
- ag.add_actions(actions)
- self.manager = gtk.UIManager()
- self.manager.insert_action_group(ag, 0)
- self.manager.add_ui_from_string(menu)
- self.menu = self.manager.get_widget('/Menubar/Menu/About').props.parent
- search = self.manager.get_widget('/Menubar/Menu/Login')
- search.get_children()[0].set_markup('<b>_Login...</b>')
- search.get_children()[0].set_use_underline(True)
- search.get_children()[0].set_use_markup(True)
- # disconnected by default
- self.disconnect()
- self.icon.set_visible(True)
- self.icon.connect('activate', self.on_activate)
- self.icon.connect('popup-menu', self.on_popup_menu)
+ # screen
+ self.screen = screen.Screen()
+
+ # find out what is our skin
+ skin_name = self.config.get("student", "skin", "DefaultSkinStudent")
+ skin_class = skins.get_skin(logger, skin_name)
+ self.skin = skin_class(logger, self)
# discover unique client ID (if any)
# specially useful for multi-seat configurations
@@ -136,7 +102,11 @@ def __init__(self, logger=None, max_missed_commands=30):
self.name = None
self.outfile = None
self.missed_commands = 0
- self.max_missed_commands = max_missed_commands
+ try:
+ self.max_missed_commands = int(self.config.get("student", "student", "30"))
+ except:
+ self.logget.exception("Detecting max missed commands")
+ self.max_client_timeout = 30
# Inicializa as threads
self.bcast = network.BcastListener(logger=self.logger, port=network.LISTENPORT)
@@ -145,48 +115,16 @@ def __init__(self, logger=None, max_missed_commands=30):
self.mcast = network.McastListener()
- self.screen = screen.Screen()
-
- # drawing
- self.projection_window = gtk.Window()
- self.projection_window.set_resizable(False)
- #self.projection_window.set_has_frame(False)
- #self.projection_window.set_decorated(False)
- self.projection_window.set_keep_above(True)
- self.projection_window.connect('delete-event', lambda *w: True)
- self.projection_window.visible = False
- self.projection_window.is_fullscreen = False
- vbox = gtk.VBox()
- self.projection_window.add(vbox)
- self.gc = None
- self.drawing = gtk.DrawingArea()
- self.drawing.set_size_request(self.screen.width, self.screen.height)
- vbox.pack_start(self.drawing)
- self.projection_window.hide()
-
- # attention
- self.attention_window = gtk.Window()
- self.attention_window.set_resizable(False)
- self.attention_window.set_has_frame(False)
- self.attention_window.set_decorated(False)
- self.attention_window.set_keep_above(True)
- self.attention_window.connect('delete-event', lambda *w: True)
- self.attention_window.visible = False
-
- vbox = gtk.VBox()
- self.attention_window.add(vbox)
- self.attention_label = gtk.Label()
- self.attention_label.set_use_markup(True)
- vbox.pack_start(self.attention_label)
-
- self.attention_window.hide()
-
- self.__grabwindow = None
-
# initialize list of teachers
self.teachers = gtk.combo_box_new_text()
self.teachers_addr = {}
+ # disconnected by default
+ self.disconnect()
+
+ # Building UI
+ self.__grabwindow = None
+
# login dialog
self.create_login_dialog(None)
self.login(None)
@@ -599,16 +537,21 @@ def monitor_bcast(self):
# configure logging
logger = system.setup_logger("openclass_student")
+ # configuration file
+ config = config.Config(logger, CONFIGFILE, SYSTEM_CONFIGFILE)
+ config.load()
+
# configura o timeout padrao para sockets
socket.setdefaulttimeout(5)
# Atualizando a lista de interfaces
gtk.gdk.threads_init()
gtk.gdk.threads_enter()
logger.info("Starting GUI..")
- gui = Student(logger=logger)
+ gui = Student(logger=logger, config=config)
try:
gtk.main()
+ config.save()
gtk.gdk.threads_leave()
except:
logger.info("exiting..")

0 comments on commit e5a57c7

Please sign in to comment.