Exemplo n.º 1
0
    def __init__(self, handle):
        """Creates a plotter application window."""
        activity.Activity.__init__(self, handle)

        # create toolbox: this provides default sugar controls
        toolbox = activity.ActivityToolbox(self)
        self.set_toolbox(toolbox)
        toolbox.show()

        # setup container for glade widgets
        main_view = gtk.VBox()

        # load Glade XML and get main window
        # get the VBox that's a child of the glade window
        self._app = app = Plotter()
        app.plot_scrolledwindow.reparent(main_view)
        app.plot_scrolledwindow.show()

        # create edit toolbar
        edit_toolbar = activity.EditToolbar()
        toolbox.add_toolbar(_("Edit"), edit_toolbar)
        edit_toolbar.show()

        # connect undo/redo to app events
        edit_toolbar.undo.connect("clicked", app.on_undo)
        edit_toolbar.redo.connect("clicked", app.on_redo)
        edit_toolbar.copy.connect("clicked", app.on_copy)
        edit_toolbar.paste.connect("clicked", app.on_paste)

        # make main_view act as our canvas
        main_view.show()
        self.set_canvas(main_view)
        self.show_all()
Exemplo n.º 2
0
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)

        logging.debug('Starting the Frotz activity')

        self.set_title(_('Frotz'))
        self.connect('key-press-event', self.__key_press_cb)

        toolbox = activity.ActivityToolbox(self)

        self._edit_toolbar = activity.EditToolbar()
        toolbox.add_toolbar(_('Edit'), self._edit_toolbar)
        self._edit_toolbar.show()
        self._edit_toolbar.undo.props.visible = False
        self._edit_toolbar.redo.props.visible = False
        self._edit_toolbar.separator.props.visible = False
        self._edit_toolbar.copy.connect('clicked', self._copy_cb)
        self._edit_toolbar.paste.connect('clicked', self._paste_cb)

        activity_toolbar = toolbox.get_activity_toolbar()
        activity_toolbar.share.props.visible = False
        activity_toolbar.keep.props.visible = False

        # Add a button that will send you to the ifarchive to get more games
        activity_toolbar.get_games = ToolButton('activity-get-games')
        activity_toolbar.get_games.set_tooltip(_('Get More Games'))
        activity_toolbar.get_games.connect('clicked', self._get_games_cb)
        activity_toolbar.insert(activity_toolbar.get_games, 2)
        activity_toolbar.get_games.show()

        self.set_toolbox(toolbox)
        toolbox.show()

        box = gtk.HBox(False, 4)

        self._vte = VTE()
        self._vte.show()
        self._vte.connect("child-exited", self._quit_cb)

        scrollbar = gtk.VScrollbar(self._vte.get_adjustment())
        scrollbar.show()

        box.pack_start(self._vte)
        box.pack_start(scrollbar, False, False, 0)

        self.set_canvas(box)
        box.show()

        self._vte.grab_focus()

        self.game_started = False
        default_game_file = os.path.join(activity.get_bundle_path(),
                                         "Advent.z5")
        # when we return to the idle state, launch the default game
        # if read_file is called, that will override this
        gobject.idle_add(self.start_game, default_game_file)
Exemplo n.º 3
0
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)

        #setup activity sharing here!!!

        self.canvas = sim.Canvas()
        self.canvas.show()

        # Creates the Toolbox. It contains the Activity Toolbar, which is the
        # bar that appears on every Sugar window and contains essential
        # functionalities, such as the 'Collaborate' and 'Close' buttons.
        toolbox = activity.ActivityToolbox(self)

        self.edit_toolbar = activity.EditToolbar()
        toolbox.add_toolbar(_('Edit'), self.edit_toolbar)
        self.edit_toolbar.show()

        self.model_toolbar = sim.ModelToolbar()
        toolbox.add_toolbar(_('Model'), self.model_toolbar)
        self.model_toolbar.show()

        self.model_toolbar.stock.connect('toggled', self.drawing_tool_toggled)
        self.model_toolbar.flow.connect('toggled', self.drawing_tool_toggled)
        self.model_toolbar.influence.connect('toggled',
                                             self.drawing_tool_toggled)
        self.model_toolbar.variable.connect('toggled',
                                            self.drawing_tool_toggled)

        self.simulate_toolbar = sim.SimulateToolbar()
        toolbox.add_toolbar(_('Simulate'), self.simulate_toolbar)
        self.simulate_toolbar.show()

        self.view_toolbar = sim.ViewToolbar()
        toolbox.add_toolbar(_('View'), self.view_toolbar)
        self.view_toolbar.show()

        self.set_toolbox(toolbox)
        toolbox.show()

        self.set_canvas(self.canvas)
