class ColorItem(Item): __gsignals__ = { 'updated': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING, )) } def __init__(self, parent=None, important=False): Item.__init__(self, gtk.STOCK_SELECT_COLOR) self.color = '#FFFFFF' def set_color(self, color): self.color = color if self.toolitem and self.color: self.toolitem.set_color(gtk.gdk.Color(self.color)) def get_tool_item(self): self.toolitem = ColorToolButton() self.toolitem.connect('notify::color', self._color_changed_cb) self.setup_tooltip() self.set_color(self.color) return self.toolitem def setup_tooltip(self): if self.tooltip: self.toolitem.set_title(self.tooltip) else: text = gtk.stock_lookup(self.stock_id)[1] self.toolitem.set_title(text.replace('_', '')) self.setup_accelerator() def _color_changed_cb(self, widget, pspec): color_gdk = widget.get_color() self.color = color2string(color_gdk) self.emit('updated', self.color)
def build_colors_toolbar(self, toolbox): colors_bar = gtk.Toolbar() ######################################################################## # Point color item = gtk.ToolItem() label = gtk.Label() label.set_text('%s ' % _('Player 1')) item.add(label) colors_bar.insert(item, -1) # select color item = gtk.ToolItem() _fill_color = ColorToolButton() c = gtk.gdk.Color() c.red = 65535 c.green = 65535 c.blue = 65535 _fill_color.set_color(c) _fill_color.connect('notify::color', self.color_player1_change) item.add(_fill_color) colors_bar.insert(item, -1) # Separator separator = gtk.SeparatorToolItem() colors_bar.insert(separator, -1) separator.show() ######################################################################## # Back color item = gtk.ToolItem() label = gtk.Label() label.set_text('%s ' % _('Player 2')) item.add(label) colors_bar.insert(item, -1) # select color item = gtk.ToolItem() _fill_color = ColorToolButton() c = gtk.gdk.Color() c.red = 0 c.green = 0 c.blue = 0 _fill_color.set_color(c) _fill_color.connect('notify::color', self.color_player2_change) item.add(_fill_color) colors_bar.insert(item, -1) # Separator separator = gtk.SeparatorToolItem() colors_bar.insert(separator, -1) separator.show() ######################################################################## # Line color item = gtk.ToolItem() label = gtk.Label() label.set_text('%s ' % _('Lines')) item.add(label) colors_bar.insert(item, -1) # select color item = gtk.ToolItem() _fill_color = ColorToolButton() _fill_color.connect('notify::color', self.color_line_change) item.add(_fill_color) colors_bar.insert(item, -1) # Separator separator = gtk.SeparatorToolItem() colors_bar.insert(separator, -1) separator.show() ######################################################################## # Line color item = gtk.ToolItem() label = gtk.Label() label.set_text('%s ' % _('Background')) item.add(label) colors_bar.insert(item, -1) # select color item = gtk.ToolItem() _fill_color = ColorToolButton() _fill_color.connect('notify::color', self.color_back_change) item.add(_fill_color) colors_bar.insert(item, -1) # Separator separator = gtk.SeparatorToolItem() colors_bar.insert(separator, -1) separator.show() ######################################################################## # Line color item = gtk.ToolItem() label = gtk.Label() label.set_text('%s ' % _('Board')) item.add(label) colors_bar.insert(item, -1) # select color item = gtk.ToolItem() _fill_color = ColorToolButton() _fill_color.connect('notify::color', self.color_board_change) item.add(_fill_color) colors_bar.insert(item, -1) ######################################################################## colors_bar.show_all() colors_button = ToolbarButton(label=_('Colors'), page=colors_bar, icon_name='toolbar-colors') toolbox.toolbar.insert(colors_button, -1) colors_button.show()
def __init__(self, main_area): gtk.Toolbar.__init__(self) self._main_area = main_area self._font_list = ['ABC123', 'Sans', 'Serif', 'Monospace', 'Symbol'] self._font_sizes = [ '8', '9', '10', '11', '12', '14', '16', '20', '22', '24', '26', '28', '36', '48', '72' ] self.font_button = ToolButton('font-text') self.font_button.set_tooltip(_('Select font')) self.font_button.connect('clicked', self.__font_selection_cb) self.insert(self.font_button, -1) self._setup_font_palette() self.insert(gtk.SeparatorToolItem(), -1) self.font_size_up = ToolButton('resize+') self.font_size_up.set_tooltip(_('Bigger')) self.font_size_up.connect('clicked', self.__font_sizes_cb, True) self.insert(self.font_size_up, -1) if len(self._main_area.selected) > 0: font_size = self._main_area.font_size else: font_size = utils.default_font_size self.size_label = gtk.Label(str(font_size)) self.size_label.show() toolitem = gtk.ToolItem() toolitem.add(self.size_label) toolitem.show() self.insert(toolitem, -1) self.font_size_down = ToolButton('resize-') self.font_size_down.set_tooltip(_('Smaller')) self.font_size_down.connect('clicked', self.__font_sizes_cb, False) self.insert(self.font_size_down, -1) self.insert(gtk.SeparatorToolItem(), -1) self.bold = ToolButton('bold-text') self.bold.set_tooltip(_('Bold')) self.bold.connect('clicked', self.__bold_cb) self.insert(self.bold, -1) self.italics = ToolButton('italics-text') self.italics.set_tooltip(_('Italics')) self.italics.connect('clicked', self.__italics_cb) self.insert(self.italics, -1) self.underline = ToolButton('underline-text') self.underline.set_tooltip(_('Underline')) self.underline.connect('clicked', self.__underline_cb) self.insert(self.underline, -1) foreground_color = ColorToolButton() foreground_color.set_title(_('Set font color')) foreground_color.connect('color-set', self.__foreground_color_cb) self.insert(foreground_color, -1) bakground_color = ColorToolButton() bakground_color.set_title(_('Set background color')) bakground_color.connect('color-set', self.__background_color_cb) bakground_color.set_color(gtk.gdk.Color(65535, 65535, 65535)) self.insert(bakground_color, -1) self.show_all()
def get_tool_item(self): self.toolitem = ColorToolButton() self.toolitem.connect('notify::color', self._color_changed_cb) self.setup_tooltip() self.set_color(self.color) return self.toolitem
class SimpleGraph(activity.Activity): 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() import_stopwatch = ToolButton("import-stopwatch") import_stopwatch.connect("clicked", self.__import_stopwatch_cb) import_stopwatch.set_tooltip(_("Read StopWatch data")) activity_btn_toolbar.insert(import_stopwatch, -1) import_stopwatch.show() import_measure = ToolButton("import-measure") import_measure.set_tooltip(_("Read Measure data")) if utils.get_channels() == 1: import_measure.connect("clicked", self.__import_measure_cb, 1) else: import_measure.connect("clicked", self._measure_btn_clicked) self._create_measure_palette(import_measure) activity_btn_toolbar.insert(import_measure, -1) import_measure.show() activity_btn_toolbar.keep.hide() toolbarbox.toolbar.insert(activity_button, 0) add_v = ToolButton("row-insert") add_v.connect("clicked", self._add_value) add_v.set_tooltip(_("Add a value")) toolbarbox.toolbar.insert(add_v, -1) remove_v = ToolButton("row-remove") remove_v.connect("clicked", self._remove_value) remove_v.set_tooltip(_("Remove the selected value")) toolbarbox.toolbar.insert(remove_v, -1) 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 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) options_button = ToolbarButton(icon_name='preferences-system') options_toolbar = gtk.Toolbar() self.chart_color_btn = ColorToolButton() self.chart_color_btn.set_color(_COLOR1) self.chart_color_btn.set_title(_("Chart Color")) self.chart_color_btn.connect('notify::color', self._set_chart_color) options_toolbar.insert(self.chart_color_btn, -1) self.line_color_btn = ColorToolButton() self.line_color_btn.set_color(_COLOR2) self.line_color_btn.set_title(_("Line Color")) self.line_color_btn.connect('notify::color', self._set_chart_line_color) options_toolbar.insert(self.line_color_btn, -1) separator = gtk.SeparatorToolItem() separator.set_draw(True) separator.set_expand(False) options_toolbar.insert(separator, -1) h_label_icon = Icon(icon_name="hlabel") h_label_tool_item = gtk.ToolItem() h_label_tool_item.add(h_label_icon) options_toolbar.insert(h_label_tool_item, -1) self.h_label = Entry(_("Horizontal label...")) self.h_label.entry.connect("changed", self._set_h_label) options_toolbar.insert(self.h_label, -1) separator = gtk.SeparatorToolItem() separator.set_draw(False) separator.set_expand(False) options_toolbar.insert(separator, -1) v_label_icon = Icon(icon_name="vlabel") v_label_tool_item = gtk.ToolItem() v_label_tool_item.add(v_label_icon) options_toolbar.insert(v_label_tool_item, -1) self.v_label = Entry(_("Vertical label...")) self.v_label.entry.connect("changed", self._set_v_label) options_toolbar.insert(self.v_label, -1) options_button.props.page = options_toolbar options_toolbar.show_all() toolbarbox.toolbar.insert(options_button, -1) 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) separator = gtk.SeparatorToolItem() separator.set_draw(False) separator.set_expand(True) toolbarbox.toolbar.insert(separator, -1) simplegraphhelp.create_help(toolbarbox.toolbar) 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.POLICY_AUTOMATIC, gtk.POLICY_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.STATE_NORMAL, _WHITE) eventbox.add(self.charts_area) paned.add2(eventbox) self.set_canvas(paned) self.show_all() def _create_measure_palette(self, button): palette = button.get_palette() hbox = gtk.HBox() channel1 = ToolButton("measure-channel-1") channel1.connect("clicked", self.__import_measure_cb, 1) channel2 = ToolButton("measure-channel-2") channel2.connect("clicked", self.__import_measure_cb, 2) hbox.pack_start(channel1, False, True, 0) hbox.pack_end(channel2, False, True, 0) hbox.show_all() palette.set_content(hbox) def _measure_btn_clicked(self, button): palette = button.get_palette() palette.popup() def _add_value(self, widget, label="", value="0.0"): data = (label, float(value)) if not data in self.chart_data: pos = self.labels_and_values.add_value(label, value) self.chart_data.insert(pos, data) self._update_chart_data() def _remove_value(self, widget): path = self.labels_and_values.remove_selected_value() del self.chart_data[path] self._update_chart_data() def _add_chart_cb(self, widget, type="vbar"): self.current_chart = Chart(type) self.update_chart() def _chart_size_allocate(self, widget, allocation): self._render_chart() def unfullscreen(self): self.box.show() activity.Activity.unfullscreen(self) def __fullscreen_cb(self, button): self.box.hide() self._render_chart(fullscreen=True) activity.Activity.fullscreen(self) def _render_chart(self, fullscreen=False): if self.current_chart is None or self.charts_area is None: return try: # Resize the chart for all the screen sizes xpos, ypos, width, height = self.get_allocation() if fullscreen: new_width = width new_height = height if not fullscreen: sxpos, sypos, width, height = self.charts_area.get_allocation() new_width = width - 40 new_height = height - 40 self.current_chart.width = new_width self.current_chart.height = new_height # Set options self.current_chart.set_color_scheme(color=self.chart_color) self.current_chart.set_line_color(self.chart_line_color) if self.current_chart.type == "pie": self.current_chart.render(self) else: self.current_chart.render() self.charts_area.queue_draw() except (ZeroDivisionError, ValueError): pass return False def _update_chart_data(self): if self.current_chart is None: return self.current_chart.data_set(self.chart_data) self._update_chart_labels() def _set_chart_title(self, widget): self._update_chart_labels(title=widget.get_text()) def _update_chart_labels(self, title=""): if self.current_chart is None: return if not title and self.metadata["title"]: title = self.metadata["title"] self.current_chart.set_title(title) self.current_chart.set_x_label(self.x_label) self.current_chart.set_y_label(self.y_label) self._render_chart() def update_chart(self): if self.current_chart: self.current_chart.data_set(self.chart_data) self.current_chart.set_title(self.metadata["title"]) self.current_chart.set_x_label(self.x_label) self.current_chart.set_y_label(self.y_label) self._render_chart() def _label_changed(self, treeview, path, new_label): path = int(path) self.chart_data[path] = (new_label, self.chart_data[path][1]) self._update_chart_data() def _value_changed(self, treeview, path, new_value): path = int(path) self.chart_data[path] = (self.chart_data[path][0], float(new_value)) self._update_chart_data() def _set_h_label(self, widget): new_text = widget.get_text() if new_text != self.h_label._text: self.x_label = new_text self._update_chart_labels() def _set_v_label(self, widget): new_text = widget.get_text() if new_text != self.v_label._text: self.y_label = new_text self._update_chart_labels() def _set_chart_color(self, widget, pspec): self.chart_color = utils.rgb2html(widget.get_color()) self._render_chart() def _set_chart_line_color(self, widget, pspec): self.chart_line_color = utils.rgb2html(widget.get_color()) self._render_chart() def _object_chooser(self, mime_type, type_name): chooser = ObjectChooser() matches_mime_type = False response = chooser.run() if response == gtk.RESPONSE_ACCEPT: jobject = chooser.get_selected_object() metadata = jobject.metadata file_path = jobject.file_path if metadata['mime_type'] == mime_type: matches_mime_type = True else: alert = Alert() alert.props.title = _('Invalid object') alert.props.msg = \ _('The selected object must be a %s file' % (type_name)) ok_icon = Icon(icon_name='dialog-ok') alert.add_button(gtk.RESPONSE_OK, _('Ok'), ok_icon) ok_icon.show() alert.connect('response', lambda a, r: self.remove_alert(a)) self.add_alert(alert) alert.show() return matches_mime_type, file_path, metadata['title'] def _graph_from_reader(self, reader): self.labels_and_values.model.clear() self.chart_data = [] chart_data = reader.get_chart_data() horizontal, vertical = reader.get_labels_name() self.v_label.entry.set_text(horizontal) self.h_label.entry.set_text(vertical) # Load the data for row in chart_data: self._add_value(None, label=row[0], value=float(row[1])) self.update_chart() def __import_stopwatch_cb(self, widget): matches_mime_type, file_path, title = self._object_chooser( _STOPWATCH_MIME_TYPE, _('StopWatch')) if matches_mime_type: f = open(file_path) reader = StopWatchReader(f) self._graph_from_reader(reader) f.close() def __import_measure_cb(self, widget, channel=1): matches_mime_type, file_path, title = self._object_chooser( _CSV_MIME_TYPE, _('Measure')) if matches_mime_type: f = open(file_path) reader = MeasureReader(f, channel) self._graph_from_reader(reader) f.close() def _save_as_image(self, widget): if self.current_chart: jobject = datastore.create() jobject.metadata['title'] = self.metadata["title"] jobject.metadata['mime_type'] = "image/png" self.current_chart.as_png(_CHART_FILE) jobject.set_file_path(_CHART_FILE) datastore.write(jobject) def write_file(self, file_path): self.metadata['mime_type'] = "application/x-simplegraph-activity" if self.current_chart: data = {} data['title'] = self.metadata["title"] data['x_label'] = self.x_label data['y_label'] = self.y_label data['chart_color'] = self.chart_color data['chart_line_color'] = self.chart_line_color data['current_chart.type'] = self.current_chart.type data['chart_data'] = self.chart_data f = open(file_path, 'w') try: simplejson.dump(data, f) finally: f.close() def read_file(self, file_path): f = open(file_path, 'r') try: data = simplejson.load(f) finally: f.close() self.metadata["title"] = data['title'] self.x_label = data['x_label'] self.y_label = data['y_label'] self.chart_color = data['chart_color'] self.chart_line_color = data['chart_line_color'] self.current_chart.type = data['current_chart.type'] chart_data = data['chart_data'] # Update charts buttons type = data["current_chart.type"] if type == "vbar": self.chart_type_buttons[0].set_active(True) elif type == "hbar": self.chart_type_buttons[1].set_active(True) elif type == "line": self.chart_type_buttons[2].set_active(True) elif type == "pie": self.chart_type_buttons[3].set_active(True) # Update the controls in the config subtoolbar self.chart_color_btn.set_color(gtk.gdk.Color(self.chart_color)) self.line_color_btn.set_color(gtk.gdk.Color(self.chart_line_color)) # If the saved label is not '', set the text entry with the saved label if self.x_label != '': self.h_label.entry.set_text(self.x_label) if self.y_label != '': self.v_label.entry.set_text(self.y_label) #load the data for row in chart_data: self._add_value(None, label=row[0], value=float(row[1])) self.update_chart()
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() import_stopwatch = ToolButton("import-stopwatch") import_stopwatch.connect("clicked", self.__import_stopwatch_cb) import_stopwatch.set_tooltip(_("Read StopWatch data")) activity_btn_toolbar.insert(import_stopwatch, -1) import_stopwatch.show() import_measure = ToolButton("import-measure") import_measure.set_tooltip(_("Read Measure data")) if utils.get_channels() == 1: import_measure.connect("clicked", self.__import_measure_cb, 1) else: import_measure.connect("clicked", self._measure_btn_clicked) self._create_measure_palette(import_measure) activity_btn_toolbar.insert(import_measure, -1) import_measure.show() activity_btn_toolbar.keep.hide() toolbarbox.toolbar.insert(activity_button, 0) add_v = ToolButton("row-insert") add_v.connect("clicked", self._add_value) add_v.set_tooltip(_("Add a value")) toolbarbox.toolbar.insert(add_v, -1) remove_v = ToolButton("row-remove") remove_v.connect("clicked", self._remove_value) remove_v.set_tooltip(_("Remove the selected value")) toolbarbox.toolbar.insert(remove_v, -1) 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 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) options_button = ToolbarButton(icon_name='preferences-system') options_toolbar = gtk.Toolbar() self.chart_color_btn = ColorToolButton() self.chart_color_btn.set_color(_COLOR1) self.chart_color_btn.set_title(_("Chart Color")) self.chart_color_btn.connect('notify::color', self._set_chart_color) options_toolbar.insert(self.chart_color_btn, -1) self.line_color_btn = ColorToolButton() self.line_color_btn.set_color(_COLOR2) self.line_color_btn.set_title(_("Line Color")) self.line_color_btn.connect('notify::color', self._set_chart_line_color) options_toolbar.insert(self.line_color_btn, -1) separator = gtk.SeparatorToolItem() separator.set_draw(True) separator.set_expand(False) options_toolbar.insert(separator, -1) h_label_icon = Icon(icon_name="hlabel") h_label_tool_item = gtk.ToolItem() h_label_tool_item.add(h_label_icon) options_toolbar.insert(h_label_tool_item, -1) self.h_label = Entry(_("Horizontal label...")) self.h_label.entry.connect("changed", self._set_h_label) options_toolbar.insert(self.h_label, -1) separator = gtk.SeparatorToolItem() separator.set_draw(False) separator.set_expand(False) options_toolbar.insert(separator, -1) v_label_icon = Icon(icon_name="vlabel") v_label_tool_item = gtk.ToolItem() v_label_tool_item.add(v_label_icon) options_toolbar.insert(v_label_tool_item, -1) self.v_label = Entry(_("Vertical label...")) self.v_label.entry.connect("changed", self._set_v_label) options_toolbar.insert(self.v_label, -1) options_button.props.page = options_toolbar options_toolbar.show_all() toolbarbox.toolbar.insert(options_button, -1) 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) separator = gtk.SeparatorToolItem() separator.set_draw(False) separator.set_expand(True) toolbarbox.toolbar.insert(separator, -1) simplegraphhelp.create_help(toolbarbox.toolbar) 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.POLICY_AUTOMATIC, gtk.POLICY_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.STATE_NORMAL, _WHITE) eventbox.add(self.charts_area) paned.add2(eventbox) self.set_canvas(paned) self.show_all()
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)
def build_colors_toolbar(self, toolbox): colors_bar = gtk.Toolbar() ######################################################################## # Point color item = gtk.ToolItem() label = gtk.Label() label.set_text('%s ' % _('Points')) item.add(label) colors_bar.insert(item, -1) # select color item = gtk.ToolItem() fill_color = ColorToolButton() fill_color.connect('notify::color', self.color_point_change) item.add(fill_color) colors_bar.insert(item, -1) # Separator separator = gtk.SeparatorToolItem() colors_bar.insert(separator, -1) separator.show() ######################################################################## # Back color item = gtk.ToolItem() label = gtk.Label() label.set_text('%s ' % _('Background')) item.add(label) colors_bar.insert(item, -1) # select color item = gtk.ToolItem() _fill_color = ColorToolButton() c = gtk.gdk.Color() c.red = 21588 c.green = 47546 c.blue = 18504 _fill_color.set_color(c) _fill_color.connect('notify::color', self.color_back_change) item.add(_fill_color) colors_bar.insert(item, -1) # Separator separator = gtk.SeparatorToolItem() colors_bar.insert(separator, -1) separator.show() ######################################################################## # Line color item = gtk.ToolItem() label = gtk.Label() label.set_text('%s ' % _('Lines')) item.add(label) colors_bar.insert(item, -1) # select color item = gtk.ToolItem() _fill_color = ColorToolButton() _fill_color.connect('notify::color', self.color_line_change) item.add(_fill_color) colors_bar.insert(item, -1) # Separator separator = gtk.SeparatorToolItem() colors_bar.insert(separator, -1) separator.show() ######################################################################## # Owner color item = gtk.ToolItem() label = gtk.Label() label.set_text('%s ' % _('Owner')) item.add(label) colors_bar.insert(item, -1) # select color item = gtk.ToolItem() _fill_color = ColorToolButton() c = gtk.gdk.Color() c.red = 65535 _fill_color.set_color(c) _fill_color.connect('notify::color', self.color_owner_change) item.add(_fill_color) colors_bar.insert(item, -1) colors_bar.show_all() colors_button = ToolbarButton(label=_('Colors'), page=colors_bar, icon_name='toolbar-colors') toolbox.toolbar.insert(colors_button, -1) colors_button.show()
except ImportError: print 'NO SE ESTA EN SUGAR.. SALIENDO' sys.exit() Fonts = Combo() Fonts.set_items([ "Purisa 8", "Purisa 12", "Purisa 24", "Monospace 8", "Monospace 12", "Monospace 24", "Times New Roman 8", "Times New Roman 12", "Times New Roman 24", "FreeSans 8", "FreeSans 12", "FreeSans 24" ]) Title_Tam = Combo() Title_Tam.set_items([ "Purisa 8", "Purisa 12", "Purisa 24", "Monospace 8", "Monospace 12", "Monospace 24", "Times New Roman 8", "Times New Roman 12", "Times New Roman 24", "FreeSans 8", "FreeSans 12", "FreeSans 24" ]) ColorLetra = ColorToolButton() ColorTitle = ColorToolButton() ColorFondo = ColorToolButton() Col = gtk.gdk.Color('#ffffff') ColorFondo.set_color(Col) restart_button = ToolButton("home") reading_button = ToolButton("read") load_button = ToolButton("open-from-journal") #credits = ToolButton("credits") tutorial = ToolButton("tutorial") tutorial.set_tooltip(_("Tutorial book")) new_button = ToolButton("new") book_button = ToolButton("edit-p") page_button = ToolButton("edit-c") check_button = ToolButton("broken")
def __init__(self): gtk.HBox.__init__(self) self.toolbar = VTray() copy = ToolButton("edit-copy") copy.set_tooltip('Copy') copy.connect("clicked", self.__copy_cb) copy.show() self.toolbar.add_item(copy, -1) paste = ToolButton("edit-paste") paste.set_tooltip("Paste") paste.connect("clicked", self.__paste_cb) paste.show() self.toolbar.add_item(paste, -1) fgcolor = ColorToolButton() fgcolor.get_child()._title = "Font Color" self.toolbar.add_item(fgcolor, -1) fgcolor.connect('notify::color', self._fgcolor_cb) fgcolor.show_all() bgcolor = ColorToolButton() bgcolor.get_child()._title = "Background Color" bgcolor.connect('notify::color', self._bgcolor_cb) self.toolbar.add_item(bgcolor, -1) bgcolor.show_all() self.console = Console() self.console.set_bgcolor(gtk.gdk.color_parse("#FFFFFF")) self.console.set_fgcolor(gtk.gdk.color_parse("#000000")) bgcolor.set_color(gtk.gdk.color_parse("#FFFFFF")) fgcolor.set_color(gtk.gdk.color_parse("#000000")) self.console.show() font = ToolButton("format-text") font.set_tooltip("Console Font") fontselection = gtk.FontSelection() fontselection.get_family_list().get_selection().connect("changed", self.update_font, fontselection) fontselection.get_face_list().get_selection().connect("changed", self.update_font, fontselection) fontselection.get_size_entry().connect("changed", self.update_font, fontselection) fontselection.get_size_entry().connect("activate", self.update_font, fontselection) fontselection.show() font.props.palette.set_content(fontselection) fontselection.set_font_name("Monospace Regular 10") font.show() self.toolbar.add_item(font, -1) reset = ToolButton("view-refresh") reset.set_tooltip("Reset Console") reset.connect("clicked", self.reset) reset.show() self.toolbar.add_item(reset, -1) self.toolbar.show() self.pack_start(self.toolbar, False, True, 0) self.console.run_command("python") self.pack_start(self.console)
def __init__(self, main_area): gtk.Toolbar.__init__(self) self._main_area = main_area self._font_list = ['ABC123', 'Sans', 'Serif', 'Monospace', 'Symbol'] self._font_sizes = ['8', '9', '10', '11', '12', '14', '16', '20', '22', '24', '26', '28', '36', '48', '72'] self.font_button = ToolButton('font-text') self.font_button.set_tooltip(_('Select font')) self.font_button.connect('clicked', self.__font_selection_cb) self.insert(self.font_button, -1) self._setup_font_palette() self.insert(gtk.SeparatorToolItem(), -1) self.font_size_up = ToolButton('resize+') self.font_size_up.set_tooltip(_('Bigger')) self.font_size_up.connect('clicked', self.__font_sizes_cb, True) self.insert(self.font_size_up, -1) if len(self._main_area.selected) > 0: font_size = self._main_area.font_size else: font_size = utils.default_font_size self.size_label = gtk.Label(str(font_size)) self.size_label.show() toolitem = gtk.ToolItem() toolitem.add(self.size_label) toolitem.show() self.insert(toolitem, -1) self.font_size_down = ToolButton('resize-') self.font_size_down.set_tooltip(_('Smaller')) self.font_size_down.connect('clicked', self.__font_sizes_cb, False) self.insert(self.font_size_down, -1) self.insert(gtk.SeparatorToolItem(), -1) self.bold = ToolButton('bold-text') self.bold.set_tooltip(_('Bold')) self.bold.connect('clicked', self.__bold_cb) self.insert(self.bold, -1) self.italics = ToolButton('italics-text') self.italics.set_tooltip(_('Italics')) self.italics.connect('clicked', self.__italics_cb) self.insert(self.italics, -1) self.underline = ToolButton('underline-text') self.underline.set_tooltip(_('Underline')) self.underline.connect('clicked', self.__underline_cb) self.insert(self.underline, -1) foreground_color = ColorToolButton() foreground_color.set_title(_('Set font color')) foreground_color.connect('color-set', self.__foreground_color_cb) self.insert(foreground_color, -1) bakground_color = ColorToolButton() bakground_color.set_title(_('Set background color')) bakground_color.connect('color-set', self.__background_color_cb) bakground_color.set_color(gtk.gdk.Color(65535, 65535, 65535)) self.insert(bakground_color, -1) self.show_all()