Exemplo n.º 1
0
 def _build_palette(self, tool):
     if tool.palette_enabled:
         if tool.palette_mode == tools.PALETTE_MODE_ICONS:
             grid = Gtk.Grid()
             for s, settings in enumerate(tool.palette_settings):
                 self.game.toolList[tool.name].buttons.append([])
                 for i, icon_value in enumerate(settings['icon_values']):
                     if i == 0:
                         button = RadioToolButton(group=None)
                         firstbutton = button
                     else:
                         button = RadioToolButton(group=firstbutton)
                     button.set_icon_name(settings['icons'][i])
                     button.connect('clicked',
                                    self._palette_icon_clicked,
                                    tool.name,
                                    s,
                                    settings['name'],
                                    icon_value)
                     grid.attach(button, i, s, 1, 1)
                     self.game.toolList[tool.name].buttons[s].append(button)
                     button.show()
                     if settings['active'] == settings['icons'][i]:
                         button.set_icon_name(settings['icons'][i] +
                                              '-selected')
                         button.set_active(True)
             return grid
     else:
         return None
Exemplo n.º 2
0
 def _build_palette(self, tool):
     if tool.palette_enabled:
         if tool.palette_mode == tools.PALETTE_MODE_ICONS:
             grid = Gtk.Grid()
             for s, settings in enumerate(tool.palette_settings):
                 self.game.toolList[tool.name].buttons.append([])
                 for i, icon_value in enumerate(settings['icon_values']):
                     if i == 0:
                         button = RadioToolButton(group=None)
                         firstbutton = button
                     else:
                         button = RadioToolButton(group=firstbutton)
                     button.set_icon_name(settings['icons'][i])
                     button.connect('clicked', self._palette_icon_clicked,
                                    tool.name, s, settings['name'],
                                    icon_value)
                     grid.attach(button, i, s, 1, 1)
                     self.game.toolList[tool.name].buttons[s].append(button)
                     button.show()
                     if settings['active'] == settings['icons'][i]:
                         button.set_icon_name(settings['icons'][i] +
                                              '-selected')
                         button.set_active(True)
             return grid
     else:
         return None
Exemplo n.º 3
0
    def __init__(self, favorite_view):
        RadioToolButton.__init__(self)

        self.props.tooltip = _('Favorites view %d' % (favorite_view + 1))
        self.props.accelerator = _('<Ctrl>%d' % (favorite_view + 1))
        self.props.group = None
        self.props.icon_name = desktop.get_view_icons()[favorite_view]

        favorites_settings = favoritesview.get_settings(favorite_view)
        self._layout = favorites_settings.layout

        # someday, this will be a Gtk.Table()
        layouts_grid = Gtk.HBox()
        layout_item = None
        for layoutid, layoutclass in sorted(favoritesview.LAYOUT_MAP.items()):
            layout_item = RadioToolButton(icon_name=layoutclass.icon_name,
                                          group=layout_item,
                                          active=False)
            if layoutid == self._layout:
                layout_item.set_active(True)
            layouts_grid.pack_start(layout_item, True, False, 0)
            layout_item.connect('toggled', self.__layout_activate_cb, layoutid,
                                favorite_view)
        layouts_grid.show_all()
        self.props.palette.set_content(layouts_grid)
Exemplo n.º 4
0
    def _create_chart_buttons(self, toolbar):
        add_vbar_chart = RadioToolButton()
        add_vbar_chart.set_tooltip(_('Vertical Bar Chart'))
        add_vbar_chart.props.icon_name = 'vbar'
        charts_group = add_vbar_chart

        toolbar.insert(add_vbar_chart, -1)

        add_hbar_chart = RadioToolButton()
        add_hbar_chart.set_tooltip(_('Horizontal Bar Chart'))
        add_hbar_chart.props.icon_name = 'hbar'
        add_hbar_chart.props.group = charts_group
        toolbar.insert(add_hbar_chart, -1)

        add_line_chart = RadioToolButton()
        add_line_chart.set_tooltip(_('Line Chart'))
        add_line_chart.props.icon_name = 'line'
        add_line_chart.props.group = charts_group
        toolbar.insert(add_line_chart, -1)

        add_pie_chart = RadioToolButton()
        add_pie_chart.set_active(True)
        add_pie_chart.set_tooltip(_('Pie Chart'))
        add_pie_chart.props.icon_name = 'pie'
        add_pie_chart.props.group = charts_group
        toolbar.insert(add_pie_chart, -1)

        add_vbar_chart.connect('toggled', self._add_chart_cb,
                               charts.VERTICAL_BAR)
        add_hbar_chart.connect('toggled', self._add_chart_cb,
                               charts.HORIZONTAL_BAR)
        add_line_chart.connect('toggled', self._add_chart_cb, charts.LINE)
        add_pie_chart.connect('toggled', self._add_chart_cb, charts.PIE)

        self.chart_type_buttons.append(add_vbar_chart)
        self.chart_type_buttons.append(add_hbar_chart)
        self.chart_type_buttons.append(add_line_chart)
        self.chart_type_buttons.append(add_pie_chart)

        self._add_chart_cb(add_vbar_chart, charts.VERTICAL_BAR)
Exemplo n.º 5
0
    def _insert_stop_play_button(self, toolbar):

        self.stop_play_toolbar = ToolbarButton()
        st_toolbar = self.stop_play_toolbar
        st_toolbar.props.page = Gtk.Toolbar()
        st_toolbar.props.icon_name = "media-playback-stop"

        self.stop_play_state = True
        self.stop_play = ToolButton("media-playback-stop")
        self.stop_play.set_tooltip(_("Stop"))
        self.stop_play.set_accelerator(_("<ctrl>space"))
        self.stop_play.connect("clicked", self.stop_play_cb)
        self._insert_item(st_toolbar, self.stop_play)
        self.stop_play.show()

        slowest_button = RadioToolButton(group=None)
        slowest_button.set_icon_name("slow-walk-milton-raposo")
        slowest_button.set_tooltip(_("Run slower"))
        slowest_button.connect("clicked", self._set_fps_cb, SLOWEST_FPS)
        self._insert_item(st_toolbar, slowest_button)
        slowest_button.show()

        slow_button = RadioToolButton(group=slowest_button)
        slow_button.set_icon_name("walking")
        slow_button.set_tooltip(_("Run slow"))
        slow_button.connect("clicked", self._set_fps_cb, SLOW_FPS)
        self._insert_item(st_toolbar, slow_button)
        slow_button.show()

        fast_button = RadioToolButton(group=slowest_button)
        fast_button.set_icon_name("running")
        fast_button.set_tooltip("Run fast")
        fast_button.connect("clicked", self._set_fps_cb, FAST_FPS)
        self._insert_item(st_toolbar, fast_button)
        fast_button.show()
        fast_button.set_active(True)

        toolbar.insert(self.stop_play_toolbar, -1)
        self.stop_play_toolbar.show_all()
Exemplo n.º 6
0
    def _insert_stop_play_button(self, toolbar):

        self.stop_play_toolbar = ToolbarButton()
        st_toolbar = self.stop_play_toolbar
        st_toolbar.props.page = Gtk.Toolbar()
        st_toolbar.props.icon_name = 'media-playback-stop'

        self.stop_play_state = True
        self.stop_play = ToolButton('media-playback-stop')
        self.stop_play.set_tooltip(_('Stop'))
        self.stop_play.set_accelerator(_('<ctrl>space'))
        self.stop_play.connect('clicked', self.stop_play_cb)
        self._insert_item(st_toolbar, self.stop_play)
        self.stop_play.show()

        slowest_button = RadioToolButton(group=None)
        slowest_button.set_icon_name('slow-walk-milton-raposo')
        slowest_button.set_tooltip(_('Run slower'))
        slowest_button.connect('clicked', self._set_fps_cb, SLOWEST_FPS)
        self._insert_item(st_toolbar, slowest_button)
        slowest_button.show()

        slow_button = RadioToolButton(group=slowest_button)
        slow_button.set_icon_name('walking')
        slow_button.set_tooltip(_('Run slow'))
        slow_button.connect('clicked', self._set_fps_cb, SLOW_FPS)
        self._insert_item(st_toolbar, slow_button)
        slow_button.show()

        fast_button = RadioToolButton(group=slowest_button)
        fast_button.set_icon_name('running')
        fast_button.set_tooltip('Run fast')
        fast_button.connect('clicked', self._set_fps_cb, FAST_FPS)
        self._insert_item(st_toolbar, fast_button)
        fast_button.show()
        fast_button.set_active(True)

        toolbar.insert(self.stop_play_toolbar, -1)
        self.stop_play_toolbar.show_all()
Exemplo n.º 7
0
    def __init__(self, favorite_view):
        RadioToolButton.__init__(self)

        self.props.tooltip = desktop.get_favorite_names()[favorite_view]
        self.props.accelerator = _("<Ctrl>%d" % (favorite_view + 1))
        self.props.group = None
        self.props.icon_name = desktop.get_view_icons()[favorite_view]

        favorites_settings = favoritesview.get_settings(favorite_view)
        self._layout = favorites_settings.layout

        # someday, this will be a Gtk.Table()
        layouts_grid = Gtk.HBox()
        layout_item = None
        for layoutid, layoutclass in sorted(favoritesview.LAYOUT_MAP.items()):
            layout_item = RadioToolButton(icon_name=layoutclass.icon_name, group=layout_item, active=False)
            if layoutid == self._layout:
                layout_item.set_active(True)
            layouts_grid.pack_start(layout_item, True, False, 0)
            layout_item.connect("toggled", self.__layout_activate_cb, layoutid, favorite_view)
        layouts_grid.show_all()
        self.props.palette.set_content(layouts_grid)
Exemplo n.º 8
0
    def _insert_stop_play_button(self, toolbar):

        self.stop_play_toolbar = ToolbarButton()
        st_toolbar = self.stop_play_toolbar
        st_toolbar.props.page = Gtk.Toolbar()
        st_toolbar.props.icon_name = 'media-playback-stop'

        self.stop_play_state = True
        self.stop_play = ToolButton('media-playback-stop')
        self.stop_play.set_tooltip(_('Stop'))
        self.stop_play.set_accelerator(_('<ctrl>space'))
        self.stop_play.connect('clicked', self.stop_play_cb)
        self._insert_item(st_toolbar, self.stop_play)
        self.stop_play.show()

        slowest_button = RadioToolButton(group=None)
        slowest_button.set_icon_name('slow-walk-milton-raposo')
        slowest_button.set_tooltip(_('Run slower'))
        slowest_button.connect('clicked', self._set_fps_cb, SLOWEST_FPS)
        self._insert_item(st_toolbar, slowest_button)
        slowest_button.show()

        slow_button = RadioToolButton(group=slowest_button)
        slow_button.set_icon_name('walking')
        slow_button.set_tooltip(_('Run slow'))
        slow_button.connect('clicked', self._set_fps_cb, SLOW_FPS)
        self._insert_item(st_toolbar, slow_button)
        slow_button.show()

        fast_button = RadioToolButton(group=slowest_button)
        fast_button.set_icon_name('running')
        fast_button.set_tooltip('Run fast')
        fast_button.connect('clicked', self._set_fps_cb, FAST_FPS)
        self._insert_item(st_toolbar, fast_button)
        fast_button.show()
        fast_button.set_active(True)

        toolbar.insert(self.stop_play_toolbar, -1)
        self.stop_play_toolbar.show_all()
Exemplo n.º 9
0
    def __init__(self):
        RadioToolButton.__init__(self)

        self.props.tooltip = _('Favorites view')
        self.props.accelerator = _('<Ctrl>1')
        self.props.group = None

        favorites_settings = favoritesview.get_settings()
        self._layout = favorites_settings.layout
        self._update_icon()

        # someday, this will be a Gtk.Table()
        layouts_grid = Gtk.HBox()
        layout_item = None
        for layoutid, layoutclass in sorted(favoritesview.LAYOUT_MAP.items()):
            layout_item = RadioToolButton(icon_name=layoutclass.icon_name,
                                          group=layout_item, active=False)
            if layoutid == self._layout:
                layout_item.set_active(True)
            layouts_grid.pack_start(layout_item, True, False, 0)
            layout_item.connect('toggled', self.__layout_activate_cb,
                                layoutid)
        layouts_grid.show_all()
        self.props.palette.set_content(layouts_grid)
