예제 #1
0
파일: mathme.py 프로젝트: worg/MathMe
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)
        self._name = handle

        self.num = mynum.Numbers()

        if NEW_TOOLBARS:
            toolbar_box = ToolbarBox()

            separator = gtk.SeparatorToolItem()
            separator.props.draw = False
            separator.set_expand(True)
            toolbar_box.toolbar.insert(separator, -1)
            separator.show()

            stop_button = StopButton(self)
            stop_button.props.accelerator = '<Ctrl><Shift>Q'
            toolbar_box.toolbar.insert(stop_button, -1)
            stop_button.show()

            self.set_toolbar_box(toolbar_box)
            toolbar_box.show()

        else:
            toolbox = ActivityToolbox(self)
            self.set_toolbox(toolbox)
            toolbox.show()

        if self.num.widget.parent:
            self.num.widget.parent.remove(self.num.widget)

        self.num.widget.show()
        self.set_canvas(self.num.widget)
        self.show_all()
        self.num.setActivity(self)
예제 #2
0
    def _configure_toolbars(self):
        if _USE_OLD_TOOLBARS:
            toolbox = ActivityToolbox(self)
            toolbar = gtk.Toolbar()
        else:
            toolbar_box = ToolbarBox()
            toolbar = toolbar_box.toolbar

            activity_button = ActivityToolbarButton(self)
            toolbar_box.toolbar.insert(activity_button, 0)
            activity_button.show()

            self._add_expander(toolbar_box.toolbar)

            toolbar.add(gtk.SeparatorToolItem())

        if _USE_OLD_TOOLBARS:
            self.set_toolbox(toolbox)
            toolbox.show()
        else:
            stop_button = StopButton(self)
            stop_button.props.accelerator = '<Ctrl><Shift>Q'
            toolbar_box.toolbar.insert(stop_button, -1)
            stop_button.show()

            self.set_toolbar_box(toolbar_box)
            toolbar_box.show()
예제 #3
0
    def new_instance(self):
        browser = gtk.VBox()
        browser.show()
        self.canvas.append_page(browser)

        self.path = Path()
        path_box = gtk.EventBox()
        path_box.modify_bg(gtk.STATE_NORMAL,
                           style.COLOR_TOOLBAR_GREY.get_gdk_color())
        path_box.add(self.path)
        path_box.show_all()
        browser.pack_end(path_box, False)

        self.workspace = gtk.HPaned()
        self.workspace.show()
        self.workspace.connect('notify::position', self._workspace_position_cb)
        browser.pack_start(self.workspace)

        self.tags = TagSidebar()
        self.tags.show()
        self.workspace.add1(self.tags)

        self.objects = gtk.Notebook()
        self.objects.show()
        self.objects.props.show_border = False
        self.objects.props.show_tabs = False
        self.workspace.add2(self.objects)

        scrollbox = gtk.ScrolledWindow()
        scrollbox.show()
        scrollbox.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.objects_compat = ObjectCompact()
        scrollbox.add(self.objects_compat)
        self.objects.append_page(scrollbox)
        model.object_model.view = self.objects_compat

        self.object_thumbs = ObjectThumbs()
        self.object_thumbs.show()
        self.objects.append_page(self.object_thumbs)

        self.editor = ObjectEditor()
        self.editor.show()
        self.canvas.append_page(self.editor)

        toolbox = ActivityToolbox(self)
        toolbox.show()
        self.set_toolbox(toolbox)

        self.toolbars = [[(_('Library'), BrowseToolbar())],
                         [(_('Edit'), EditToolbar())]]

        self.browse()
        model.source.query()
예제 #4
0
    def buildToolbar(self):
        """ Build GUI Toolbar
        """
        self._toolbox = ActivityToolbox(self._activity)
        self._toolbar = self._toolbox.get_activity_toolbar()

        # Remove share button
        self._toolbar.remove(self._toolbar.share)
        self._toolbar.share = None

        self._activity.set_toolbox(self._toolbox)

        # we do not have collaboration features
        # make the share option insensitive
        self._activity.max_participants = 1
예제 #5
0
    def build_toolbars(self):
        self.settings_bar = gtk.Toolbar()

        self.settings_buttons = {}

        self.settings_buttons['reload_video'] = ToolButton('view-spiral')
        self.settings_buttons['reload_video'].set_tooltip(_("Reload Screen"))
        self.settings_buttons['reload_video'].connect("clicked",
                                                      self.force_redraw, None)
        self.settings_bar.insert(self.settings_buttons['reload_video'], -1)

        self.toolbox = ActivityToolbox(self.activity)
        self.toolbox.add_toolbar(_("Settings"), self.settings_bar)

        self.activity.set_toolbox(self.toolbox)
        self.toolbox.show_all()
    def loadUI(self):
        """Create and show UI
        """
        # we do not have collaboration features
        # make the share option insensitive
        self.max_participants = 1

        # Toolbar
        toolbox = ActivityToolbox(self)
        self._toolbar = toolbox.get_activity_toolbar()

        self._toolbar.remove(self._toolbar.share)
        self._toolbar.share = None
        self._toolbar.remove(self._toolbar.keep)
        self._toolbar.keep = None
        self.set_toolbox(toolbox)
예제 #7
0
    def build_old_toolbar(self):
        toolbox = ActivityToolbox(self)
        activityToolbar = toolbox.get_activity_toolbar()
        activityToolbar.keep.props.visible = False
        self.J2JToolbar = Jam2JamToolBar(self)

        toolbox.add_toolbar("Transform", self.J2JToolbar)
        self.set_toolbox(toolbox)
        self.J2JToolbar.show()
        toolbox.show()

        self.toolbox.set_current_toolbar(1)

        self.connect("shared", self.shared_cb)
        self.connect("joined", self.joined_cb)

        if self.get_shared():
            self.joined_cb()
        log.info("FINISHED building toolbar")
        return toolbox
    def __init__(self, handle):
        Activity.__init__(self, handle)
        logger.debug('Starting Jigsaw Puzzle activity... %s' %
                     str(get_bundle_path()))
        os.chdir(get_bundle_path())

        self.connect('destroy', self._destroy_cb)

        toolbox = ActivityToolbox(self)
        self.set_toolbox(toolbox)
        toolbox.show()

        # Toolbar title size hack
        title_widget = toolbox._activity_toolbar.title
        title_widget.set_size_request(
            title_widget.get_layout().get_pixel_size()[0] + 30, -1)

        self.ui = JigsawPuzzleUI(self)
        self.set_canvas(self.ui)

        self.show_all()

        TubeHelper.__init__(self, tube_class=GameTube, service=SERVICE)
    def __init__(self, handle):
        Activity.__init__(self, handle)
        logger.debug('Starting Slider Puzzle activity... %s' %
                     str(get_bundle_path()))
        os.chdir(get_bundle_path())
        self.connect('destroy', self._destroy_cb)

        toolbox = ActivityToolbox(self)
        self.set_toolbox(toolbox)
        toolbox.show()
        title_widget = toolbox._activity_toolbar.title
        title_widget.set_size_request(
            title_widget.get_layout().get_pixel_size()[0] + 20, -1)

        self.ui = SliderPuzzleUI(self)

        self.set_canvas(self.ui)
        self.show_all()

        self.frozen = FrozenState(self.ui)
        self.ui.game.connect('shuffled', self.frozen.sync)

        TubeHelper.__init__(self, tube_class=GameTube, service=SERVICE)
예제 #10
0
    def __init__(self, handle):
        Activity.__init__(self, handle)

        root = self.make_root()
        self.set_canvas(root)
        root.show_all()
        self.entry.grab_focus()

        toolbox = ActivityToolbox(self)
        activity_toolbar = toolbox.get_activity_toolbar()
        activity_toolbar.keep.props.visible = False
        self.set_toolbox(toolbox)
        toolbox.show()

        self.owner = self._pservice.get_owner()
        # Auto vs manual scrolling:
        self._scroll_auto = True
        self._scroll_value = 0.0
        # Track last message, to combine several messages:
        self._last_msg = None
        self._last_msg_sender = None
        self.text_channel = None

        if self._shared_activity:
            # we are joining the activity
            self.connect('joined', self._joined_cb)
            if self.get_shared():
                # we have already joined
                self._joined_cb()
        else:
            # we are creating the activity
            if not self.metadata or self.metadata.get(
                    'share-scope', SCOPE_PRIVATE) == SCOPE_PRIVATE:
                # if we are in private session
                self._alert(_('Off-line'), _('Share, or invite someone.'))
            self.connect('shared', self._shared_cb)
