def __init__(self, model=None, changed_cb=None, value=None): gtk.HBox.__init__(self) self._left_button = borderless_button(tooltip=_("Previous item")) self._left_button.add(gtk.Arrow(gtk.ARROW_LEFT, self.ARROW_SHADOW_TYPE)) self._left_button.connect("clicked", self._spin_button_clicked, -1) self._right_button = borderless_button(tooltip=_("Next item")) self._right_button.add(gtk.Arrow(gtk.ARROW_RIGHT, self.ARROW_SHADOW_TYPE)) self._right_button.connect("clicked", self._spin_button_clicked, 1) self._label = gtk.Label() self.pack_start(self._left_button, False, False) self.pack_start(self._label, True, True) self.pack_start(self._right_button, False, False) self._changed_cb = None self.set_changed_callback(changed_cb) self._model = None self._model_index = None self.set_model(model, value)
def __init__(self): gtk.ToolItem.__init__(self) self.history_images = [] self.main_image = ManagedBrushPreview() self.dropdown_button = dropdownpanel.DropdownPanelButton(self.main_image) self.app = None self.image_size = ToolbarManager.icon_size self.connect("toolbar-reconfigured", self.on_toolbar_reconf) self.connect("create-menu-proxy", lambda *a: True) self.set_tooltip_text(_("Brush history etc.")) self.add(self.dropdown_button) from application import get_app app = get_app() self.app = app bm = self.app.brushmanager bm.brush_selected += self.on_brush_selected self.app.doc.input_stroke_ended_observers\ .append(self.doc_input_stroke_ended_cb) self.update_history_images() panel_frame = gtk.Frame() panel_frame.set_shadow_type(gtk.SHADOW_OUT) self.dropdown_button.set_property("panel-widget", panel_frame) panel_vbox = gtk.VBox() panel_vbox.set_spacing(widgets.SPACING_TIGHT) panel_vbox.set_border_width(widgets.SPACING) panel_frame.add(panel_vbox) # Quick brush changer section_frame = widgets.section_frame(_("Change Brush")) panel_vbox.pack_start(section_frame, True, True) section_vbox = gtk.VBox() section_vbox.set_border_width(widgets.SPACING) section_vbox.set_spacing(widgets.SPACING_TIGHT) section_frame.add(section_vbox) quick_changer = dialogs.QuickBrushChooser(app, self.on_quick_change_select) evbox = gtk.EventBox() evbox.add(quick_changer) section_vbox.pack_start(evbox, True, True) # List editor button # FIXME: perhaps list out the brush groups now? # Brush history section_frame = widgets.section_frame(_("Recently Used")) panel_vbox.pack_start(section_frame, True, True) history_hbox = gtk.HBox() history_hbox.set_border_width(widgets.SPACING) section_frame.add(history_hbox) for i, image in enumerate(self.history_images): button = widgets.borderless_button() button.add(image) button.connect("clicked", self.on_history_button_clicked, i) history_hbox.pack_end(button, True, True)
def set_app(self, app): self.app = app bm = self.app.brushmanager bm.selected_brush_observers.append(self.on_selected_brush) self.app.doc.input_stroke_ended_observers\ .append(self.doc_input_stroke_ended_cb) self.update_history_images() panel_frame = gtk.Frame() panel_frame.set_shadow_type(gtk.SHADOW_OUT) self.dropdown_button.set_property("panel-widget", panel_frame) panel_vbox = gtk.VBox() panel_vbox.set_spacing(widgets.SPACING_TIGHT) panel_vbox.set_border_width(widgets.SPACING) panel_frame.add(panel_vbox) # Quick brush changer section_frame = widgets.section_frame(_("Change Brush")) panel_vbox.pack_start(section_frame, True, True) section_vbox = gtk.VBox() section_vbox.set_border_width(widgets.SPACING) section_vbox.set_spacing(widgets.SPACING_TIGHT) section_frame.add(section_vbox) quick_changer = dialogs.QuickBrushChooser(app, self.on_quick_change_select) evbox = gtk.EventBox() evbox.add(quick_changer) section_vbox.pack_start(evbox, True, True) # List editor button list_editor_button = gtk.ToggleButton() list_editor_action = self.app.find_action("BrushSelectionWindow") list_editor_button.set_related_action(list_editor_action) close_panel_cb = lambda *a: self.dropdown_button.panel_hide() list_editor_button.connect("clicked", close_panel_cb) section_vbox.pack_start(list_editor_button, False, False) # Brush history section_frame = widgets.section_frame(_("Recently Used")) panel_vbox.pack_start(section_frame, True, True) history_hbox = gtk.HBox() history_hbox.set_border_width(widgets.SPACING) section_frame.add(history_hbox) for i, image in enumerate(self.history_images): button = widgets.borderless_button() button.add(image) button.connect("clicked", self.on_history_button_clicked, i) history_hbox.pack_end(button, True, True)
def __init__(self, app): Gtk.HBox.__init__(self) self._app = app self._history = [] self.set_border_width(widgets.SPACING) s = HISTORY_PREVIEW_SIZE mgr = app.brush_color_manager for i, color in enumerate(mgr.get_history()): button = widgets.borderless_button() preview = ColorPreview(color) preview.set_size_request(s, s) button.add(preview) button.connect("clicked", self._button_clicked_cb, i) self.pack_end(button, True, False, 0) self._history.append(preview) self.set_color_manager(mgr)
def __init__(self, app): Gtk.HBox.__init__(self) self._app = app bm = app.brushmanager self._history_images = [] s = HISTORY_PREVIEW_SIZE self.set_border_width(widgets.SPACING) for i, brush in enumerate(bm.history): image = ManagedBrushPreview() image.set_size_request(s, s) self._history_images.append(image) button = widgets.borderless_button() button.add(image) button.connect("clicked", self._history_button_clicked_cb, i) self.pack_end(button, True, False, 0) app.doc.input_stroke_ended += self._stroke_ended_cb self._update_history_images()
def __init__(self, toolitem): gtk.HBox.__init__(self) self.__history_blobs = [] self.__app = toolitem.app self.__toolitem = toolitem self.set_border_width(widgets.SPACING) s = HISTORY_PREVIEW_SIZE mgr = self.__app.brush_color_manager for color in mgr.get_history(): button = widgets.borderless_button() blob = ColorBlob(color) blob.set_size_request(s, s) button.add(blob) button.connect("clicked", self.__button_clicked_cb) self.pack_end(button, True, True) self.__history_blobs.append(blob) self.set_color_manager(mgr)
def __init__(self): GObject.GObject.__init__(self) from application import get_app app = get_app() self.app = app self.set_spacing(widgets.SPACING_CRAMPED) self.set_border_width(widgets.SPACING_TIGHT) # GtkTreeView init docmodel = app.doc.model view = Gtk.TreeView() treemodel = layers.RootStackTreeModelWrapper(docmodel) view.set_model(treemodel) self._treemodel = treemodel view.set_reorderable(True) view.set_headers_visible(False) view.connect("button-press-event", self._view_button_press_cb) self._treeview = view # Motion and modifier keys during drag view.connect("drag-begin", self._view_drag_begin_cb) view.connect("drag-end", self._view_drag_end_cb) view.connect("drag-motion", self._view_drag_motion_cb) statusbar_cid = app.statusbar.get_context_id(self.STATUSBAR_CONTEXT) self._drag_statusbar_context_id = statusbar_cid # View behaviour and appearance sel = view.get_selection() sel.set_mode(Gtk.SelectionMode.SINGLE) view_scroll = Gtk.ScrolledWindow() view_scroll.set_shadow_type(Gtk.ShadowType.ETCHED_IN) scroll_pol = Gtk.PolicyType.AUTOMATIC view_scroll.set_policy(scroll_pol, scroll_pol) view_scroll.add(view) view_scroll.set_size_request(-1, 100) view_scroll.set_hexpand(True) view_scroll.set_vexpand(True) # Context menu ui_dir = os.path.dirname(os.path.abspath(__file__)) ui_path = os.path.join(ui_dir, "layerswindow.xml") self.app.ui_manager.add_ui_from_file(ui_path) menu = self.app.ui_manager.get_widget("/LayersWindowPopup") menu.set_title(_("Layer")) self.connect("popup-menu", self._popup_menu_cb) menu.attach_to_widget(self, None) self._menu = menu self._layer_specific_ui_mergeids = [] self._layer_specific_ui_class = None # Type column cell = Gtk.CellRendererPixbuf() col = Gtk.TreeViewColumn(_("Type")) col.pack_start(cell, expand=False) datafunc = layers.layer_type_pixbuf_datafunc col.set_cell_data_func(cell, datafunc) col.set_max_width(24) col.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) view.append_column(col) self._type_col = col # Name column cell = Gtk.CellRendererText() cell.set_property("ellipsize", Pango.EllipsizeMode.END) col = Gtk.TreeViewColumn(_("Name")) col.pack_start(cell, expand=True) datafunc = layers.layer_name_text_datafunc col.set_cell_data_func(cell, datafunc) col.set_expand(True) col.set_min_width(48) col.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) view.append_column(col) self._name_col = col # Visibility column cell = Gtk.CellRendererPixbuf() col = Gtk.TreeViewColumn(_("Visible")) col.pack_start(cell, expand=False) datafunc = layers.layer_visible_pixbuf_datafunc col.set_cell_data_func(cell, datafunc) col.set_max_width(24) view.append_column(col) self._visible_col = col # Locked column cell = Gtk.CellRendererPixbuf() col = Gtk.TreeViewColumn(_("Locked")) col.pack_start(cell, expand=False) datafunc = layers.layer_locked_pixbuf_datafunc col.set_cell_data_func(cell, datafunc) col.set_max_width(24) view.append_column(col) self._locked_col = col # View appearance view.set_show_expanders(True) view.set_enable_tree_lines(True) view.set_expander_column(self._name_col) # Main layout grid grid = Gtk.Grid() grid.set_row_spacing(widgets.SPACING_TIGHT) grid.set_column_spacing(widgets.SPACING) # Mode dropdown row = 0 label = Gtk.Label(label=_('Mode:')) label.set_tooltip_text( _("Blending mode: how the current layer combines with the " "layers underneath it.")) label.set_alignment(0, 0.5) label.set_hexpand(False) grid.attach(label, 0, row, 1, 1) store = Gtk.ListStore(int, str, bool) modes = lib.layer.STACK_MODES + lib.layer.STANDARD_MODES for mode in modes: label, desc = lib.layer.MODE_STRINGS.get(mode) store.append([mode, label, True]) combo = Gtk.ComboBox() combo.set_model(store) combo.set_hexpand(True) cell = Gtk.CellRendererText() combo.pack_start(cell) combo.add_attribute(cell, "text", 1) combo.add_attribute(cell, "sensitive", 2) self._layer_mode_combo = combo grid.attach(combo, 1, row, 5, 1) # Opacity slider row += 1 opacity_lbl = Gtk.Label(label=_('Opacity:')) opacity_lbl.set_tooltip_text( _("Layer opacity: how much of the current layer to use. " "Smaller values make it more transparent.")) opacity_lbl.set_alignment(0, 0.5) opacity_lbl.set_hexpand(False) adj = Gtk.Adjustment(lower=0, upper=100, step_incr=1, page_incr=10) self._opacity_scale = Gtk.HScale(adj) self._opacity_scale.set_draw_value(False) self._opacity_scale.set_hexpand(True) grid.attach(opacity_lbl, 0, row, 1, 1) grid.attach(self._opacity_scale, 1, row, 5, 1) # Layer list and controls row += 1 layersbox = Gtk.VBox() style = layersbox.get_style_context() style.add_class(Gtk.STYLE_CLASS_LINKED) style = view_scroll.get_style_context() style.set_junction_sides(Gtk.JunctionSides.BOTTOM) list_tools = inline_toolbar( self.app, [ ("NewPaintingLayerAbove", "mypaint-add-symbolic"), ("RemoveLayer", "mypaint-remove-symbolic"), ("RaiseLayerInStack", "mypaint-up-symbolic"), ("LowerLayerInStack", "mypaint-down-symbolic"), ("DuplicateLayer", None), ("MergeLayerDown", None), ] ) style = list_tools.get_style_context() style.set_junction_sides(Gtk.JunctionSides.TOP) layersbox.pack_start(view_scroll, True, True) layersbox.pack_start(list_tools, False, False) layersbox.set_hexpand(True) layersbox.set_vexpand(True) grid.attach(layersbox, 0, row, 6, 1) # Background layer controls row += 1 show_bg_btn = Gtk.CheckButton() change_bg_act = self.app.find_action("BackgroundWindow") change_bg_btn = widgets.borderless_button(action=change_bg_act) show_bg_act = self.app.find_action("ShowBackgroundToggle") show_bg_btn.set_related_action(show_bg_act) grid.attach(show_bg_btn, 0, row, 5, 1) grid.attach(change_bg_btn, 5, row, 1, 1) # Pack self.pack_start(grid, False, True, 0) # Updates self._processing_model_updates = False self._opacity_scale.connect('value-changed', self._opacity_scale_changed_cb) self._layer_mode_combo.connect('changed', self._layer_mode_combo_changed_cb) rootstack = docmodel.layer_stack rootstack.expand_layer += self._expand_layer_cb rootstack.collapse_layer += self._collapse_layer_cb rootstack.layer_content_changed += self._layer_content_changed rootstack.layer_properties_changed += self._layer_propchange_cb rootstack.current_layer_solo_changed += self._treeview_redraw_all rootstack.current_path_updated += self._current_path_updated_cb # Initial update self.connect("show", self._show_cb)
def __init__(self): GObject.GObject.__init__(self) from application import get_app app = get_app() self.app = app self.set_spacing(widgets.SPACING_CRAMPED) self.set_border_width(widgets.SPACING_TIGHT) # GtkTreeView init docmodel = app.doc.model view = layers.RootStackTreeView(docmodel) self._treemodel = view.get_model() self._treeview = view # RootStackTreeView events view.current_layer_rename_requested += self._layer_properties_cb view.current_layer_changed += self._blink_current_layer_cb view.current_layer_menu_requested += self._popup_menu_cb # Drag and drop view.drag_began += self._view_drag_began_cb view.drag_ended += self._view_drag_ended_cb statusbar_cid = app.statusbar.get_context_id(self.STATUSBAR_CONTEXT) self._drag_statusbar_context_id = statusbar_cid # View scrolls view_scroll = Gtk.ScrolledWindow() view_scroll.set_shadow_type(Gtk.ShadowType.ETCHED_IN) vscroll_pol = Gtk.PolicyType.ALWAYS hscroll_pol = Gtk.PolicyType.AUTOMATIC view_scroll.set_policy(hscroll_pol, vscroll_pol) view_scroll.add(view) view_scroll.set_size_request(-1, 200) view_scroll.set_hexpand(True) view_scroll.set_vexpand(True) # Context menu ui_dir = os.path.dirname(os.path.abspath(__file__)) ui_path = os.path.join(ui_dir, "layerswindow.xml") self.app.ui_manager.add_ui_from_file(ui_path) menu = self.app.ui_manager.get_widget("/LayersWindowPopup") menu.set_title(_("Layer")) self.connect("popup-menu", self._popup_menu_cb) menu.attach_to_widget(self, None) self._menu = menu self._layer_specific_ui_mergeids = [] self._layer_specific_ui_class = None # Main layout grid grid = Gtk.Grid() grid.set_row_spacing(widgets.SPACING_TIGHT) grid.set_column_spacing(widgets.SPACING) # Mode dropdown row = 0 label = Gtk.Label(label=_('Mode:')) label.set_tooltip_text( _("Blending mode: how the current layer combines with the " "layers underneath it.")) label.set_alignment(0, 0.5) label.set_hexpand(False) grid.attach(label, 0, row, 1, 1) store = Gtk.ListStore(int, str, bool) modes = STACK_MODES + STANDARD_MODES for mode in modes: label, desc = MODE_STRINGS.get(mode) store.append([mode, label, True]) combo = Gtk.ComboBox() combo.set_model(store) combo.set_hexpand(True) cell = Gtk.CellRendererText() combo.pack_start(cell, True) combo.add_attribute(cell, "text", 1) combo.add_attribute(cell, "sensitive", 2) self._layer_mode_combo = combo grid.attach(combo, 1, row, 5, 1) # Opacity slider row += 1 opacity_lbl = Gtk.Label(label=_('Opacity:')) opacity_lbl.set_tooltip_text( _("Layer opacity: how much of the current layer to use. " "Smaller values make it more transparent.")) opacity_lbl.set_alignment(0, 0.5) opacity_lbl.set_hexpand(False) adj = Gtk.Adjustment(lower=0, upper=100, step_incr=1, page_incr=10) self._opacity_scale = Gtk.HScale.new(adj) self._opacity_scale.set_draw_value(False) self._opacity_scale.set_hexpand(True) grid.attach(opacity_lbl, 0, row, 1, 1) grid.attach(self._opacity_scale, 1, row, 5, 1) # Layer list and controls row += 1 layersbox = Gtk.VBox() style = layersbox.get_style_context() style.add_class(Gtk.STYLE_CLASS_LINKED) style = view_scroll.get_style_context() style.set_junction_sides(Gtk.JunctionSides.BOTTOM) list_tools = inline_toolbar( self.app, [ ("NewLayerGroupAbove", "mypaint-layer-group-new-symbolic"), ("NewPaintingLayerAbove", "mypaint-add-symbolic"), ("RemoveLayer", "mypaint-remove-symbolic"), ("RaiseLayerInStack", "mypaint-up-symbolic"), ("LowerLayerInStack", "mypaint-down-symbolic"), ("DuplicateLayer", None), ("MergeLayerDown", None), ] ) style = list_tools.get_style_context() style.set_junction_sides(Gtk.JunctionSides.TOP) layersbox.pack_start(view_scroll, True, True, 0) layersbox.pack_start(list_tools, False, False, 0) layersbox.set_hexpand(True) layersbox.set_vexpand(True) grid.attach(layersbox, 0, row, 6, 1) # Background layer controls row += 1 show_bg_btn = Gtk.CheckButton() change_bg_act = self.app.find_action("BackgroundWindow") change_bg_btn = widgets.borderless_button(action=change_bg_act) show_bg_act = self.app.find_action("ShowBackgroundToggle") show_bg_btn.set_related_action(show_bg_act) grid.attach(show_bg_btn, 0, row, 5, 1) grid.attach(change_bg_btn, 5, row, 1, 1) # Pack self.pack_start(grid, False, True, 0) # Updates from the real layers tree (TODO: move to lib/layers.py) self._processing_model_updates = False self._opacity_scale.connect('value-changed', self._opacity_scale_changed_cb) self._layer_mode_combo.connect('changed', self._layer_mode_combo_changed_cb) rootstack = docmodel.layer_stack rootstack.layer_properties_changed += self._layer_propchange_cb rootstack.current_path_updated += self._current_path_updated_cb # Initial update self.connect("show", self._show_cb)
def __init__(self): gtk.ToolItem.__init__(self) self.set_homogeneous(False) self.button_image = gtk.Image() self.button_image.set_from_stock(self.inactive_stock_id, ToolbarManager.icon_size) self.button_shows_modified = False self.button = dropdownpanel.DropdownPanelButton(self.button_image) self.vbox = gtk.VBox() frame = gtk.Frame() frame.add(self.vbox) frame.set_shadow_type(gtk.SHADOW_OUT) self.button.set_property("panel-widget", frame) self.add(self.button) self.connect("create-menu-proxy", lambda *a: True) from application import get_app app = get_app() self.app = app # A limited subset of the available brush settings. frame = widgets.section_frame(_("Quick Brush Settings")) table = gtk.Table() table.set_homogeneous(False) table.set_row_spacings(widgets.SPACING_TIGHT) table.set_col_spacings(widgets.SPACING) table.set_border_width(widgets.SPACING) frame.add(table) self.vbox.pack_start(frame, True, True) sg_row_height = gtk.SizeGroup(gtk.SIZE_GROUP_VERTICAL) sg_slider_width = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) row = 0 for setting_cname in self.setting_cnames: scale = gtk.HScale() scale.set_size_request(128, -1) scale.set_draw_value(False) scale.set_can_focus(False) scale.set_can_default(False) s = brushsettings.settings_dict[setting_cname] adj = app.brush_adjustment[setting_cname] scale.set_adjustment(adj) scale.set_tooltip_text(s.tooltip) #scale.set_update_policy(gtk.UPDATE_DISCONTINUOUS) sg_row_height.add_widget(scale) sg_slider_width.add_widget(scale) label = gtk.Label(_("%s:") % s.name) label.set_alignment(0.0, 0.5) label.set_tooltip_text(s.tooltip) sg_row_height.add_widget(label) reset_button = widgets.borderless_button( stock_id=gtk.STOCK_CLEAR, tooltip=_("Restore '%s' to this brush's saved value") % s.name) reset_button.connect("clicked", self.reset_button_clicked_cb, adj, setting_cname) sg_row_height.add_widget(reset_button) adj.connect("value-changed", self.adjustment_changed_cb, reset_button, setting_cname) adj.value_changed() table.attach(label, 0, 1, row, row + 1, gtk.FILL) table.attach(scale, 1, 2, row, row + 1, gtk.FILL | gtk.EXPAND) table.attach(reset_button, 2, 3, row, row + 1, gtk.FILL) row += 1 table.set_col_spacing(1, widgets.SPACING_TIGHT) # Access to the brush settings window, and a big reset-all button # aligned with the settings above. frame = widgets.section_frame(_("Detailed Brush Settings")) hbox = gtk.HBox() hbox.set_spacing(widgets.SPACING) hbox.set_border_width(widgets.SPACING) frame.add(hbox) self.vbox.pack_start(frame, True, True) widget = gtk.ToggleButton() action = self.app.find_action("BrushEditorWindow") widget.set_related_action(action) #widget.set_label(_("Edit All Settings")) hbox.pack_start(widget, True, True) widget.connect("toggled", lambda a: self.button.panel_hide()) sg_slider_width.add_widget(widget) widget = gtk.ToggleButton() action = self.app.find_action("BrushIconEditorWindow") widget.set_related_action(action) #widget.set_label(_("Edit Icon")) hbox.pack_start(widget, True, True) widget.connect("toggled", lambda a: self.button.panel_hide()) sg_slider_width.add_widget(widget) widget = gtk.Button(_("Restore Saved Settings")) widget.connect("clicked", self.reset_all_clicked_cb) widget.set_tooltip_text( _("Reset all brush settings to the current brush's saved values")) hbox.pack_start(widget, True, True) sg_slider_width.add_widget(widget) self.reset_all_button = widget # Brush blend modes vbox = gtk.VBox() vbox.set_border_width(widgets.SPACING) vbox.set_spacing(widgets.SPACING_TIGHT) frame = widgets.section_frame(_("Brush Blend Mode")) frame.add(vbox) self.vbox.pack_start(frame, True, True) table = gtk.Table(2, 2, homogeneous=True) topts = gtk.EXPAND | gtk.FILL tpad = 0 table.set_row_spacings(widgets.SPACING_TIGHT) table.set_col_spacings(widgets.SPACING) for la, ra, ta, ba, action_name in self.blend_modes_table: action = self.app.find_action(action_name) button = gtk.ToggleButton() button.set_related_action(action) button.set_can_focus(False) button.set_can_default(False) button.set_image_position(gtk.POS_LEFT) button.set_alignment(0.0, 0.5) button.set_relief(gtk.RELIEF_HALF) image = action.create_icon(gtk.ICON_SIZE_BUTTON) image.set_padding(widgets.SPACING_TIGHT, widgets.SPACING_TIGHT) button.set_image(image) table.attach(button, la, ra, ta, ba, topts, topts, tpad, tpad) button.connect("clicked", self.blendmode_button_clicked_cb) vbox.pack_start(table, False, False) self.vbox.set_border_width(widgets.SPACING) self.vbox.set_spacing(widgets.SPACING) self.app.brush.observers.append(self.brush_settings_changed_cb)
def __init__(self): gtk.ToolItem.__init__(self) self.set_homogeneous(False) self.button_image = gtk.Image() self.button_image.set_from_stock(self.inactive_stock_id, ToolbarManager.icon_size) self.button_shows_modified = False self.button = dropdownpanel.DropdownPanelButton(self.button_image) self.vbox = gtk.VBox() frame = gtk.Frame() frame.add(self.vbox) frame.set_shadow_type(gtk.SHADOW_OUT) self.button.set_property("panel-widget", frame) self.add(self.button) self.connect("create-menu-proxy", lambda *a: True) from application import get_app app = get_app() self.app = app # A limited subset of the available brush settings. frame = widgets.section_frame(_("Quick Brush Settings")) table = gtk.Table() table.set_homogeneous(False) table.set_row_spacings(widgets.SPACING_TIGHT) table.set_col_spacings(widgets.SPACING) table.set_border_width(widgets.SPACING) frame.add(table) self.vbox.pack_start(frame, True, True) sg_row_height = gtk.SizeGroup(gtk.SIZE_GROUP_VERTICAL) sg_slider_width = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) row = 0 for setting_cname in self.setting_cnames: scale = gtk.HScale() scale.set_size_request(128, -1) scale.set_draw_value(False) scale.set_can_focus(False) scale.set_can_default(False) s = brushsettings.settings_dict[setting_cname] adj = app.brush_adjustment[setting_cname] scale.set_adjustment(adj) scale.set_tooltip_text(s.tooltip) #scale.set_update_policy(gtk.UPDATE_DISCONTINUOUS) sg_row_height.add_widget(scale) sg_slider_width.add_widget(scale) label = gtk.Label(_("%s:") % s.name) label.set_alignment(0.0, 0.5) label.set_tooltip_text(s.tooltip) sg_row_height.add_widget(label) reset_button = widgets.borderless_button( stock_id=gtk.STOCK_CLEAR, tooltip=_("Restore '%s' to this brush's saved value") % s.name) reset_button.connect("clicked", self.reset_button_clicked_cb, adj, setting_cname) sg_row_height.add_widget(reset_button) adj.connect("value-changed", self.adjustment_changed_cb, reset_button, setting_cname) adj.value_changed() table.attach(label, 0, 1, row, row+1, gtk.FILL) table.attach(scale, 1, 2, row, row+1, gtk.FILL|gtk.EXPAND) table.attach(reset_button, 2, 3, row, row+1, gtk.FILL) row += 1 table.set_col_spacing(1, widgets.SPACING_TIGHT) # Access to the brush settings window, and a big reset-all button # aligned with the settings above. frame = widgets.section_frame(_("Detailed Brush Settings")) hbox = gtk.HBox() hbox.set_spacing(widgets.SPACING) hbox.set_border_width(widgets.SPACING) frame.add(hbox) self.vbox.pack_start(frame, True, True) widget = gtk.ToggleButton() action = self.app.find_action("BrushEditorWindow") widget.set_related_action(action) #widget.set_label(_("Edit All Settings")) hbox.pack_start(widget, True, True) widget.connect("toggled", lambda a: self.button.panel_hide()) sg_slider_width.add_widget(widget) widget = gtk.ToggleButton() action = self.app.find_action("BrushIconEditorWindow") widget.set_related_action(action) #widget.set_label(_("Edit Icon")) hbox.pack_start(widget, True, True) widget.connect("toggled", lambda a: self.button.panel_hide()) sg_slider_width.add_widget(widget) widget = gtk.Button(_("Restore Saved Settings")) widget.connect("clicked", self.reset_all_clicked_cb) widget.set_tooltip_text(_("Reset all brush settings to the current brush's saved values")) hbox.pack_start(widget, True, True) sg_slider_width.add_widget(widget) self.reset_all_button = widget # Brush blend modes vbox = gtk.VBox() vbox.set_border_width(widgets.SPACING) vbox.set_spacing(widgets.SPACING_TIGHT) frame = widgets.section_frame(_("Brush Blend Mode")) frame.add(vbox) self.vbox.pack_start(frame, True, True) table = gtk.Table(2, 2, homogeneous=True) topts = gtk.EXPAND|gtk.FILL tpad = 0 table.set_row_spacings(widgets.SPACING_TIGHT) table.set_col_spacings(widgets.SPACING) for la, ra, ta, ba, action_name in self.blend_modes_table: action = self.app.find_action(action_name) button = gtk.ToggleButton() button.set_related_action(action) button.set_can_focus(False) button.set_can_default(False) button.set_image_position(gtk.POS_LEFT) button.set_alignment(0.0, 0.5) button.set_relief(gtk.RELIEF_HALF) image = action.create_icon(gtk.ICON_SIZE_BUTTON) image.set_padding(widgets.SPACING_TIGHT, widgets.SPACING_TIGHT) button.set_image(image) table.attach(button, la, ra, ta, ba, topts, topts, tpad, tpad) button.connect("clicked", self.blendmode_button_clicked_cb) vbox.pack_start(table, False, False) self.vbox.set_border_width(widgets.SPACING) self.vbox.set_spacing(widgets.SPACING) self.app.brush.observers.append(self.brush_settings_changed_cb)
def __init__(self): GObject.GObject.__init__(self) from application import get_app app = get_app() self.app = app self.set_spacing(widgets.SPACING_CRAMPED) self.set_border_width(widgets.SPACING_TIGHT) # GtkTreeView init docmodel = app.doc.model view = layers.RootStackTreeView(docmodel) self._treemodel = view.get_model() self._treeview = view # RootStackTreeView events view.current_layer_rename_requested += self._layer_properties_cb view.current_layer_changed += self._blink_current_layer_cb view.current_layer_menu_requested += self._popup_menu_cb # Drag and drop view.drag_began += self._view_drag_began_cb view.drag_ended += self._view_drag_ended_cb statusbar_cid = app.statusbar.get_context_id(self.STATUSBAR_CONTEXT) self._drag_statusbar_context_id = statusbar_cid # View scrolls view_scroll = Gtk.ScrolledWindow() view_scroll.set_shadow_type(Gtk.ShadowType.ETCHED_IN) vscroll_pol = Gtk.PolicyType.ALWAYS hscroll_pol = Gtk.PolicyType.AUTOMATIC view_scroll.set_policy(hscroll_pol, vscroll_pol) view_scroll.add(view) view_scroll.set_size_request(-1, 200) view_scroll.set_hexpand(True) view_scroll.set_vexpand(True) # Context menu ui_dir = os.path.dirname(os.path.abspath(__file__)) ui_path = os.path.join(ui_dir, "layerswindow.xml") self.app.ui_manager.add_ui_from_file(ui_path) menu = self.app.ui_manager.get_widget("/LayersWindowPopup") menu.set_title(_("Layer")) self.connect("popup-menu", self._popup_menu_cb) menu.attach_to_widget(self, None) self._menu = menu self._layer_specific_ui_mergeids = [] self._layer_specific_ui_class = None # Main layout grid grid = Gtk.Grid() grid.set_row_spacing(widgets.SPACING_TIGHT) grid.set_column_spacing(widgets.SPACING) row = -1 # Visibility set management row += 1 layer_view_ui = gui.layervis.LayerViewUI(docmodel) grid.attach(layer_view_ui.widget, 0, row, 6, 1) self._layer_view_ui = layer_view_ui # Mode dropdown row += 1 # ComboBox w/ list model (mode_num, label, sensitive, scale) store = Gtk.ListStore(int, str, bool, float) modes = list(STACK_MODES + STANDARD_MODES) modes.remove(DEFAULT_MODE) modes.insert(0, DEFAULT_MODE) for mode in modes: label, desc = MODE_STRINGS.get(mode) sensitive = True scale = 1/1.2 # PANGO_SCALE_SMALL store.append([mode, label, sensitive, scale]) combo = Gtk.ComboBox() combo.set_model(store) combo.set_hexpand(True) combo.set_vexpand(False) cell = Gtk.CellRendererText() combo.pack_start(cell, True) combo.add_attribute(cell, "text", 1) combo.add_attribute(cell, "sensitive", 2) combo.add_attribute(cell, "scale", 3) combo.set_wrap_width(2) combo.set_app_paintable(True) self._layer_mode_combo = combo grid.attach(combo, 0, row, 5, 1) # Opacity widgets adj = Gtk.Adjustment(lower=0, upper=100, step_incr=1, page_incr=10) sbut = Gtk.ScaleButton() sbut.set_adjustment(adj) sbut.remove(sbut.get_child()) sbut.set_hexpand(False) sbut.set_vexpand(False) label_text_widest = self.OPACITY_LABEL_TEXT_TEMPLATE % (100,) label = Gtk.Label(label_text_widest) label.set_width_chars(len(label_text_widest)) # prog = Gtk.ProgressBar() # prog.set_show_text(False) sbut.add(label) self._opacity_scale_button = sbut # self._opacity_progress = prog self._opacity_label = label self._opacity_adj = adj grid.attach(sbut, 5, row, 1, 1) # Layer list and controls row += 1 layersbox = Gtk.VBox() style = layersbox.get_style_context() style.add_class(Gtk.STYLE_CLASS_LINKED) style = view_scroll.get_style_context() style.set_junction_sides(Gtk.JunctionSides.BOTTOM) list_tools = inline_toolbar( self.app, [ ("NewLayerGroupAbove", "mypaint-layer-group-new-symbolic"), ("NewPaintingLayerAbove", "mypaint-add-symbolic"), ("RemoveLayer", "mypaint-remove-symbolic"), ("RaiseLayerInStack", "mypaint-up-symbolic"), ("LowerLayerInStack", "mypaint-down-symbolic"), ("DuplicateLayer", None), ("MergeLayerDown", None), ] ) style = list_tools.get_style_context() style.set_junction_sides(Gtk.JunctionSides.TOP) layersbox.pack_start(view_scroll, True, True, 0) layersbox.pack_start(list_tools, False, False, 0) layersbox.set_hexpand(True) layersbox.set_vexpand(True) grid.attach(layersbox, 0, row, 6, 1) # Background layer controls row += 1 show_bg_btn = Gtk.CheckButton() change_bg_act = self.app.find_action("BackgroundWindow") change_bg_btn = widgets.borderless_button(action=change_bg_act) show_bg_act = self.app.find_action("ShowBackgroundToggle") show_bg_btn.set_related_action(show_bg_act) grid.attach(show_bg_btn, 0, row, 5, 1) grid.attach(change_bg_btn, 5, row, 1, 1) # Pack self.pack_start(grid, False, True, 0) # Updates from the real layers tree (TODO: move to lib/layers.py) self._processing_model_updates = False self._opacity_adj.connect('value-changed', self._opacity_adj_changed_cb) self._layer_mode_combo.connect('changed', self._layer_mode_combo_changed_cb) rootstack = docmodel.layer_stack rootstack.layer_properties_changed += self._layer_propchange_cb rootstack.current_path_updated += self._current_path_updated_cb # Initial update self.connect("show", self._show_cb)
def __init__(self): GObject.GObject.__init__(self) from application import get_app app = get_app() self.app = app self.set_spacing(widgets.SPACING_CRAMPED) self.set_border_width(widgets.SPACING_TIGHT) # GtkTreeView init docmodel = app.doc.model view = Gtk.TreeView() treemodel = layers.RootStackTreeModelWrapper(docmodel) view.set_model(treemodel) self._treemodel = treemodel view.set_reorderable(True) view.set_headers_visible(False) view.connect("button-press-event", self._view_button_press_cb) self._treeview = view # View behaviour and appearance sel = view.get_selection() sel.set_mode(Gtk.SelectionMode.SINGLE) view_scroll = Gtk.ScrolledWindow() view_scroll.set_shadow_type(Gtk.ShadowType.ETCHED_IN) scroll_pol = Gtk.PolicyType.AUTOMATIC view_scroll.set_policy(scroll_pol, scroll_pol) view_scroll.add(view) view_scroll.set_size_request(-1, 100) view_scroll.set_hexpand(True) view_scroll.set_vexpand(True) # Context menu ui_dir = os.path.dirname(os.path.abspath(__file__)) ui_path = os.path.join(ui_dir, "layerswindow.xml") self.app.ui_manager.add_ui_from_file(ui_path) menu = self.app.ui_manager.get_widget("/LayersWindowPopup") menu.set_title(_("Layer")) self.connect("popup-menu", self._popup_menu_cb) menu.attach_to_widget(self, None) self._menu = menu self._layer_specific_ui_mergeid = None self._layer_specific_ui_class = None # Type column cell = Gtk.CellRendererPixbuf() col = Gtk.TreeViewColumn(_("Type")) col.pack_start(cell, expand=False) datafunc = layers.layer_type_pixbuf_datafunc col.set_cell_data_func(cell, datafunc) col.set_max_width(24) col.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) view.append_column(col) self._type_col = col # Name column cell = Gtk.CellRendererText() cell.set_property("ellipsize", Pango.EllipsizeMode.END) col = Gtk.TreeViewColumn(_("Name")) col.pack_start(cell, expand=True) datafunc = layers.layer_name_text_datafunc col.set_cell_data_func(cell, datafunc) col.set_expand(True) col.set_min_width(48) col.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) view.append_column(col) self._name_col = col # Visibility column cell = Gtk.CellRendererPixbuf() col = Gtk.TreeViewColumn(_("Visible")) col.pack_start(cell, expand=False) datafunc = layers.layer_visible_pixbuf_datafunc col.set_cell_data_func(cell, datafunc) col.set_max_width(24) view.append_column(col) self._visible_col = col # Locked column cell = Gtk.CellRendererPixbuf() col = Gtk.TreeViewColumn(_("Locked")) col.pack_start(cell, expand=False) datafunc = layers.layer_locked_pixbuf_datafunc col.set_cell_data_func(cell, datafunc) col.set_max_width(24) view.append_column(col) self._locked_col = col # View appearance view.set_show_expanders(True) view.set_enable_tree_lines(True) view.set_expander_column(self._name_col) # Main layout grid grid = Gtk.Grid() grid.set_row_spacing(widgets.SPACING_TIGHT) grid.set_column_spacing(widgets.SPACING) # Mode dropdown row = 0 label = Gtk.Label(label=_('Mode:')) label.set_tooltip_text( _("Blending mode: how the current layer combines with the " "layers underneath it.")) label.set_alignment(0, 0.5) label.set_hexpand(False) grid.attach(label, 0, row, 1, 1) store = Gtk.ListStore(str, str) for mode in range(NUM_COMBINE_MODES): label, desc = COMBINE_MODE_STRINGS.get(mode) store.append([str(mode), label]) combo = Gtk.ComboBox() combo.set_model(store) combo.set_hexpand(True) cell = Gtk.CellRendererText() combo.pack_start(cell) combo.add_attribute(cell, "text", 1) combo.set_id_column(0) self._layer_mode_combo = combo grid.attach(combo, 1, row, 5, 1) # Opacity slider row += 1 opacity_lbl = Gtk.Label(label=_('Opacity:')) opacity_lbl.set_tooltip_text( _("Layer opacity: how much of the current layer to use. " "Smaller values make it more transparent.")) opacity_lbl.set_alignment(0, 0.5) opacity_lbl.set_hexpand(False) adj = Gtk.Adjustment(lower=0, upper=100, step_incr=1, page_incr=10) self._opacity_scale = Gtk.HScale(adj) self._opacity_scale.set_draw_value(False) self._opacity_scale.set_hexpand(True) grid.attach(opacity_lbl, 0, row, 1, 1) grid.attach(self._opacity_scale, 1, row, 5, 1) # Layer list and controls row += 1 layersbox = Gtk.VBox() style = layersbox.get_style_context() style.add_class(Gtk.STYLE_CLASS_LINKED) style = view_scroll.get_style_context() style.set_junction_sides(Gtk.JunctionSides.BOTTOM) list_tools = inline_toolbar(self.app, [ ("NewLayerFG", "mypaint-add-symbolic"), ("RemoveLayer", "mypaint-remove-symbolic"), ("RaiseLayerInStack", "mypaint-up-symbolic"), ("LowerLayerInStack", "mypaint-down-symbolic"), ("DuplicateLayer", None), ("MergeLayerDown", None), ]) style = list_tools.get_style_context() style.set_junction_sides(Gtk.JunctionSides.TOP) layersbox.pack_start(view_scroll, True, True) layersbox.pack_start(list_tools, False, False) layersbox.set_hexpand(True) layersbox.set_vexpand(True) grid.attach(layersbox, 0, row, 6, 1) # Background layer controls row += 1 show_bg_btn = Gtk.CheckButton() change_bg_act = self.app.find_action("BackgroundWindow") change_bg_btn = widgets.borderless_button(action=change_bg_act) show_bg_act = self.app.find_action("ShowBackgroundToggle") show_bg_btn.set_related_action(show_bg_act) grid.attach(show_bg_btn, 0, row, 5, 1) grid.attach(change_bg_btn, 5, row, 1, 1) # Pack self.pack_start(grid, False, True, 0) # Updates self._processing_model_updates = False self._opacity_scale.connect('value-changed', self._opacity_scale_changed_cb) self._layer_mode_combo.connect('changed', self._layer_mode_combo_changed_cb) rootstack = docmodel.layer_stack rootstack.expand_layer += self._expand_layer_cb rootstack.collapse_layer += self._collapse_layer_cb rootstack.layer_content_changed += self._layer_content_changed rootstack.layer_properties_changed += self._layer_propchange_cb rootstack.current_layer_solo_changed += self._treeview_redraw_all rootstack.current_path_updated += self._current_path_updated_cb # Initial update self.connect("show", self._show_cb)