Exemplo n.º 10
0
    def __init__(self, handle):
        """Set up the Develop activity."""
        self._dirty = False
        super(DevelopActivity, self).__init__(handle)
        self.max_participants = 1

        self.current_theme = "light"

        logging.info(repr(handle.get_dict()))

        # Source buffer
        self.editor = sourceview_editor.GtkSourceview2Editor()
        self.editor.connect('tab-changed', self.__editor_tab_changed_cb)
        self.editor.connect('changed', self.__editor_changed_cb)
        # Show tabs after Welcome Page
        self.editor.set_show_tabs(False)

        toolbarbox = ToolbarBox()
        activity_button = ActivityToolbarButton(self)
        toolbarbox.toolbar.insert(activity_button, 0)
        self.set_toolbar_box(toolbarbox)

        view_btn = ToolbarButton()
        view_toolbar = DevelopViewToolbar(self)
        view_btn.props.page = view_toolbar
        view_btn.props.icon_name = 'toolbar-view'
        view_btn.props.label = _('View')
        view_toolbar.connect('theme-changed', self.editor.theme_changed_cb)
        view_toolbar.connect('font-size-changed', self.editor.font_changed_cb)
        toolbarbox.toolbar.insert(view_btn, -1)
        self.view_toolbar = view_toolbar

        edit_btn = ToolbarButton()
        edit_btn.props.page = DevelopEditToolbar(self)
        edit_btn.props.icon_name = 'toolbar-edit'
        edit_btn.props.label = _('Edit')
        toolbarbox.toolbar.insert(edit_btn, -1)

        search_btn = ToolbarButton()
        search_btn.props.page = DevelopSearchToolbar(self)
        search_btn.props.icon_name = 'search'
        search_btn.props.label = _('Search')
        toolbarbox.toolbar.insert(search_btn, -1)

        toolbarbox.toolbar.insert(Gtk.SeparatorToolItem(), -1)

        show_files_btn = RadioToolButton()
        show_files_btn.props.icon_name = 'sources'
        show_files_btn.props.group = show_files_btn
        show_files_btn.set_active(True)
        show_files_btn.set_tooltip(_('Show source files'))
        toolbarbox.toolbar.insert(show_files_btn, -1)
        show_files_btn.connect('clicked', self._change_treenotebook_page, 0)

        show_symbols_btn = RadioToolButton()
        show_symbols_btn.props.icon_name = 'symbols'
        show_symbols_btn.props.group = show_files_btn
        show_symbols_btn.set_active(False)
        show_symbols_btn.set_tooltip(_('Show file symbols'))
        toolbarbox.toolbar.insert(show_symbols_btn, -1)
        show_symbols_btn.connect('clicked', self._explore_code)

        show_log_btn = RadioToolButton()
        show_log_btn.props.icon_name = 'logs'
        show_log_btn.props.group = show_files_btn
        show_log_btn.set_active(False)
        show_log_btn.set_tooltip(_('Show log files'))
        toolbarbox.toolbar.insert(show_log_btn, -1)
        show_log_btn.connect('clicked', self._change_treenotebook_page, 2)

        toolbarbox.toolbar.insert(Gtk.SeparatorToolItem(), -1)

        create_file_btn = ToolButton('text-x-generic')
        create_file_btn.set_tooltip(_('Create empty file'))
        toolbarbox.toolbar.insert(create_file_btn, -1)
        create_file_btn.show()
        create_file_btn.connect('clicked', self.__create_empty_file_cb)

        erase_btn = ToolButton('erase')
        erase_btn.set_tooltip(_('Remove file'))
        toolbarbox.toolbar.insert(erase_btn, -1)
        erase_btn.show()
        erase_btn.connect('clicked', self.__remove_file_cb)

        toolbarbox.toolbar.insert(Gtk.SeparatorToolItem(), -1)

        run_btn = ToolButton('activity-start')
        run_btn.set_tooltip(_('Run activity'))
        toolbarbox.toolbar.insert(run_btn, -1)
        run_btn.connect('clicked', self.__run_actvity_cb)

        separator = Gtk.SeparatorToolItem()
        separator.set_draw(False)
        separator.set_expand(True)
        toolbarbox.toolbar.insert(separator, -1)

        stopbtn = StopButton(self)
        toolbarbox.toolbar.insert(stopbtn, -1)

        save_bundle_btn = ToolButton('save-as-bundle')
        save_bundle_btn.set_tooltip(_('Create bundle (.xo file)'))
        activity_button.get_page().insert(save_bundle_btn, -1)
        save_bundle_btn.connect('clicked', self.save_bundle)
        save_bundle_btn.show()

        toolbarbox.show_all()

        # Main layout.
        hbox = Gtk.HPaned()

        # The treeview and selected pane reflect each other.
        self.numb = False

        # Wait to save until first change, but save an unchanged
        # backup copy when that happens.
        self.save_unchanged = False

        # The sidebar
        sidebar = Gtk.VBox()
        self.treenotebook = notebook.Notebook(can_close_tabs=False)
        self.treenotebook.set_show_tabs(False)
        sidebar.pack_start(self.treenotebook, True, True, 0)

        self.activity_tree_view = FileViewer()
        self.treenotebook.add_page(_("Activity"), self.activity_tree_view)
        self.treenotebook.set_size_request(Gdk.Screen.width() / 5, -1)

        # Symbols tree
        self._symbolstree = SymbolsTree()
        self._symbolstree.connect('symbol-selected',
                                  self.editor.symbol_selected_cb)
        scrolled = Gtk.ScrolledWindow()
        scrolled.add(self._symbolstree)
        scrolled.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        self.treenotebook.add_page(_('Symbols Tree'), scrolled)

        hbox.pack1(sidebar, resize=True, shrink=False)
        # Show sidebar after welcome page ends
        # sidebar.show()
        self.sidebar = sidebar

        logging.info('finished check')
        self.editor.show()
        hbox.pack2(self.editor, resize=True, shrink=True)
        self.set_canvas(hbox)
        hbox.show()
        logging.critical('finished initialization')
        self.activity_dir = None
        self.show()

        if not handle.object_id or not self.metadata.get('source'):
            GObject.timeout_add(10, self._show_welcome)
Exemplo n.º 11
0
    def build_toolbar(self):
        toolbox = ToolbarBox()
        toolbar = toolbox.toolbar

        activity_button = ActivityButton(self)
        toolbar.insert(activity_button, -1)
        toolbar.insert(Gtk.SeparatorToolItem(), -1)

        new_game = ToolButton("hear")
        new_game.set_tooltip(_("Hear new hint"))
        new_game.connect("clicked", self.game.new_game)

        play_sound = ToolButton("repeat")
        play_sound.set_tooltip(_("Repeat hint"))
        play_sound.connect("clicked", self.game.sound_current_game)

        toolbar.insert(new_game, -1)
        toolbar.insert(play_sound, -1)

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

        item = Gtk.ToolItem()
        item.add(self.word_label)
        toolbar.insert(item, -1)

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

        en_button = RadioToolButton(icon_name='en')
        en_button.set_tooltip(_("English"))
        en_button.connect("clicked", self.game.change_language)
        toolbar.insert(en_button, -1)

        fr_button = RadioToolButton(icon_name='fr', group=en_button)
        fr_button.set_tooltip(_("French"))
        fr_button.connect("clicked", self.game.change_language)
        toolbar.insert(fr_button, -1)

        es_button = RadioToolButton(icon_name='es', group=en_button)
        es_button.set_tooltip(_("Spanish"))
        es_button.connect("clicked", self.game.change_language)
        toolbar.insert(es_button, -1)

        locale = os.environ["LANG"]
        locale = locale.split("_")[0]

        if locale == "en":
            en_button.set_active(True)
        elif locale == "fr":
            fr_button.set_active(True)
        elif locale == "es":
            es_button.set_active(True)
        else:
            en_button.set_active(True)

        separator = Gtk.SeparatorToolItem()
        toolbar.insert(separator, -1)

        stopbtn = StopButton(self)
        toolbar.insert(stopbtn, -1)
        toolbar.show_all()

        self.set_toolbar_box(toolbox)
Exemplo n.º 12
0
class ToolbarSpeed(Gtk.Toolbar):

    __gsignals__ = {
        "speed-changed": (GObject.SIGNAL_RUN_FIRST, None, [float]),
    }

    def __init__(self):
        Gtk.Toolbar.__init__(self)

        self.button = ToolbarButton(page=self, icon_name="media-playback-stop")
        self.playing = True
        self.speed = None

        self.stop_play = ToolButton("media-playback-stop")
        self.stop_play.set_tooltip(_("Stop"))
        self.stop_play.connect("clicked", self._stop_play)
        self.insert(self.stop_play, -1)

        self.slow_button = RadioToolButton(group=None,
                                           icon_name="slow-walk-milton-raposo")
        self.slow_button.set_tooltip(_("Run slow"))
        self.slow_button.connect("clicked", self._speed_changed_cb, Speed.SLOW)
        self.insert(self.slow_button, -1)

        self.normal_button = RadioToolButton(group=self.slow_button,
                                             icon_name="walking")
        self.normal_button.set_tooltip(_("Run Normal"))
        self.normal_button.connect("clicked", self._speed_changed_cb,
                                   Speed.NORMAL)
        self.insert(self.normal_button, -1)

        self.fast_button = RadioToolButton(group=self.slow_button,
                                           icon_name="running")
        self.fast_button.set_tooltip(_("Run fast"))
        self.fast_button.connect("clicked", self._speed_changed_cb, Speed.FAST)
        self.insert(self.fast_button, -1)

        self.slow_button.set_active(True)

        self.show_all()

    def _stop_play(self, button=None):
        self.playing = not self.playing

        if self.playing:
            self.stop_play.set_icon_name("media-playback-stop")
            self.stop_play.set_tooltip(_("Stop"))
            self.button.set_icon_name("media-playback-stop")

            if self.speed is None:
                self.speed = Speed.SLOW

            self.emit("speed-changed", self.speed)

        else:
            self.stop_play.set_icon_name("media-playback-start")
            self.stop_play.set_tooltip(_("Start"))
            self.button.set_icon_name("media-playback-start")

            self.emit("speed-changed", Speed.STOPPED)

    def _speed_changed_cb(self, button, speed):
        if not self.playing:
            self.speed = speed
            self._stop_play()

        else:
            self.emit("speed-changed", speed)
            self.speed = speed

    def enable(self):
        self.set_sensitive_buttons(True)

    def disable(self):
        self.set_sensitive_buttons(False)

    def set_sensitive_buttons(self, sensitive):
        self.stop_play.set_sensitive(sensitive)
        self.slow_button.set_sensitive(sensitive)
        self.normal_button.set_sensitive(sensitive)
        self.fast_button.set_sensitive(sensitive)
Exemplo n.º 13
0
    def create_palette(self):
        self._palette = self.get_child().create_palette()

        color_palette_hbox = self._palette._picker_hbox
        self.custom_box = Gtk.VBox()

        self.vbox_brush_options = Gtk.VBox()

        # This is where we set restrictions for size:
        # Initial value, minimum value, maximum value, step

        adj = Gtk.Adjustment(self.properties['line size'], 1.0, 100.0, 1.0)
        self.size_scale = Gtk.HScale()
        self.size_scale.set_adjustment(adj)
        self.size_scale.set_draw_value(False)
        self.size_scale.set_size_request(style.zoom(200), -1)
        self.size_label = Gtk.Label(label=_('Size'))
        self.size_label.props.halign = Gtk.Align.START
        self.vbox_brush_options.pack_start(self.size_label, True, True, 0)
        self.vbox_brush_options.pack_start(self.size_scale, True, True, 0)

        self.size_scale.connect('value-changed', self._on_value_changed)

        # Control alpha
        alpha = self.properties['alpha'] * 100
        adj_alpha = Gtk.Adjustment(alpha, 10.0, 100.0, 1.0)
        self.alpha_scale = Gtk.HScale()
        self.alpha_scale.set_adjustment(adj_alpha)
        self.alpha_scale.set_draw_value(False)
        self.alpha_scale.set_size_request(style.zoom(200), -1)
        self.alpha_label = Gtk.Label(label=_('Opacity'))
        self.alpha_label.props.halign = Gtk.Align.START
        self.vbox_brush_options.pack_start(self.alpha_label, True, True, 0)
        self.vbox_brush_options.pack_start(self.alpha_scale, True, True, 0)

        self.alpha_scale.connect('value-changed', self._on_alpha_changed)

        # User is able to choose Shapes for 'Brush' and 'Eraser'
        self.shape_box = Gtk.HBox()
        self.custom_box.pack_start(self.vbox_brush_options, True, True, 0)
        item1 = RadioToolButton()
        item1.set_icon_name('tool-shape-ellipse')

        item2 = RadioToolButton()
        item2.set_icon_name('tool-shape-rectangle')
        item2.props.group = item1

        if self.properties['line shape'] == 'circle':
            item1.set_active(True)
        else:
            item2.set_active(True)

        item1.connect('toggled', self._on_toggled, self.properties, 'circle')
        item2.connect('toggled', self._on_toggled, self.properties, 'square')

        self.shape_box.pack_start(Gtk.Label(_('Shape')), True, True, 0)
        self.shape_box.pack_start(item1, True, True, 0)
        self.shape_box.pack_start(item2, True, True, 0)

        self.vbox_brush_options.pack_start(self.shape_box, True, True, 0)

        self.keep_aspect_checkbutton = Gtk.CheckButton(_('Keep aspect'))
        ratio = self._activity.area.keep_aspect_ratio
        self.keep_aspect_checkbutton.set_active(ratio)
        self.keep_aspect_checkbutton.connect(
            'toggled', self._keep_aspect_checkbutton_toggled)
        self.vbox_brush_options.pack_start(self.keep_aspect_checkbutton, True,
                                           True, 0)

        self.custom_separator = Gtk.VSeparator()
        color_palette_hbox.pack_start(self.custom_separator,
                                      True,
                                      True,
                                      padding=style.DEFAULT_SPACING)
        color_palette_hbox.pack_start(self.custom_box,
                                      True,
                                      True,
                                      padding=style.DEFAULT_SPACING)
        color_palette_hbox.show_all()
        self._update_palette()
        return self._palette