예제 #11
0
    def instance(self):
        book.wiki = book.WikiBook()
        if not book.custom:
            book.custom = book.CustomBook()

        self.edit_page = 1
        self.edit = edit.View()
        self.library = library.View(self)

        if OLD_TOOLBAR:
            self.edit_toolbar = gtk.Toolbar()
            self.edit_bar = edit.ToolbarBuilder(self.edit, self.edit_toolbar)
            self.edit_toolbar.show_all()

            self.library_toolbar = gtk.Toolbar()
            self.library_bar = library.ToolbarBuilder(self.library,
                                                      self.library_toolbar)
            self.library_toolbar.show_all()

            toolbox = ActivityToolbox(self)
            toolbox.connect('current-toolbar-changed',
                            self._toolbar_changed_cb)
            self.set_toolbox(toolbox)
            toolbox.add_toolbar(_('Library'), self.library_toolbar)
            toolbox.add_toolbar(_('Edit'), self.edit_toolbar)
            toolbox.set_current_toolbar(1)
        else:
            toolbar_box = ToolbarBox()
            activity_button = ActivityToolbarButton(self)
            toolbar_box.toolbar.insert(activity_button, 0)
            self.set_toolbar_box(toolbar_box)
            self._toolbar = toolbar_box.toolbar

            tool_group = None
            search_button = RadioToolButton()
            search_button.props.group = tool_group
            tool_group = search_button
            search_button.props.icon_name = 'white-search'
            search_button.set_tooltip(_('Library'))
            search_button.mode = 'search'
            search_button.connect('clicked', self.__mode_button_clicked)
            self._toolbar.insert(search_button, -1)

            edit_button = RadioToolButton()
            edit_button.props.group = tool_group
            edit_button.props.icon_name = 'toolbar-edit'
            edit_button.set_tooltip(_('Edit'))
            edit_button.mode = 'edit'
            edit_button.connect('clicked', self.__mode_button_clicked)
            self._toolbar.insert(edit_button, -1)
            self._toolbar.insert(gtk.SeparatorToolItem(), -1)
            self.edit_bar = edit.ToolbarBuilder(self.edit, self._toolbar)
            self.library_bar = library.ToolbarBuilder(self.library,
                                                      self._toolbar)

        edit_fake = gtk.EventBox()

        self.notebook.append_page(self.library)
        self.notebook.append_page(self.edit)
        self.notebook.append_page(edit_fake)

        self.show_all()

        if not OLD_TOOLBAR:
            self.__mode_button_clicked(search_button)
            separator = gtk.SeparatorToolItem()
            separator.props.draw = False
            separator.set_expand(True)
            separator.show()
            self._toolbar.insert(separator, -1)
            stop_button = StopButton(self)
            stop_button.show()
            self._toolbar.insert(stop_button, -1)
예제 #12
0
    def __init__(self, handle):
        # self.initiating indicates whether this instance has initiated sharing
        # it always starts false, but will be set to true if this activity
        # initiates sharing. In particular, if Activity.__init__ calls
        # self.share(), self.initiating will be set to True.
        self.initiating = False
        # self._processed_share indicates whether when_shared() has been called
        self._processed_share = False
        # self.initialized tracks whether the Activity's display is up and running
        self.initialized = False

        self.early_setup()

        super(GroupActivity, self).__init__(handle)
        self.dbus_name = self.get_bundle_id()
        self.logger = logging.getLogger(self.dbus_name)

        self._handle = handle

        ##gobject.threads_init()

        self._sharing_completed = not self._shared_activity
        self._readfile_completed = not handle.object_id
        if self._shared_activity:
            self.message = self.message_joining
        elif handle.object_id:
            self.message = self.message_loading
        else:
            self.message = self.message_preparing

        if OLD_TOOLBAR:
            self.toolbox = ActivityToolbox(self)
            self.set_toolbox(self.toolbox)
            self.toolbox.show()
            self.set_toolbox(self.toolbox)
        else:
            toolbar_box = ToolbarBox()
            self.activity_button = ActivityToolbarButton(self)
            toolbar_box.toolbar.insert(self.activity_button, 0)
            self.set_toolbar_box(toolbar_box)

        v = gtk.VBox()
        self.startup_label = gtk.Label(self.message)
        v.pack_start(self.startup_label)
        Window.set_canvas(self, v)
        self.show_all()

        # The show_all method queues up draw events, but they aren't executed
        # until the mainloop has a chance to process them.  We want to process
        # them immediately, because we need to show the waiting screen
        # before the waiting starts, not after.
        exhaust_event_loop()
        # exhaust_event_loop() provides the possibility that write_file could
        # be called at this time, so write_file is designed to trigger read_file
        # itself if that path occurs.

        self.tubebox = groupthink.TubeBox()
        self.timer = groupthink.TimeHandler("main", self.tubebox)
        self.cloud = groupthink.Group(self.tubebox)
        # self.cloud is extremely important.  It is the unified reference point
        # that contains all state in the system.  Everything else is stateless.
        # self.cloud has to be defined before the call to self.set_canvas, because
        # set_canvas can trigger almost anything, including pending calls to read_file,
        # which relies on self.cloud.

        # get the Presence Service
        self.pservice = presenceservice.get_instance()
        # Buddy object for you
        owner = self.pservice.get_owner()
        self.owner = owner

        self.connect('shared', self._shared_cb)
        self.connect('joined', self._joined_cb)
        if self.get_shared():
            if self.initiating:
                self._shared_cb(self)
            else:
                self._joined_cb(self)

        self.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK)
        self.connect("visibility-notify-event", self._visible_cb)
        self.connect("notify::active", self._active_cb)

        if not self._readfile_completed:
            self.read_file(self._jobject.file_path)
        elif not self._shared_activity:
            gobject.idle_add(self._initialize_cleanstart)
