def build_toolbar(self): """Build our Activity toolbar for the Sugar system.""" toolbar_box = ToolbarBox() activity_button = ActivityToolbarButton(self) toolbar_box.toolbar.insert(activity_button, -1) activity_button.show() separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) toolbar_box.toolbar.insert(separator, -1) separator.show() stop_button = StopButton(self) toolbar_box.toolbar.insert(stop_button, -1) stop_button.show() self.set_toolbar_box(toolbar_box) toolbar_box.show_all() self.connect("destroy", self.__stop_pygame) return toolbar_box
def build_toolbar(self): toolbox = ToolbarBox() activity_button = ActivityToolbarButton(self) toolbox.toolbar.insert(activity_button, -1) activity_button.show() barra = toolbox.toolbar """ separator1 = gtk.SeparatorToolItem() separator1.props.draw = True separator1.set_expand(False) barra.insert(separator1,-1) save_button = ToolButton('filesave') save_button.set_tooltip(_('Save Image')) save_button.connect('clicked', self._savebutton_cb) barra.insert(save_button, -1) save_button.show()""" separator2 = gtk.SeparatorToolItem() separator2.props.draw = False separator2.set_expand(True) barra.insert(separator2, -1) stop_button = StopButton(self) stop_button.props.accelerator = '<Ctrl>q' barra.insert(stop_button, -1) stop_button.show() self.set_toolbar_box(toolbox) toolbox.show_all()
def build_toolbar(self): toolbar_box = ToolbarBox() activity_button = ActivityToolbarButton(self) toolbar_box.toolbar.insert(activity_button, 0) activity_button.show() separator = gtk.SeparatorToolItem() toolbar_box.toolbar.insert(separator, -1) separator.show() separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_size_request(0, -1) 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_all() return toolbar_box
def _setup_toolbar(self): if pre_086_toolbars: self.toolbox = Toolbox() self.set_toolbox(self.toolbox) toolbar = gtk.Toolbar() self.toolbox.add_toolbar('Toolbar', toolbar) toolbar_box = self.toolbox else: toolbar_box = ToolbarBox() toolbar = toolbar_box.toolbar self.set_toolbar_box(toolbar_box) self._restore_button = RestoreButton() self._restore_button.connect('clicked', self._restore_cb) self._restore_button.set_sensitive(False) toolbar.insert(self._restore_button, -1) separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) toolbar.insert(separator, -1) stop_button = StopButton(self) toolbar.insert(stop_button, -1) toolbar_box.show_all()
def create_toolbar(self): """ This function creates the game toolbar """ toolbar_box = ToolbarBox() self.set_toolbar_box(toolbar_box) toolbar_box.toolbar.insert(ActivityToolbarButton(self), -1) separator = gtk.SeparatorToolItem() separator.props.draw = False toolbar_box.toolbar.insert(separator, -1) scoreButton = ScoreButton(self) toolbar_box.toolbar.insert(scoreButton, -1) separator = gtk.SeparatorToolItem() separator.props.draw = False toolbar_box.toolbar.insert(separator, -1) self._modes = ToolComboBox() self._modelist = ['Select Mode', '+ Addition', '- Subtraction'] for i, f in enumerate(self._modelist): self._modes.combo.append_item(i, f) self.modes_handle_id = self._modes.combo.connect("changed", self._change_modes_toolbar) toolbar_box.toolbar.insert(self._modes, -1) self._modes.combo.set_active(0) separator = gtk.SeparatorToolItem() separator.props.draw = False toolbar_box.toolbar.insert(separator, -1) scorestats = VisualScore(self) toolbar_box.toolbar.insert(scorestats, -1) separator = gtk.SeparatorToolItem() separator.props.draw = False toolbar_box.toolbar.insert(separator, -1) separator = gtk.SeparatorToolItem() separator.props.draw = False toolbar_box.toolbar.insert(separator, -1) timestats = VisualTime(self) toolbar_box.toolbar.insert(timestats, -1) separator = gtk.SeparatorToolItem() separator.props.draw = False toolbar_box.toolbar.insert(separator, -1) separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) toolbar_box.toolbar.insert(separator, -1) stopButton = StopButton(self) toolbar_box.toolbar.insert(stopButton, -1) toolbar_box.show_all()
def build_toolbar(self): self.max_participants = 1 toolbox = ToolbarBox() activity_button = ActivityToolbarButton(self) toolbox.toolbar.insert(activity_button, -1) activity_button.show() pano_toolbar = toolbox.toolbar new_button = ToolButton('stock_refresh') new_button.set_tooltip(_('New Panorama')) new_button.connect('clicked', self.new_event) pano_toolbar.insert(new_button, -1) new_button.show() capture_button = ToolButton('add_capture') capture_button.set_tooltip(_('Add a capture to the Panorama')) capture_button.connect('clicked', self.capture_event) pano_toolbar.insert(capture_button, -1) capture_button.show() stitch_button = ToolButton('format-columns-triple') stitch_button.set_tooltip(_('Stitch Panorama')) stitch_button.connect('clicked', self.stitch_event) pano_toolbar.insert(stitch_button, -1) stitch_button.show() stiching_auto = ToolButton('media-playback-start') stiching_auto.set_tooltip(_('Enable auto-stitch')) stiching_auto.connect('clicked', self.change_stich) pano_toolbar.insert(stiching_auto, -1) save_button = ToolButton('filesave') save_button.set_tooltip(_('Save Panorama')) save_button.connect('clicked', self.save_event) pano_toolbar.insert(save_button, -1) save_button.show() separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) pano_toolbar.insert(separator,-1) stop_button = StopButton(self) stop_button.props.accelerator = '<Ctrl>q' pano_toolbar.insert(stop_button, -1) stop_button.show() self.set_toolbar_box(toolbox) toolbox.show_all()
def build_toolbar(self): toolbar_box = ToolbarBox() toolbar_box.show() activity_button = ActivityToolbarButton(self) toolbar_box.toolbar.insert(activity_button, -1) activity_button.show() separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) toolbar_box.toolbar.insert(separator, -1) stop_button = StopButton(self) toolbar_box.toolbar.insert(stop_button, -1) stop_button.show() self.set_toolbar_box(toolbar_box) toolbar_box.show_all()
def build_toolbar(self): toolbox = ToolbarBox() activity_button = ActivityToolbarButton(self) toolbox.toolbar.insert(activity_button, -1) activity_button.show() separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) toolbox.toolbar.insert(separator, -1) stop_button = StopButton(self) stop_button.props.accelerator = '<Ctrl>q' toolbox.toolbar.insert(stop_button, -1) stop_button.show() self.set_toolbar_box(toolbox) toolbox.show_all()
def __init__(self, handle): activity.Activity.__init__(self, handle) # we do not have collaboration features # make the share option insensitive self.max_participants = 1 # toolbar with the new toolbar redesign toolbar_box = ToolbarBox() activity_button = ActivityToolbarButton(self) toolbar_box.toolbar.insert(activity_button, 0) toolbar_box.toolbar.insert(gtk.SeparatorToolItem(), -1) self.image_viewer = ImageCollectionViewer(False) prev_bt = ToolButton("go-previous-paired") prev_bt.connect("clicked", self.image_viewer.prev_anim_clicked_cb, None) toolbar_box.toolbar.insert(prev_bt, -1) next_bt = ToolButton("go-next-paired") next_bt.connect("clicked", self.image_viewer.next_anim_clicked_cb, None) toolbar_box.toolbar.insert(next_bt, -1) separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) toolbar_box.toolbar.insert(separator, -1) stop_button = StopButton(self) toolbar_box.toolbar.insert(stop_button, -1) self.set_toolbar_box(toolbar_box) toolbar_box.show_all() self.modify_bg(gtk.STATE_NORMAL, style.COLOR_WHITE.get_gdk_color()) self.set_canvas(self.image_viewer)
def __init__(self, handle): activity.Activity.__init__(self, handle) # we do not have collaboration features # make the share option insensitive self.max_participants = 1 # toolbar with the new toolbar redesign toolbar_box = ToolbarBox() activity_button = ActivityToolbarButton(self) toolbar_box.toolbar.insert(activity_button, 0) toolbar_box.toolbar.insert(gtk.SeparatorToolItem(), -1) self.image_viewer = ImageCollectionViewer(False) prev_bt = ToolButton("go-previous-paired") prev_bt.connect("clicked", self.image_viewer.prev_anim_clicked_cb, None) toolbar_box.toolbar.insert(prev_bt, -1) next_bt = ToolButton("go-next-paired") next_bt.connect("clicked", self.image_viewer.next_anim_clicked_cb, None) toolbar_box.toolbar.insert(next_bt, -1) separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) toolbar_box.toolbar.insert(separator, -1) stop_button = StopButton(self) toolbar_box.toolbar.insert(stop_button, -1) self.set_toolbar_box(toolbar_box) toolbar_box.show_all() self.modify_bg(gtk.STATE_NORMAL, style.COLOR_WHITE.get_gdk_color()) self.set_canvas(self.image_viewer)
def build_toolbar(self): """Build our Activity toolbar for the Sugar system.""" toolbar_box = ToolbarBox() activity_button = ActivityToolbarButton(self) toolbar_box.toolbar.insert(activity_button, 0) activity_button.show() separator = gtk.SeparatorToolItem() toolbar_box.toolbar.insert(separator, -1) separator.show() easier_button = ToolButton('create-easier') easier_button.set_tooltip(_('Easier level')) easier_button.connect('clicked', self._easier_button_cb) toolbar_box.toolbar.insert(easier_button, -1) harder_button = ToolButton('create-harder') harder_button.set_tooltip(_('Harder level')) harder_button.connect('clicked', self._harder_button_cb) toolbar_box.toolbar.insert(harder_button, -1) separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_size_request(0, -1) 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_all() self.connect("destroy", self.__stop_pygame) return toolbar_box
class CalcLayout: FONT_SMALL_POINTS = 10 FONT_SMALL = "sans %d" % FONT_SMALL_POINTS FONT_SMALL_NARROW = "sans italic %d" % FONT_SMALL_POINTS FONT_BIG_POINTS = 14 FONT_BIG = "sans bold %d" % FONT_BIG_POINTS FONT_BIG_NARROW = "sans italic 14" FONT_BIGGER_POINTS = 18 FONT_BIGGER = "sans bold %d" % FONT_BIGGER_POINTS def __init__(self, parent): self._parent = parent self._own_equations = [] self._other_equations = [] self._showing_history = True self._showing_all_history = True self._var_textviews = {} self.graph_selected = None self.create_dialog() def create_color(self, rf, gf, bf): return gtk.gdk.Color(int(rf * 0xFFFF), int(gf * 0xFFFF), int(bf * 0xFFFF)) def create_button_data(self): """Create a list with button information. We need to do that here because we want to include the lambda functions.""" mul_sym = self._parent.ml.mul_sym div_sym = self._parent.ml.div_sym equ_sym = self._parent.ml.equ_sym self.button_data = [ # [x, y, width, label, bgcol, cb] [0, 0, 2, 1, u'\u2190', self.col_gray3, lambda w: self._parent.move_left()], [2, 0, 2, 1, u'\u2192', self.col_gray3, lambda w: self._parent.move_right()], [4, 0, 2, 1, u'\u232B', self.col_gray3, lambda w: self._parent.remove_character(-1)], [0, 1, 1, 2, '7', self.col_gray2, lambda w: self._parent.add_text('7')], [1, 1, 1, 2, '8', self.col_gray2, lambda w: self._parent.add_text('8')], [2, 1, 1, 2, '9', self.col_gray2, lambda w: self._parent.add_text('9')], [0, 3, 1, 2, '4', self.col_gray2, lambda w: self._parent.add_text('4')], [1, 3, 1, 2, '5', self.col_gray2, lambda w: self._parent.add_text('5')], [2, 3, 1, 2, '6', self.col_gray2, lambda w: self._parent.add_text('6')], [0, 5, 1, 2, '1', self.col_gray2, lambda w: self._parent.add_text('1')], [1, 5, 1, 2, '2', self.col_gray2, lambda w: self._parent.add_text('2')], [2, 5, 1, 2, '3', self.col_gray2, lambda w: self._parent.add_text('3')], [0, 7, 2, 2, '0', self.col_gray2, lambda w: self._parent.add_text('0')], [2, 7, 1, 2, '.', self.col_gray2, lambda w: self._parent.add_text('.')], [3, 1, 3, 2, _('Clear'), self.col_gray1, lambda w: self._parent.clear()], [3, 3, 1, 2, '+', self.col_gray3, lambda w: self._parent.add_text('+')], [4, 3, 1, 2, '-', self.col_gray3, lambda w: self._parent.add_text('-')], [5, 3, 1, 2, '(', self.col_gray3, lambda w: self._parent.add_text('(')], [3, 5, 1, 2, mul_sym, self.col_gray3, lambda w: self._parent.add_text(mul_sym)], [4, 5, 1, 2, div_sym, self.col_gray3, lambda w: self._parent.add_text(div_sym)], [5, 5, 1, 2, ')', self.col_gray3, lambda w: self._parent.add_text(')')], [3, 7, 3, 2, equ_sym, self.col_gray1, lambda w: self._parent.process()], ] def create_dialog(self): """Setup most of the dialog.""" # Toolbar try: self._toolbar_box = ToolbarBox() activity_button = ActivityToolbarButton(self._parent) self._toolbar_box.toolbar.insert(activity_button, 0) def append(icon_name, label, page, position): toolbar_button = ToolbarButton() toolbar_button.props.page = page toolbar_button.props.icon_name = icon_name toolbar_button.props.label = label self._toolbar_box.toolbar.insert(toolbar_button, position) append('toolbar-edit', _('Edit'), EditToolbar(self._parent), -1) append('toolbar-algebra', _('Algebra'), AlgebraToolbar(self._parent), -1) append('toolbar-trigonometry', _('Trigonometry'), TrigonometryToolbar(self._parent), -1) append('toolbar-boolean', _('Boolean'), BooleanToolbar(self._parent), -1) self._misc_toolbar = MiscToolbar( self._parent, target_toolbar=self._toolbar_box.toolbar) append('toolbar-constants', _('Miscellaneous'), self._misc_toolbar, 5) self._stop_separator = gtk.SeparatorToolItem() self._stop_separator.props.draw = False self._stop_separator.set_expand(True) self._stop_separator.show() self._toolbar_box.toolbar.insert(self._stop_separator, -1) self._stop = StopButton(self._parent) self._toolbar_box.toolbar.insert(self._stop, -1) self._toolbar_box.show_all() self._parent.set_toolbar_box(self._toolbar_box) except NameError: # Use old toolbar design toolbox = activity.ActivityToolbox(self._parent) self._parent.set_toolbox(toolbox) toolbox.add_toolbar(_('Edit'), EditToolbar(self._parent)) toolbox.add_toolbar(_('Algebra'), AlgebraToolbar(self._parent)) toolbox.add_toolbar( _('Trigonometry'), TrigonometryToolbar(self._parent)) toolbox.add_toolbar(_('Boolean'), BooleanToolbar(self._parent)) toolbox.add_toolbar(_('Miscellaneous'), MiscToolbar(self._parent)) toolbox.show_all() # Some layout constants self.input_font = pango.FontDescription(str='sans bold 12') self.button_font = pango.FontDescription(str='sans bold 16') self.col_white = self.create_color(1.00, 1.00, 1.00) self.col_gray1 = self.create_color(0.76, 0.76, 0.76) self.col_gray2 = self.create_color(0.50, 0.50, 0.50) self.col_gray3 = self.create_color(0.25, 0.25, 0.25) self.col_black = self.create_color(0.00, 0.00, 0.00) self.col_red = self.create_color(1.00, 0.00, 0.00) # Big - Table, 16 rows, 10 columns, homogeneously divided self.grid = gtk.Table(26, 11, True) self.grid.set_border_width(0) self.grid.set_row_spacings(0) self.grid.set_col_spacings(4) # Left part: container and input vc1 = gtk.VBox(False, 0) hc1 = gtk.HBox(False, 10) eb = gtk.EventBox() eb.add(hc1) eb.modify_bg(gtk.STATE_NORMAL, self.col_black) eb.set_border_width(12) eb2 = gtk.EventBox() eb2.add(eb) eb2.modify_bg(gtk.STATE_NORMAL, self.col_black) label1 = gtk.Label(_('Label:')) label1.modify_fg(gtk.STATE_NORMAL, self.col_white) label1.set_alignment(1, 0.5) hc1.pack_start(label1, expand=False, fill=False, padding=10) self.label_entry = gtk.Entry() self.label_entry.modify_bg(gtk.STATE_INSENSITIVE, self.col_black) hc1.pack_start(self.label_entry, expand=True, fill=True, padding=0) vc1.pack_start(eb2, expand=False) self.text_entry = gtk.Entry() try: self.text_entry.props.im_module = 'gtk-im-context-simple' except AttributeError: pass self.text_entry.set_size_request(-1, 75) self.text_entry.connect('key_press_event', self._parent.ignore_key_cb) self.text_entry.modify_font(self.input_font) self.text_entry.modify_bg(gtk.STATE_INSENSITIVE, self.col_black) eb = gtk.EventBox() eb.add(self.text_entry) eb.modify_bg(gtk.STATE_NORMAL, self.col_black) eb.set_border_width(12) eb2 = gtk.EventBox() eb2.add(eb) eb2.modify_bg(gtk.STATE_NORMAL, self.col_black) vc1.pack_start(eb2, expand=True, fill=True, padding=0) self.grid.attach(vc1, 0, 7, 0, 6) # Left part: buttons self.pad = gtk.Table(9, 6, True) self.pad.set_row_spacings(12) self.pad.set_col_spacings(12) self.pad.set_border_width(12) self.create_button_data() self.buttons = {} for x, y, w, h, cap, bgcol, cb in self.button_data: button = self.create_button( _(cap), cb, self.col_white, bgcol, w, h) self.buttons[cap] = button self.pad.attach(button, x, x + w, y, y + h) eb = gtk.EventBox() eb.add(self.pad) eb.modify_bg(gtk.STATE_NORMAL, self.col_black) self.grid.attach(eb, 0, 7, 6, 26) # Right part: container and equation button hc2 = gtk.HBox() combo = ComboBox() combo.append_item(0, _('All equations')) combo.append_item(1, _('My equations')) combo.append_item(2, _('Show variables')) combo.set_active(0) combo.connect('changed', self._history_filter_cb) hc2.pack_start(combo) hc2.set_border_width(6) self.grid.attach(hc2, 7, 11, 0, 2) # Right part: last equation self.last_eq = gtk.TextView() self.last_eq.set_editable(False) self.last_eq.set_wrap_mode(gtk.WRAP_WORD_CHAR) self.last_eq.connect('realize', self._textview_realize_cb) self.last_eq.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse( sugar.profile.get_color().get_fill_color())) self.last_eq.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse( sugar.profile.get_color().get_stroke_color())) self.last_eq.set_border_window_size(gtk.TEXT_WINDOW_LEFT, 4) self.last_eq.set_border_window_size(gtk.TEXT_WINDOW_RIGHT, 4) self.last_eq.set_border_window_size(gtk.TEXT_WINDOW_TOP, 4) self.last_eq.set_border_window_size(gtk.TEXT_WINDOW_BOTTOM, 4) # TODO Fix for old Sugar 0.82 builds, red_float not available xo_color = sugar.profile.get_color() bright = ( gtk.gdk.color_parse(xo_color.get_fill_color()).red_float + gtk.gdk.color_parse(xo_color.get_fill_color()).green_float + gtk.gdk.color_parse(xo_color.get_fill_color()).blue_float) / 3.0 if bright < 0.5: self.last_eq.modify_text(gtk.STATE_NORMAL, self.col_white) else: self.last_eq.modify_text(gtk.STATE_NORMAL, self.col_black) self.grid.attach(self.last_eq, 7, 11, 2, 7) # Right part: history scrolled_window = gtk.ScrolledWindow() scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) self.history_vbox = gtk.VBox() self.history_vbox.set_homogeneous(False) self.history_vbox.set_border_width(0) self.history_vbox.set_spacing(4) self.variable_vbox = gtk.VBox() self.variable_vbox.set_homogeneous(False) self.variable_vbox.set_border_width(0) self.variable_vbox.set_spacing(4) vbox = gtk.VBox() vbox.pack_start(self.history_vbox) vbox.pack_start(self.variable_vbox) scrolled_window.add_with_viewport(vbox) self.grid.attach(scrolled_window, 7, 11, 7, 26) gtk.gdk.screen_get_default().connect('size-changed', self._configure_cb) def _configure_cb(self, event): # Maybe redo layout self._toolbar_box.toolbar.remove(self._stop) self._toolbar_box.toolbar.remove(self._stop_separator) self._misc_toolbar.update_layout() self._toolbar_box.toolbar.insert(self._stop_separator, -1) self._toolbar_box.toolbar.insert(self._stop, -1) def show_it(self): """Show the dialog.""" self._parent.set_canvas(self.grid) self._parent.show_all() self.show_history() self.text_entry.grab_focus() def showing_history(self): """Return whether we're currently showing the history (or otherwise the list of variables).""" return self._showing_history def show_history(self): """Show the history VBox.""" self._showing_history = True self.variable_vbox.hide() self.history_vbox.show() def toggle_select_graph(self, widget, host=None): # if we have a graph already selected, we must deselect it first if self.graph_selected and self.graph_selected != widget: self.toggle_select_graph(self.graph_selected) if not self.graph_selected: widget.set_visible_window(True) widget.set_above_child(True) self.graph_selected = widget white = gtk.gdk.color_parse('white') widget.modify_bg(gtk.STATE_NORMAL, white) else: widget.set_visible_window(False) self.graph_selected = False def add_equation(self, textview, own, prepend=False): """Add a gtk.TextView of an equation to the history_vbox.""" GraphEventBox = None if isinstance(textview, gtk.Image): # Add the image inside the eventBox GraphEventBox = gtk.EventBox() GraphEventBox.add(textview) GraphEventBox.set_visible_window(False) GraphEventBox.connect( 'button_press_event', self.toggle_select_graph) GraphEventBox.show() if prepend: if GraphEventBox: self.history_vbox.pack_start(GraphEventBox, False, True) self.history_vbox.reorder_child(GraphEventBox, 0) else: self.history_vbox.pack_start(textview, False, True) self.history_vbox.reorder_child(textview, 0) else: if GraphEventBox: self.history_vbox.pack_end(GraphEventBox, False, True) else: self.history_vbox.pack_end(textview, False, True) if own: if GraphEventBox: self._own_equations.append(GraphEventBox) GraphEventBox.child.show() else: self._own_equations.append(textview) textview.show() else: if self._showing_all_history: if GraphEventBox: self._other_equations.append(GraphEventBox) GraphEventBox.child.show() else: self._other_equations.append(textview) textview.show() def show_all_history(self): """Show both owned and other equations.""" self._showing_all_history = True for key in self._other_equations: if isinstance(key, gtk.EventBox): key.child.show() else: key.show() def show_own_history(self): """Show only owned equations.""" self._showing_all_history = False for key in self._other_equations: if isinstance(key, gtk.EventBox): key.child.hide() else: key.hide() def add_variable(self, varname, textview): """Add a gtk.TextView of a variable to the variable_vbox.""" if varname in self._var_textviews: self.variable_vbox.remove(self._var_textviews[varname]) del self._var_textviews[varname] self._var_textviews[varname] = textview self.variable_vbox.pack_start(textview, False, True) # Reorder textviews for a sorted list names = self._var_textviews.keys() names.sort() for i in range(len(names)): self.variable_vbox.reorder_child(self._var_textviews[names[i]], i) textview.show() def show_variables(self): """Show the variables VBox.""" self._showing_history = False self.history_vbox.hide() self.variable_vbox.show() def create_button(self, cap, cb, fgcol, bgcol, width, height): """Create a button that is set up properly.""" button = gtk.Button(_(cap)) self.modify_button_appearance(button, fgcol, bgcol, width, height) button.connect("clicked", cb) button.connect("key_press_event", self._parent.ignore_key_cb) return button def modify_button_appearance(self, button, fgcol, bgcol, width, height): """Modify button style.""" width = 50 * width height = 50 * height button.get_child().set_size_request(width, height) button.get_child().modify_font(self.button_font) button.get_child().modify_fg(gtk.STATE_NORMAL, fgcol) button.modify_bg(gtk.STATE_NORMAL, bgcol) button.modify_bg(gtk.STATE_PRELIGHT, bgcol) def _history_filter_cb(self, combo): selection = combo.get_active() if selection == 0: self.show_history() self.show_all_history() elif selection == 1: self.show_history() self.show_own_history() elif selection == 2: self.show_variables() def _textview_realize_cb(self, widget): '''Change textview properties once window is created.''' win = widget.get_window(gtk.TEXT_WINDOW_TEXT) win.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND1)) return False
class Navidad(activity.Activity): def __init__(self,handle): activity.Activity.__init__(self, handle, True) cs = ActivityToolbarButton(self) c = gtk.SeparatorToolItem() c.set_expand(True) lugar = activity.get_bundle_path() self.Musica = gst.element_factory_make('playbin') self.Musica.set_property('uri','file://'+lugar+'/Musica.ogg') self.Musica.set_state(gst.STATE_PLAYING) self.Toolbar = ToolbarBox() self.Toolbar.toolbar.insert(cs,-1) self.F = ToolButton('F') self.Toolbar.toolbar.insert(self.F,-1) self.cambiado = False self.cambiadoc = False self.E = ToolButton('E') self.Toolbar.toolbar.insert(self.E,-1) self.L = ToolButton('L') self.Toolbar.toolbar.insert(self.L,-1) self.I = ToolButton('I') self.Toolbar.toolbar.insert(self.I,-1) self.Z = ToolButton('Z') self.Toolbar.toolbar.insert(self.Z,-1) self.N = ToolButton('N') self.Toolbar.toolbar.insert(self.N,-1) self.AA = ToolButton('A') self.Toolbar.toolbar.insert(self.AA,-1) self.V = ToolButton('V') self.Toolbar.toolbar.insert(self.V,-1) self.II = ToolButton('I') self.Toolbar.toolbar.insert(self.II,-1) self.D = ToolButton('D') self.Toolbar.toolbar.insert(self.D,-1) self.AAA = ToolButton('A') self.Toolbar.toolbar.insert(self.AAA,-1) self.DD = ToolButton('D') self.Toolbar.toolbar.insert(self.DD,-1) self.cambiar() Stop = StopButton(self) b = gtk.SeparatorToolItem() b.set_expand(True) self.Toolbar.toolbar.insert(Stop,-1) self.vox = gtk.EventBox() vs = gtk.VBox() self.vox.add(vs) Imagen = gtk.Image() Imagen.set_from_file('Imagen.svg') bs = gtk.TextBuffer() bs.set_text('El equipo de CeibalJAM! te desea feliz navidad y prospero año nuevo') entry = gtk.TextView(bs) fuente = pango.FontDescription('11') entry.set_editable(False) entry.modify_font(fuente) self.vox.connect('button-release-event',self.color,entry) self.color('a','b',entry) self.label = gtk.Label(saber()) self.label.modify_font(fuente) vs.pack_start(self.label,False,False,0) color(self.label) vs.pack_end(entry,False,False,0) self.set_canvas(self.vox) vs.pack_start(Imagen,True,True,0) self.set_toolbar_box(self.Toolbar) self.show_all() gobject.timeout_add(37500, self.sonido) def sonido(self): self.Musica.set_state(gst.STATE_NULL) self.Musica.set_state(gst.STATE_PLAYING) gobject.timeout_add(37500, self.sonido) def color(self,widget=None,event=None,entrada=None): colores = ["#FA2635","#33DA40"] cc = random.choice(colores) entrada.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(cc)) self.vox.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(cc)) self.vox.show_all() gobject.timeout_add(500, self.color,'a','b',entrada) def cc(self,a=None,b=None,c=None,d=None): if self.cambiadoc: self.cambiado = True if not self.cambiadoc: self.cambiado = False def cambiar(self,a=None,b=None): if not self.cambiado: """ a cambiar """ self.F.set_icon('Fr') # 1 self.L.set_icon('Lr') # 3 self.Z.set_icon('Zr') # self.AA.set_icon('Ar') # self.II.set_icon('Ir') # self.AAA.set_icon('Ar') # """ VUELVEN """ self.E.set_icon('E') # Feliz Navidad # self.I.set_icon('I') self.N.set_icon('N') self.V.set_icon('V') self.D.set_icon('D') self.DD.set_icon('D') self.cambiadoc = True self.Toolbar.show_all() if self.cambiado: """ a cambiar """ self.F.set_icon('F') # 1 self.L.set_icon('L') # 3 self.Z.set_icon('Z') # self.AA.set_icon('A') # self.II.set_icon('I') # self.AAA.set_icon('A') # """ VUELVEN """ self.E.set_icon('Er') # Feliz Navidad # self.I.set_icon('Ir') self.N.set_icon('Nr') self.V.set_icon('Vr') self.D.set_icon('Dr') self.DD.set_icon('Dr') self.cambiadoc = False self.Toolbar.show_all() gobject.timeout_add(500, self.cc) gobject.timeout_add(500, self.cambiar)
def build_toolbar(self): toolbox = ToolbarBox() activity_button = ActivityToolbarButton(self) toolbox.toolbar.insert(activity_button, -1) activity_button.show() barra = toolbox.toolbar separador1 = gtk.SeparatorToolItem() separador1.props.draw = True barra.insert(separador1, 1) item1 = gtk.ToolItem() self.label_radio1 = gtk.Label() self.label_radio1.set_text(_('Circles between') + ' ') item1.add(self.label_radio1) barra.insert(item1, 2) item2 = gtk.ToolItem() self.cradio1 = gtk.SpinButton() self.cradio1.set_range(1, 20) self.cradio1.set_increments(1, 2) self.cradio1.props.value = self.radio_uno self.cradio1_handler = self.cradio1.connect('notify::value', self.cradio1_valor) item2.add(self.cradio1) barra.insert(item2, 3) item3 = gtk.ToolItem() self.label_and = gtk.Label() self.label_and.set_text(' ' + _('and') + ' ') item3.add(self.label_and) barra.insert(item3, 4) item4 = gtk.ToolItem() self.cradio2 = gtk.SpinButton() self.cradio2.set_range(1, 20) self.cradio2.set_increments(1, 2) self.cradio2.props.value = self.radio_dos self.cradio2_handler = self.cradio2.connect('notify::value', self.cradio2_valor) item4.add(self.cradio2) barra.insert(item4, 5) separator1 = gtk.SeparatorToolItem() separator1.props.draw = True separator1.set_expand(False) barra.insert(separator1, 6) save_button = ToolButton('filesave') save_button.set_tooltip(_('Save Image')) save_button.connect('clicked', self._savebutton_cb) barra.insert(save_button, 7) save_button.show() separator2 = gtk.SeparatorToolItem() separator2.props.draw = False separator2.set_expand(True) barra.insert(separator2, 8) stop_button = StopButton(self) stop_button.props.accelerator = '<Ctrl>q' barra.insert(stop_button, 9) stop_button.show() self.set_toolbar_box(toolbox) toolbox.show_all()
def build_toolbar(self): toolbox = ToolbarBox() activity_button = ActivityToolbarButton(self) toolbox.toolbar.insert(activity_button, -1) activity_button.show() barra = toolbox.toolbar separador1 = gtk.SeparatorToolItem() separador1.props.draw = True barra.insert(separador1, 1) item1 = gtk.ToolItem() self.label_radio1 = gtk.Label() self.label_radio1.set_text(_('Circles between') + ' ') item1.add(self.label_radio1) barra.insert(item1, 2) item2 = gtk.ToolItem() self.cradio1 = gtk.SpinButton() self.cradio1.set_range(1, 20) self.cradio1.set_increments(1, 2) self.cradio1.props.value = self.radio_uno self.cradio1_handler = self.cradio1.connect('notify::value', self.cradio1_valor) item2.add(self.cradio1) barra.insert(item2, 3) item3 = gtk.ToolItem() self.label_and = gtk.Label() self.label_and.set_text(' ' + _('and') + ' ') item3.add(self.label_and) barra.insert(item3, 4) item4 = gtk.ToolItem() self.cradio2 = gtk.SpinButton() self.cradio2.set_range(1, 20) self.cradio2.set_increments(1, 2) self.cradio2.props.value = self.radio_dos self.cradio2_handler = self.cradio2.connect('notify::value', self.cradio2_valor) item4.add(self.cradio2) barra.insert(item4, 5) separator1 = gtk.SeparatorToolItem() separator1.props.draw = True separator1.set_expand(False) barra.insert(separator1,6) save_button = ToolButton('filesave') save_button.set_tooltip(_('Save Image')) save_button.connect('clicked', self._savebutton_cb) barra.insert(save_button, 7) save_button.show() separator2 = gtk.SeparatorToolItem() separator2.props.draw = False separator2.set_expand(True) barra.insert(separator2,8) stop_button = StopButton(self) stop_button.props.accelerator = '<Ctrl>q' barra.insert(stop_button, 9) stop_button.show() self.set_toolbar_box(toolbox) toolbox.show_all()
def __init__(self, handle): smilies.init() self.chatbox = ChatBox() super(ChatStudioSelf, self).__init__(handle) self.entry = None self.no_of_mistake = 0 root = self.make_root() self.set_canvas(root) root.show_all() self.entry.grab_focus() self.score1 = 0 self.accuracy = 0.0 toolbar_box = ToolbarBox() self.set_toolbar_box(toolbar_box) toolbar_box.toolbar.insert(ActivityButton(self), -1) toolbar_box.toolbar.insert(TitleEntry(self), -1) try: from sugar.activity.widgets import DescriptionItem except ImportError: logger.debug("DescriptionItem button is not available, " "toolkit version < 0.96") else: description_item = DescriptionItem(self) toolbar_box.toolbar.insert(description_item, -1) description_item.show() StartLabel = gtk.Label(_("START: ")) StartLabel.show() tool_item_StartLabel = gtk.ToolItem() tool_item_StartLabel.add(StartLabel) toolbar_box.toolbar.insert(tool_item_StartLabel, -1) tool_item_StartLabel.show() mc1 = MathCompEntry1(self) toolbar_box.toolbar.insert(mc1, -1) AddLabel = gtk.Label(_(" ADD: ")) AddLabel.show() tool_item_AddLabel = gtk.ToolItem() tool_item_AddLabel.add(AddLabel) toolbar_box.toolbar.insert(tool_item_AddLabel, -1) tool_item_AddLabel.show() mc2 = MathCompEntry2(self) toolbar_box.toolbar.insert(mc2, -1) separator = gtk.SeparatorToolItem() toolbar_box.toolbar.insert(separator, -1) separator = gtk.SeparatorToolItem() toolbar_box.toolbar.insert(separator, -1) self._smiley = RadioMenuButton(icon_name="smilies") self._smiley.palette = Palette(_("Insert smiley")) self._smiley.props.sensitive = True # toolbar_box.toolbar.insert(self._smiley, -1) separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(False) toolbar_box.toolbar.insert(separator, -1) scoreButton = ScoreButton(self) toolbar_box.toolbar.insert(scoreButton, -1) stopButton = StopButton(self) toolbar_box.toolbar.insert(stopButton, -1) toolbar_box.show_all() self.a1 = c1 self.a2 = c2 self.sum1 = self.a1 + self.a2 pservice = presenceservice.get_instance() self.owner = pservice.get_owner() # Chat is room or one to one: self._chat_is_room = False self.text_channel = None if self.shared_activity: # we are joining the activity self.connect("joined", self._joined_cb) if self.get_shared(): # we have already joined self._joined_cb(self) elif handle.uri: # XMPP non-Sugar incoming chat, not sharable share_button.props.visible = False self._one_to_one_connection(handle.uri) else: # we are creating the activity # if not self.metadata or self.metadata.get('share-scope',activity.SCOPE_PRIVATE) == activity.SCOPE_PRIVATE: # if we are in private session # self._alert(_('Off-line'), _('Share, or invite someone.')) self.connect("shared", self._shared_cb)
def __init__(self, handle): activity.Activity.__init__(self, handle) if HASTOOLBARBOX: self.max_participants = 1 toolbar_box = ToolbarBox() self.set_toolbar_box(toolbar_box) activity_button = ActivityToolbarButton(self) toolbar_box.toolbar.insert(activity_button, 0) separator = gtk.SeparatorToolItem() separator.props.draw = True activity_button.props.page.insert(separator, -1) separator.show() tool = ToolButton('pdf-export') tool.set_tooltip(_('Portable Document Format (PDF)')) tool.connect('clicked', self.__export_pdf_cb) activity_button.props.page.insert(tool, -1) tool.show() tool = ToolButton('png-export') tool.set_tooltip(_('Portable Network Graphic (PNG)')) tool.connect('clicked', self.__export_png_cb) activity_button.props.page.insert(tool, -1) tool.show() tool = ToolbarButton() self.edit_toolbar = EditToolbar(self) tool.props.page = self.edit_toolbar tool.props.icon_name = 'toolbar-edit' tool.props.label = _('Edit'), toolbar_box.toolbar.insert(tool, -1) self._undo = UndoManager.UndoManager(self, self.edit_toolbar.undo.child, self.edit_toolbar.redo.child) self.__build_main_canvas_area() tool = ToolbarButton() tool.props.page = ViewToolbar(self._main_area) tool.props.icon_name = 'toolbar-view' tool.props.label = _('View'), toolbar_box.toolbar.insert(tool, -1) tool = ToolbarButton() self.text_format_toolbar = TextAttributesToolbar(self._main_area) tool.props.page = self.text_format_toolbar tool.props.icon_name = 'toolbar-text' tool.props.label = _('Text') toolbar_box.toolbar.insert(tool, -1) # self._main_area.set_text_attributes(self.text_format_toolbar) self.thought_toolbar = ToolbarButton() self.thought_toolbar.props.page = ThoughtsToolbar(self) self.thought_toolbar.props.icon_name = 'thought' self.thought_toolbar.props.label = _('Thought Type') toolbar_box.toolbar.insert(self.thought_toolbar, -1) self.action_buttons = ActionButtons(self) toolbar_box.show_all() else: # Use old <= 0.84 toolbar design toolbox = activity.ActivityToolbox(self) self.set_toolbox(toolbox) activity_toolbar = toolbox.get_activity_toolbar() keep_palette = activity_toolbar.keep.get_palette() menu_item = MenuItem(_('Portable Document Format (PDF)')) menu_item.connect('activate', self.__export_pdf_cb) keep_palette.menu.append(menu_item) menu_item.show() menu_item = MenuItem(_('Portable Network Graphic (PNG)')) menu_item.connect('activate', self.__export_png_cb) keep_palette.menu.append(menu_item) menu_item.show() self.edit_toolbar = EditToolbar(self) toolbox.add_toolbar(_('Edit'), self.edit_toolbar) separator = gtk.SeparatorToolItem() self.edit_toolbar.insert(separator, 0) self.edit_toolbar.show() self._undo = UndoManager.UndoManager(self, self.edit_toolbar.undo.child, self.edit_toolbar.redo.child) self.__build_main_canvas_area() view_toolbar = ViewToolbar(self._main_area) toolbox.add_toolbar(_('View'), view_toolbar) activity_toolbar = toolbox.get_activity_toolbar() activity_toolbar.share.props.visible = False toolbox.set_current_toolbar(1) self.show_all() self.__configure_cb(None) self._mode = MMapArea.MODE_TEXT self._main_area.set_mode(self._mode) self.set_focus_child(self._main_area)
def _setup_toolbar(self): if pre_086_toolbars: self.toolbox = Toolbox() self.set_toolbox(self.toolbox) toolbar = gtk.Toolbar() self.toolbox.add_toolbar('Toolbar', toolbar) toolbar_box = self.toolbox else: toolbar_box = ToolbarBox() toolbar = toolbar_box.toolbar self.set_toolbar_box(toolbar_box) self._media_combo_model = gtk.ListStore(str, str, str, str) self._media_combo = gtk.ComboBox(self._media_combo_model) if not pre_086_toolbars: icon_renderer = CellRendererIcon(self._media_combo) icon_renderer.props.xo_color = self._color icon_renderer.props.width = style.STANDARD_ICON_SIZE + \ style.DEFAULT_SPACING icon_renderer.props.height = style.STANDARD_ICON_SIZE icon_renderer.props.size = style.STANDARD_ICON_SIZE icon_renderer.props.xpad = style.DEFAULT_PADDING icon_renderer.props.ypad = style.DEFAULT_PADDING self._media_combo.pack_start(icon_renderer, False) self._media_combo.add_attribute(icon_renderer, 'icon_name', self._MEDIA_COMBO_ICON_COLUMN) # FIXME: icon_renderer for pre-0.86 name_renderer = gtk.CellRendererText() self._media_combo.pack_start(name_renderer, False) self._media_combo.add_attribute(name_renderer, 'text', self._MEDIA_COMBO_NAME_COLUMN) free_renderer = gtk.CellRendererText() self._media_combo.pack_start(free_renderer, False) self._media_combo.add_attribute(free_renderer, 'text', self._MEDIA_COMBO_FREE_COLUMN) tool_item = gtk.ToolItem() tool_item.add(self._media_combo) # FIXME: looks like plain GTK, not like Sugar tooltip_text = _('Storage medium to store the backup on') tool_item.set_tooltip_text(tooltip_text.encode('utf-8')) toolbar.insert(tool_item, -1) if pre_086_toolbars: self._backup_button = gtk.ToolButton() self._backup_button.props.icon_name = 'journal-export' label_text = _('Backup Journal') try: self._backup_button.props.tooltip = label_text.encode('utf-8') except AttributeError: pass else: self._backup_button = BackupButton() self._backup_button.connect('clicked', self._backup_cb) self._backup_button.set_sensitive(False) toolbar.insert(self._backup_button, -1) separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) toolbar.insert(separator, -1) stop_button = StopButton(self) toolbar.insert(stop_button, -1) toolbar_box.show_all()
def __init__(self, handle): super(Chat, self).__init__(handle) smilies.init() self.entry = None self.chatbox = None root = self.make_root() self.set_canvas(root) root.show_all() self.entry.grab_focus() toolbar_box = ToolbarBox() self.set_toolbar_box(toolbar_box) toolbar_box.toolbar.insert(ActivityButton(self), -1) toolbar_box.toolbar.insert(TitleEntry(self), -1) share_button = ShareButton(self) toolbar_box.toolbar.insert(share_button, -1) separator = gtk.SeparatorToolItem() toolbar_box.toolbar.insert(separator, -1) self._smiley = RadioMenuButton(icon_name='smilies') self._smiley.palette = Palette(_('Insert smiley')) self._smiley.props.sensitive = False toolbar_box.toolbar.insert(self._smiley, -1) table = self._create_pallete_smiley_table() table.show_all() self._smiley.palette.set_content(table) separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) toolbar_box.toolbar.insert(separator, -1) toolbar_box.toolbar.insert(StopButton(self), -1) toolbar_box.show_all() pservice = presenceservice.get_instance() self.owner = pservice.get_owner() # Chat is room or one to one: self._chat_is_room = False self.text_channel = None if self.shared_activity: # we are joining the activity self.connect('joined', self._joined_cb) if self.get_shared(): # we have already joined self._joined_cb(self) elif handle.uri: # XMPP non-Sugar incoming chat, not sharable share_button.props.visible = False self._one_to_one_connection(handle.uri) else: # we are creating the activity if not self.metadata or self.metadata.get( 'share-scope', activity.SCOPE_PRIVATE) == activity.SCOPE_PRIVATE: # if we are in private session self._alert(_('Off-line'), _('Share, or invite someone.')) self.connect('shared', self._shared_cb)
def __init__ (self, handle): if os.path.exists('/tmp/1'): os.remove('/tmp/1') activity.Activity.__init__ (self, handle) # abiword uses the current directory for all its file dialogs os.chdir(os.path.expanduser('~')) # create our main abiword canvas self.abiword_canvas = Canvas() self.set_canvas(self.abiword_canvas) self.abiword_canvas.connect_after('map-event', self.__map_event_cb) self.abiword_canvas.show() if os.path.exists('/tmp/2'): os.remove('/tmp/2') toolbar_box = ToolbarBox() activity_button = ActivityToolbarButton(self) separator = gtk.SeparatorToolItem() separator.show() activity_button.props.page.insert(separator, 2) export_button = ExportButton(self, self.abiword_canvas) export_button.show() activity_button.props.page.insert(export_button, 2) toolbar_box.toolbar.insert(activity_button, 0) edit_toolbar = ToolbarButton() edit_toolbar.props.page = EditToolbar(self, toolbar_box) edit_toolbar.props.icon_name = 'toolbar-edit' edit_toolbar.props.label = _('Edit') toolbar_box.toolbar.insert(edit_toolbar, -1) view_toolbar = ToolbarButton() view_toolbar.props.page = ViewToolbar(self.abiword_canvas) view_toolbar.props.icon_name = 'toolbar-view' view_toolbar.props.label = _('View') toolbar_box.toolbar.insert(view_toolbar, -1) separator = gtk.SeparatorToolItem() toolbar_box.toolbar.insert(separator, -1) toolbar_box.show_all() self.set_toolbar_box(toolbar_box) if os.path.exists('/tmp/3'): os.remove('/tmp/3') text_toolbar = ToolbarButton() text_toolbar.props.page = TextToolbar(self.abiword_canvas) text_toolbar.props.icon_name = 'format-text' text_toolbar.props.label = _('Text') toolbar_box.toolbar.insert(text_toolbar, -1) para_toolbar = ToolbarButton() para_toolbar.props.page = ParagraphToolbar(self.abiword_canvas) para_toolbar.props.icon_name = 'paragraph-bar' para_toolbar.props.label = _('Paragraph') toolbar_box.toolbar.insert(para_toolbar, -1) list_toolbar = ToolbarButton() list_toolbar.props.page = ListToolbar(self.abiword_canvas) list_toolbar.props.icon_name = 'toolbar-bulletlist' list_toolbar.props.label = _('Bullet List') toolbar_box.toolbar.insert(list_toolbar, -1) insert_toolbar = ToolbarButton() insert_toolbar.props.page = InsertToolbar(self.abiword_canvas) insert_toolbar.props.icon_name = 'insert-table' insert_toolbar.props.label = _('Table') toolbar_box.toolbar.insert(insert_toolbar, -1) separator = gtk.SeparatorToolItem() toolbar_box.toolbar.insert(separator, -1) bold = ToggleToolButton('format-text-bold') bold.set_tooltip(_('Bold')) bold_id = bold.connect('clicked', lambda sender: self.abiword_canvas.toggle_bold()) self.abiword_canvas.connect('bold', lambda abi, b: self._setToggleButtonState(bold, b, bold_id)) toolbar_box.toolbar.insert(bold, -1) italic = ToggleToolButton('format-text-italic') italic.set_tooltip(_('Italic')) italic_id = italic.connect('clicked', lambda sender: self.abiword_canvas.toggle_italic()) self.abiword_canvas.connect('italic', lambda abi, b: self._setToggleButtonState(italic, b, italic_id)) toolbar_box.toolbar.insert(italic, -1) underline = ToggleToolButton('format-text-underline') underline.set_tooltip(_('Underline')) underline_id = underline.connect('clicked', lambda sender: self.abiword_canvas.toggle_underline()) self.abiword_canvas.connect('underline', lambda abi, b: self._setToggleButtonState(underline, b, underline_id)) toolbar_box.toolbar.insert(underline, -1) separator = gtk.SeparatorToolItem() toolbar_box.toolbar.insert(separator, -1) color = ColorToolButton() color.connect('color-set', self._text_color_cb, self.abiword_canvas) tool_item = gtk.ToolItem() tool_item.add(color) toolbar_box.toolbar.insert(tool_item, -1) self.abiword_canvas.connect('color', lambda abi, r, g, b: color.set_color(gtk.gdk.Color(r * 256, g * 256, b * 256))) separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) separator.show() toolbar_box.toolbar.insert(separator, -1) stop = StopButton(self) toolbar_box.toolbar.insert(stop, -1) toolbar_box.show_all() self.set_toolbar_box(toolbar_box) self._zoom_handler = self.abiword_canvas.connect("zoom", self.__zoom_cb)
class JAMEdit(activity.Activity): def __init__(self, handle): activity.Activity.__init__(self, handle, True) self.max_participants = 1 # ****** Editor ****** self.editor = Editor(self) self.editor.set_size_request(800, 790) scroll = gtk.ScrolledWindow() scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scroll.add(self.editor) scroll.show_all() vbox = gtk.VBox() vbox.pack_start(scroll, True, True, 0) vbox.show_all() self.set_canvas(vbox) # ****** Toolbars ****** self.toolbar_box = ToolbarBox() activity_button = ActivityToolbarButton(self) activity_toolbar = activity_button.page # Abrir objeto / Open object open_obj_btn = ToolButton("open-from-journal") open_obj_btn.connect("clicked", file_choosers.open_from_journal, None, self) open_obj_btn.set_tooltip(_("Open object from journal")) activity_toolbar.insert(open_obj_btn, -1) # Separador / Separator separator = gtk.SeparatorToolItem() separator.set_draw(True) separator.set_expand(False) activity_toolbar.insert(separator, -1) # ****** Open File button ****** open_btn = ToolButton("fileopen") open_btn.set_tooltip(_("Open File")) open_btn.set_accelerator('<ctrl>o') open_btn.connect("clicked", self.open_file) activity_toolbar.insert(open_btn, -1) # ****** Save File button ****** save_btn = ToolButton("stock_save") save_btn.set_tooltip(_("Save this file")) save_btn.set_accelerator('<ctrl>s') save_btn.connect("clicked", self.save_file) activity_toolbar.insert(save_btn, -1) activity_toolbar.show_all() activity_toolbar.stop.hide() # Guardar como / Save As save_as = gtk.MenuItem(_("Save on the file system.")) activity_toolbar.keep.props.palette.menu.append(save_as) save_as.connect("activate", self.save_file_as) save_as.show() # Nuevo / New new = ToolButton("new") new.set_tooltip(_("New file")) new.set_accelerator('<ctrl>n') new.connect("clicked", self.new) activity_toolbar.insert(new, 6) new.show() activity_toolbar.keep.show() self.toolbar_box.toolbar.insert(activity_button, 0) # Edicion / Edit Toolbar edit_toolbar = EditToolbar() edit_toolbar_button = ToolbarButton(label=_("Edit"), page=edit_toolbar, icon_name='toolbar-edit') edit_toolbar.cut = ToolButton("cut") edit_toolbar.cut.set_tooltip(_("Cut")) edit_toolbar.cut.set_accelerator('<ctrl>x') edit_toolbar.insert(edit_toolbar.cut, 4) separator = gtk.SeparatorToolItem() separator.set_draw(False) separator.set_expand(True) edit_toolbar.insert(separator, -1) edit_toolbar.pep8_btn = ToolButton('pep8') edit_toolbar.pep8_btn.set_tooltip(_("PEP 8 Check")) edit_toolbar.pep8_btn.connect("clicked", self.pep8_check) edit_toolbar.insert(edit_toolbar.pep8_btn, -1) edit_toolbar.pep8_datetime_separator = gtk.SeparatorToolItem() edit_toolbar.pep8_datetime_separator.set_draw(True) edit_toolbar.insert(edit_toolbar.pep8_datetime_separator, -1) insert_datetime = ToolButton("insert-datetime") insert_datetime.connect("clicked", self.editor._insert_date_time) insert_datetime.set_tooltip(_("Insert date and time")) edit_toolbar.insert(insert_datetime, -1) insert_datetime.show_all() edit_toolbar.copy.connect("clicked", self.editor._copy_cb) edit_toolbar.paste.connect("clicked", self.editor._paste_cb) edit_toolbar.undo.connect("clicked", self.editor._undo_cb) edit_toolbar.redo.connect("clicked", self.editor._redo_cb) edit_toolbar.cut.connect("clicked", self.editor._cut_cb) edit_toolbar.show_all() edit_toolbar.pep8_btn.hide() edit_toolbar.pep8_datetime_separator.set_draw(False) self.toolbar_box.toolbar.insert(edit_toolbar_button, -1) self.edit_toolbar = edit_toolbar # Separador / Separator separator = gtk.SeparatorToolItem() separator.set_draw(False) self.toolbar_box.toolbar.insert(separator, -1) # Buscar / Search search_entry = iconentry.IconEntry() search_entry.set_size_request(gtk.gdk.screen_width() / 3, -1) search_entry.set_icon_from_name(iconentry.ICON_ENTRY_PRIMARY, 'system-search') search_entry.add_clear_button() search_entry.connect('activate', self.editor._search_entry_activate_cb) search_entry.connect('changed', self.editor._search_entry_changed_cb) search_item = gtk.ToolItem() search_item.add(search_entry) self.toolbox.toolbar.insert(search_item, -1) self._search_prev = ToolButton('go-previous-paired') self._search_prev.set_tooltip(_('Previous')) self._search_prev.connect('clicked', self.editor._search_prev_cb) self.toolbox.toolbar.insert(self._search_prev, -1) self._search_next = ToolButton('go-next-paired') self._search_next.set_tooltip(_('Next')) self._search_next.connect('clicked', self.editor._search_next_cb) self.toolbox.toolbar.insert(self._search_next, -1) # Preferencias / preferences preferences_toolbar = gtk.Toolbar() show_line_numbers = ToggleToolButton('show-numbers') show_line_numbers.set_tooltip(_("Show line numbers")) show_line_numbers.set_active(True) show_line_numbers.connect("clicked", \ self.editor._set_show_line_numbers) show_line_numbers.show() preferences_toolbar.insert(show_line_numbers, -1) self.editor._make_languages_combo(preferences_toolbar) self.editor.make_style_combo(preferences_toolbar) preferences = ToolbarButton() preferences.props.page = preferences_toolbar preferences.props.icon_name = 'preferences-system' preferences.show_all() self.toolbar_box.toolbar.insert(preferences, -1) font_options = FontToolbarButton() font_options.connect("load-pango-context", self.load_pango_context) font_options.load_toolbar() font_options.connect("font-changed", self.change_font) self.toolbar_box.toolbar.insert(font_options, -1) font_options.show() # Separador / Separator separator = gtk.SeparatorToolItem() separator.set_draw(False) separator.set_expand(True) self.toolbar_box.toolbar.insert(separator, -1) # Boton salir / Stop Button exit = StopButton(self) self.toolbar_box.toolbar.insert(exit, -1) self.toolbar_box.show_all() self.set_toolbar_box(self.toolbar_box) # Barra de estado de PEP8 / PEP8 status bar self.pep8_bar = gtk.Statusbar() self.pep8_bar.label = gtk.Label() self.pep8_bar.add(self.pep8_bar.label) vbox.pack_end(self.pep8_bar, False, True, 0) def change_font(self, widget, family, face, size): self.editor.modify_font( pango.FontDescription("%s %s %d" % (family, face, size))) def load_pango_context(self, widget): return self.editor.get_pango_context() def pep8_check(self, widget): self.editor.pep8.check_file(self.editor._get_all_text(), self.editor) def close(self, skip_save=False): close = True if not self.editor.file: close = self.save_file(None, type="exit", mode=2) if close: activity.Activity.close(self) def open_file(self, widget, from_journal=False): self.editor.pep8.check_exit() self.save_file(None, type="exit") if not from_journal: file_path, remember = file_choosers.open_file_dialog() if file_path != None: self.set_title(os.path.split(file_path)[-1]) mime_type = mime.get_from_file_name(file_path) self.metadata["mime_type"] = mime_type file = open(file_path, "r") self.editor.buffer.set_text(file.read()) if remember: self.editor.file = file_path self.editor._search_and_active_language(mime_type) file.close() if from_journal: file_path = from_journal mime_type = mime.get_from_file_name(file_path) self.metadata["mime_type"] = mime_type file = open(file_path, "r") self.editor.buffer.set_text(file.read()) self.editor.file = file_path self.editor._search_and_active_language(mime_type) file.close() def new(self, widget): self.editor.pep8.check_exit() _continue = self.save_file(None, type="exit") if _continue: self.metadata["mime_type"] = mime.GENERIC_TYPE_TEXT self.editor.lang = None self.editor.file = None self.editor.lang_combo.set_active(0) self.editor.buffer.set_highlight_syntax(False) self.edit_toolbar.pep8_btn.hide() self.edit_toolbar.pep8_datetime_separator.set_draw(False) self.editor.buffer.set_text("") self.set_title(_("New")) def save_file_as(self, widget): file_path = file_choosers.save_file_dialog() if file_path: self.editor.file = file_path file = open(self.editor.file, "w") file.write(self.editor._get_all_text()) file.close() self.set_title(os.path.split(file_path)[-1]) mime_type = mime.get_from_file_name(file_path) self.metadata["mime_type"] = mime_type self.editor.file = file_path self.editor._search_and_active_language(mime_type) def save_file(self, widget, type=None, mode=1): if not type: if self.editor.file: file = open(self.editor.file, "w") file.write(self.editor._get_all_text()) file.close() else: file_path = file_choosers.save_file_dialog() if file_path: self.editor.file = file_path file = open(self.editor.file, "w") file.write(self.editor._get_all_text()) file.close() if type == "exit": dialog = gtk.MessageDialog(type=gtk.MESSAGE_QUESTION) dialog.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_NO, gtk.RESPONSE_NO, gtk.STOCK_YES, gtk.RESPONSE_YES) dialog.set_markup("<b>%s</b>" % _("Save changes...")) if mode == 1: dialog.format_secondary_text(_("Do you want to save changes?")) elif mode == 2: dialog.format_secondary_text( _("Do you want to save changes\nin the file system?")) response = dialog.run() dialog.destroy() if not response == gtk.RESPONSE_CANCEL: if response == gtk.RESPONSE_YES: if self.editor.file: file = open(self.editor.file, "w") file.write(self.editor._get_all_text()) file.close() else: file_path = \ file_choosers.save_file_dialog() if file_path: self.editor.file = \ file_path file = open(self.editor.file, "w") file.write(self.editor._get_all_text()) file.close() return True else: return False def write_file(self, file_path): if self.editor.lang: lang_mime_type = self.editor.lang.get_mime_types()[0] elif not self.editor.lang: lang_mime_type = mime.GENERIC_TYPE_TEXT self.metadata['mime_type'] = lang_mime_type jfile = open(file_path, "w") jfile.write(self.editor._get_all_text()) jfile.close() def read_file(self, file_path): fpath = open(file_path, "r") text = fpath.read() fpath.close() mime_type = self.metadata["mime_type"] self.editor.buffer.set_text(text) self.editor._search_and_active_language(mime_type)
class CalcLayout: FONT_SMALL_POINTS = 10 FONT_SMALL = "sans %d" % FONT_SMALL_POINTS FONT_SMALL_NARROW = "sans italic %d" % FONT_SMALL_POINTS FONT_BIG_POINTS = 14 FONT_BIG = "sans bold %d" % FONT_BIG_POINTS FONT_BIG_NARROW = "sans italic 14" FONT_BIGGER_POINTS = 18 FONT_BIGGER = "sans bold %d" % FONT_BIGGER_POINTS def __init__(self, parent): self._parent = parent self._own_equations = [] self._other_equations = [] self._showing_history = True self._showing_all_history = True self._var_textviews = {} self.graph_selected = None self.create_dialog() def create_color(self, rf, gf, bf): return gtk.gdk.Color(int(rf*0xFFFF), int(gf*0xFFFF), int(bf*0xFFFF)) def create_button_data(self): """Create a list with button information. We need to do that here because we want to include the lambda functions.""" mul_sym = self._parent.ml.mul_sym div_sym = self._parent.ml.div_sym equ_sym = self._parent.ml.equ_sym self.button_data = [ # [x, y, width, label, bgcol, cb] [0, 0, 2, 1, u'\u2190', self.col_gray3, lambda w: self._parent.move_left()], [2, 0, 2, 1, u'\u2192', self.col_gray3, lambda w: self._parent.move_right()], [4, 0, 2, 1, u'\u232B', self.col_gray3, lambda w: self._parent.remove_character(-1)], [0, 1, 1, 2, '7', self.col_gray2, lambda w: self._parent.add_text('7')], [1, 1, 1, 2, '8', self.col_gray2, lambda w: self._parent.add_text('8')], [2, 1, 1, 2, '9', self.col_gray2, lambda w: self._parent.add_text('9')], [0, 3, 1, 2, '4', self.col_gray2, lambda w: self._parent.add_text('4')], [1, 3, 1, 2, '5', self.col_gray2, lambda w: self._parent.add_text('5')], [2, 3, 1, 2, '6', self.col_gray2, lambda w: self._parent.add_text('6')], [0, 5, 1, 2, '1', self.col_gray2, lambda w: self._parent.add_text('1')], [1, 5, 1, 2, '2', self.col_gray2, lambda w: self._parent.add_text('2')], [2, 5, 1, 2, '3', self.col_gray2, lambda w: self._parent.add_text('3')], [0, 7, 2, 2, '0', self.col_gray2, lambda w: self._parent.add_text('0')], [2, 7, 1, 2, '.', self.col_gray2, lambda w: self._parent.add_text('.')], [3, 1, 3, 2, _('Clear'), self.col_gray1, lambda w: self._parent.clear()], [3, 3, 1, 2, '+', self.col_gray3, lambda w: self._parent.add_text('+')], [4, 3, 1, 2, '-', self.col_gray3, lambda w: self._parent.add_text('-')], [5, 3, 1, 2, '(', self.col_gray3, lambda w: self._parent.add_text('(')], [3, 5, 1, 2, mul_sym, self.col_gray3, lambda w: self._parent.add_text(mul_sym)], [4, 5, 1, 2, div_sym, self.col_gray3, lambda w: self._parent.add_text(div_sym)], [5, 5, 1, 2, ')', self.col_gray3, lambda w: self._parent.add_text(')')], [3, 7, 3, 2, equ_sym, self.col_gray1, lambda w: self._parent.process()], ] def create_dialog(self): """Setup most of the dialog.""" # Toolbar try: self._toolbar_box = ToolbarBox() activity_button = ActivityToolbarButton(self._parent) self._toolbar_box.toolbar.insert(activity_button, 0) def append(icon_name, label, page, position): toolbar_button = ToolbarButton() toolbar_button.props.page = page toolbar_button.props.icon_name = icon_name toolbar_button.props.label = label self._toolbar_box.toolbar.insert(toolbar_button, position) append('toolbar-edit', _('Edit'), EditToolbar(self._parent), -1) append('toolbar-algebra', _('Algebra'), AlgebraToolbar(self._parent), -1) append('toolbar-trigonometry', _('Trigonometry'), TrigonometryToolbar(self._parent), -1) append('toolbar-boolean', _('Boolean'), BooleanToolbar(self._parent), -1) self._misc_toolbar = MiscToolbar( self._parent, target_toolbar=self._toolbar_box.toolbar) append('toolbar-constants', _('Miscellaneous'), self._misc_toolbar, 5) self._stop_separator = gtk.SeparatorToolItem() self._stop_separator.props.draw = False self._stop_separator.set_expand(True) self._stop_separator.show() self._toolbar_box.toolbar.insert(self._stop_separator, -1) self._stop = StopButton(self._parent) self._toolbar_box.toolbar.insert(self._stop, -1) self._toolbar_box.show_all() self._parent.set_toolbar_box(self._toolbar_box) except NameError: # Use old toolbar design toolbox = activity.ActivityToolbox(self._parent) self._parent.set_toolbox(toolbox) toolbox.add_toolbar(_('Edit'), EditToolbar(self._parent)) toolbox.add_toolbar(_('Algebra'), AlgebraToolbar(self._parent)) toolbox.add_toolbar(_('Trigonometry'), TrigonometryToolbar(self._parent)) toolbox.add_toolbar(_('Boolean'), BooleanToolbar(self._parent)) toolbox.add_toolbar(_('Miscellaneous'), MiscToolbar(self._parent)) toolbox.show_all() # Some layout constants self.input_font = pango.FontDescription(str='sans bold 12') self.button_font = pango.FontDescription(str='sans bold 16') self.col_white = self.create_color(1.00, 1.00, 1.00) self.col_gray1 = self.create_color(0.76, 0.76, 0.76) self.col_gray2 = self.create_color(0.50, 0.50, 0.50) self.col_gray3 = self.create_color(0.25, 0.25, 0.25) self.col_black = self.create_color(0.00, 0.00, 0.00) self.col_red = self.create_color(1.00, 0.00, 0.00) # Big - Table, 16 rows, 10 columns, homogeneously divided self.grid = gtk.Table(26, 11, True) self.grid.set_border_width(0) self.grid.set_row_spacings(0) self.grid.set_col_spacings(4) # Left part: container and input vc1 = gtk.VBox(False, 0) hc1 = gtk.HBox(False, 10) eb = gtk.EventBox() eb.add(hc1) eb.modify_bg(gtk.STATE_NORMAL, self.col_black) eb.set_border_width(12) eb2 = gtk.EventBox() eb2.add(eb) eb2.modify_bg(gtk.STATE_NORMAL, self.col_black) label1 = gtk.Label(_('Label:')) label1.modify_fg(gtk.STATE_NORMAL, self.col_white) label1.set_alignment(1, 0.5) hc1.pack_start(label1, expand=False, fill=False, padding=10) self.label_entry = gtk.Entry() self.label_entry.modify_bg(gtk.STATE_INSENSITIVE, self.col_black) hc1.pack_start(self.label_entry, expand=True, fill=True, padding=0) vc1.pack_start(eb2, expand=False) self.text_entry = gtk.Entry() try: self.text_entry.props.im_module = 'gtk-im-context-simple' except AttributeError: pass self.text_entry.set_size_request(-1, 75) self.text_entry.connect('key_press_event', self._parent.ignore_key_cb) self.text_entry.modify_font(self.input_font) self.text_entry.modify_bg(gtk.STATE_INSENSITIVE, self.col_black) eb = gtk.EventBox() eb.add(self.text_entry) eb.modify_bg(gtk.STATE_NORMAL, self.col_black) eb.set_border_width(12) eb2 = gtk.EventBox() eb2.add(eb) eb2.modify_bg(gtk.STATE_NORMAL, self.col_black) vc1.pack_start(eb2, expand=True, fill=True, padding=0) self.grid.attach(vc1, 0, 7, 0, 6) # Left part: buttons self.pad = gtk.Table(9, 6, True) self.pad.set_row_spacings(12) self.pad.set_col_spacings(12) self.pad.set_border_width(12) self.create_button_data() self.buttons = {} for x, y, w, h, cap, bgcol, cb in self.button_data: button = self.create_button(_(cap), cb, self.col_white, bgcol, w, h) self.buttons[cap] = button self.pad.attach(button, x, x + w, y, y + h) eb = gtk.EventBox() eb.add(self.pad) eb.modify_bg(gtk.STATE_NORMAL, self.col_black) self.grid.attach(eb, 0, 7, 6, 26) # Right part: container and equation button hc2 = gtk.HBox() combo = ComboBox() combo.append_item(0, _('All equations')) combo.append_item(1, _('My equations')) combo.append_item(2, _('Show variables')) combo.set_active(0) combo.connect('changed', self._history_filter_cb) hc2.pack_start(combo) hc2.set_border_width(6) self.grid.attach(hc2, 7, 11, 0, 2) # Right part: last equation self.last_eq = gtk.TextView() self.last_eq.set_editable(False) self.last_eq.set_wrap_mode(gtk.WRAP_WORD_CHAR) self.last_eq.connect('realize', self._textview_realize_cb) self.last_eq.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse( sugar.profile.get_color().get_fill_color())) self.last_eq.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse( sugar.profile.get_color().get_stroke_color())) self.last_eq.set_border_window_size(gtk.TEXT_WINDOW_LEFT, 4) self.last_eq.set_border_window_size(gtk.TEXT_WINDOW_RIGHT, 4) self.last_eq.set_border_window_size(gtk.TEXT_WINDOW_TOP, 4) self.last_eq.set_border_window_size(gtk.TEXT_WINDOW_BOTTOM, 4) # TODO Fix for old Sugar 0.82 builds, red_float not available bright = (gtk.gdk.color_parse(sugar.profile.get_color().get_fill_color()).red_float + gtk.gdk.color_parse(sugar.profile.get_color().get_fill_color()).green_float + gtk.gdk.color_parse(sugar.profile.get_color().get_fill_color()).blue_float) / 3.0 if bright < 0.5: self.last_eq.modify_text(gtk.STATE_NORMAL, self.col_white) else: self.last_eq.modify_text(gtk.STATE_NORMAL, self.col_black) self.grid.attach(self.last_eq, 7, 11, 2, 7) # Right part: history scrolled_window = gtk.ScrolledWindow() scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) self.history_vbox = gtk.VBox() self.history_vbox.set_homogeneous(False) self.history_vbox.set_border_width(0) self.history_vbox.set_spacing(4) self.variable_vbox = gtk.VBox() self.variable_vbox.set_homogeneous(False) self.variable_vbox.set_border_width(0) self.variable_vbox.set_spacing(4) vbox = gtk.VBox() vbox.pack_start(self.history_vbox) vbox.pack_start(self.variable_vbox) scrolled_window.add_with_viewport(vbox) self.grid.attach(scrolled_window, 7, 11, 7, 26) gtk.gdk.screen_get_default().connect('size-changed', self._configure_cb) def _configure_cb(self, event): # Maybe redo layout self._toolbar_box.toolbar.remove(self._stop) self._toolbar_box.toolbar.remove(self._stop_separator) self._misc_toolbar.update_layout() self._toolbar_box.toolbar.insert(self._stop_separator, -1) self._toolbar_box.toolbar.insert(self._stop, -1) def show_it(self): """Show the dialog.""" self._parent.set_canvas(self.grid) self._parent.show_all() self.show_history() self.text_entry.grab_focus() def showing_history(self): """Return whether we're currently showing the history (or otherwise the list of variables).""" return self._showing_history def show_history(self): """Show the history VBox.""" self._showing_history = True self.variable_vbox.hide() self.history_vbox.show() def toggle_select_graph(self, widget, host=None): # if we have a graph already selected, we must deselect it first if self.graph_selected and self.graph_selected != widget: self.toggle_select_graph(self.graph_selected) if not self.graph_selected: widget.set_visible_window(True) widget.set_above_child(True) self.graph_selected = widget white = gtk.gdk.color_parse('white') widget.modify_bg(gtk.STATE_NORMAL, white) else: widget.set_visible_window(False) self.graph_selected = False def add_equation(self, textview, own, prepend=False): """Add a gtk.TextView of an equation to the history_vbox.""" GraphEventBox = None if isinstance(textview, gtk.Image): # Add the image inside the eventBox GraphEventBox = gtk.EventBox() GraphEventBox.add(textview) GraphEventBox.set_visible_window(False) GraphEventBox.connect('button_press_event', self.toggle_select_graph) GraphEventBox.show() if prepend: if GraphEventBox: self.history_vbox.pack_start(GraphEventBox, False, True) self.history_vbox.reorder_child(GraphEventBox, 0) else: self.history_vbox.pack_start(textview, False, True) self.history_vbox.reorder_child(textview, 0) else: if GraphEventBox: self.history_vbox.pack_end(GraphEventBox, False, True) else: self.history_vbox.pack_end(textview, False, True) if own: if GraphEventBox: self._own_equations.append(GraphEventBox) GraphEventBox.child.show() else: self._own_equations.append(textview) textview.show() else: if self._showing_all_history: if GraphEventBox: self._other_equations.append(GraphEventBox) GraphEventBox.child.show() else: self._other_equations.append(textview) textview.show() def show_all_history(self): """Show both owned and other equations.""" self._showing_all_history = True for key in self._other_equations: if isinstance(key, gtk.EventBox): key.child.show() else: key.show() def show_own_history(self): """Show only owned equations.""" self._showing_all_history = False for key in self._other_equations: if isinstance(key, gtk.EventBox): key.child.hide() else: key.hide() def add_variable(self, varname, textview): """Add a gtk.TextView of a variable to the variable_vbox.""" if varname in self._var_textviews: self.variable_vbox.remove(self._var_textviews[varname]) del self._var_textviews[varname] self._var_textviews[varname] = textview self.variable_vbox.pack_start(textview, False, True) # Reorder textviews for a sorted list names = self._var_textviews.keys() names.sort() for i in range(len(names)): self.variable_vbox.reorder_child(self._var_textviews[names[i]], i) textview.show() def show_variables(self): """Show the variables VBox.""" self._showing_history = False self.history_vbox.hide() self.variable_vbox.show() def create_button(self, cap, cb, fgcol, bgcol, width, height): """Create a button that is set up properly.""" button = gtk.Button(_(cap)) self.modify_button_appearance(button, fgcol, bgcol, width, height) button.connect("clicked", cb) button.connect("key_press_event", self._parent.ignore_key_cb) return button def modify_button_appearance(self, button, fgcol, bgcol, width, height): """Modify button style.""" width = 50 * width height = 50 * height button.get_child().set_size_request(width, height) button.get_child().modify_font(self.button_font) button.get_child().modify_fg(gtk.STATE_NORMAL, fgcol) button.modify_bg(gtk.STATE_NORMAL, bgcol) button.modify_bg(gtk.STATE_PRELIGHT, bgcol) def _history_filter_cb(self, combo): selection = combo.get_active() if selection == 0: self.show_history() self.show_all_history() elif selection == 1: self.show_history() self.show_own_history() elif selection == 2: self.show_variables() def _textview_realize_cb(self, widget): '''Change textview properties once window is created.''' win = widget.get_window(gtk.TEXT_WINDOW_TEXT) win.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND1)) return False
def __init__(self, handle): smilies.init() self.chatbox = ChatBox() super(Chat, self).__init__(handle) self.entry = None root = self.make_root() self.set_canvas(root) root.show_all() self.entry.grab_focus() toolbar_box = ToolbarBox() self.set_toolbar_box(toolbar_box) toolbar_box.toolbar.insert(ActivityButton(self), -1) toolbar_box.toolbar.insert(TitleEntry(self), -1) try: from sugar.activity.widgets import DescriptionItem except ImportError: logger.debug('DescriptionItem button is not available, ' \ 'toolkit version < 0.96') else: description_item = DescriptionItem(self) toolbar_box.toolbar.insert(description_item, -1) description_item.show() share_button = ShareButton(self) toolbar_box.toolbar.insert(share_button, -1) separator = gtk.SeparatorToolItem() toolbar_box.toolbar.insert(separator, -1) self._smiley = RadioMenuButton(icon_name='smilies') self._smiley.palette = Palette(_('Insert smiley')) self._smiley.props.sensitive = False toolbar_box.toolbar.insert(self._smiley, -1) table = self._create_pallete_smiley_table() table.show_all() self._smiley.palette.set_content(table) separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) toolbar_box.toolbar.insert(separator, -1) toolbar_box.toolbar.insert(StopButton(self), -1) toolbar_box.show_all() pservice = presenceservice.get_instance() self.owner = pservice.get_owner() # Chat is room or one to one: self._chat_is_room = False self.text_channel = None if self.shared_activity: # we are joining the activity self.connect('joined', self._joined_cb) if self.get_shared(): # we have already joined self._joined_cb(self) elif handle.uri: # XMPP non-Sugar incoming chat, not sharable share_button.props.visible = False self._one_to_one_connection(handle.uri) else: # we are creating the activity if not self.metadata or self.metadata.get('share-scope', activity.SCOPE_PRIVATE) == activity.SCOPE_PRIVATE: # if we are in private session self._alert(_('Off-line'), _('Share, or invite someone.')) self.connect('shared', self._shared_cb)
def __init__(self, handle): activity.Activity.__init__(self, handle) try: # Use new >= 0.86 toolbar design self.max_participants = 1 toolbar_box = ToolbarBox() activity_button = ActivityToolbarButton(self) toolbar_box.toolbar.insert(activity_button, 0) separator = gtk.SeparatorToolItem() separator.props.draw = True activity_button.props.page.insert(separator, -1) separator.show() tool = ToolButton('pdf-export') tool.set_tooltip(_('Portable Document Format (PDF)')) tool.connect('clicked', self.__export_pdf_cb) activity_button.props.page.insert(tool, -1) tool.show() tool = ToolButton('png-export') tool.set_tooltip(_('Portable Network Graphic (PNG)')) tool.connect('clicked', self.__export_png_cb) activity_button.props.page.insert(tool, -1) tool.show() self.edit_toolbar = ToolbarButton() self.edit_toolbar.props.page = EditToolbar(self) self.edit_toolbar.props.icon_name = 'toolbar-edit' self.edit_toolbar.props.label = _('Edit'), toolbar_box.toolbar.insert(self.edit_toolbar, -1) self._undo = UndoManager.UndoManager( self, self.edit_toolbar.props.page.undo.child, self.edit_toolbar.props.page.redo.child) self.__build_main_canvas_area() tool = ToolbarButton() tool.props.page = ViewToolbar(self._main_area) tool.props.icon_name = 'toolbar-view' tool.props.label = _('View'), toolbar_box.toolbar.insert(tool, -1) separator = gtk.SeparatorToolItem() toolbar_box.toolbar.insert(separator, -1) separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) separator.show() toolbar_box.toolbar.insert(separator, -1) target_toolbar = toolbar_box.toolbar tool_offset = 4 tool = StopButton(self) toolbar_box.toolbar.insert(tool, -1) toolbar_box.show_all() self.set_toolbar_box(toolbar_box) except NameError: # Use old <= 0.84 toolbar design toolbox = activity.ActivityToolbox(self) self.set_toolbox(toolbox) activity_toolbar = toolbox.get_activity_toolbar() keep_palette = activity_toolbar.keep.get_palette() menu_item = MenuItem(_('Portable Document Format (PDF)')) menu_item.connect('activate', self.__export_pdf_cb) keep_palette.menu.append(menu_item) menu_item.show() menu_item = MenuItem(_('Portable Network Graphic (PNG)')) menu_item.connect('activate', self.__export_png_cb) keep_palette.menu.append(menu_item) menu_item.show() self.edit_toolbar = EditToolbar(self) toolbox.add_toolbar(_('Edit'), self.edit_toolbar) separator = gtk.SeparatorToolItem() self.edit_toolbar.insert(separator, 0) self.edit_toolbar.show() target_toolbar = self.edit_toolbar tool_offset = 0 self._undo = UndoManager.UndoManager(self, self.edit_toolbar.undo.child, self.edit_toolbar.redo.child) self.__build_main_canvas_area() view_toolbar = ViewToolbar(self._main_area) toolbox.add_toolbar(_('View'), view_toolbar) activity_toolbar = toolbox.get_activity_toolbar() activity_toolbar.share.props.visible = False toolbox.set_current_toolbar(1) self.mods = [None] * 6 self.mods[0] = RadioToolButton(named_icon='select-mode') self.mods[0].set_tooltip(_('Edit mode')) self.mods[0].set_accelerator(_('<ctrl>e')) self.mods[0].set_group(None) self.mods[0].connect('clicked', self.__mode_cb, MMapArea.MODE_NULL) target_toolbar.insert(self.mods[0], tool_offset) self.mods[1] = RadioToolButton(named_icon='text-mode') self.mods[1].set_tooltip(_('Text mode')) self.mods[1].set_accelerator(_('<ctrl>t')) self.mods[1].set_group(self.mods[0]) self.mods[1].connect('clicked', self.__mode_cb, MMapArea.MODE_TEXT) target_toolbar.insert(self.mods[1], tool_offset + 1) self.mods[2] = RadioToolButton(named_icon='draw-mode') self.mods[2].set_group(self.mods[0]) self.mods[2].set_tooltip(_('Drawing mode')) self.mods[2].set_accelerator(_('<ctrl>d')) self.mods[2].connect('clicked', self.__mode_cb, MMapArea.MODE_DRAW) target_toolbar.insert(self.mods[2], tool_offset + 2) self.mods[3] = RadioToolButton(named_icon='image-mode') self.mods[3].set_group(self.mods[0]) self.mods[3].set_tooltip(_('Image add mode')) self.mods[3].set_accelerator(_('<ctrl>i')) self.mods[3].connect('clicked', self.__mode_cb, MMapArea.MODE_IMAGE) target_toolbar.insert(self.mods[3], tool_offset + 3) self.mods[5] = RadioToolButton(named_icon='label-mode') self.mods[5].set_tooltip(_('Label mode')) self.mods[5].set_accelerator(_('<ctrl>a')) self.mods[5].set_group(self.mods[0]) self.mods[5].connect('clicked', self.__mode_cb, MMapArea.MODE_LABEL) target_toolbar.insert(self.mods[5], tool_offset + 4) separator = gtk.SeparatorToolItem() target_toolbar.insert(separator, tool_offset + 5) tool = ToolButton('link') tool.set_tooltip(_('Link/unlink two selected thoughts')) tool.set_accelerator(_('<ctrl>l')) tool.connect('clicked', self.__link_cb) target_toolbar.insert(tool, tool_offset + 6) tool = ToolButton('edit-delete') tool.set_tooltip(_('Erase selected thought(s)')) tool.connect('clicked', self.__delete_cb) target_toolbar.insert(tool, tool_offset + 7) self.show_all() self._mode = MMapArea.MODE_TEXT self._main_area.set_mode(self._mode) self.mods[MMapArea.MODE_TEXT].set_active(True) self.set_focus_child(self._main_area)
def __init__(self, handle): super(SpeakActivity, self).__init__(handle) self._notebook = gtk.Notebook() self.set_canvas(self._notebook) self._notebook.show() self._colors = profile.get_color().to_string().split(',') lighter = style.Color(self._colors[ _lighter_color(self._colors)]) self._mode = MODE_TYPE self._tablet_mode = _is_tablet_mode() self._robot_idle_id = None self._active_eyes = None self._active_number_of_eyes = None self._current_voice = None # make an audio device for playing back and rendering audio self.connect('notify::active', self._active_cb) self._cfg = {} # make a box to type into hbox = gtk.HBox() if self._tablet_mode: self._entry = gtk.Entry() hbox.pack_start(self._entry, expand=True) talk_button = ToolButton('microphone') talk_button.set_tooltip(_('Speak')) talk_button.connect('clicked', self._talk_cb) hbox.pack_end(talk_button, expand=False) else: self._entrycombo = gtk.combo_box_entry_new_text() self._entrycombo.connect('changed', self._combo_changed_cb) self._entry = self._entrycombo.child self._entry.set_size_request(-1, style.GRID_CELL_SIZE) hbox.pack_start(self._entrycombo, expand=True) self._entry.set_editable(True) self._entry.connect('activate', self._entry_activate_cb) self._entry.connect('key-press-event', self._entry_key_press_cb) self._entry.modify_font(pango.FontDescription(str='sans bold 24')) hbox.show() self.face = face.View(fill_color=lighter) self.face.set_size_request( -1, gtk.gdk.screen_height() - 2 * style.GRID_CELL_SIZE) self.face.show() # layout the screen box = gtk.VBox(homogeneous=False) if self._tablet_mode: box.pack_start(hbox, expand=False) box.pack_start(self.face) else: box.pack_start(self.face, expand=True) box.pack_start(hbox) self.add_events(gtk.gdk.POINTER_MOTION_HINT_MASK | gtk.gdk.POINTER_MOTION_MASK) self.connect('motion_notify_event', self._mouse_moved_cb) box.add_events(gtk.gdk.BUTTON_PRESS_MASK) box.connect('button_press_event', self._mouse_clicked_cb) # desktop self._notebook.show() self._notebook.props.show_border = False self._notebook.props.show_tabs = False box.show_all() self._notebook.append_page(box) self._chat = chat.View() self._chat.show_all() self._notebook.append_page(self._chat) # make the text box active right away if not self._tablet_mode: self._entry.grab_focus() self._entry.connect('move-cursor', self._cursor_moved_cb) self._entry.connect('changed', self._cursor_moved_cb) toolbox = ToolbarBox() self._activity_button = ActivityToolbarButton(self) self._activity_button.connect('clicked', self._configure_cb) toolbox.toolbar.insert(self._activity_button, -1) mode_type = RadioToolButton( named_icon='mode-type', tooltip=_('Type something to hear it')) mode_type.connect('toggled', self.__toggled_mode_type_cb) toolbox.toolbar.insert(mode_type, -1) mode_robot = RadioToolButton( named_icon='mode-robot', group=mode_type, tooltip=_('Ask robot any question')) mode_robot.connect('toggled', self.__toggled_mode_robot_cb) toolbox.toolbar.insert(mode_robot, -1) self._mode_chat = RadioToolButton( named_icon='mode-chat', group=mode_type, tooltip=_('Voice chat')) self._mode_chat.connect('toggled', self.__toggled_mode_chat_cb) toolbox.toolbar.insert(self._mode_chat, -1) self._voice_button = ToolbarButton( page=self._make_voice_bar(), label=_('Voice'), icon_name='voice') self._voice_button.connect('clicked', self._configure_cb) toolbox.toolbar.insert(self._voice_button, -1) self._face_button = ToolbarButton( page=self._make_face_bar(), label=_('Face'), icon_name='face') self._face_button.connect('clicked', self._configure_cb) toolbox.toolbar.insert(self._face_button, -1) separator = gtk.SeparatorToolItem() separator.set_draw(False) separator.set_expand(True) toolbox.toolbar.insert(separator, -1) toolbox.toolbar.insert(StopButton(self), -1) toolbox.show_all() self.toolbar_box = toolbox gtk.gdk.screen_get_default().connect('size-changed', self._configure_cb) self._first_time = True self._new_instance() self._configure_cb() self._poll_accelerometer() if self.shared_activity: # we are joining the activity self.connect('joined', self._joined_cb) if self.get_shared(): # we have already joined self._joined_cb(self) self._mode_chat.set_active(True) self._setup_chat_mode() elif handle.uri: # XMPP non-sugar3 incoming chat, not sharable self._activity_button.props.page.share.props.visible = \ False self._one_to_one_connection(handle.uri) else: # we are creating the activity self.connect('shared', self._shared_cb)
def __init__(self, handle): activity.Activity.__init__(self, handle) if HASTOOLBARBOX: self.max_participants = 1 toolbar_box = ToolbarBox() self.set_toolbar_box(toolbar_box) activity_button = ActivityToolbarButton(self) toolbar_box.toolbar.insert(activity_button, 0) separator = gtk.SeparatorToolItem() separator.props.draw = True activity_button.props.page.insert(separator, -1) separator.show() tool = ToolButton('pdf-export') tool.set_tooltip(_('Portable Document Format (PDF)')) tool.connect('clicked', self.__export_pdf_cb) activity_button.props.page.insert(tool, -1) tool.show() tool = ToolButton('png-export') tool.set_tooltip(_('Portable Network Graphic (PNG)')) tool.connect('clicked', self.__export_png_cb) activity_button.props.page.insert(tool, -1) tool.show() tool = ToolButton('txt-export') tool.set_tooltip(_('Plain Text (TXT)')) tool.connect('clicked', self.__export_txt_cb) activity_button.props.page.insert(tool, -1) tool.show() tool = ToolbarButton() self.edit_toolbar = EditToolbar(self) tool.props.page = self.edit_toolbar tool.props.icon_name = 'toolbar-edit' tool.props.label = _('Edit'), toolbar_box.toolbar.insert(tool, -1) self._undo = UndoManager.UndoManager(self, self.edit_toolbar.undo.child, self.edit_toolbar.redo.child) self.__build_main_canvas_area() tool = ToolbarButton() tool.props.page = ViewToolbar(self._main_area) tool.props.icon_name = 'toolbar-view' tool.props.label = _('View'), toolbar_box.toolbar.insert(tool, -1) tool = ToolbarButton() self.text_format_toolbar = TextAttributesToolbar(self._main_area) tool.props.page = self.text_format_toolbar tool.props.icon_name = 'toolbar-text' tool.props.label = _('Text') toolbar_box.toolbar.insert(tool, -1) # self._main_area.set_text_attributes(self.text_format_toolbar) self.thought_toolbar = ToolbarButton() self.thought_toolbar.props.page = ThoughtsToolbar(self) self.thought_toolbar.props.icon_name = 'thought' self.thought_toolbar.props.label = _('Thought Type') toolbar_box.toolbar.insert(self.thought_toolbar, -1) self.action_buttons = ActionButtons(self) toolbar_box.show_all() else: # Use old <= 0.84 toolbar design toolbox = activity.ActivityToolbox(self) self.set_toolbox(toolbox) activity_toolbar = toolbox.get_activity_toolbar() keep_palette = activity_toolbar.keep.get_palette() menu_item = MenuItem(_('Portable Document Format (PDF)')) menu_item.connect('activate', self.__export_pdf_cb) keep_palette.menu.append(menu_item) menu_item.show() menu_item = MenuItem(_('Portable Network Graphic (PNG)')) menu_item.connect('activate', self.__export_png_cb) keep_palette.menu.append(menu_item) menu_item.show() menu_item = MenuItem(_('Plain Text (TXT)')) menu_item.connect('activate', self.__export_txt_cb) keep_palette.menu.append(menu_item) menu_item.show() self.edit_toolbar = EditToolbar(self) toolbox.add_toolbar(_('Edit'), self.edit_toolbar) separator = gtk.SeparatorToolItem() self.edit_toolbar.insert(separator, 0) self.edit_toolbar.show() self._undo = UndoManager.UndoManager(self, self.edit_toolbar.undo.child, self.edit_toolbar.redo.child) self.__build_main_canvas_area() view_toolbar = ViewToolbar(self._main_area) toolbox.add_toolbar(_('View'), view_toolbar) activity_toolbar = toolbox.get_activity_toolbar() activity_toolbar.share.props.visible = False toolbox.set_current_toolbar(1) self.show_all() self.__configure_cb(None) self._mode = MMapArea.MODE_TEXT self._main_area.set_mode(self._mode) self.set_focus_child(self._main_area)