Exemplo n.º 14
0
    def __init__(self, handle):
        """Set up the Develop activity."""
        self._dirty = False
        super(DevelopActivity, self).__init__(handle)
        self.max_participants = 1

        self.current_theme = "light"

        logging.info(repr(handle.get_dict()))

        # Source buffer
        self.editor = sourceview_editor.GtkSourceview2Editor()
        self.editor.connect('tab-changed', self.__editor_tab_changed_cb)
        self.editor.connect('changed', self.__editor_changed_cb)
        # Show tabs after Welcome Page
        self.editor.set_show_tabs(False)

        toolbarbox = ToolbarBox()
        activity_button = ActivityToolbarButton(self)
        toolbarbox.toolbar.insert(activity_button, 0)
        self.set_toolbar_box(toolbarbox)

        view_btn = ToolbarButton()
        view_toolbar = DevelopViewToolbar(self)
        view_btn.props.page = view_toolbar
        view_btn.props.icon_name = 'toolbar-view'
        view_btn.props.label = _('View')
        view_toolbar.connect('theme-changed',
                             self.editor.theme_changed_cb)
        view_toolbar.connect('font-size-changed',
                             self.editor.font_changed_cb)
        toolbarbox.toolbar.insert(view_btn, -1)
        self.view_toolbar = view_toolbar

        edit_btn = ToolbarButton()
        edit_btn.props.page = DevelopEditToolbar(self)
        edit_btn.props.icon_name = 'toolbar-edit'
        edit_btn.props.label = _('Edit')
        toolbarbox.toolbar.insert(edit_btn, -1)

        search_btn = ToolbarButton()
        search_btn.props.page = DevelopSearchToolbar(self)
        search_btn.props.icon_name = 'search'
        search_btn.props.label = _('Search')
        toolbarbox.toolbar.insert(search_btn, -1)

        toolbarbox.toolbar.insert(Gtk.SeparatorToolItem(), -1)

        show_files_btn = RadioToolButton()
        show_files_btn.props.icon_name = 'sources'
        show_files_btn.props.group = show_files_btn
        show_files_btn.set_active(True)
        show_files_btn.set_tooltip(_('Show source files'))
        toolbarbox.toolbar.insert(show_files_btn, -1)
        show_files_btn.connect('clicked', self._change_treenotebook_page, 0)

        show_symbols_btn = RadioToolButton()
        show_symbols_btn.props.icon_name = 'symbols'
        show_symbols_btn.props.group = show_files_btn
        show_symbols_btn.set_active(False)
        show_symbols_btn.set_tooltip(_('Show file symbols'))
        toolbarbox.toolbar.insert(show_symbols_btn, -1)
        show_symbols_btn.connect('clicked', self._explore_code)

        show_log_btn = RadioToolButton()
        show_log_btn.props.icon_name = 'logs'
        show_log_btn.props.group = show_files_btn
        show_log_btn.set_active(False)
        show_log_btn.set_tooltip(_('Show log files'))
        toolbarbox.toolbar.insert(show_log_btn, -1)
        show_log_btn.connect('clicked', self._change_treenotebook_page, 2)

        toolbarbox.toolbar.insert(Gtk.SeparatorToolItem(), -1)

        create_file_btn = ToolButton('text-x-generic')
        create_file_btn.set_tooltip(_('Create empty file'))
        toolbarbox.toolbar.insert(create_file_btn, -1)
        create_file_btn.show()
        create_file_btn.connect('clicked', self.__create_empty_file_cb)

        erase_btn = ToolButton('erase')
        erase_btn.set_tooltip(_('Remove file'))
        toolbarbox.toolbar.insert(erase_btn, -1)
        erase_btn.show()
        erase_btn.connect('clicked', self.__remove_file_cb)

        toolbarbox.toolbar.insert(Gtk.SeparatorToolItem(), -1)

        run_btn = ToolButton('activity-start')
        run_btn.set_tooltip(_('Run activity'))
        toolbarbox.toolbar.insert(run_btn, -1)
        run_btn.connect('clicked', self.__run_actvity_cb)

        separator = Gtk.SeparatorToolItem()
        separator.set_draw(False)
        separator.set_expand(True)
        toolbarbox.toolbar.insert(separator, -1)

        stopbtn = StopButton(self)
        toolbarbox.toolbar.insert(stopbtn, -1)

        save_bundle_btn = ToolButton('save-as-bundle')
        save_bundle_btn.set_tooltip(_('Create bundle (.xo file)'))
        activity_button.get_page().insert(save_bundle_btn, -1)
        save_bundle_btn.connect('clicked', self.save_bundle)
        save_bundle_btn.show()

        toolbarbox.show_all()

        # Main layout.
        hbox = Gtk.HPaned()

        # The treeview and selected pane reflect each other.
        self.numb = False

        # Wait to save until first change, but save an unchanged
        # backup copy when that happens.
        self.save_unchanged = False

        # The sidebar
        sidebar = Gtk.VBox()
        self.treenotebook = notebook.Notebook(can_close_tabs=False)
        self.treenotebook.set_show_tabs(False)
        sidebar.pack_start(self.treenotebook, True, True, 0)

        self.activity_tree_view = FileViewer()
        self.treenotebook.add_page(_("Activity"), self.activity_tree_view)
        self.treenotebook.set_size_request(Gdk.Screen.width() / 5, -1)

        # Symbols tree
        self._symbolstree = SymbolsTree()
        self._symbolstree.connect('symbol-selected',
                                  self.editor.symbol_selected_cb)
        scrolled = Gtk.ScrolledWindow()
        scrolled.add(self._symbolstree)
        scrolled.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        self.treenotebook.add_page(_('Symbols Tree'), scrolled)

        hbox.pack1(sidebar, resize=True, shrink=False)
        # Show sidebar after welcome page ends
        # sidebar.show()
        self.sidebar = sidebar

        logging.info('finished check')
        self.editor.show()
        hbox.pack2(self.editor, resize=True, shrink=True)
        self.set_canvas(hbox)
        hbox.show()
        logging.critical('finished initialization')
        self.activity_dir = None
        self.show()

        if not handle.object_id or not self.metadata.get('source'):
            GObject.timeout_add(10, self._show_welcome)
Exemplo n.º 15
0
    def create_palette(self):
        self._palette = self.get_child().create_palette()

        color_palette_hbox = self._palette._picker_hbox
        self.custom_box = Gtk.VBox()

        self.vbox_brush_options = Gtk.VBox()

        # This is where we set restrictions for size:
        # Initial value, minimum value, maximum value, step

        adj = Gtk.Adjustment(self.properties['line size'], 1.0, 100.0, 1.0)
        self.size_scale = Gtk.HScale()
        self.size_scale.set_adjustment(adj)
        self.size_scale.set_draw_value(False)
        self.size_scale.set_size_request(style.zoom(200), -1)
        self.size_label = Gtk.Label(label=_('Size'))
        self.size_label.props.halign = Gtk.Align.START
        self.vbox_brush_options.pack_start(self.size_label, True, True, 0)
        self.vbox_brush_options.pack_start(self.size_scale, True, True, 0)

        self.size_scale.connect('value-changed', self._on_value_changed)

        # Control alpha
        alpha = self.properties['alpha'] * 100
        adj_alpha = Gtk.Adjustment(alpha, 10.0, 100.0, 1.0)
        self.alpha_scale = Gtk.HScale()
        self.alpha_scale.set_adjustment(adj_alpha)
        self.alpha_scale.set_draw_value(False)
        self.alpha_scale.set_size_request(style.zoom(200), -1)
        self.alpha_label = Gtk.Label(label=_('Opacity'))
        self.alpha_label.props.halign = Gtk.Align.START
        self.vbox_brush_options.pack_start(self.alpha_label, True, True, 0)
        self.vbox_brush_options.pack_start(self.alpha_scale, True, True, 0)

        self.alpha_scale.connect('value-changed', self._on_alpha_changed)

        # User is able to choose Shapes for 'Brush' and 'Eraser'
        self.shape_box = Gtk.HBox()
        self.custom_box.pack_start(self.vbox_brush_options, True, True, 0)
        item1 = RadioToolButton()
        item1.set_icon_name('tool-shape-ellipse')

        item2 = RadioToolButton()
        item2.set_icon_name('tool-shape-rectangle')
        item2.props.group = item1

        if self.properties['line shape'] == 'circle':
            item1.set_active(True)
        else:
            item2.set_active(True)

        item1.connect('toggled', self._on_toggled, self.properties, 'circle')
        item2.connect('toggled', self._on_toggled, self.properties, 'square')

        self.shape_box.pack_start(Gtk.Label(_('Shape')), True, True, 0)
        self.shape_box.pack_start(item1, True, True, 0)
        self.shape_box.pack_start(item2, True, True, 0)

        self.vbox_brush_options.pack_start(self.shape_box, True, True, 0)

        self.keep_aspect_checkbutton = Gtk.CheckButton(_('Keep aspect'))
        ratio = self._activity.area.keep_aspect_ratio
        self.keep_aspect_checkbutton.set_active(ratio)
        self.keep_aspect_checkbutton.connect(
            'toggled', self._keep_aspect_checkbutton_toggled)
        self.vbox_brush_options.pack_start(self.keep_aspect_checkbutton, True,
                                           True, 0)

        self.custom_separator = Gtk.VSeparator()
        color_palette_hbox.pack_start(self.custom_separator, True, True,
                                      padding=style.DEFAULT_SPACING)
        color_palette_hbox.pack_start(self.custom_box, True, True,
                                      padding=style.DEFAULT_SPACING)
        color_palette_hbox.show_all()
        self._update_palette()
        return self._palette