예제 #13
0
    def __init__(self, handle):
        ''' Init canvas, toolbars, etc.
        The toolbars are in sensor_toolbar.py and toolbar_side.py
        The audio controls are in audiograb.py
        The rendering happens in drawwaveform.py
        Logging is in journal.py '''

        activity.Activity.__init__(self, handle)

        self.mode_images = {}
        self.mode_images['sound'] = gtk.gdk.pixbuf_new_from_file_at_size(
            os.path.join(ICONS_DIR, 'media-audio.svg'), 45, 45)
        self.mode_images['resistance'] = gtk.gdk.pixbuf_new_from_file_at_size(
            os.path.join(ICONS_DIR, 'resistance.svg'), 45, 45)
        self.mode_images['voltage'] = gtk.gdk.pixbuf_new_from_file_at_size(
            os.path.join(ICONS_DIR, 'voltage.svg'), 45, 45)

        self._using_gconf = _using_gconf
        self.icon_colors = self.get_icon_colors_from_sugar()
        self.stroke_color, self.fill_color = self.icon_colors.split(',')
        self.nick = self.get_nick_from_sugar()
        self.CONTEXT = ''
        self.adjustmentf = None  # Freq. slider control
        self.hw = _get_hardware()
        self.new_recording = False
        self.session_id = 0
        self.read_metadata()

        self._active = True
        self._dsobject = None

        self.connect('notify::active', self._notify_active_cb)
        self.connect('destroy', self.on_quit)

        self.data_logger = DataLogger(self)

        self.hw = _get_hardware()
        log.debug('running on %s hardware' % (self.hw))
        self.wave = DrawWaveform(self)
        if self.hw == XO15:
            self.audiograb = AudioGrab_XO15(self.wave.new_buffer, self)
        elif self.hw == XO175:
            self.audiograb = AudioGrab_XO175(self.wave.new_buffer, self)
        elif self.hw == XO1:
            self.audiograb = AudioGrab_XO1(self.wave.new_buffer, self)
        else:
            self.audiograb = AudioGrab_Unknown(self.wave.new_buffer, self)

        # no sharing
        self.max_participants = 1

        self.has_toolbarbox = _has_toolbarbox

        box3 = gtk.HBox(False, 0)
        box3.pack_start(self.wave, True, True, 0)

        # We need event boxes in order to set the background color.
        side_eventboxes = []
        self.side_toolbars = []
        for i in range(self.audiograb.channels):
            side_eventboxes.append(gtk.EventBox())
            side_eventboxes[i].modify_bg(
                gtk.STATE_NORMAL, style.COLOR_TOOLBAR_GREY.get_gdk_color())
            self.side_toolbars.append(SideToolbar(self, channel=i))
            side_eventboxes[i].add(self.side_toolbars[i].box1)
            box3.pack_start(side_eventboxes[i], False, True, 0)

        event_box = gtk.EventBox()
        self.text_box = gtk.Label()
        self.text_box.set_justify(gtk.JUSTIFY_LEFT)
        alist = pango.AttrList()
        alist.insert(pango.AttrForeground(65535, 65535, 65535, 0, -1))
        self.text_box.set_attributes(alist)
        event_box.add(self.text_box)
        event_box.modify_bg(gtk.STATE_NORMAL,
                            style.COLOR_TOOLBAR_GREY.get_gdk_color())

        box1 = gtk.VBox(False, 0)
        box1.pack_start(box3, True, True, 0)
        box1.pack_start(event_box, False, True, 0)

        self.set_canvas(box1)

        if self.has_toolbarbox:
            toolbox = ToolbarBox()

            activity_button = ActivityToolbarButton(self)
            toolbox.toolbar.insert(activity_button, 0)
            activity_button.show()
        else:
            toolbox = ActivityToolbox(self)

            # no sharing
            if hasattr(toolbox, 'share'):
                toolbox.share.hide()
            elif hasattr(toolbox, 'props'):
                toolbox.props.visible = False
            self.set_toolbox(toolbox)

        self.sensor_toolbar = SensorToolbar(self, self.audiograb.channels)
        #Added by Butia
        # Enciendo el bobot Server
        log.debug('Starting Bobot-Server...')
        os.system(bobot_cmd_on)
        log.debug("Start : %s" % time.ctime())
        time.sleep(bobot_delay_start)
        log.debug("Started : %s" % time.ctime())
        self.butia_toolbar = ButiaToolbar(self, self.audiograb.channels)
        #Butia end
        self.tuning_toolbar = TuningToolbar(self)
        self.new_instrument_toolbar = InstrumentToolbar(self)
        self.control_toolbar = gtk.Toolbar()
        if self.has_toolbarbox:
            sensor_button = ToolbarButton(label=_('Sensors'),
                                          page=self.sensor_toolbar,
                                          icon_name='sensor-tools')
            toolbox.toolbar.insert(sensor_button, -1)
            #Added by Butia
            sensor_button.connect('clicked', self._sensor_toolbar_cb)
            #Butia end
            sensor_button.show()
            #Added by Butia
            butia_button = ToolbarButton(label=_('Butia'),
                                         page=self.butia_toolbar,
                                         icon_name='butia-tools')
            toolbox.toolbar.insert(butia_button, -1)
            butia_button.connect('clicked', self._butia_toolbar_cb)
            butia_button.show()
            #Butia end
            tuning_button = ToolbarButton(
                # TRANS: Tuning insruments
                label=_('Tuning'),
                page=self.tuning_toolbar,
                icon_name='tuning-tools')
            toolbox.toolbar.insert(tuning_button, -1)
            tuning_button.show()
            new_instrument_button = ToolbarButton(
                label=_('Add instrument'),
                page=self.new_instrument_toolbar,
                icon_name='view-source')
            toolbox.toolbar.insert(new_instrument_button, -1)
            new_instrument_button.show()
        else:
            toolbox.add_toolbar(_('Sensors'), self.sensor_toolbar)
            #Added by butia
            toolbox.add_toolbar(_('Butia'), self.butia_toolbar)
            #Butia end
            # TRANS: Tuning insruments
            toolbox.add_toolbar(_('Tuning'), self.tuning_toolbar)
            toolbox.add_toolbar(_('Add instrument'),
                                self.new_instrument_toolbar)
            toolbox.add_toolbar(_('Controls'), self.control_toolbar)
        self.sensor_toolbar.show()
        #Added by butia
        self.butia_toolbar.show()
        #Butia end

        if self.has_toolbarbox:
            # Set up Frequency-domain Button
            self.freq = ToolButton('domain-time')
            toolbox.toolbar.insert(self.freq, -1)
            self.freq.show()
            self.freq.set_tooltip(_('Time Base'))
            self.freq.connect('clicked', self.timefreq_control)

            self.sensor_toolbar.add_frequency_slider(toolbox.toolbar)
            self._pause = ToolButton('media-playback-pause')
            toolbox.toolbar.insert(self._pause, -1)
            self._pause.set_tooltip(_('Freeze the display'))
            self._pause.connect('clicked', self._pause_play_cb)

            self._capture = ToolButton('image-saveoff')
            toolbox.toolbar.insert(self._capture, -1)
            self._capture.set_tooltip(_('Capture sample now'))
            self._capture.connect('clicked', self._capture_cb)

            separator = gtk.SeparatorToolItem()
            separator.props.draw = False
            separator.set_expand(True)
            toolbox.toolbar.insert(separator, -1)
            separator.show()

            stop_button = StopButton(self)
            stop_button.props.accelerator = _('<Ctrl>Q')
            toolbox.toolbar.insert(stop_button, -1)
            stop_button.show()

            self.set_toolbox(toolbox)
            sensor_button.set_expanded(True)

        else:
            # Set up Frequency-domain Button
            self.freq = ToolButton('domain-time')
            self.control_toolbar.insert(self.freq, -1)
            self.freq.show()
            self.freq.set_tooltip(_('Time Base'))
            self.freq.connect('clicked', self.timefreq_control)

            self.sensor_toolbar.add_frequency_slider(self.control_toolbar)

            separator = gtk.SeparatorToolItem()
            separator.props.draw = True
            self.control_toolbar.insert(separator, -1)
            separator.show()

            self._pause = ToolButton('media-playback-pause')
            self.control_toolbar.insert(self._pause, -1)
            self._pause.set_tooltip(_('Freeze the display'))
            self._pause.connect('clicked', self._pause_play_cb)

            self._capture = ToolButton('image-saveoff')
            self.control_toolbar.insert(self._capture, -1)
            self._capture.set_tooltip(_('Capture sample now'))
            self._capture.connect('clicked', self._capture_cb)

            toolbox.set_current_toolbar(1)

        toolbox.show()
        self.sensor_toolbar.update_page_size()

        self.show_all()

        self._first = True

        # Always start in 'sound' mode.
        self.sensor_toolbar.set_mode('sound')
        self.sensor_toolbar.set_sound_context()
        self.sensor_toolbar.set_show_hide_windows()
        self.wave.set_active(True)
        self.wave.set_context_on()
예제 #14
0
    def __init__(self, handle):
        # Initialize the parent
        Activity.__init__(self, handle)
        logger.debug('Initiating MathGraph32')
     
        # Set the activity toolbox
        toolbox = ActivityToolbox(self)
        self.set_toolbox(toolbox)

        self.ceibaljam_icon_path = os.getenv("SUGAR_BUNDLE_PATH") + "/images/ceibaljam.png"

        self.java_path = self.get_java_path()

	#
	# There's a good explanation of the use of boxes in PyGTK here:
	# http://www.pygtk.org/pygtk2tutorial/sec-DetailsOfBoxes.html
	#
 
        box_canvas = gtk.VBox(False, 0)
        self.set_canvas(box_canvas)


        # Title

        box_title = gtk.VBox(False, 0)
        label_title = gtk.Label(_("MathGraph32"))
        label_title.set_justify(gtk.JUSTIFY_CENTER)
        label_title.modify_font(pango.FontDescription("Arial 22"))

        box_title.add(gtk.Label("\n\n"))
        box_title.add(label_title)
        box_title.add(gtk.Label("\n"))

        # Author

        box_author = gtk.VBox(False, 0)
        #box_author.add(gtk.Label(""))
        box_author.add(gtk.Label(_("Created by Yves Biton")))
        label_author_url = gtk.Label('<b>http://www.mathgraph32.org</b>')
        label_author_url.set_use_markup(True)
        box_author.add(label_author_url)

        # Credits

        box_credits = gtk.VBox(False, 0)
        box_credits.add(gtk.Label(""))
        box_credits.add(gtk.Label(_('Spanish translation and pedagogical evaluation by %(TEACHER)s') % { 'TEACHER': 'Luis Belcredi' }))
        label_teacher_email= gtk.Label('<b>http://xsubcero.50webs.biz</b>')
        label_teacher_email.set_use_markup(True)
        box_credits.add(label_teacher_email)
        box_credits.add(gtk.Label(""))
        box_credits.add(gtk.Label(_('Sugarized by %(SUGARIZER)s') % { 'SUGARIZER': 'Marcos Orfila' }))
        label_sugarizer_website = gtk.Label('<b>http://www.marcosorfila.com</b>')
        label_sugarizer_website.set_use_markup(True)
        box_credits.add(label_sugarizer_website)
        box_credits.add(gtk.Label(""))

        # Footer box (Activities on CeibalJAM! website)

        box_footer = gtk.VBox(False, 0)
        box_footer.add(gtk.Label(""))
        box_footer.add(gtk.Label(_('Find more activities on %(CEIBALJAM)s website:') % { 'CEIBALJAM': 'CeibalJAM!'}))
        label_ceibaljam_website = gtk.Label('<b>http://activities.ceibaljam.org</b>')
        label_ceibaljam_website.set_use_markup(True)
        box_footer.add(label_ceibaljam_website)
        box_footer.add(gtk.Label(""))

        # CeibalJAM! image

        box_ceibaljam_image = gtk.VBox(False, 0)
        image_ceibaljam = gtk.Image()
        image_ceibaljam.set_from_file(self.ceibaljam_icon_path)
        box_ceibaljam_image.pack_end(image_ceibaljam, False, False, 0)


	# Get all the boxes together

        box_canvas.pack_start(box_title, False, False, 0)
        box_canvas.pack_start(box_author, False, False, 0)
        box_canvas.pack_start(gtk.Label("\n"), False, False, 0)
        if self.java_path == "":
           box_java_not_found = gtk.VBox(False, 0)
           label_java_not_found = gtk.Label('<span foreground="red"><b>' + _("Java was not found!") + '</b></span>')
           label_java_not_found.set_justify(gtk.JUSTIFY_CENTER)
           label_java_not_found.set_use_markup(True)
           label_java_not_found.modify_font(pango.FontDescription("Arial 20"))
           box_java_not_found.add(label_java_not_found)
           box_java_not_found.add(gtk.Label(_('You can download the Java activity from %(CEIBALJAM)s website (see below)') % { 'CEIBALJAM': 'CeibalJAM!'}))
           box_canvas.pack_start(box_java_not_found, False, False, 0)
           box_canvas.pack_start(gtk.Label(""), False, False, 0)
        else:
           box_java_found = gtk.VBox(False, 0)
           label_version_info_title = gtk.Label('<b>' + _("Java version found:") + '</b>')
           label_version_info_title.set_use_markup(True)
           version_information = commands.getoutput(self.java_path + " -version")
           label_version_info = gtk.Label(version_information)
           label_version_info.set_justify(gtk.JUSTIFY_CENTER)
           box_java_found.add(label_version_info_title)
           box_java_found.add(label_version_info)
           box_canvas.pack_start(box_java_found, False, False, 0)
        box_canvas.pack_end(gtk.Label("\n"), False, False, 0)
        self.add_buttons(box_canvas)
        box_canvas.pack_end(box_footer, False, False, 0)
        box_canvas.pack_end(box_ceibaljam_image, False, False, 0)
        box_canvas.pack_end(box_credits, False, False, 0)

        if self.java_path != '':
           self.button_play.grab_focus()
        else:
           self.button_exit.grab_focus()
        self.show_all()