Exemplo n.º 4
0
    def __init__(self, handle):
        import gtk
        import pango
        import vte
        from sugar.graphics.toolbutton import ToolButton
        from gettext import gettext as _
        super(VteActivity, self).__init__(handle)
        toolbox = activity.ActivityToolbox(self)
        toolbar = toolbox.get_activity_toolbar()
        self.set_toolbox(toolbox)
        toolbox.show()

        # add 'copy' icon from standard toolbar.
        edittoolbar = activity.EditToolbar()
        edittoolbar.copy.set_tooltip(_('Copy selected text to clipboard'))
        edittoolbar.copy.connect('clicked', self._on_copy_clicked_cb)
        edittoolbar.paste.connect('clicked', self._on_paste_clicked_cb)
        # as long as nothing is selected, copy needs to be insensitive.
        edittoolbar.copy.set_sensitive(False)
        toolbox.add_toolbar(_('Edit'), edittoolbar)
        edittoolbar.show()
        self._copy_button = edittoolbar.copy

        # creates vte widget
        self._vte = vte.Terminal()
        self._vte.set_size(30, 5)
        self._vte.set_size_request(200, 300)
        font = 'Monospace 10'
        self._vte.set_font(pango.FontDescription(font))
        self._vte.set_colors(gtk.gdk.color_parse('#000000'),
                             gtk.gdk.color_parse('#E7E7E7'), [])
        self._vte.connect('selection-changed', self._on_selection_changed_cb)
        self._vte.drag_dest_set(gtk.DEST_DEFAULT_ALL,
                                [("text/plain", 0, TARGET_TYPE_TEXT)],
                                gtk.gdk.ACTION_COPY)
        self._vte.connect('drag_data_received', self._on_drop_cb)
        # ...and its scrollbar
        vtebox = gtk.HBox()
        vtebox.pack_start(self._vte)
        vtesb = gtk.VScrollbar(self._vte.get_adjustment())
        vtesb.show()
        vtebox.pack_start(vtesb, False, False, 0)
        self.set_canvas(vtebox)
        self.show_all()
        # hide the buttons we don't use.
        toolbar.share.hide()  # this should share bundle.
        toolbar.keep.hide()
        edittoolbar.undo.hide()
        edittoolbar.redo.hide()
        edittoolbar.separator.hide()

        # now start subprocess.
        self._vte.connect('child-exited', self.on_child_exit)
        self._vte.grab_focus()
        bundle_path = activity.get_bundle_path()
        # the 'sleep 1' works around a bug with the command dying before
        # the vte widget manages to snarf the last bits of its output
        self._pid = self._vte.fork_command(
            command='/bin/sh',
            argv=[
                '/bin/sh', '-c',
                'python %s/pippy_app.py; sleep 1' % bundle_path
            ],
            envv=["PYTHONPATH=%s/library" % bundle_path],
            directory=bundle_path)
    def __init__(self, handle):
        "The entry point to the Activity"
        global page
        activity.Activity.__init__(self, handle)
        
        toolbox = activity.ActivityToolbox(self)
        activity_toolbar = toolbox.get_activity_toolbar()
        activity_toolbar.keep.props.visible = False
        activity_toolbar.share.props.visible = False

        self.edit_toolbar = activity.EditToolbar()
        self.edit_toolbar.undo.props.visible = False
        self.edit_toolbar.redo.props.visible = False
        self.edit_toolbar.separator.props.visible = False
        self.edit_toolbar.copy.set_sensitive(False)
        self.edit_toolbar.copy.connect('clicked', self.edit_toolbar_copy_cb)
        self.edit_toolbar.paste.props.visible = False
        toolbox.add_toolbar(_('Edit'), self.edit_toolbar)
        self.edit_toolbar.show()
        
        self.read_toolbar = ReadToolbar()
        toolbox.add_toolbar(_('Read'), self.read_toolbar)
        self.read_toolbar.back.connect('clicked', self.go_back_cb)
        self.read_toolbar.forward.connect('clicked', self.go_forward_cb)
        self.read_toolbar.num_page_entry.connect('activate',
                                     self.num_page_entry_activate_cb)
        self.read_toolbar.show()

        self.view_toolbar = ViewToolbar()
        toolbox.add_toolbar(_('View'), self.view_toolbar)
        self.view_toolbar.connect('go-fullscreen',
                self.view_toolbar_go_fullscreen_cb)
        self.view_toolbar.zoom_in.connect('clicked', self.zoom_in_cb)
        self.view_toolbar.zoom_out.connect('clicked', self.zoom_out_cb)
        self.view_toolbar.show()

        self.set_toolbox(toolbox)
        toolbox.show()
        self.scrolled_window = gtk.ScrolledWindow()
        self.scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
        self.scrolled_window.props.shadow_type = gtk.SHADOW_NONE

        self.textview = gtk.TextView()
        self.textview.set_editable(False)
        self.textview.set_cursor_visible(False)
        self.textview.set_left_margin(50)
        self.textview.connect("key_press_event", self.keypress_cb)

        self.scrolled_window.add(self.textview)
        self.set_canvas(self.scrolled_window)
        self.textview.show()
        self.scrolled_window.show()
        page = 0
        self.clipboard = gtk.Clipboard(display=gtk.gdk.display_get_default(), \
                                       selection="CLIPBOARD")
        self.textview.grab_focus()
        self.font_desc = pango.FontDescription("sans %d" % style.zoom(10))
        self.textview.modify_font(self.font_desc)

        buffer = self.textview.get_buffer()
        self.markset_id = buffer.connect("mark-set", self.mark_set_cb)
        self.toolbox.set_current_toolbar(TOOLBAR_READ)