Exemplo n.º 16
0
class SensorToolbar(Gtk.Toolbar):
    ''' The toolbar for specifiying the sensor: sound, resitance, or
    voltage '''

    LOWER = 0.0
    UPPER = 1.0
    STR_DC_R = \
        _("Resistive sensor (connect sensor to pink 'Mic In' on left side \
of XO)"       ) + ' '
    STR_DC_V = \
        _("Voltage sensor (connect sensor to pink 'Mic In' on left side \
of XO)"       ) + ' '
    STR_AC = _('Sound') + ' '
    STR_RESISTANCE = _('Resistance') + ' (' + _('Ohms') + ') '
    STR_VOLTAGE = _('Voltage') + ' (' + _('Volts') + ') '
    STR_TIME = _('Time Base') + ' '
    STR_FREQUENCY = _('Frequency Base') + ' '
    STR_INVERT = ' ' + _('Invert') + ' '
    STR_XAXIS_TEXT = _('X Axis Scale: 1 division = %(division)s %(unit)s')
    # TRANSLATORS: This is milli seconds.
    MS = _('ms')
    # TRANSLATORS: This is Hertz, so 1/second.
    HZ = _('Hz')

    def __init__(self, activity, channels):
        ''' By default, start with resistance mode '''

        super(type(self), self).__init__()

        self.activity = activity
        self._channels = channels
        self._lock_radio_buttons = False
        self._radio_button_pushed = False
        self.values = []
        for i in range(self._channels):
            self.values.append('')

        self.string_for_textbox = ''

        self.gain = 1.0
        self.y_mag = 3.0
        self.capture_gain = CAPTURE_GAIN
        self.mic_boost = MIC_BOOST

        self.mode = 'sound'

        # Set up Time-domain Button
        self.time = RadioToolButton(icon_name='media-audio', group=None)
        self.insert(self.time, -1)
        self.time.set_tooltip(_('Sound'))
        self.time.connect('clicked', self.analog_resistance_voltage_mode_cb,
                          'sound')

        # Set up Resistance Button
        self.resistance = RadioToolButton(icon_name='resistance',
                                          group=self.time)
        if _can_use_dc(self.activity.hw):
            self.insert(self.resistance, -1)
        self.resistance.show()
        self.resistance.set_tooltip(_('Resistance Sensor'))
        self.resistance.connect('clicked',
                                self.analog_resistance_voltage_mode_cb,
                                'resistance')

        # Set up Voltage Button
        self.voltage = RadioToolButton(icon_name='voltage', group=self.time)
        if _can_use_dc(self.activity.hw):
            self.insert(self.voltage, -1)
        self.voltage.set_tooltip(_('Voltage Sensor'))
        self.voltage.connect('clicked', self.analog_resistance_voltage_mode_cb,
                             'voltage')

        separator = Gtk.SeparatorToolItem()
        separator.props.draw = True
        self.insert(separator, -1)

        self._log_value = LOG_TIMER_VALUES[1]
        self.log_label = Gtk.Label(self._log_to_string(self._log_value))
        toolitem = Gtk.ToolItem()
        toolitem.add(self.log_label)
        self.insert(toolitem, -1)

        self._log_button = ToolButton('timer-10')
        self._log_button.set_tooltip(_('Select logging interval'))
        self._log_button.connect('clicked', self._log_selection_cb)
        self.insert(self._log_button, -1)
        self._setup_log_palette()

        # Set up Logging/Stop Logging Button
        self._record = ToolButton('media-record')
        self.insert(self._record, -1)
        self._record.set_tooltip(_('Start logging'))
        self._record.connect('clicked', self.record_control_cb)

        separator = Gtk.SeparatorToolItem()
        separator.props.draw = True
        self.insert(separator, -1)

        toolitem = Gtk.ToolItem()
        self.trigger_label = Gtk.Label(_('Trigger'))
        toolitem.add(self.trigger_label)
        self.insert(toolitem, -1)

        # Set up Trigger Combo box
        self.trigger_none = RadioToolButton()
        self.trigger_none.set_icon_name('trigger-none')
        self.insert(self.trigger_none, -1)
        self.trigger_none.set_tooltip(_('None'))
        self.trigger_none.connect('clicked', self.update_trigger_control_cb,
                                  self.activity.wave.TRIGGER_NONE)

        self.trigger_rise = RadioToolButton(group=self.trigger_none)
        self.trigger_rise.set_icon_name('trigger-rise')
        self.insert(self.trigger_rise, -1)
        self.trigger_rise.set_tooltip(_('Rising Edge'))
        self.trigger_rise.connect('clicked', self.update_trigger_control_cb,
                                  self.activity.wave.TRIGGER_POS)

        self.trigger_fall = RadioToolButton(group=self.trigger_none)
        self.trigger_fall.set_icon_name('trigger-fall')
        self.insert(self.trigger_fall, -1)
        self.trigger_fall.set_tooltip(_('Falling Edge'))
        self.trigger_fall.connect('clicked', self.update_trigger_control_cb,
                                  self.activity.wave.TRIGGER_NEG)

        self.show_all()

    def get_log(self):
        return self._log_value

    def get_log_idx(self):
        if self._log_value in LOG_TIMER_VALUES:
            return LOG_TIMER_VALUES.index(self._log_value)
        else:
            return LOG_TIMER_VALUES[0]

    def set_log_idx(self, idx):
        self._log_value = LOG_TIMER_VALUES[idx]
        self.log_label.set_text(self._log_to_string(self._log_value))
        if hasattr(self, '_log_button'):
            self._log_button.set_icon('timer-%d' % (self._log_value))

    def _log_selection_cb(self, widget):
        if self._log_palette:
            if not self._log_palette.is_up():
                self._log_palette.popup(immediate=True)
            else:
                self._log_palette.popdown(immediate=True)
            return

    def _log_to_seconds(self, tenth_seconds):
        return tenth_seconds / 10.

    def _log_to_string(self, tenth_seconds):
        if tenth_seconds in LOG_TIMER_LABELS:
            return LOG_TIMER_LABELS[tenth_seconds]
        else:
            return _('1 second')

    def _setup_log_palette(self):
        self._log_palette = self._log_button.get_palette()

        for tenth_seconds in LOG_TIMER_VALUES:
            text = self._log_to_string(tenth_seconds)
            menu_item = MenuItem(icon_name='timer-%d' % (tenth_seconds),
                                 text_label=text)
            menu_item.connect('activate', self._log_selected_cb, tenth_seconds)
            self._log_palette.menu.append(menu_item)
            menu_item.show()

    def _log_selected_cb(self, button, seconds):
        self.set_log_idx(LOG_TIMER_VALUES.index(seconds))

    def add_frequency_slider(self, toolbox):
        ''' Either on the Sound toolbar or the Main toolbar '''
        self._freq_stepper_up = ToolButton('freq-high')
        self._freq_stepper_up.set_tooltip(_('Zoom out'))
        self._freq_stepper_up.connect('clicked', self._freq_stepper_up_cb)
        self._freq_stepper_up.show()
        self.activity.adjustmentf = Gtk.Adjustment(0.5, self.LOWER, self.UPPER,
                                                   0.01, 0.1, 0)
        self.activity.adjustmentf.connect('value_changed', self.cb_page_sizef)
        self._freq_range = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL,
                                     adjustment=self.activity.adjustmentf)
        self._freq_range.set_inverted(True)
        self._freq_range.set_draw_value(False)
        self._freq_range.set_size_request(120, 15)
        self._freq_range.show()

        self._freq_stepper_down = ToolButton('freq-low')
        self._freq_stepper_down.set_tooltip(_('Zoom in'))
        self._freq_stepper_down.connect('clicked', self._freq_stepper_down_cb)
        self._freq_stepper_down.show()

        self._freq_range_tool = Gtk.ToolItem()
        self._freq_range_tool.add(self._freq_range)
        self._freq_range_tool.show()

        toolbox.add(self._freq_stepper_up)
        toolbox.add(self._freq_range_tool)
        toolbox.add(self._freq_stepper_down)
        return

    def update_trigger_control_cb(self, button, value):
        if button is None:
            value = self.activity.wave.TRIGGER_NONE
        if self.activity.wave.get_fft_mode():
            self.trigger_none.set_active(True)
        else:
            self.activity.wave.set_trigger(value)

    def analog_resistance_voltage_mode_cb(self,
                                          button=None,
                                          mode_to_set='sound'):
        ''' Callback for Analog/Resistance/Voltage Buttons '''
        if self._lock_radio_buttons:
            logging.debug('mode selector locked')
            self._radio_button_pushed = True
            return
        if self.mode == mode_to_set:
            logging.debug('mode already set to %s' % mode_to_set)
            return
        self._lock_radio_buttons = True
        if self.activity.CONTEXT == 'sound':
            self.sound_context_off()
        else:
            self.sensor_context_off()

        # Force time domain when switching modes
        if self.activity.wave.get_fft_mode():
            self.activity.timefreq_control()
        # Turn off logging when switching modes
        if self.activity.audiograb.we_are_logging:
            self.record_control_cb()

        self.set_mode(mode_to_set)
        if mode_to_set == 'sound':
            self.set_sound_context()
        elif mode_to_set == 'resistance':
            self.set_sensor_context()
        elif mode_to_set == 'voltage':
            self.set_sensor_context()
        self.update_string_for_textbox()
        return False

    def unlock_radio_buttons(self):
        ''' Enable radio button selection '''
        logging.debug('unlocking radio buttons')
        if self._radio_button_pushed:
            if self.mode == 'sound':
                self.time.set_active(True)
            elif self.mode == 'resistance':
                self.resistance.set_active(True)
            elif self.mode == 'voltage':
                self.voltage.set_active(True)
        self._lock_radio_buttons = False
        self._radio_button_pushed = False

    def set_mode(self, mode='sound'):
        ''' Set the mixer settings to match the current mode. '''
        self.mode = mode
        self.activity.audiograb.set_sensor_type(self.mode)
        for i in range(self._channels):
            self.values[i] = 0.0
        return

    def get_mode(self):
        ''' Get the mixer settings. '''
        return self.mode

    def _freq_stepper_up_cb(self, button=None):
        ''' Moves the horizontal zoom slider to the left one notch,
        where one notch is 1/100 of the total range. This correspond
        to zooming out as a larger number of Hertz or milliseconds
        will be represented by the same space on the screen. '''
        new_value = self._freq_range.get_value() + \
            (self.UPPER - self.LOWER) / 100.0
        if new_value <= self.UPPER:
            self._freq_range.set_value(new_value)
        else:
            self._freq_range.set_value(self.UPPER)

    def _freq_stepper_down_cb(self, button=None):
        ''' Moves the horizontal zoom slider to the right one notch,
        where one notch is 1/100 of the total range. This corresponds
        to zooming in. '''
        new_value = self._freq_range.get_value() - \
            (self.UPPER - self.LOWER) / 100.0
        if new_value >= self.LOWER:
            self._freq_range.set_value(new_value)
        else:
            self._freq_range.set_value(self.LOWER)

    def cb_page_sizef(self, button=None):
        ''' Callback to scale the frequency range (zoom in and out) '''
        if self._update_page_size_id:
            GObject.source_remove(self._update_page_size_id)
        self._update_page_size_id =\
            GObject.timeout_add(250, self.update_page_size)
        return True

    def update_page_size(self):
        ''' Set up the scaling of the display. '''
        self._update_page_size_id = None
        value = self.activity.adjustmentf.get_value()
        new_value = round(value * 100.0) / 100.0
        if value != new_value:
            self.activity.adjustmentf.set_value(new_value)
            return False
        time_div = 0.001 * max(value, 0.05)
        freq_div = 1000 * max(value, 0.01)
        self.activity.wave.set_div(time_div, freq_div)
        self.update_string_for_textbox()
        return False

    def set_sound_context(self):
        ''' Called when analog sensing is selected '''
        self.set_show_hide_windows(mode='sound')
        GObject.timeout_add(500, self.sound_context_on)
        self.activity.CONTEXT = 'sound'

    def set_sensor_context(self):
        ''' Called when digital sensing is selected '''
        self.set_show_hide_windows(mode='sensor')
        GObject.timeout_add(500, self.sensor_context_on)
        self.activity.CONTEXT = 'sensor'

    def set_show_hide_windows(self, mode='sound'):
        ''' Shows the appropriate window identified by the mode '''
        self.activity.wave.set_context_on()
        for i in range(self._channels):
            self.activity.side_toolbars[i].set_show_hide(True, mode)

    def sensor_context_off(self):
        ''' Called when a DC sensor is no longer selected '''
        # self.activity.audiograb.pause_grabbing()
        self.activity.audiograb.stop_grabbing()

    def sensor_context_on(self):
        ''' Called when a DC sensor is selected '''
        self.update_string_for_textbox()
        self.activity.wave.set_trigger(self.activity.wave.TRIGGER_NONE)
        # self.activity.audiograb.resume_grabbing()
        self.activity.audiograb.start_grabbing()
        return False

    def sound_context_off(self):
        ''' Called when an analog sensor is no longer selected '''
        self.gain, self.y_mag = self.activity.wave.get_mag_params()
        self.capture_gain = self.activity.audiograb.get_capture_gain()
        self.mic_boost = self.activity.audiograb.get_mic_boost()
        self.activity.audiograb.stop_grabbing()

    def sound_context_on(self):
        ''' Called when an analog sensor is selected '''
        self.activity.wave.set_mag_params(self.gain, self.y_mag)
        self.update_string_for_textbox()
        self.update_trigger_control_cb(None, self.activity.wave.TRIGGER_NONE)
        self.activity.audiograb.start_grabbing()
        return False

    def set_sample_value(self, value='', channel=0):
        ''' Write a sample value to the textbox. '''
        self.values[channel] = value
        self.update_string_for_textbox()
        return

    def record_control_cb(self, button=None):
        ''' Depending upon the selected interval, does either a logging
        session, or just logs the current buffer. '''
        if self.activity.audiograb.we_are_logging:
            self.activity.audiograb.set_logging_params(start_stop=False)
            self._record.set_icon_name('media-record')
            self._record.show()
            self._record.set_tooltip(_('Start Recording'))
        else:
            Xscale = (1.00 / self.activity.audiograb.get_sampling_rate())
            Yscale = 0.0
            interval = self._log_value / 10.  # self.interval_convert()
            username = self.activity.nick
            if self.activity.wave.get_fft_mode():
                self.activity.data_logger.start_new_session(
                    username,
                    Xscale,
                    Yscale,
                    self._log_to_string(self._log_value),
                    channels=self._channels,
                    mode='frequency')
            else:
                self.activity.data_logger.start_new_session(
                    username,
                    Xscale,
                    Yscale,
                    self._log_to_string(self._log_value),
                    channels=self._channels,
                    mode=self.mode)
            self.activity.audiograb.set_logging_params(start_stop=True,
                                                       interval=interval)
            self._record.set_icon_name('record-stop')
            self._record.show()
            self._record.set_tooltip(_('Stop Recording'))
            self.activity.new_recording = True

    def update_string_for_textbox(self):
        ''' Update the status field at the bottom of the canvas. '''
        if self.mode == 'resistance':
            string_for_textbox = (self.STR_DC_R + '\n')
            string_for_textbox += self.STR_RESISTANCE
        elif self.mode == 'voltage':
            string_for_textbox = (self.STR_DC_V + '\n')
            string_for_textbox += self.STR_VOLTAGE
        else:
            string_for_textbox = (self.STR_AC + '\t')
        if self.activity.wave.get_fft_mode():
            scalex = self.STR_XAXIS_TEXT % {
                'unit': self.HZ,
                'division': self.activity.wave.freq_div
            }
            string_for_textbox += self.STR_FREQUENCY
            string_for_textbox += ('\n' + scalex)
        elif self.mode == 'sound':
            scalex = self.STR_XAXIS_TEXT % {
                'unit': self.MS,
                'division': self.activity.wave.time_div * 1000
            }
            string_for_textbox += self.STR_TIME
            string_for_textbox += ('\n' + scalex)
        else:
            for i in range(self._channels):
                string_for_textbox += '\t(%s)' % (self.values[i])
        invert = False
        for i in range(self._channels):
            if self.activity.wave.get_invert_state(channel=i):
                invert = True
        if invert:
            string_for_textbox += self.STR_INVERT
        self.activity.text_box.set_label(string_for_textbox)