예제 #15
0
    def __init__(self, handle):
        # Initialize the parent
        Activity.__init__(self, handle)
        logger.debug('Initiating Tuxmath')

        # Set the activity toolbox
        toolbox = ActivityToolbox(self)
        self.set_toolbox(toolbox)

        self.ceibaljam_icon_path = os.getenv(
            "SUGAR_BUNDLE_PATH") + "/images/ceibaljam.png"

        #
        # There's a good explanation of the use of boxes in PyGTK here:
        # http://www.pygtk.org/pygtk2tutorial/sec-DetailsOfBoxes.html
        #

        box_canvas = gtk.VBox(False, 0)
        self.set_canvas(box_canvas)

        # Title

        box_title = gtk.VBox(False, 0)
        label_title = gtk.Label(_("Tuxmath"))
        label_title.set_justify(gtk.JUSTIFY_CENTER)
        label_title.modify_font(pango.FontDescription("Arial 22"))

        box_title.add(gtk.Label("\n\n\n"))
        box_title.add(label_title)
        box_title.add(gtk.Label("\n"))

        # Author

        box_author = gtk.VBox(False, 0)
        box_author.add(gtk.Label(""))
        box_author.add(gtk.Label(_("Created by Tux4kids")))
        label_author_url = gtk.Label(
            '<b>http://tux4kids.alioth.debian.org</b>')
        label_author_url.set_use_markup(True)
        box_author.add(label_author_url)

        # Options box

        box_options = gtk.VBox(False, 0)
        label_options = gtk.Label(_("Options:"))
        label_options.set_justify(gtk.JUSTIFY_LEFT)
        self.checkbtn_sound = gtk.CheckButton(label=_("No sound"))
        self.checkbtn_sound.set_active(True)
        self.checkbtn_negatives = gtk.CheckButton(
            label=_("Include negative numbers"))
        self.checkbtn_negatives.set_active(False)
        # Pack the checkboxes in HBoxes to center them
        hbox1 = gtk.HBox(False, 0)
        hbox1.add(gtk.Label(""))
        hbox1.add(gtk.Label(""))
        hbox1.add(gtk.Label(""))
        hbox1.add(gtk.Label(""))
        hbox1.add(gtk.Label(""))
        hbox1.add(gtk.Label(""))
        hbox1.add(gtk.Label(""))
        hbox1.add(self.checkbtn_sound)
        hbox1.add(gtk.Label(""))
        hbox1.add(gtk.Label(""))
        hbox1.add(gtk.Label(""))
        hbox1.add(gtk.Label(""))
        hbox1.add(gtk.Label(""))
        hbox1.add(gtk.Label(""))
        box_options.add(hbox1)
        #box_options.add(gtk.Label(""))
        #box_options.add(label_options)
        #box_options.add(self.checkbtn_sound)
        #box_options.add(self.checkbtn_negatives)

        # Credits

        box_credits = gtk.VBox(False, 0)
        box_credits.add(gtk.Label(""))
        box_credits.add(
            gtk.Label(
                _('Spanish translation and pedagogical evaluation by %(TEACHER)s'
                  ) % {'TEACHER': 'Ana Cichero'}))
        label_teacher_email = gtk.Label('<b>[email protected]</b>')
        label_teacher_email.set_use_markup(True)
        box_credits.add(label_teacher_email)
        box_credits.add(
            gtk.Label(
                _('Sugarized by %(SUGARIZER)s') %
                {'SUGARIZER': 'Marcos Orfila'}))
        label_sugarizer_website = gtk.Label(
            '<b>http://www.marcosorfila.com</b>')
        label_sugarizer_website.set_use_markup(True)
        box_credits.add(label_sugarizer_website)
        box_credits.add(gtk.Label(""))

        # Footer box (Activities on CeibalJAM! website)

        box_footer = gtk.VBox(False, 0)
        box_footer.add(gtk.Label(""))
        box_footer.add(
            gtk.Label(
                _('Find more activities on %(CEIBALJAM)s website:') %
                {'CEIBALJAM': 'CeibalJAM!'}))
        label_ceibaljam_website = gtk.Label(
            '<b>http://activities.ceibaljam.org</b>')
        label_ceibaljam_website.set_use_markup(True)
        box_footer.add(label_ceibaljam_website)
        box_footer.add(gtk.Label(""))

        # CeibalJAM! image

        box_ceibaljam_image = gtk.VBox(False, 0)
        image_ceibaljam = gtk.Image()
        image_ceibaljam.set_from_file(self.ceibaljam_icon_path)
        box_ceibaljam_image.pack_end(image_ceibaljam, False, False, 0)

        # Buttons box

        box_buttons = gtk.HBox(False, 0)
        self.button_play = gtk.Button(_("Play"))
        self.button_play.connect("clicked", self._button_play_clicked_cb)
        self.button_exit = gtk.Button(_("Exit"))
        self.button_exit.connect("clicked", self._button_exit_clicked_cb)
        box_buttons.add(gtk.VBox())
        box_buttons.add(self.button_play)
        box_buttons.add(gtk.VBox())
        box_buttons.add(self.button_exit)
        box_buttons.add(gtk.VBox())

        # Get all the boxes together

        box_canvas.pack_start(box_title, False, False, 0)
        box_canvas.pack_start(box_options, False, False, 0)
        box_canvas.pack_end(gtk.Label("\n\n"), False, False, 0)
        box_canvas.pack_end(box_buttons, False, False, 0)
        box_canvas.pack_end(gtk.Label("\n"), False, False, 0)
        box_canvas.pack_end(box_footer, False, False, 0)
        box_canvas.pack_end(box_ceibaljam_image, False, False, 0)
        box_canvas.pack_end(box_credits, False, False, 0)
        box_canvas.pack_end(box_author, False, False, 0)

        self.button_play.grab_focus()
        self.show_all()
예제 #16
0
    def build_toolbars(self):
        self.action_buttons = {}

        # BUILD CUSTOM TOOLBAR
        self.action_bar = gtk.Toolbar()
        self.action_buttons['add'] = ToolButton('fs_gtk-add')
        self.action_buttons['add'].set_tooltip(_("Add Object"))

        self.action_buttons['rem'] = ToolButton('fs_gtk-remove')
        self.action_buttons['rem'].set_tooltip(_("Remove Object(s)"))

        self.action_buttons['save'] = ToolButton('filesave')
        self.action_buttons['save'].set_tooltip(_("Copy Object(s) to Journal"))

        self.action_buttons['down'] = ToolButton('epiphany-download')
        self.action_buttons['down'].set_tooltip(_('Download Object(s)'))

        self.action_buttons['admin'] = ToolButton('gtk-network')
        self.action_buttons['admin'].set_tooltip(_('Server Permissions'))

        self.action_buttons['server'] = ToolButton('gaim-link')
        self.action_buttons['server'].set_tooltip(_('Connect to Server'))
        self.action_buttons['server'].set_sensitive(False)

        if self.activity.isServer:
            self.action_buttons['add'].connect("clicked",
                                               self.guiHandler.requestAddFile,
                                               None)
            self.action_buttons['save'].connect("clicked",
                                                self.guiHandler.requestInsFile,
                                                None)
            self.action_buttons['rem'].connect("clicked",
                                               self.guiHandler.requestRemFile,
                                               None)
            self.action_buttons['server'].connect(
                "clicked", self.guiHandler.switch_to_server, None)

            self.action_bar.insert(self.action_buttons['add'], -1)
            self.action_bar.insert(self.action_buttons['save'], -1)
            self.action_bar.insert(self.action_buttons['rem'], -1)
            self.action_bar.insert(self.action_buttons['server'], -1)

            # Check for server, if found activate connect link
            def check_server_status():
                try:
                    if self.activity.check_for_server():
                        self.action_buttons['server'].set_sensitive(True)
                except ServerRequestFailure:
                    pass

            threading.Thread(target=check_server_status).start()

        else:
            self.action_buttons['down'].connect(
                "clicked", self.guiHandler.requestDownloadFile, None)
            self.action_bar.insert(self.action_buttons['down'], -1)

            if self.activity._mode == 'SERVER' and self.activity._user_permissions != 0:
                self.action_buttons['add'].connect(
                    "clicked", self.guiHandler.requestAddFile,
                    {'upload': True})
                self.action_buttons['rem'].connect(
                    "clicked", self.guiHandler.requestRemFile,
                    {'remove': True})

                self.action_bar.insert(self.action_buttons['add'], -1)
                self.action_bar.insert(self.action_buttons['rem'], -1)

                if self.activity._user_permissions == 2:
                    self.action_buttons['admin'].connect(
                        "clicked", self.guiHandler.showAdmin, None)
                    self.action_bar.insert(self.action_buttons['admin'], -1)

        self.action_bar.show_all()

        self.toolbar_set_selection(False)

        # Create Toolbox
        self.toolbox = ActivityToolbox(self.activity)

        self.toolbox.add_toolbar(_("Actions"), self.action_bar)

        self.activity.set_toolbox(self.toolbox)
        self.toolbox.show()
        self.toolbox.set_current_toolbar(1)