Exemplo n.º 6
0
    def initialize_display(self):
        self._logger = logging.getLogger('butialo-activity')

        # Top toolbar with share and close buttons:

        if OLD_TOOLBAR:
            activity_toolbar = self.toolbox.get_activity_toolbar()
        else:
            activity_toolbar = self.activity_button.page

        # add 'make bundle' entry to 'keep' palette.
        palette = activity_toolbar.keep.get_palette()
        # XXX: should clear out old palette entries?
        from sugar.graphics.menuitem import MenuItem
        from sugar.graphics.icon import Icon
        menu_item = MenuItem(_('As Butialo Document'))
        menu_item.set_image(Icon(file=('%s/activity/activity-icon.svg' %
                                       get_bundle_path()),
                                 icon_size=gtk.ICON_SIZE_MENU))
        menu_item.connect('activate', self.keepbutton_cb)
        palette.menu.append(menu_item)
        menu_item.show()
        #xop guardar como bundle
        #menu_item = MenuItem(_('As Activity Bundle'))
        #menu_item.set_image(Icon(file=('%s/activity/activity-default.svg' %
        #                               get_bundle_path()),
        #                         icon_size=gtk.ICON_SIZE_MENU))
        #menu_item.connect('activate', self.makebutton_cb)
        #palette.menu.append(menu_item)
        #menu_item.show()

        self._edit_toolbar = activity.EditToolbar()

        if OLD_TOOLBAR:
            activity_toolbar = gtk.Toolbar()
            self.toolbox.add_toolbar(_('Actions'), activity_toolbar)
            self.toolbox.set_current_toolbar(1)
            self.toolbox.add_toolbar(_('Edit'), self._edit_toolbar)
        else:
            edit_toolbar_button = ToolbarButton()
            edit_toolbar_button.set_page(self._edit_toolbar)
            edit_toolbar_button.props.icon_name = 'toolbar-edit'
            edit_toolbar_button.props.label = _('Edit')
            self.get_toolbar_box().toolbar.insert(edit_toolbar_button, -1)

        self._edit_toolbar.show()

        self._edit_toolbar.undo.connect('clicked', self.__undobutton_cb)
        self._edit_toolbar.redo.connect('clicked', self.__redobutton_cb)
        self._edit_toolbar.copy.connect('clicked', self.__copybutton_cb)
        self._edit_toolbar.paste.connect('clicked', self.__pastebutton_cb)

        if OLD_TOOLBAR:
            actions_toolbar = activity_toolbar
        else:
            actions_toolbar = self.get_toolbar_box().toolbar

        # The "go" button
        goicon_bw = gtk.Image()
        goicon_bw.set_from_file("%s/icons/run_bw.svg" % os.getcwd())
        goicon_color = gtk.Image()
        goicon_color.set_from_file("%s/icons/run_color.svg" % os.getcwd())
        gobutton = ToolButton(label=_("_Run!"))
        gobutton.props.accelerator = _('<alt>r')
        gobutton.set_icon_widget(goicon_bw)
        gobutton.set_tooltip("Run")
        gobutton.connect('clicked', self.flash_cb, dict({'bw': goicon_bw,
            'color': goicon_color}))
        gobutton.connect('clicked', self.gobutton_cb)
        actions_toolbar.insert(gobutton, -1)

        # The "stop" button
        stopicon_bw = gtk.Image()
        stopicon_bw.set_from_file("%s/icons/stopit_bw.svg" % os.getcwd())
        stopicon_color = gtk.Image()
        stopicon_color.set_from_file("%s/icons/stopit_color.svg" % os.getcwd())
        stopbutton = ToolButton(label=_("_Stop"))
        stopbutton.props.accelerator = _('<alt>s')
        stopbutton.set_icon_widget(stopicon_bw)
        stopbutton.connect('clicked', self.flash_cb, dict({'bw': stopicon_bw,
            'color': stopicon_color}))
        stopbutton.connect('clicked', self.stopbutton_cb)
        stopbutton.set_tooltip("Stop Running")
        actions_toolbar.insert(stopbutton, -1)

        # The "refresh" button
        refreshicon_bw = gtk.Image()
        refreshicon_bw.set_from_file("%s/icons/butiaoff.svg" % os.getcwd())
        refreshicon_color = gtk.Image()
        refreshicon_color.set_from_file("%s/icons/butiaon.svg" % os.getcwd())
        refreshbutton = ToolButton(label=_("_Reload"))
        refreshbutton.props.accelerator = _('<alt>d')
        refreshbutton.set_icon_widget(refreshicon_bw)
        refreshbutton.connect('clicked', self.flash_cb, dict({'bw': refreshicon_bw,
            'color': refreshicon_color}))
        refreshbutton.connect('clicked', self.initialize_snippets_cb)
        refreshbutton.set_tooltip("Reload devices")
        actions_toolbar.insert(refreshbutton, -1)

        # The "clear" button
        #clearicon_bw = gtk.Image()
        #clearicon_bw.set_from_file("%s/icons/eraser_bw.svg" % os.getcwd())
        #clearicon_color = gtk.Image()
        #clearicon_color.set_from_file("%s/icons/eraser_color.svg" %
        #                              os.getcwd())
        #clearbutton = ToolButton(label=_("_Clear"))
        #clearbutton.props.accelerator = _('<alt>c')
        #clearbutton.set_icon_widget(clearicon_bw)
        #clearbutton.connect('clicked', self.clearbutton_cb)
        #clearbutton.connect('clicked', self.flash_cb, dict({'bw': clearicon_bw,
        #    'color': clearicon_color}))
        #clearbutton.set_tooltip("Clear")
        #actions_toolbar.insert(clearbutton, -1)

        # The "beautify" button
        beautifyicon_bw = gtk.Image()
        beautifyicon_bw.set_from_file("%s/icons/beautifyicon_bw.svg" % os.getcwd())
        beautifyicon_color = gtk.Image()
        beautifyicon_color.set_from_file("%s/icons/beautifyicon_color.svg" %
                                      os.getcwd())
        beautifybutton = ToolButton(label=_("_Auto-format"))
        beautifybutton.props.accelerator = _('<alt>f')
        beautifybutton.set_icon_widget(beautifyicon_bw)
        beautifybutton.connect('clicked', self.beautifybutton_cb)
        beautifybutton.connect('clicked', self.flash_cb, dict({'bw': beautifyicon_bw,
            'color': beautifyicon_color}))
        beautifybutton.set_tooltip("Auto-format")
        actions_toolbar.insert(beautifybutton, -1)

        activity_toolbar.show()

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

            stop = StopButton(self)
            self.get_toolbar_box().toolbar.insert(stop, -1)

        # Main layout.
        self.hpane = gtk.HPaned()
        self.vpane = gtk.VPaned()

        # The sidebar.
        self.sidebar = gtk.VBox()
        self.model = gtk.TreeStore(gobject.TYPE_PYOBJECT, gobject.TYPE_STRING)
        treeview = gtk.TreeView(self.model)
        cellrenderer = gtk.CellRendererText()
        treecolumn = gtk.TreeViewColumn(_("Available"), cellrenderer, text=1)
        treeview.get_selection().connect("changed", self.selection_cb)
        treeview.append_column(treecolumn)
        treeview.set_size_request(int(SIZE_X * 0.3), SIZE_Y)

        # Create scrollbars around the view.
        scrolled = gtk.ScrolledWindow()
        scrolled.add(treeview)
        self.sidebar.pack_start(scrolled)
        self.hpane.add1(self.sidebar)

        #root = os.path.join(get_bundle_path(), 'data')

        #initialize snippets 
        self.initialize_snippets_cb(None)

        # Source buffer
        import gtksourceview2
        global text_buffer
        lang_manager = gtksourceview2.language_manager_get_default()
        if hasattr(lang_manager, 'list_languages'):
            langs = lang_manager.list_languages()
        else:
            lang_ids = lang_manager.get_language_ids()
            langs = [lang_manager.get_language(lang_id)
                     for lang_id in lang_ids]
        for lang in langs:
            for m in lang.get_mime_types():
                if m == "text/x-lua":
                    text_buffer.set_language(lang)

        if hasattr(text_buffer, 'set_highlight'):
            text_buffer.set_highlight(True)
        else:
            text_buffer.set_highlight_syntax(True)

        # The GTK source view window
        self.text_view = gtksourceview2.View(text_buffer)
        self.text_view.set_size_request(0, int(SIZE_Y * 0.5))
        self.text_view.set_editable(True)
        self.text_view.set_cursor_visible(True)
        self.text_view.set_show_line_numbers(True)
        self.text_view.set_wrap_mode(gtk.WRAP_CHAR)
        self.text_view.set_insert_spaces_instead_of_tabs(True)
        self.text_view.set_tab_width(2)
        self.text_view.set_auto_indent(True)
        self.text_view.modify_font(pango.FontDescription("Monospace " +
            str(font_zoom(style.FONT_SIZE))))

        # We could change the color theme here, if we want to.
        #mgr = gtksourceview2.style_manager_get_default()
        #style_scheme = mgr.get_scheme('kate')
        #self.text_buffer.set_style_scheme(style_scheme)

        codesw = gtk.ScrolledWindow()
        codesw.set_policy(gtk.POLICY_AUTOMATIC,
                      gtk.POLICY_AUTOMATIC)
        codesw.add(self.text_view)
        self.vpane.add1(codesw)

        # An hbox to hold the vte window and its scrollbar.
        outbox = gtk.HBox()

        # The vte python window
        self._vte = vte.Terminal()
        self._vte.set_encoding('utf-8')
        self._vte.set_size(30, 5)
        font = 'Monospace ' + str(font_zoom(style.FONT_SIZE))
        self._vte.set_font(pango.FontDescription(font))
        self._vte.set_colors(gtk.gdk.color_parse('#000000'),
                             gtk.gdk.color_parse('#E7E7E7'),
                             [])
        self._vte.connect('child_exited', self.child_exited_cb)
        self._child_exited_handler = None
        self._vte.drag_dest_set(gtk.DEST_DEFAULT_ALL,
                                [("text/plain", 0, TARGET_TYPE_TEXT)],
                                gtk.gdk.ACTION_COPY)
        self._vte.connect('drag_data_received', self.vte_drop_cb)
        outbox.pack_start(self._vte)

        outsb = gtk.VScrollbar(self._vte.get_adjustment())
        outsb.show()
        outbox.pack_start(outsb, False, False, 0)
        self.vpane.add2(outbox)
        self.hpane.add2(self.vpane)
        return self.hpane