Exemplo n.º 17
0
    def __init__(self, handle):
        """Set up the HelloWorld activity."""
        activity.Activity.__init__(self, handle)

        # Change the following number to change max participants
        self.max_participants = 1

        toolbar_box = ToolbarBox()

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

        toolbar_box.toolbar.insert(Gtk.SeparatorToolItem(), -1)

        show_pictograms_btn = RadioToolButton(icon_name='pictograms')
        show_pictograms_btn.props.group = show_pictograms_btn
        show_pictograms_btn.set_active(True)
        show_pictograms_btn.set_tooltip(_('Show pictograms'))
        toolbar_box.toolbar.insert(show_pictograms_btn, -1)
        show_pictograms_btn.connect('clicked', self._change_treenotebook_page,
                                    0)

        show_bords_btn = RadioToolButton(icon_name='boards')
        show_bords_btn.props.group = show_pictograms_btn
        show_bords_btn.set_active(False)
        show_bords_btn.set_tooltip(_('Show boards'))
        toolbar_box.toolbar.insert(show_bords_btn, -1)
        show_bords_btn.connect('clicked', self._change_treenotebook_page, 1)

        toolbar_box.toolbar.insert(Gtk.SeparatorToolItem(), -1)

        add_image_btn = ToolButton(icon_name='insert-picture')
        add_image_btn.set_tooltip(_('Add image from Journal'))
        toolbar_box.toolbar.insert(add_image_btn, -1)
        # add_image_btn.connect('clicked', self._change_treenotebook_page, 1)

        accept_board_btn = ToolButton(icon_name='dialog-ok')
        accept_board_btn.set_tooltip(_('Store board'))
        toolbar_box.toolbar.insert(accept_board_btn, -1)
        accept_board_btn.connect('clicked', self.__store_board_cb)

        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)
        toolbar_box.show()

        self._boards = []

        background = Gtk.EventBox()
        background.modify_bg(Gtk.StateType.NORMAL,
                             style.Color('#FFFFFF').get_gdk_color())
        self.set_canvas(background)

        # canvas
        hbox = Gtk.HBox()
        background.add(hbox)

        self._treenotebook = Gtk.Notebook()
        self._treenotebook.set_show_tabs(False)
        hbox.pack_start(self._treenotebook, False, False, 0)

        # treeview with pictograms
        self._create_picto_treeview()
        scrolled = Gtk.ScrolledWindow()
        scrolled.props.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC
        scrolled.props.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC
        scrolled.set_size_request(Gdk.Screen.width() / 4, -1)
        scrolled.add_with_viewport(self._picto_tree_view)
        self._treenotebook.append_page(scrolled, None)

        # treeview with boards
        self._create_boards_treeview()
        scrolled = Gtk.ScrolledWindow()
        scrolled.props.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC
        scrolled.props.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC
        scrolled.set_size_request(Gdk.Screen.width() / 4, -1)
        scrolled.add_with_viewport(self._boards_tree_view)
        self._treenotebook.append_page(scrolled, None)

        self._board_edit_panel = BoardEditPanel()
        hbox.pack_start(self._board_edit_panel, True, True, 0)

        self._load_pictograms()

        self.show_all()
Exemplo n.º 18
0
    def __init__(self, handle):
        """Set up the HelloWorld activity."""
        activity.Activity.__init__(self, handle)

        # Change the following number to change max participants
        self.max_participants = 1

        toolbar_box = ToolbarBox()

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

        toolbar_box.toolbar.insert(Gtk.SeparatorToolItem(), -1)

        show_pictograms_btn = RadioToolButton(icon_name="pictograms")
        show_pictograms_btn.props.group = show_pictograms_btn
        show_pictograms_btn.set_active(True)
        show_pictograms_btn.set_tooltip(_("Show pictograms"))
        toolbar_box.toolbar.insert(show_pictograms_btn, -1)
        show_pictograms_btn.connect("clicked", self._change_treenotebook_page, 0)

        show_bords_btn = RadioToolButton(icon_name="boards")
        show_bords_btn.props.group = show_pictograms_btn
        show_bords_btn.set_active(False)
        show_bords_btn.set_tooltip(_("Show boards"))
        toolbar_box.toolbar.insert(show_bords_btn, -1)
        show_bords_btn.connect("clicked", self._change_treenotebook_page, 1)

        toolbar_box.toolbar.insert(Gtk.SeparatorToolItem(), -1)

        add_image_btn = ToolButton(icon_name="insert-picture")
        add_image_btn.set_tooltip(_("Add image from Journal"))
        toolbar_box.toolbar.insert(add_image_btn, -1)
        # add_image_btn.connect('clicked', self._change_treenotebook_page, 1)

        accept_board_btn = ToolButton(icon_name="dialog-ok")
        accept_board_btn.set_tooltip(_("Store board"))
        toolbar_box.toolbar.insert(accept_board_btn, -1)
        accept_board_btn.connect("clicked", self.__store_board_cb)

        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)
        toolbar_box.show()

        self._boards = []

        background = Gtk.EventBox()
        background.modify_bg(Gtk.StateType.NORMAL, style.Color("#FFFFFF").get_gdk_color())
        self.set_canvas(background)

        # canvas
        hbox = Gtk.HBox()
        background.add(hbox)

        self._treenotebook = Gtk.Notebook()
        self._treenotebook.set_show_tabs(False)
        hbox.pack_start(self._treenotebook, False, False, 0)

        # treeview with pictograms
        self._create_picto_treeview()
        scrolled = Gtk.ScrolledWindow()
        scrolled.props.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC
        scrolled.props.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC
        scrolled.set_size_request(Gdk.Screen.width() / 4, -1)
        scrolled.add_with_viewport(self._picto_tree_view)
        self._treenotebook.append_page(scrolled, None)

        # treeview with boards
        self._create_boards_treeview()
        scrolled = Gtk.ScrolledWindow()
        scrolled.props.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC
        scrolled.props.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC
        scrolled.set_size_request(Gdk.Screen.width() / 4, -1)
        scrolled.add_with_viewport(self._boards_tree_view)
        self._treenotebook.append_page(scrolled, None)

        self._board_edit_panel = BoardEditPanel()
        hbox.pack_start(self._board_edit_panel, True, True, 0)

        self._load_pictograms()

        self.show_all()