예제 #17
0
    def __init__(self, handle):
        """Set up the StopWatch activity."""
        Activity.__init__(self, handle)
        self._logger = logging.getLogger('stopwatch-activity')

        gobject.threads_init()

        # top toolbar with share and close buttons:
        OLD_TOOLBAR = False

        try:
            from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton
            from sugar.activity.widgets import ActivityToolbarButton, StopButton, \
                    ShareButton, TitleEntry, ActivityButton
        except ImportError:
            OLD_TOOLBAR = True

        if OLD_TOOLBAR:
            toolbox = ActivityToolbox(self)
            self.set_toolbox(toolbox)
            toolbox.show()
        else:
            toolbar_box = ToolbarBox()
            self.activity_button = ActivityButton(self)
            toolbar_box.toolbar.insert(self.activity_button, 0)
            self.activity_button.show()

            title_entry = TitleEntry(self)
            toolbar_box.toolbar.insert(title_entry, -1)
            title_entry.show()

            try:
                from sugar.activity.widgets import DescriptionItem
                description_item = DescriptionItem(self)
                toolbar_box.toolbar.insert(description_item, -1)
                description_item.show()
            except:
                pass

            share_button = ShareButton(self)
            toolbar_box.toolbar.insert(share_button, -1)
            share_button.show()

            separator = gtk.SeparatorToolItem()
            separator.props.draw = False
            separator.set_expand(True)
            toolbar_box.toolbar.insert(separator, -1)
            separator.show()

            stop_button = StopButton(self)
            toolbar_box.toolbar.insert(stop_button, -1)
            stop_button.show()

            self.set_toolbar_box(toolbar_box)

        self.tubebox = dobject.TubeBox()
        self.timer = dobject.TimeHandler("main", self.tubebox)
        self.gui = stopwatch.GUIView(self.tubebox, self.timer)

        self.set_canvas(self.gui.display)
        self.show_all()

        self.initiating = False

        # get the Presence Service
        self.pservice = presenceservice.get_instance()
        # Buddy object for you
        owner = self.pservice.get_owner()
        self.owner = owner

        self.connect('shared', self._shared_cb)
        self.connect('joined', self._joined_cb)

        self.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK)
        self.connect("visibility-notify-event", self._visible_cb)
        self.connect("notify::active", self._active_cb)
예제 #18
0
    def __init__(self, handle):
        """ Init canvas, toolbars, etc.
        The toolbars are in toolbar_top.py and toolbar_side.py
        The audio controls are in audiograb.py
        The rendering happens in drawwaveform.py
        Logging (Journal interactions) are in journal.py """

        activity.Activity.__init__(self, handle)

        try:
            tmp_dir = path.join(activity.get_activity_root(), "data")
        except AttributeError:
            # Early versions of Sugar (e.g., 656) didn't support
            # get_activity_root()
            tmp_dir = path.join(
                environ['HOME'],
                ".sugar/default/org.laptop.MeasureActivity/data")
        self.using_gconf = _using_gconf
        self.icon_colors = self.get_icon_colors_from_sugar()
        self.stroke_color, self.fill_color = self.icon_colors.split(',')
        self.nick = self.get_nick_from_sugar()
        self.active_status = True
        self.ACTIVE = True
        self.LOGGING_IN_SESSION = False
        self.CONTEXT = ''
        self.adjustmentf = None  # Freq. slider control
        self.connect('notify::active', self._active_cb)
        self.connect('destroy', self.on_quit)
        self.hw = _get_hardware()

        self.closedSound = None
        self.openedSound = None

        self.session_id = 0

        self.ji = JournalInteraction(self)
        colorBlack = Color()
        colorBlack.init_rgba(0, 0, 0, 255)
        self.playsoundWin = PlayVideoWindow(colorBlack.gColor)
        self.playsound = Gplay()
        self.playsound.window = self.playsoundWin
        self.wave = DrawWaveform(self, self.playsound)

        self.hw = _get_hardware()
        log.debug('running on %s hardware' % (self.hw))
        if self.hw == XO15:
            self.audiograb = AudioGrab_XO15(self.wave.new_buffer, self)
        elif self.hw == XO1:
            self.audiograb = AudioGrab_XO1(self.wave.new_buffer, self)
        else:
            self.audiograb = AudioGrab_Unknown(self.wave.new_buffer, self)

        # no sharing
        self.max_participants = 1

        self.has_toolbarbox = _has_toolbarbox

        self.side_toolbar = SideToolbar(self)
        self.text_box = TextBox()

        self.box3 = gtk.HBox(False, 0)
        self.box3.pack_start(self.wave, True, True, 0)
        self.box3.pack_start(self.side_toolbar.box1, False, True, 0)

        self.box1 = gtk.VBox(False, 0)
        self.box1.pack_start(self.box3, True, True, 0)
        self.box1.pack_start(self.text_box.box_main, False, True, 0)

        self.set_canvas(self.box1)
        self.toolbox = None

        if self.has_toolbarbox:
            toolbox = ToolbarBox()
            self.toolbox = toolbox
            activity_button = ActivityToolbarButton(self)
            toolbox.toolbar.insert(activity_button, 0)
            activity_button.show()
        else:
            toolbox = ActivityToolbox(self)
            self.toolbox = toolbox
            # no sharing
            if hasattr(toolbox, 'share'):
                toolbox.share.hide()
            elif hasattr(toolbox, 'props'):
                toolbox.props.visible = False

            self.set_toolbox(toolbox)
            toolbox.connect('current-toolbar-changed',
                            self._toolbar_changed_cb)

        self.sound_toolbar = SoundToolbar(self)
        if self.has_toolbarbox:
            self._sound_button = ToolbarButton(label=_('Sound'),
                                               page=self.sound_toolbar,
                                               icon_name='sound-tools')
            toolbox.toolbar.insert(self._sound_button, -1)
            self._sound_button.show()
        else:
            toolbox.add_toolbar(_('Sound'), self.sound_toolbar)
        self.sound_toolbar.show()

        if _is_xo(self.hw):
            self.sensor_toolbar = SensorToolbar(self)
            if self.has_toolbarbox:
                self._sensor_button = ToolbarButton(label=_('Sensors'),
                                                    page=self.sensor_toolbar,
                                                    icon_name='sensor-tools')
                toolbox.toolbar.insert(self._sensor_button, -1)
                self._sensor_button.show()
            else:
                toolbox.add_toolbar(_('Sensors'), self.sensor_toolbar)
            self.sensor_toolbar.show()

        if self.has_toolbarbox:
            _separator = gtk.SeparatorToolItem()
            _separator.props.draw = False
            toolbox.toolbar.insert(_separator, -1)
            _separator.show()

            # add a "dummy" button to indicate what capture mode we are in
            self.label_button = ToolButton('domain-time2')
            toolbox.toolbar.insert(self.label_button, -1)
            self.label_button.show()
            self.label_button.set_tooltip(_('Time Base'))
            self.label_button.connect('clicked', self._label_cb)

            self.sound_toolbar.add_frequency_slider(toolbox.toolbar)

            _separator = gtk.SeparatorToolItem()
            _separator.props.draw = False
            _separator.set_expand(True)
            toolbox.toolbar.insert(_separator, -1)
            _separator.show()
            _stop_button = StopButton(self)
            _stop_button.props.accelerator = _('<Ctrl>Q')
            toolbox.toolbar.insert(_stop_button, -1)
            _stop_button.show()

            self.set_toolbox(toolbox)
            self._sound_button.set_expanded(True)

        else:
            toolbox.set_current_toolbar(TOOLBARS.index('sensor'))

        toolbox.show()
        self.sound_toolbar.update_page_size()

        self.show_all()

        self.first = True

        self.set_sound_context()
        self.set_sensor_context()
        self.set_show_hide_windows()
        self.wave.set_active(True)
        self.wave.set_context_on()

        self.set_show_hide_windows()
    def __init__(self, handle):
        print "running activity init", handle
        Activity.__init__(self, handle)
        print "activity running"

        self._logger = logging.getLogger('scribble-activity')

        toolbox = ActivityToolbox(self)
        self.set_toolbox(toolbox)
        toolbox.show()

        pencilbtn = sugar.graphics.radiotoolbutton.RadioToolButton()
        pencilbtn.set_named_icon('tool-pencil')
        pencilbtn.set_tooltip(_("Pencil"))
        pencilbtn.connect('toggled', self._pencil_cb)

        circlebtn = sugar.graphics.radiotoolbutton.RadioToolButton()
        circlebtn.set_named_icon('tool-shape-ellipse')
        circlebtn.set_tooltip(_("Ellipse"))
        circlebtn.connect('toggled', self._circle_cb)
        circlebtn.set_group(pencilbtn)

        rectbtn = sugar.graphics.radiotoolbutton.RadioToolButton()
        rectbtn.set_named_icon('tool-shape-rectangle')
        rectbtn.set_tooltip(_("Rectangle"))
        rectbtn.connect('toggled', self._rect_cb)
        rectbtn.set_group(circlebtn)

        polybtn = sugar.graphics.radiotoolbutton.RadioToolButton()
        polybtn.set_named_icon('tool-shape-freeform')
        polybtn.set_tooltip(_("Shape"))
        polybtn.connect('toggled', self._poly_cb)
        polybtn.set_group(rectbtn)

        sep = gtk.SeparatorToolItem()
        sep.set_expand(False)
        sep.set_draw(True)

        erasebtn = sugar.graphics.radiotoolbutton.RadioToolButton()
        erasebtn.set_named_icon('tool-eraser')
        erasebtn.set_tooltip(_("Erase"))
        erasebtn.connect('toggled', self._erase_cb)
        erasebtn.set_group(polybtn)

        toolbar = gtk.Toolbar()
        toolbar.insert(pencilbtn, -1)
        toolbar.insert(circlebtn, -1)
        toolbar.insert(rectbtn, -1)
        toolbar.insert(polybtn, -1)
        toolbar.insert(sep, -1)
        toolbar.insert(erasebtn, -1)

        sep = gtk.SeparatorToolItem()
        sep.set_expand(True)
        sep.set_draw(False)
        toolbar.insert(sep, -1)

        exportbtn = ExportButton(self)
        toolbar.insert(exportbtn, -1)
        exportbtn.show()

        toolbox.add_toolbar(_('Toolbox'), toolbar)
        toolbar.show_all()

        self._scribblewidget = scribblewidget.ScribbleWidget()
        self._scribblewidget.connect('item-added', \
                self.scribblewidget_item_added_cb)
        colors = profile.get_color()
        self._scribblewidget.set_fill_color(colors.get_fill_color())
        self._scribblewidget.set_stroke_color(colors.get_stroke_color())
        self._scribblewidget.set_tool('pencil')

        sw = gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        sw.add(self._scribblewidget)

        self.set_canvas(sw)
        sw.show_all()

        self.cmdtube = None  # Shared session
        self.initiating = False

        # get the Presence Service
        self.pservice = presenceservice.get_instance()
        # Buddy object for you
        owner = self.pservice.get_owner()
        self.owner = owner

        self.connect('shared', self._shared_cb)
        self.connect('joined', self._joined_cb)