Exemplo n.º 19
0
class MusicpainterActivity(activity.Activity):
    def __init__(self, handle):

        self.to_read = ''
        self.btn_added = False

        activity.Activity.__init__(self, handle)
        self.max_participants = 1

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

        #load the sugar toolbar
        self.toolbar_box = ToolbarBox()

        self.activity_btn = ActivityToolbarButton(self)
        self.activity_btn.connect('clicked', self.to_detail_mode)

        self.new_file_btn = ToolButton('file_new')
        self.new_file_btn.set_tooltip('New')
        self.new_file_btn.connect('clicked', self.new_file)

        self.save_file_btn = ToolButton('file_save')
        self.save_file_btn.set_tooltip('Save')
        self.save_file_btn.connect('clicked', self.save_file)

        self.save_file_as_btn = ToolButton('file_save_as')
        self.save_file_as_btn.set_tooltip('Save As')
        self.save_file_as_btn.connect('clicked', self.save_file_as)

        self.share_file_btn = ToolButton('file_upload')
        self.share_file_btn.set_tooltip('Share')
        self.share_file_btn.connect('clicked', self.share_file)

        separator = Gtk.SeparatorToolItem()
        separator.show()

        toolbar = self.activity_btn.props.page
        self.title_box = toolbar.get_nth_item(0)
        self.desc_btn = toolbar.get_nth_item(1)
        toolbar.insert(separator, 2)
        toolbar.insert(self.new_file_btn, -1)
        toolbar.insert(self.save_file_btn, -1)
        toolbar.insert(self.save_file_as_btn, -1)
        toolbar.insert(self.share_file_btn, -1)

        self.toolbar_box.toolbar.insert(self.activity_btn, 0)

        self.toolbar_box.toolbar.insert(Gtk.SeparatorToolItem(), 1)

        self.home_btn = RadioToolButton()
        self.home_btn.set_tooltip('Home')
        self.home_btn.props.icon_name = 'toolbox_home'
        self.home_btn.props.group = self.home_btn
        self.home_btn.connect('clicked', self.go_home)
        self.toolbar_box.toolbar.insert(self.home_btn, 2)

        self.canvas_mode_btn = RadioToolButton()
        self.canvas_mode_btn.set_tooltip('Canvas')
        self.canvas_mode_btn.props.icon_name = 'toolbox_canvas'
        self.canvas_mode_btn.props.group = self.home_btn
        self.canvas_mode_btn.connect('clicked', self.to_canvas_mode)
        self.toolbar_box.toolbar.insert(self.canvas_mode_btn, 3)

        self.keyboard_mode_btn = RadioToolButton()
        self.keyboard_mode_btn.set_tooltip('Keyboard')
        self.keyboard_mode_btn.props.icon_name = 'toolbox_keyboard'
        self.keyboard_mode_btn.props.group = self.home_btn
        self.keyboard_mode_btn.connect('clicked', self.to_keyboard_mode)
        self.toolbar_box.toolbar.insert(self.keyboard_mode_btn, 4)

        self.configure_ins_btn = RadioToolButton()
        self.configure_ins_btn.set_tooltip('Select instruments')
        self.configure_ins_btn.props.icon_name = 'toolbox_instrument'
        self.configure_ins_btn.props.group = self.home_btn
        self.configure_ins_btn.connect('clicked', self.configure_ins)
        self.toolbar_box.toolbar.insert(self.configure_ins_btn, 5)

        self.seperator = Gtk.SeparatorToolItem()
        #self.toolbar_box.toolbar.insert(self.seperator, 6)

        self.configure_scale_btn = ToggleToolButton()
        self.configure_scale_btn.set_tooltip('Select scale')
        self.configure_scale_btn.props.icon_name = 'toolbox_scale'
        self.configure_scale_btn.connect('toggled', self.choose_scale)
        #self.toolbar_box.toolbar.insert(self.configure_scale_btn, 7)

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

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

        self.set_toolbar_box(self.toolbar_box)
        self.toolbar_box.show_all()

        #self.set_toolbox(toolbox)

        #activity_toolbar = toolbox.get_activity_toolbar()
        #activity_toolbar.remove(activity_toolbar.share)
        #activity_toolbar.share = None
        #activity_toolbar.keep.connect('clicked', self._keep_cb)
        #activity_toolbar.stop.can_focus = True
        #activity_toolbar.keep.can_focus = True

        #toolbox.show()
        #activity_toolbar.keep.grab_focus()

        self.gamename = 'Musicpainter'
        self.set_title("Music Painter")

        ## connect to the in/out events
        #self.connect('notify::active', self.onActive)
        #self.connect('focus_in_event', self._focus_in)
        #self.connect('focus_out_event', self._focus_out)

        self.musicpainter = Musicpainter.Musicpainter()
        presenceService = presenceservice.get_instance()
        xoOwner = presenceService.get_owner()  # get my name
        self.musicpainter.initSugar(self, xoOwner.props.nick)
        if not (self.to_read == '' or self.uid == ''):
            #try:
            print "Read journal uid: (" + self.uid + "), filename: " + self.to_read
            self.musicpainter.score.read_journal(self.to_read, self.uid)
            #except:
            #print "Exception caught when reading journal."
            #try:
            print "Init view: " + self.metadata['view']
            self.musicpainter.init_view(self.metadata['view'])
            self.init_view_sugar(self.metadata['view'])
            #except:
        #print "No initial view."
        else:
            self.musicpainter.score.new_score()  # init a canvas
            #self.musicpainter.init_view('canvas')
            #self.init_view_sugar('canvas')

            self.musicpainter.init_view('home')
            self.init_view_sugar('home')

        #self.create_journal()

        #bus = dbus.SessionBus()
        #remote_object = bus.get_object(DS_DBUS_SERVICE, DS_DBUS_PATH)
        #_datastore = dbus.Interface(remote_object, DS_DBUS_INTERFACE)
        #_datastore.connect_to_signal('Created', self.datastore_created_cb)
        #_datastore.connect_to_signal('Updated', self.datastore_updated_cb)
        #_datastore.connect_to_signal('Deleted', self.datastore_deleted_cb)

    def new_file(self, widget):
        self.musicpainter.score.new_score()
        self.to_canvas_mode(widget)
        self.activity_btn.set_expanded(False)
        self.toolbar_changed(widget)

    def msg_box_callback(self):
        self.to_canvas_mode(self.w)
        #self.activity_btn.set_expanded(False)
        #self.toolbar_changed(self.w)

    def upload_callback(self):
        self.musicpainter.detail_view.show_message_box("Upload successful! ")

    def save_file(self, widget):
        if self.musicpainter.current_view != 'detail':
            self.to_detail_mode(widget)
            self.musicpainter.detail_view.set_toolbar_expanded(
                self.musicpainter.toolbar_expanded)
        if self.musicpainter.score.save_score():
            self.w = widget
            self.musicpainter.detail_view.show_message_box("Save successful!")

    def save_file_as(self, widget):
        if self.musicpainter.current_view != 'detail':
            self.to_detail_mode(widget)
            self.musicpainter.detail_view.set_toolbar_expanded(
                self.musicpainter.toolbar_expanded)
        if self.musicpainter.score.save_score_as():
            self.w = widget
            self.musicpainter.detail_view.show_message_box("Save successful!")

    def share_file(self, widget):
        if self.musicpainter.current_view != 'detail':
            self.to_detail_mode(widget)
            self.musicpainter.detail_view.set_toolbar_expanded(
                self.musicpainter.toolbar_expanded)
        if not self.musicpainter.score.upload_eligible():
            self.w = widget
            self.musicpainter.detail_view.show_message_box(
                "Please make changes before upload. ")
        else:
            self.w = widget
            self.musicpainter.score.save_score()
            self.musicpainter.network.upload_music(
                self.musicpainter.score.uid + ".png")

    def toolbar_changed(self, widget):
        #print "activity.toolbar_changed()"
        self.musicpainter.toolbar_switch()

    def go_home(self, widget):
        self.musicpainter.go_home()
        self.hide_scale_btn()

        if self.musicpainter.toolbar_expanded:
            self.activity_btn.set_expanded(False)
            self.toolbar_changed(widget)

    def to_detail_mode(self, widget):
        if self.musicpainter.to_detail_mode_from_sugar():
            self.show_scale_btn()
        else:
            self.hide_scale_btn()

    def to_canvas_mode(self, widget):
        self.musicpainter.to_canvas_view()
        self.show_scale_btn()

        if self.musicpainter.toolbar_expanded:
            self.activity_btn.set_expanded(False)
            self.toolbar_changed(widget)

    def to_keyboard_mode(self, widget):
        self.musicpainter.to_keyboard_mode()
        self.show_scale_btn()

        if self.musicpainter.toolbar_expanded:
            self.activity_btn.set_expanded(False)
            self.toolbar_changed(widget)

    def configure_ins(self, widget):
        self.musicpainter.to_instrument_view()
        self.hide_scale_btn()

        if self.musicpainter.toolbar_expanded:
            self.activity_btn.set_expanded(False)
            self.toolbar_changed(widget)

    def choose_scale(self, widget):
        self.musicpainter.choose_scale()

    def hide_scale_btn(self):
        if self.btn_added:
            self.seperator.set_visible(False)
            self.configure_scale_btn.set_visible(False)

    def show_scale_btn(self):
        if not self.btn_added:
            self.toolbar_box.toolbar.insert(self.seperator, 6)
            self.toolbar_box.toolbar.insert(self.configure_scale_btn, 7)
            self.toolbar_box.show_all()
            self.btn_added = True
        else:
            self.seperator.set_visible(True)
            self.configure_scale_btn.set_visible(True)

    def set_active_btn(self, mode):
        if mode == 'canvas':
            self.canvas_mode_btn.set_active(True)
        elif mode == 'keyboard':
            self.keyboard_mode_btn.set_active(True)
        elif mode == 'instruments':
            self.configure_ins_btn.set_active(True)

    def set_scale(self, flag):
        self.configure_scale_btn.set_active(flag)

    def hide_scale_btn(self):
        self.seperator.set_visible(False)
        self.configure_scale_btn.set_visible(False)

    def _keep_cb(self, data=None):
        #print "to keep()"
        #self.musicpainter.canvas.save_file()
        return

    def _cleanup_cb(self, data=None):
        return

    def _focus_in(self, event, data=None):
        return

    def _focus_out(self, event, data=None):
        return

    def onActive(self, widget=None, event=None):
        #if widget.props.active == False:
        #    print "MusicpainterActivity.onActive: to disconnect"
        #    self.musicpainter.deactivate()
        ##else:
        #    #print "MusicpainterActivity.onActive: to re-connect"
        #    #self.musicpainter.reactivate()
        return

    def read_file(self, file_path):
        #'''Read file from Sugar Journal.'''
        #print "read file: " + file_path + " pending"
        self.to_read = file_path
        self.uid = self.metadata['uid']
        #print self.metadata.keys()
        return

    #def create_journal(self):

#file_path = 'temp.mpn'
#journal_entry = datastore.create()
#try:
#print "new entry uid after create: " + str(journal_entry.metadata['uid'])
#except:
#print "no uid"
#journal_entry.metadata['title'] = 'create journal test'
#journal_entry.file_path = file_path
#self.musicpainter.score.write_journal(file_path)
#datastore.write(journal_entry)
#os.remove(file_path)
#print "journal created"
#try:
#print "new entry uid: " + str(journal_entry.metadata['uid'])
#except:
#print "no uid"

#def create_journal(self):
#print 'create_journal()'
#journal_entry = datastore.create()
#journal_entry.metadata['activity'] = self.get_bundle_id()
#journal_entry.metadata['mime_type'] = 'application/x-musicpainter'
#datastore.write(journal_entry)

    def update_uid(self,
                   uid):  # actually, this is meant to screw up the original id
        #self.metadata['uid'] = uid
        self._jobject.object_id = uid

    def update_title(self, title):
        self.metadata['title'] = title
        self.title_box.entry.set_text(title)

    def get_description(self):
        try:
            return self.metadata['description']
        except:
            return

    def write_file(self, file_path):
        #'''Save file on Sugar Journal. '''
        print "write journal: " + file_path
        #print "uid = " + self.metadata['uid']
        #if self._jobject.object_id == None or self.metadata['uid'] == None:
        #print 'no uid yet'
        uid = self.musicpainter.score.uid
        #uid = self.metadata['uid']
        #else:

        #print "wait for uid"
        #return
        self.musicpainter.score.title = self.metadata['title']
        try:
            self.musicpainter.score.description = self.metadata['description']
        except:
            print "no description"
        self.musicpainter.score.write_journal(file_path, uid)
        #self.musicpainter.score.write_journal(file_path, self._jobject.object_id)
        self.metadata['activity'] = self.get_bundle_id()
        self.metadata['mime_type'] = 'activity-musicpainter'
        self.metadata['view'] = self.musicpainter.get_current_view()

    def init_view_sugar(self, view):
        if view == 'canvas':
            self.toolbar_box.toolbar.insert(self.seperator, 6)
            self.toolbar_box.toolbar.insert(self.configure_scale_btn, 7)
            self.toolbar_box.show_all()
            self.btn_added = True
        elif view == 'keyboard':
            self.toolbar_box.toolbar.insert(self.seperator, 6)
            self.toolbar_box.toolbar.insert(self.configure_scale_btn, 7)
            self.toolbar_box.show_all()
            self.btn_added = True
        self.set_active_btn(view)
Exemplo n.º 20
0
    def __init__(self, handle):

        activity.Activity.__init__(self, handle, True)

        self.max_participants = 1

        # CHART_OPTIONS

        self.x_label = ""
        self.y_label = ""
        self.chart_color = utils.get_user_fill_color('str')
        self.chart_line_color = utils.get_user_stroke_color('str')
        self.current_chart = None
        self.charts_area = None
        self.chart_data = []

        # TOOLBARS
        toolbarbox = ToolbarBox()

        activity_button = ActivityToolbarButton(self)
        activity_btn_toolbar = activity_button.page

        activity_btn_toolbar.title.connect('changed', self._set_chart_title)

        save_as_image = ToolButton("save-as-image")
        save_as_image.connect("clicked", self._save_as_image)
        save_as_image.set_tooltip(_("Save as image"))
        activity_btn_toolbar.insert(save_as_image, -1)

        save_as_image.show()

        toolbarbox.toolbar.insert(activity_button, 0)

        import_freespace = ToolButton("import-freespace")
        import_freespace.connect("clicked", self.__import_freespace_cb)
        import_freespace.set_tooltip(_("Read Freespace data"))
        toolbarbox.toolbar.insert(import_freespace, -1)
        import_freespace.show()

        import_journal = ToolButton('import-journal')
        import_journal.connect('clicked', self.__import_journal_cb)
        import_journal.set_tooltip(_('Read Journal data'))
        toolbarbox.toolbar.insert(import_journal, -1)
        import_journal.show()

        import_turtle = ToolButton('import-turtle')
        import_turtle.connect('clicked', self.__import_turtle_cb)
        import_turtle.set_tooltip(_('Read Turtle data'))
        toolbarbox.toolbar.insert(import_turtle, -1)
        import_turtle.show()

        separator = Gtk.SeparatorToolItem()
        separator.set_draw(True)
        separator.set_expand(False)
        toolbarbox.toolbar.insert(separator, -1)

        add_vbar_chart = RadioToolButton()
        add_vbar_chart.connect("clicked", self._add_chart_cb, "vbar")
        add_vbar_chart.set_tooltip(_("Vertical Bar Chart"))
        add_vbar_chart.props.icon_name = "vbar"
        charts_group = add_vbar_chart
        toolbarbox.toolbar.insert(add_vbar_chart, -1)

        add_hbar_chart = RadioToolButton()
        add_hbar_chart.connect("clicked", self._add_chart_cb, "hbar")
        add_hbar_chart.set_tooltip(_("Horizontal Bar Chart"))
        add_hbar_chart.props.icon_name = "hbar"
        add_hbar_chart.props.group = charts_group
        toolbarbox.toolbar.insert(add_hbar_chart, -1)

        add_line_chart = RadioToolButton()
        add_line_chart.connect("clicked", self._add_chart_cb, "line")
        add_line_chart.set_tooltip(_("Line Bar Chart"))
        add_line_chart.props.icon_name = "line"
        add_line_chart.props.group = charts_group
        toolbarbox.toolbar.insert(add_line_chart, -1)

        add_pie_chart = RadioToolButton()
        add_pie_chart.connect("clicked", self._add_chart_cb, "pie")
        add_pie_chart.set_tooltip(_("Pie Chart"))
        add_pie_chart.props.icon_name = "pie"
        add_pie_chart.props.group = charts_group
        add_pie_chart.set_active(True)
        toolbarbox.toolbar.insert(add_pie_chart, -1)

        self.chart_type_buttons = [
            add_vbar_chart, add_hbar_chart, add_line_chart, add_pie_chart
        ]

        separator = Gtk.SeparatorToolItem()
        separator.set_draw(True)
        separator.set_expand(False)
        toolbarbox.toolbar.insert(separator, -1)

        fullscreen_btn = ToolButton('view-fullscreen')
        fullscreen_btn.set_tooltip(_('Fullscreen'))
        fullscreen_btn.connect("clicked", self.__fullscreen_cb)

        toolbarbox.toolbar.insert(fullscreen_btn, -1)

        charthelp.create_help(toolbarbox.toolbar)

        separator = Gtk.SeparatorToolItem()
        separator.set_draw(False)
        separator.set_expand(True)
        toolbarbox.toolbar.insert(separator, -1)

        stopbtn = StopButton(self)
        toolbarbox.toolbar.insert(stopbtn, -1)

        self.set_toolbar_box(toolbarbox)

        # CANVAS
        paned = Gtk.HPaned()
        box = Gtk.VBox()
        self.box = box

        # Set the info box width to 1/3 of the screen:
        def size_allocate_cb(widget, allocation):
            paned.disconnect(self._setup_handle)
            box_width = allocation.width / 3
            box.set_size_request(box_width, -1)

        self._setup_handle = paned.connect('size_allocate', size_allocate_cb)

        scroll = Gtk.ScrolledWindow()
        scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        self.labels_and_values = ChartData(self)
        scroll.add(self.labels_and_values)

        self.labels_and_values.connect("label-changed", self._label_changed)
        self.labels_and_values.connect("value-changed", self._value_changed)

        box.pack_start(scroll, True, True, 0)

        paned.add1(box)

        # CHARTS AREA

        eventbox = Gtk.EventBox()
        self.charts_area = ChartArea(self)
        self.charts_area.connect('size_allocate', self._chart_size_allocate)

        eventbox.modify_bg(Gtk.StateType.NORMAL, _WHITE)

        eventbox.add(self.charts_area)
        paned.add2(eventbox)

        self.set_canvas(paned)

        self.show_all()
Exemplo n.º 21
0
class VncLauncherActivity(activity.Activity):
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)

        self.max_participants = 1

        self.toolbarbox = ToolbarBox()
        self.toolbar = self.toolbarbox.toolbar

        self.start_vnc = RadioToolButton(icon_name="start_vnc",
                                         tooltip=_("Start VNC Server"))

        self.stop_vnc = RadioToolButton(icon_name="stop_vnc",
                                        tooltip=_("Stop VNC Server"),
                                        group=self.start_vnc)

        self.stop_vnc.set_active(True)

        self.get_ipbutton = ToolButton(icon_name="get_ip",
                                       tooltip=_("Get the current IP"))

        ##
        self.messages = Gtk.TreeView()
        self.messages.set_rules_hint(True)
        modelo = Gtk.ListStore(str, str, Gdk.Color)
        self.messages.set_model(modelo)
        render = Gtk.CellRendererText()
        render1 = Gtk.CellRendererText()

        column1 = Gtk.TreeViewColumn(_("Hour"), render, markup=0)
        column2 = Gtk.TreeViewColumn(_("Message"), render1, markup=1)
        column1.add_attribute(render, 'foreground-gdk', 2)
        column2.add_attribute(render1, 'foreground-gdk', 2)

        self.messages.append_column(column1)
        self.messages.append_column(column2)
        color = Gdk.color_parse("dark blue")
        modelo.insert(0, [
            time.strftime("\n<b>%H:%M:%S</b>\n"),
            _("\n<b>Start of activity.</b>\n"), color
        ])

        self.showed_message_stop = True
        self.showed_message_start = False
        self.isrunning = True

        self.stop_vnc.connect("clicked", self.__stop_vnc)
        self.start_vnc.connect("clicked", self.__start_vnc)
        self.clear_model = ToolButton(icon_name="clear_console",
                                      tooltip=_("Delete messages"))
        self.clear_model.connect("clicked", lambda x: modelo.clear())
        self.get_ipbutton.connect("clicked", self.__get_ip)
        self.last_message = 1

        self.__get_x11vnc_path()
        ##
        separator = Gtk.SeparatorToolItem()
        separator.props.draw = False
        separator.set_expand(True)

        self.stop_activity = StopButton(self)

        self.toolbar.insert(ActivityToolbarButton(self), -1)
        self.toolbar.insert(Gtk.SeparatorToolItem(), -1)
        self.toolbar.insert(self.start_vnc, -1)
        self.toolbar.insert(self.stop_vnc, -1)
        self.toolbar.insert(Gtk.SeparatorToolItem(), -1)
        self.toolbar.insert(self.get_ipbutton, -1)
        self.toolbar.insert(self.clear_model, -1)
        self.toolbar.insert(separator, -1)
        self.toolbar.insert(self.stop_activity, -1)

        self.messages_scroll = Gtk.ScrolledWindow()
        self.messages_scroll.set_policy(Gtk.PolicyType.AUTOMATIC,
                                        Gtk.PolicyType.AUTOMATIC)
        self.messages_scroll.add_with_viewport(self.messages)

        self.set_toolbar_box(self.toolbarbox)
        self.set_canvas(self.messages_scroll)

        self.show_all()
        GObject.timeout_add(100, self.__check_is_on)

    def __check_is_on(self):
        pid = subprocess.getoutput("pidof x11vnc")
        if self.start_vnc.get_active() and pid == "" and self.isrunning:
            self.showed_message_stop = True
            self.stop_vnc.set_active(True)
            self.start_vnc.set_active(False)
            self.showed_message_start = False

            color = Gdk.color_parse("dark red")
            self.messages.get_model().insert(self.last_message, [
                time.strftime("\n<b>%H:%M:%S</b>\n"),
                ("\n<b>It has stopped unexpectedly the server..</b>\n"), color
            ])
            self.last_message += 1

        return True

    def __get_x11vnc_path(self):
        system = platform.machine()
        color = Gdk.color_parse("dark red")
        if os.path.exists("/usr/bin/x11vnc"):
            self.path = "/usr/bin/x11vnc"
            message = _("PATH: %s") % self.path
        else:
            if "arm" in system:
                self.path = os.path.join(activity.get_bundle_path(), "bin",
                                         "arm", "x11vnc")
            elif "64" in system:
                self.path = os.path.join(activity.get_bundle_path(), "bin",
                                         "x64", "x11vnc")
            else:
                self.path = os.path.join(activity.get_bundle_path(), "bin",
                                         "i586", "x11vnc")

            os.environ["LD_LIBRARY_PATH"] = self.path.replace("x11vnc", "lib/")
            message = _("PATH: %s") % self.path

        self.messages.get_model().insert(self.last_message, [
            time.strftime("\n<b>%H:%M:%S</b>\n"), "<b>" + message + "</b>",
            color
        ])
        self.last_message += 1

    def __start_vnc(self, widget):
        def servidor():
            subprocess.getoutput(self.path)

        Thread(target=servidor).start()

        if not self.showed_message_start:
            self.showed_message_start = True
            pass
        else:
            return

        self.showed_message_stop = False
        self.isrunning = True
        color = Gdk.color_parse("green")
        self.messages.get_model().insert(self.last_message, [
            time.strftime("\n<b>%H:%M:%S</b>\n"),
            ("\n<b>VNC server is started</b>\n"), color
        ])
        self.last_message += 1

    def __stop_vnc(self, widget):

        if not self.showed_message_stop:
            self.showed_message_stop = True
            pass
        else:
            return

        self.showed_message_start = False
        self.pid_nuevo = subprocess.getoutput("pidof x11vnc")
        color = Gdk.color_parse('red')

        os.system("kill " + self.pid_nuevo)

        self.messages.get_model().insert(self.last_message, [
            time.strftime("\n<b>%H:%M:%S</b>\n"),
            ("\n<b>The VNC server is now stopped.</b>\n"), color
        ])
        self.last_message += 1

    def close(self):
        self.isrunning = False
        pid = subprocess.getoutput("pidof x11vnc")
        os.system("kill " + pid)
        self.destroy()

    def __get_ip(self, widget):
        system = platform.platform()
        if "olpc" in system:
            target = "eth0"
        else:
            target = "wlan0"

        ifconfig = "/sbin/ifconfig"
        cmd = "%s %s" % (ifconfig, target)
        output = subprocess.getoutput(cmd)
        error = _("No wireless connection.")
        ip = error
        inet = output.find('inet')
        if inet >= 0:
            start = inet + len('inet')
            end = output.find(" ", start + 1)
            ip = output[start:end]
        else:
            ip = error

        if ip == _("No wireless connection."):
            mensaje = error
        else:
            ip = ip.replace(":", "")
            ip = ip.replace("addr", "")
            ip = ip.replace(" ", "")
            mensaje = "IP: " + ip
        color = Gdk.color_parse("dark blue")
        self.messages.get_model().insert(self.last_message, [
            time.strftime("\n<b>%H:%M:%S</b>\n"), "\n<b>" + mensaje + "</b>\n",
            color
        ])

        self.last_message += 1