예제 #20
0
    def __init__(self, handle):
        # Initialize the parent
        Activity.__init__(self, handle)
        logger.debug('Initiating PlayGo')

        self.size = DEFAULT_SIZE
        self.komi = DEFAULT_KOMI

        # Set the activity toolbox
        toolbox = ActivityToolbox(self)
        self.set_toolbox(toolbox)
        self.gameToolbar = GameToolbar(self)
        toolbox.add_toolbar(_('Game'), self.gameToolbar)
        self.gameToolbar.connect('game-restart', self.restart_game)
        self.gameToolbar.connect('game-board-size', self.board_size_change)
        self.gameToolbar.connect('ai-activated', self.ai_activated_cb)
        self.gameToolbar.connect('ai-deactivated', self.ai_deactivated_cb)
        self.gameToolbar.show()

        # Initialize the game
        self.game = GoGame(self.size)
        self.CurrentColor = 'B'
        self.PlayerColor = 'B'
        self.pass_count = 0
        self.ai_activated = False
        self.set_up_ui()

        if not handle.object_id:
            self.infopanel.show(_('Welcome to PlayGo!'))
        else:
            self.show_score()
        self.lastX = -1
        self.lastY = -1

        # Set keypad actions
        self._key_actions = {
            'KP_Up': 'move_up',
            'KP_Right': 'move_right',
            'KP_Down': 'move_down',
            'KP_Left': 'move_left',
            'KP_Home': 'place_stone',
            'KP_Next': 'undo',
            'KP_End': 'pass'
        }

        self._key_grabber = KeyGrabber()
        self._key_grabber.connect('key-pressed', self._key_pressed_cb)

        # New KeyGrabber API change (ticket #7999)
        try:
            self._key_grabber.grab_keys(self._key_actions.keys())
        except:
            for key in self._key_actions.keys():
                self._key_grabber.grab(key)

        #Set up collaboration
        self.collaboration = CollaborationWrapper(self, self.buddy_joined,
                                                  self.buddy_left, self.Play,
                                                  self.game.undostack,
                                                  self.bootstrap)

        self.connect('shared', self.collaboration._shared_cb)
        if self._shared_activity:
            # We are joining the activity
            self.connect('joined', self.collaboration._joined_cb)
            if self.get_shared():
                # We've already joined
                self.collaboration._joined_cb()
예제 #21
0
    def __init__(self, handle):
        """Set up the XoScope activity."""
        activity.Activity.__init__(self, handle)

        self._instance_directory = os.path.join(self.get_activity_root(),\
                'instance')

        # we do not have collaboration features
        # make the share option insensitive
        self.max_participants = 1
        self._capturing = False
        self._mode = 'live'

        # 0, 2 or 5 second delay before capturing the image
        self._delay = 0

        # Zoom 1x, 2x, 4x
        self._zoom = 1

        # Exposure bracketing
        self._bracketing = '0'

        # Preview mode stuff
        self._num_pics = 0

        # Index of pic to be displayed in preview mode
        self._pic_index = 0

        # This holds the image titles and name information. Saved
        # across activity instances
        self._images = []

        # Flag to store whether image preview element needs to resize
        # the pixbuf
        self._needs_resize = False

        if OLD_TOOLBAR:
            self.toolbox = ActivityToolbox(self)
            self.set_toolbox(self.toolbox)
            self.toolbox.show()

            activity_toolbar = self.toolbox.get_activity_toolbar()
            activity_toolbar = gtk.Toolbar()
            self.toolbox.add_toolbar(_('Control'), activity_toolbar)
            self.toolbox.set_current_toolbar(1)
            self._controls_toolbar = activity_toolbar

            advanced_toolbar = self.toolbox.get_activity_toolbar()
            advanced_toolbar = gtk.Toolbar()
            #self.toolbox.add_toolbar(_('Advanced controls'), advanced_toolbar)
        else:
            toolbar_box = ToolbarBox()
            self.activity_button = ActivityToolbarButton(self)
            toolbar_box.toolbar.insert(self.activity_button, 0)
            self.activity_button.show()
            self.set_toolbar_box(toolbar_box)

            toolbar_box.show()
            activity_toolbar = self.activity_button.page
            self._controls_toolbar = self.get_toolbar_box().toolbar
            self._controls_toolbar.show()

            advanced_toolbar = gtk.Toolbar()
            #advanced_toolbar.show_all()
            advanced_button = ToolbarButton()
            advanced_button.props.page = advanced_toolbar
            advanced_button.props.label = _('Advanced controls')
            advanced_button.props.icon_name = 'advanced'
            #advanced_button.show()
            #toolbar_box.toolbar.insert(advanced_button, -1)

        self._live_toolitem = gtk.ToolItem()
        self._live_toolbar_container = gtk.HBox()

        self._preview_toolitem = gtk.ToolItem()
        self._preview_toolbar_container = gtk.HBox()

        separator = gtk.SeparatorToolItem()
        if not OLD_TOOLBAR:
            separator.props.draw = True
        else:
            separator.props.draw = False
        separator.set_expand(False)
        self._controls_toolbar.insert(separator, -1)
        separator.show()

        self._photo_button = ToolButton('photo')
        self._photo_button.props.label = _('Capture photo')
        self._photo_button.connect('clicked',
                self.__capture_image_cb)
        self._live_toolbar_container.add(self._photo_button)
        self._photo_button.show()

        self._delay_button = ToolButton('delay_%d' % self._delay)
        self._delay_button.props.label = _('Capture delay')
        self._delay_button.connect('clicked',
                self.__change_capture_delay_cb)
        self._live_toolbar_container.add(self._delay_button)
        self._delay_button.show()

        self._zoom_button = ToolButton('zoom_%d' % self._zoom)
        self._zoom_button.props.label = _('Image Zoom')
        self._zoom_button.connect('clicked',
                self.__change_image_zoom_cb)
        self._live_toolbar_container.add(self._zoom_button)
        self._zoom_button.show()

        #if self._check_available_control(v4l2.V4L2_CID_EXPOSURE):
        #    self._bracketing_button = ToolButton('bracketing_%s' % self._bracketing)
        #    self._bracketing_button.props.label = _('bracketing mode')
        #    self._bracketing_button.connect('clicked',
        #            self.__change_capture_bracketing_cb)
        #    self._live_toolbar_container.add(self._bracketing_button)
        #    self._bracketing_button.show()

        separator = gtk.SeparatorToolItem()
        separator.props.draw = True
        separator.set_expand(False)
        self._live_toolbar_container.add(separator)
        separator.show()

        # Camera control settings follow

        if self._check_available_control(v4l2.V4L2_CID_EXPOSURE):
            self._exposure_button = ToolButton('exposure')
            self._exposure_button.set_palette(ScalePalette('Exposure',\
                    v4l2.V4L2_CID_EXPOSURE))
            self._exposure_button.connect('clicked',
                    self.__button_clicked_cb)
            self._live_toolbar_container.add(self._exposure_button)
            self._exposure_button.show()

        if self._check_available_control(v4l2.V4L2_CID_GAIN):
            self._gain_button = ToolButton('gain')
            self._gain_button.set_palette(ScalePalette('Gain',\
                    v4l2.V4L2_CID_GAIN,
                    self._check_available_control(v4l2.V4L2_CID_AUTOGAIN)))
            self._gain_button.connect('clicked',
                    self.__button_clicked_cb)
            advanced_toolbar.insert(self._gain_button, -1)
            self._gain_button.show()

        if self._check_available_control(v4l2.V4L2_CID_BRIGHTNESS):
            self._brightness_button = ToolButton('brightness')
            self._brightness_button.set_palette(ScalePalette('Brightness',\
                    v4l2.V4L2_CID_BRIGHTNESS,
                    self._check_available_control(
                        v4l2.V4L2_CID_AUTOBRIGHTNESS)))
            self._brightness_button.connect('clicked',
                    self.__button_clicked_cb)
            self._live_toolbar_container.add(self._brightness_button)
            self._brightness_button.show()

        if self._check_available_control(v4l2.V4L2_CID_CONTRAST):
            self._contrast_button = ToolButton('contrast')
            self._contrast_button.set_palette(ScalePalette('Contrast',\
                    v4l2.V4L2_CID_CONTRAST))
            self._contrast_button.connect('clicked',
                    self.__button_clicked_cb)
            self._live_toolbar_container.add(self._contrast_button)
            self._contrast_button.show()

        if self._check_available_control(v4l2.V4L2_CID_SATURATION):
            self._saturation_button = ToolButton('saturation')
            self._saturation_button.set_palette(ScalePalette('Saturation',\
                    v4l2.V4L2_CID_SATURATION))
            self._saturation_button.connect('clicked',
                    self.__button_clicked_cb)
            advanced_toolbar.insert(self._saturation_button, -1)
            self._saturation_button.show()

        if self._check_available_control(
                v4l2.V4L2_CID_WHITE_BALANCE_TEMPERATURE):
            self._white_balance_button = ToolButton('white_balance')
            self._white_balance_button.set_palette(ScalePalette('White'
                    ' balance', v4l2.V4L2_CID_WHITE_BALANCE_TEMPERATURE,
                    self._check_available_control(
                        v4l2.V4L2_CID_AUTO_WHITE_BALANCE)))
            self._white_balance_button.connect('clicked',
                    self.__button_clicked_cb)
            advanced_toolbar.insert(self._white_balance_button, -1)
            self._white_balance_button.show()

        if self._check_available_control(v4l2.V4L2_CID_HUE):
            self._color_tone_button = ToolButton('color_tone')
            self._color_tone_button.set_palette(ScalePalette('Color'
                    ' tone', v4l2.V4L2_CID_HUE,
                    self._check_available_control(
                        v4l2.V4L2_CID_HUE_AUTO)))
            self._color_tone_button.connect('clicked',
                    self.__button_clicked_cb)
            advanced_toolbar.insert(self._color_tone_button, -1)
            self._color_tone_button.show()

        #if self._check_available_control(v4l2.V4L2_CID_NIGHT_MODE):
        #    self._night_mode_button = ToolButton('night_mode')
        #    self._night_mode_button.set_palette(ScalePalette('Night mode',\
        #            v4l2.V4L2_CID_NIGHT_MODE))
        #    self._night_mode_button.connect('clicked',
        #            self.__button_clicked_cb)
        #    self._live_toolbar_container.add(self._night_mode_button)
        #    self._night_mode_button.show()

        self._previous_image = ToolButton('go-previous-paired')
        self._previous_image.label = _('Previous image')
        self._previous_image.connect('clicked',
                self.__previous_image_clicked_cb)
        self._preview_toolbar_container.add(self._previous_image)
        self._previous_image.show()

        self._next_image = ToolButton('go-next-paired')
        self._next_image.label = _('Next image')
        self._next_image.connect('clicked',
                self.__next_image_clicked_cb)
        self._preview_toolbar_container.add(self._next_image)
        self._next_image.show()

        self._image_name_entry = gtk.Entry()
        self._image_name_entry.set_text('')
        self._image_name_entry.set_size_request(400, -1)
        self._image_name_entry.connect('activate',
                self.__image_name_entry_activated_cb)
        self._preview_toolbar_container.add(self._image_name_entry)
        self._image_name_entry.show()

        self._save_to_journal = ToolButton('save_to_journal')
        self._save_to_journal.label = _('Save to journal')
        self._save_to_journal.connect('clicked',
                self.__save_to_journal_clicked_cb)
        self._preview_toolbar_container.add(self._save_to_journal)
        self._save_to_journal.show()

        self._trash = ToolButton('trash')
        self._trash.label = _('Delete')
        self._trash.connect('clicked',
                self.__trash_clicked_cb)
        self._preview_toolbar_container.add(self._trash)
        self._trash.show()

        separator = gtk.SeparatorToolItem()
        separator.props.draw = False
        separator.set_expand(True)
        self._controls_toolbar.insert(separator, -1)
        separator.show()

        self._mode_button = ToolButton('%s_mode' % self._mode)
        self._mode_button.props.label = _('Mode')
        self._mode_button.connect('clicked',
                self.__switch_modes_cb)
        self._controls_toolbar.insert(self._mode_button, -1)
        self._mode_button.show()

        if not OLD_TOOLBAR:
            separator = gtk.SeparatorToolItem()
            separator.props.draw = True
            separator.set_expand(False)
            self._controls_toolbar.insert(separator, -1)
            separator.show()

            activity_stop = StopButton(self)
            toolbar_box.toolbar.insert(activity_stop, -1)
            activity_stop.show()

        self._preview_toolitem.add(self._preview_toolbar_container)
        self._live_toolitem.add(self._live_toolbar_container)
        self._preview_toolbar_container.show()
        self._live_toolbar_container.show()

        if self._mode == 'preview':
            self._controls_toolbar.insert(self._preview_toolitem, 1)
            self._preview_toolitem.show()
        else:
            self._controls_toolbar.insert(self._live_toolitem, 1)
            self._live_toolitem.show()
            self._mode = 'live'

        self._controls_toolbar.show()
        activity_toolbar.show()

        self._main_view = gtk.HBox()
        self._movie_window = gtk.DrawingArea()
        self._movie_window.connect('realize',
                self.__movie_window_realize_cb)
        self._movie_window.unset_flags(gtk.DOUBLE_BUFFERED)
        self._movie_window.set_flags(gtk.APP_PAINTABLE)
        self._main_view.add(self._movie_window)

        self._preview_frame = gtk.AspectFrame(None, 0.5, 0.5, 1, True)
        self._preview_window = gtk.Image()
        self._preview_frame.add(self._preview_window)
        self._preview_window.connect('size_allocate',
                self.__preview_window_size_allocate_cb)

        self.xoscope = gst.Pipeline('xoscope_pipe')
        camsrc = gst.element_factory_make('v4l2src', 'camsrc')

        caps = gst.Caps('video/x-raw-yuv')

        filt = gst.element_factory_make('capsfilter', 'filter')
        filt.set_property('caps', caps)
        ffmpegcolorspace = gst.element_factory_make('ffmpegcolorspace',
                'ffmpegcolorspace')
        self._disp_sink = gst.element_factory_make('xvimagesink', 'disp_sink')

        # http://thread.gmane.org/gmane.comp.video.gstreamer.devel/29644
        self._disp_sink.set_property('sync', False)

        self.image_sink = gst.element_factory_make('fakesink',
                'image_sink')
        self.image_sink.set_property('silent', True)

        tee = gst.element_factory_make('tee', 'tee')
        queue = gst.element_factory_make('queue', 'dispqueue')
        queue.set_property('leaky', True)
        queue.set_property('max-size-buffers', 20)

        queue2 = gst.element_factory_make('queue', 'imagequeue')
        queue2.set_property('leaky', True)
        queue2.set_property('max-size-buffers', 20)

        self._zoom_element = gst.element_factory_make('videobox', 'zoombox')

        jpeg = gst.element_factory_make('jpegenc', 'pbjpeg')
        jpeg.set_property('quality', 100)

        self.xoscope.add(camsrc, filt, ffmpegcolorspace,\
                self._zoom_element, self._disp_sink, tee, queue, queue2,\
                self.image_sink, jpeg)
        gst.element_link_many(camsrc, filt, self._zoom_element,\
                ffmpegcolorspace, tee, queue, self._disp_sink)
        gst.element_link_many(tee, queue2, jpeg, self.image_sink)

        bus = self.xoscope.get_bus()
        bus.add_signal_watch()
        bus.enable_sync_message_emission()
        bus.connect('message', self.__on_message_cb)
        bus.connect('sync-message::element', self.__on_sync_message_cb)

        self._main_view.show()
        self._movie_window.show()
        self.set_canvas(self._main_view)

        # If we start playing without a delay, the live view window
        # doesn't get attached to the main canvas properly (This is
        # a problem on slow computers like xo1).
        gobject.timeout_add(2000, self.__start_live_view)