Exemplo n.º 22
0
class HelpPanel(Gtk.Grid):

    def __init__(self, task_master):
        Gtk.Grid.__init__(self)
        self.set_row_spacing(style.DEFAULT_SPACING)
        self.set_column_spacing(style.DEFAULT_SPACING)
        self.set_column_homogeneous(True)
        self.set_border_width(style.DEFAULT_SPACING)

        self._task_master = task_master
        self._connected = False
        self._mode = _FEEDBACK_TICKET

        alignment = Gtk.Alignment.new(0., 0.5, 0., 0.)
        phone_label = Gtk.Label()
        phone_label.set_use_markup(True)
        phone_label.set_justify(Gtk.Justification.LEFT)
        phone_label.set_markup(
            '<span foreground="%s" size="large">%s</span>' %
            (style.COLOR_WHITE.get_html(), _('Call: 1-800 ONE EDU\n'
                                             'Email: [email protected]')))
        alignment.add(phone_label)
        phone_label.show()
        self.attach(alignment, 0, 0, 4, 1)
        alignment.show()

        alignment = Gtk.Alignment.new(0., 0.5, 0., 0.)
        self._info_label = Gtk.Label()
        self._info_label.set_use_markup(True)
        self._info_label.set_justify(Gtk.Justification.LEFT)
        self._info_label.set_markup(
            '<span foreground="%s" size="large">%s</span>' %
            (style.COLOR_WHITE.get_html(), _('Or use the form below:')))
        alignment.add(self._info_label)
        self._info_label.show()
        self.attach(alignment, 0, 4, 4, 1)
        alignment.show()

        self._email_entry = Gtk.Entry()
        email_address = self._task_master.read_task_data(EMAIL_UID)
        if email_address is not None:
            self._email_entry.set_text(email_address)
        else:
            self._email_entry.set_text(_EMAIL_TEXT)
        self.attach(self._email_entry, 0, 5, 4, 1)
        self._email_entry.show()
        self._email_entry.connect('changed', self._email_changed_cb)
        self._email_entry.set_can_focus(True)

        grid = Gtk.Grid()
        self._feedback_button = RadioToolButton(group=None)
        self._feedback_button.set_icon_name('edit-description')
        self._feedback_button.connect('clicked', self._feedback_button_cb)
        grid.attach(self._feedback_button, 0, 0, 1, 1)
        self._feedback_button.show()

        label = Gtk.Label()
        label.set_use_markup(True)
        label.set_justify(Gtk.Justification.LEFT)
        label.set_markup('<span foreground="%s" size="large">%s</span>' %
                         (style.COLOR_WHITE.get_html(), _('Send feedback')))
        grid.attach(label, 1, 0, 1, 1)
        label.show()

        alignment = Gtk.Alignment.new(0., 0.5, 0., 0.)
        alignment.add(grid)
        grid.show()
        self.attach(alignment, 0, 6, 2, 1)
        alignment.show()

        grid = Gtk.Grid()
        self._help_button = RadioToolButton(group=self._feedback_button)
        self._help_button.set_icon_name('toolbar-help-gray')
        self._help_button.connect('clicked', self._help_button_cb)
        grid.attach(self._help_button, 0, 0, 1, 1)
        self._help_button.show()

        label = Gtk.Label()
        label.set_use_markup(True)
        label.set_justify(Gtk.Justification.LEFT)
        label.set_markup('<span foreground="%s" size="large">%s</span>' %
                         (style.COLOR_WHITE.get_html(), _('Ask for help')))
        grid.attach(label, 1, 0, 1, 1)
        label.show()

        alignment = Gtk.Alignment.new(0., 0.5, 0., 0.)
        alignment.add(grid)
        grid.show()
        self.attach(alignment, 2, 6, 2, 1)
        alignment.show()

        self._feedback_button.set_active(True)

        self._text_view = Gtk.TextView()
        self._text_view.set_wrap_mode(Gtk.WrapMode.WORD)
        self._text_view.set_size_request(-1, style.GRID_CELL_SIZE * 2)
        self._text_buffer = self._text_view.get_buffer()
        self._text_buffer.set_text(_ACTIVE_TEXT)
        self.attach(self._text_view, 0, 7, 4, 4)
        self._text_view.show()
        self._text_view.connect('focus-in-event', self._text_focus_in_cb)

        self._check_button = Gtk.CheckButton(label=_('Include screenshot?'))
        self._check_button.set_active(True)
        self.attach(self._check_button, 0, 11, 2, 1)
        self._check_button.show()

        self._send_button = Gtk.Button(_('Send'))
        self.attach(self._send_button, 3, 11, 1, 1)
        self._send_button.connect('clicked', self._send_button_cb)
        self._send_button.show()

    def _email_changed_cb(self, widget):
        email = self._email_entry.get_text()
        if email == _EMAIL_TEXT:
            self._email_entry.set_text('')
        if utils.is_valid_email_entry(email) and self._connected:
            self._send_button.set_sensitive(True)
        else:
            self._send_button.set_sensitive(False)

    def _text_focus_in_cb(self, widget, event):
        bounds = self._text_buffer.get_bounds()
        text = self._text_buffer.get_text(bounds[0], bounds[1], True)
        email = self._email_entry.get_text()
        if text == _ACTIVE_TEXT:
            self._text_buffer.set_text('')
        if utils.is_valid_email_entry(email) and self._connected:
            self._send_button.set_sensitive(True)
        else:
            self._send_button.set_sensitive(False)

    def set_connected(self, connected):
        self._connected = connected
        if connected:
            bounds = self._text_buffer.get_bounds()
            text = self._text_buffer.get_text(bounds[0], bounds[1], True)
            if text == _INACTIVE_TEXT:
                self._text_buffer.set_text(_ACTIVE_TEXT)
            self._text_view.set_sensitive(True)
            email = self._email_entry.get_text()
            if utils.is_valid_email_entry(email):
                self._send_button.set_sensitive(True)
            else:
                self._send_button.set_sensitive(False)
        else:
            bounds = self._text_buffer.get_bounds()
            text = self._text_buffer.get_text(bounds[0], bounds[1], True)
            if text == _ACTIVE_TEXT:
                self._text_buffer.set_text(_INACTIVE_TEXT)
            self._text_buffer.set_text(_INACTIVE_TEXT)
            self._text_view.set_sensitive(False)
            self._send_button.set_sensitive(False)

    def _feedback_button_cb(self, widget=None):
        self._mode = _FEEDBACK_TICKET
        # Necessary because of a bug with Sugar radiobuttons on palettes
        self._feedback_button.set_icon_name('edit-description')
        self._help_button.set_icon_name('toolbar-help-gray')

    def _help_button_cb(self, widget=None):
        self._mode = _HELP_TICKET
        # Necessary because of a bug with Sugar radiobuttons on palettes
        self._feedback_button.set_icon_name('edit-description-gray')
        self._help_button.set_icon_name('toolbar-help')

    def _send_button_cb(self, widget=None):
        email = self._email_entry.get_text()
        if not utils.is_valid_email_entry(email):
            # We cannot send w/o valid email.
            self._email_entry.set_text(_EMAIL_TEXT)
            self._send_button.set_sensitive(False)
        else:
            self._task_master.activity.help_palette.popdown(immediate=True)
            self._task_master.activity.help_panel_visible = False
            self._task_master.activity.busy_cursor()
            GObject.idle_add(self._prepare_send_data)

    def _prepare_send_data(self):
        bounds = self._text_buffer.get_bounds()
        text = self._text_buffer.get_text(bounds[0], bounds[1], True)

        log_file_path = utils.get_log_file('org.sugarlabs.Training')

        section_index, task_index = \
            self._task_master.get_section_and_task_index()
        section_name = self._task_master.get_section_name(section_index)

        email = self._email_entry.get_text()

        name = self._task_master.read_task_data(NAME_UID)
        school = self._task_master.read_task_data(SCHOOL_NAME)
        role = self._task_master.read_task_data(ROLE_UID)

        self._data = {'ticket': self._mode, 'section': section_name,
                      'task': task_index, 'body': text, 'log': log_file_path,
                      'name': name, 'email': email, 'school': school,
                      'role': role}

        if len(self._task_master.activity.volume_data) == 1:
            training_data_path = os.path.join(
                self._task_master.activity.volume_data[0]['usb_path'],
                self._task_master.activity.volume_data[0]['uid'])
            self._data['data'] = training_data_path

        if self._check_button.get_active():
            # idle_add is not sufficient... waiting for graphics to refresh
            GObject.timeout_add(2000, self._take_screen_shot_and_send)
        else:
            self._send_data()

    def _do_send(self, data):
        subject = data['ticket']
        body = data['body']

        helper = FieldHelper()
        fields = []
        fields.append(helper.get_field(0, data['section']))
        fields.append(helper.get_field(1, data['task']))
        if data['school']:
            fields.append(helper.get_field(2, data['school']))
        if data['role']:
            fields.append(helper.get_field(3, data['role']))

        uploads = []
        if 'screenshot' in data:
            attachment = Attachment()
            attachment.create(data['screenshot'], 'shot.png', 'image/png')
            uploads.append(attachment.token())
        if 'log' in data:
            attachment = Attachment()
            attachment.create(data['log'], 'log.txt', 'text/plain')
            uploads.append(attachment.token())
        if 'data' in data:
            attachment = Attachment()
            try:
                attachment.create(data['data'], 'data.txt', 'text/plain')
            except IOError as e:
                logging.error('Could not include training data: %s' % e)
            else:
                uploads.append(attachment.token())

        ticket = Ticket()
        ticket.create(subject, body, uploads,
                      data['name'], data['email'], fields)

    def _take_screen_shot_and_send(self):
        self._data['screenshot'] = utils.take_screen_shot()
        self._send_data()

    def _send_data(self):
        logging.debug(self._data)
        try:
            self._do_send(self._data)
        except ZendeskError as e:
            _logger.error('Could not upload %s to zendesk: %s' %
                          (self._data['ticket'], e))
            self._task_master.activity.transfer_failed_signal.emit()
        else:
            self._task_master.activity.transfer_completed_signal.emit()

        self._task_master.activity.reset_cursor()
Exemplo n.º 23
0
    def __init__(self, handle):

        activity.Activity.__init__(self, handle, True)

        self.max_participants = 1

        # CHART_OPTIONS

        self.x_label = ""
        self.y_label = ""
        self.chart_color = utils.get_user_fill_color('str')
        self.chart_line_color = utils.get_user_stroke_color('str')
        self.current_chart = None
        self.charts_area = None
        self.chart_data = []

        # TOOLBARS
        toolbarbox = ToolbarBox()

        activity_button = ActivityToolbarButton(self)
        activity_btn_toolbar = activity_button.page

        activity_btn_toolbar.title.connect('changed', self._set_chart_title)

        save_as_image = ToolButton("save-as-image")
        save_as_image.connect("clicked", self._save_as_image)
        save_as_image.set_tooltip(_("Save as image"))
        activity_btn_toolbar.insert(save_as_image, -1)

        save_as_image.show()

        toolbarbox.toolbar.insert(activity_button, 0)

        import_freespace = ToolButton("import-freespace")
        import_freespace.connect("clicked", self.__import_freespace_cb)
        import_freespace.set_tooltip(_("Read Freespace data"))
        toolbarbox.toolbar.insert(import_freespace, -1)
        import_freespace.show()

        import_journal = ToolButton('import-journal')
        import_journal.connect('clicked', self.__import_journal_cb)
        import_journal.set_tooltip(_('Read Journal data'))
        toolbarbox.toolbar.insert(import_journal, -1)
        import_journal.show()

        import_turtle = ToolButton('import-turtle')
        import_turtle.connect('clicked', self.__import_turtle_cb)
        import_turtle.set_tooltip(_('Read Turtle data'))
        toolbarbox.toolbar.insert(import_turtle, -1)
        import_turtle.show()

        separator = Gtk.SeparatorToolItem()
        separator.set_draw(True)
        separator.set_expand(False)
        toolbarbox.toolbar.insert(separator, -1)

        add_vbar_chart = RadioToolButton()
        add_vbar_chart.connect("clicked", self._add_chart_cb, "vbar")
        add_vbar_chart.set_tooltip(_("Vertical Bar Chart"))
        add_vbar_chart.props.icon_name = "vbar"
        charts_group = add_vbar_chart
        toolbarbox.toolbar.insert(add_vbar_chart, -1)

        add_hbar_chart = RadioToolButton()
        add_hbar_chart.connect("clicked", self._add_chart_cb, "hbar")
        add_hbar_chart.set_tooltip(_("Horizontal Bar Chart"))
        add_hbar_chart.props.icon_name = "hbar"
        add_hbar_chart.props.group = charts_group
        toolbarbox.toolbar.insert(add_hbar_chart, -1)

        add_pie_chart = RadioToolButton()
        add_pie_chart.connect("clicked", self._add_chart_cb, "pie")
        add_pie_chart.set_tooltip(_("Pie Chart"))
        add_pie_chart.props.icon_name = "pie"
        add_pie_chart.props.group = charts_group
        add_pie_chart.set_active(True)
        toolbarbox.toolbar.insert(add_pie_chart, -1)

        self.chart_type_buttons = [add_vbar_chart,
                                   add_hbar_chart,
                                   add_pie_chart]

        separator = Gtk.SeparatorToolItem()
        separator.set_draw(True)
        separator.set_expand(False)
        toolbarbox.toolbar.insert(separator, -1)

        fullscreen_btn = ToolButton('view-fullscreen')
        fullscreen_btn.set_tooltip(_('Fullscreen'))
        fullscreen_btn.connect("clicked", self.__fullscreen_cb)

        toolbarbox.toolbar.insert(fullscreen_btn, -1)

        charthelp.create_help(toolbarbox.toolbar)

        separator = Gtk.SeparatorToolItem()
        separator.set_draw(False)
        separator.set_expand(True)
        toolbarbox.toolbar.insert(separator, -1)

        stopbtn = StopButton(self)
        toolbarbox.toolbar.insert(stopbtn, -1)

        self.set_toolbar_box(toolbarbox)

        # CANVAS
        paned = Gtk.HPaned()
        box = Gtk.VBox()
        self.box = box

        # Set the info box width to 1/3 of the screen:
        def size_allocate_cb(widget, allocation):
            paned.disconnect(self._setup_handle)
            box_width = allocation.width / 3
            box.set_size_request(box_width, -1)

        self._setup_handle = paned.connect('size_allocate',
                    size_allocate_cb)

        scroll = Gtk.ScrolledWindow()
        scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        self.labels_and_values = ChartData(self)
        scroll.add(self.labels_and_values)

        self.labels_and_values.connect("label-changed", self._label_changed)
        self.labels_and_values.connect("value-changed", self._value_changed)

        box.pack_start(scroll, True, True, 0)

        paned.add1(box)

        # CHARTS AREA

        eventbox = Gtk.EventBox()
        self.charts_area = ChartArea(self)
        self.charts_area.connect('size_allocate', self._chart_size_allocate)

        eventbox.modify_bg(Gtk.StateType.NORMAL, _WHITE)

        eventbox.add(self.charts_area)
        paned.add2(eventbox)

        self.set_canvas(paned)

        self.show_all()