예제 #22
0
    def __init__(self, handle):
        """Set up the Words activity."""
        super(WordsActivity, self).__init__(handle)
        self._logger = logging.getLogger('words-activity')

        from sugar.graphics.menuitem import MenuItem
        from sugar.graphics.icon import Icon

        # Instantiate a language model.
        # FIXME: We should ask the language model what langs it supports.
        self.langs = ["French", "German", "Italian", "Portuguese", "Spanish"]
        # Initial values.
        self.fromlang = "English"
        self.tolang = "Spanish"
        import LanguageModel
        self.languagemodel = LanguageModel.LanguageModel()

        # we do not have collaboration features
        # make the share option insensitive
        self.max_participants = 1

        # Main layout.
        hbox = gtk.HBox(homogeneous=True)
        vbox = gtk.VBox()

        # Toolbar.
        try:
            from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton
            from sugar.activity.widgets import ActivityButton, StopButton, \
                                                ShareButton, KeepButton, TitleEntry

            toolbar_box = ToolbarBox()
            activity_button = ActivityButton(self)
            toolbar_box.toolbar.insert(activity_button, 0)
            activity_button.show()

            title_entry = TitleEntry(self)
            toolbar_box.toolbar.insert(title_entry, -1)
            title_entry.show()

            share_button = ShareButton(self)
            toolbar_box.toolbar.insert(share_button, -1)
            share_button.show()

            separator = gtk.SeparatorToolItem()
            separator.props.draw = False
            separator.set_expand(True)
            toolbar_box.toolbar.insert(separator, -1)
            separator.show()

            stop_button = StopButton(self)
            toolbar_box.toolbar.insert(stop_button, -1)
            stop_button.show()

            self.set_toolbox(toolbar_box)
            toolbar_box.show()
        except ImportError:
            toolbox = ActivityToolbox(self)
            self.set_toolbox(toolbox)
            toolbox.show()

        # transbox: <label> - <text entry> - <speak button>
        transbox1 = gtk.HBox()
        transbox2 = gtk.HBox()

        # Labels.
        label1 = gtk.Label(_("Word"))
        label2 = gtk.Label(_("Translation"))

        # Text entry box to enter word to be translated.
        self.totranslate = gtk.Entry(max=50)
        self.totranslate.connect("changed", self.totranslate_cb)
        self.totranslate.modify_font(pango.FontDescription("Sans 14"))

        # Text entry box to receive word translated.
        self.translated = gtk.Entry(max=50)
        self.translated.set_property('editable', False)
        self.translated.modify_font(pango.FontDescription("Sans 14"))

        # Speak buttons.
        speak1 = gtk.Button("Speak")
        speak1.connect("clicked", self.speak1_cb)
        speak2 = gtk.Button("Speak")
        speak2.connect("clicked", self.speak2_cb)

        transbox1.pack_start(label1, expand=False)
        transbox1.pack_start(self.totranslate)
        transbox1.pack_start(speak1, expand=False)

        transbox2.pack_start(label2, expand=False)
        transbox2.pack_start(self.translated)
        transbox2.pack_start(speak2, expand=False)

        vbox.pack_start(transbox1, expand=False)
        vbox.pack_start(transbox2, expand=False)

        # The language choice combo boxes.
        combohbox = gtk.HBox(homogeneous=True)
        self.lang1combo = gtk.combo_box_new_text()
        self.lang1combo.append_text("English")
        self.lang1combo.connect("changed", self.lang1combo_cb)
        self.lang1combo.set_active(0)

        self.lang2combo = gtk.combo_box_new_text()
        for x in self.langs:
            self.lang2combo.append_text(x)
        self.lang2combo.connect("changed", self.lang2combo_cb)
        self.lang2combo.set_active(4)

        self.lang1combo.set_size_request(600, 50)
        self.lang2combo.set_size_request(600, 50)
        combohbox.pack_start(self.lang1combo, expand=False)
        combohbox.pack_start(self.lang2combo, expand=False)
        vbox.pack_start(combohbox, expand=False)

        # The "lang1" treeview box
        self.lang1model = gtk.ListStore(str)
        lang1view = gtk.TreeView(self.lang1model)
        lang1cell = gtk.CellRendererText()
        lang1treecol = gtk.TreeViewColumn("", lang1cell, text=0)
        lang1view.get_selection().connect("changed", self.lang1sel_cb)
        lang1view.append_column(lang1treecol)

        # The "lang2" box
        self.lang2model = gtk.ListStore(str)
        lang2view = gtk.TreeView(self.lang2model)
        lang2cell = gtk.CellRendererText()
        lang2treecol = gtk.TreeViewColumn("", lang2cell, text=0)
        lang2view.get_selection().connect("changed", self.lang2sel_cb)
        lang2view.append_column(lang2treecol)

        hbox.pack_start(lang1view)
        hbox.pack_start(lang2view)

        vbox.pack_start(hbox)
        self.set_canvas(vbox)
        self.totranslate.grab_focus()
        self.show_all()
예제 #23
0
    def build_toolbars(self):
        self.dungeon_buttons = {}
        self.dungeon_bar = gtk.Toolbar()
        self.view_bar = gtk.Toolbar()

        # BUILD CUSTOM TOOLBAR
        # Dungeon Bar
        self.dungeon_buttons['new'] = ToolButton('add')
        self.dungeon_buttons['new'].set_tooltip(_("New Dungeon"))
        self.dungeon_buttons['new'].connect("clicked", self.view_change_cb,
                                            'new')
        self.dungeon_bar.insert(self.dungeon_buttons['new'], -1)

        self.dungeon_buttons['load'] = ToolButton('fileopen')
        self.dungeon_buttons['load'].set_tooltip(_("Open Dungeon"))
        self.dungeon_buttons['load'].connect("clicked", self.view_change_cb,
                                             'load')
        self.dungeon_bar.insert(self.dungeon_buttons['load'], -1)

        self.dungeon_buttons['save'] = ToolButton('filesave')
        self.dungeon_buttons['save'].set_tooltip(
            _("Export dungeon file to journal"))
        self.dungeon_buttons['save'].connect("clicked", self.view_change_cb,
                                             'export')
        self.dungeon_bar.insert(self.dungeon_buttons['save'], -1)
        self.dungeon_buttons['save'].set_sensitive(False)

        # VIEW BAR
        self.dungeon_buttons['home'] = ToolButton('go-home')
        self.dungeon_buttons['home'].set_tooltip(_("Welcome Screen"))
        self.dungeon_buttons['home'].connect("clicked", self.view_change_cb,
                                             'home')
        self.view_bar.insert(self.dungeon_buttons['home'], -1)

        self.dungeon_buttons['settings'] = ToolButton('view-spiral')
        self.dungeon_buttons['settings'].set_tooltip(
            _("View Dungeon Settings"))
        self.dungeon_buttons['settings'].connect("clicked",
                                                 self.view_change_cb,
                                                 'settings')
        self.view_bar.insert(self.dungeon_buttons['settings'], -1)
        self.dungeon_buttons['settings'].set_sensitive(False)

        self.dungeon_buttons['layout'] = ToolButton('view-freeform')
        self.dungeon_buttons['layout'].set_tooltip(_("View Dungeon Layout"))
        self.dungeon_buttons['layout'].connect("clicked", self.view_change_cb,
                                               'layout')
        self.view_bar.insert(self.dungeon_buttons['layout'], -1)
        self.dungeon_buttons['layout'].set_sensitive(False)

        self.toolbox = ActivityToolbox(self)

        # Remove Share Bar
        activity_toolbar = self.toolbox.get_activity_toolbar()
        activity_toolbar.remove(activity_toolbar.share)
        activity_toolbar.share = None

        #Add our custom items to the toolbar
        self.toolbox.add_toolbar(_("Dungeon"), self.dungeon_bar)
        self.toolbox.add_toolbar(_("View"), self.view_bar)

        self.set_toolbox(self.toolbox)
        self.toolbox.show()