def add_to_grid(self, grid, row): for c in self._confmap.values(): c.setup_preference(self.get_prefpath()) outgrid = grid outrow = row if self.label is not None: self._expander = Gtk.Expander(label=self.label) self._expander.set_expanded(self.expanded) outgrid = Gtk.Grid() self._expander.add(outgrid) grid.attach(self._expander, 1, row, 1, 1) outrow = 0 row += 1 if self.removable: self._remove_btn = Gtk.Button(label="Remove") self._remove_btn.connect("clicked", self.remove) outgrid.attach(self._remove_btn, 0, outrow, 2, 1) outrow += 1 for c in self._confmap.values(): outrow = c.add_to_grid(outgrid, outrow) for sc in self._subconfigs: outrow = sc.add_to_grid(outgrid, outrow) if self.label is not None: return row return outrow
def __init__(self): SizedVBoxToolWidget.__init__(self) from gui.application import get_app self.app = get_app() self._overlay = IMproVision(self.app) self.app.doc.tdw.display_overlays.append(self._overlay) Configurable.__init__(self, subconfigs=self._overlay) toolbar = inline_toolbar(self.app, [ ("IMproVisionTrigger", None), ("IMproVisionLoop", None), ("IMproVisionStep", None), ("IMproVisionStop", None), ]) self.pack_start(toolbar, False, True, 0) options = Gtk.Alignment.new(0.5, 0.5, 1.0, 1.0) options.set_padding(0, 0, 0, 0) options.set_border_width(3) grid = Gtk.Grid() self.add_to_grid(grid, 0) options.add(grid) options.show_all() self.pack_start(options, True, True, 0) actions = { "IMproVisionTrigger": self._overlay.trigger_one, "IMproVisionStep": self._overlay.step_one, "IMproVisionLoop": self._overlay.loop, "IMproVisionStop": self._overlay.stop, } for a, cb in actions.items(): action = self.app.doc.action_group.get_action(a) action.connect("activate", cb)
def _get_gui_item(self): entry = Gtk.Entry() entry.set_buffer(self._buf) def _plus_cb(b): nn = str(self.get_value() + 1) self._buf.set_text(nn, len(nn)) plus = Gtk.Button.new_with_label("+") plus.connect("clicked", _plus_cb) def _minus_cb(b): nn = str(self.get_value() - 1) self._buf.set_text(nn, len(nn)) minus = Gtk.Button.new_with_label("-") minus.connect("clicked", _minus_cb) grid = Gtk.Grid() grid.attach(entry, 0, 0, 1, 1) grid.attach(minus, 1, 0, 1, 1) grid.attach(plus, 2, 0, 1, 1) return grid
def _get_gui_item(self): grid = Gtk.Grid() self.xref = Gtk.ComboBoxText() self.yref = Gtk.Label() def _setup_slider(slider, settype: SliderColorAdjuster, reset_color=None): pos = slider.get_bar_amount_for_color(slider.managed_color) def forced_get_background_validity(slider): if slider.color_manager.force_redraw: col = slider.get_managed_color() if col.r > 0: col = RGBColor(0, col.g, col.b) else: col = RGBColor(255, col.g, col.b) slider.color_manager.force_redraw = False return repr(col) return SliderColorAdjuster.get_background_validity(slider) setattr( slider, "get_background_validity", partial(forced_get_background_validity, slider), ) setattr( slider, "get_color_for_bar_amount", partial(settype.get_color_for_bar_amount, slider), ) setattr( slider, "get_bar_amount_for_color", partial(settype.get_bar_amount_for_color, slider), ) setattr(slider, "samples", settype.samples) slider.color_manager.force_redraw = True if reset_color is not None: slider.color_manager.set_color(reset_color) newcol = slider.get_color_for_bar_amount(pos) slider.color_manager.set_color(newcol) def _update_xref(combo): xref = combo.get_active_text() v = self.get_value() if xref in v.references: v.xref = xref self._set_value(v) v = self.get_value() for r in v.references.keys(): if r == v.yref: self.yref.set_text(r) _setup_slider( self._color_sliders["xmin"], v.references[v.xref][1], self._color_sliders["target"].managed_color, ) _setup_slider( self._color_sliders["xmax"], v.references[v.xref][1], self._color_sliders["target"].managed_color, ) _setup_slider( self._color_sliders["ymin"], v.references[v.yref][1], self._color_sliders["target"].managed_color, ) _setup_slider( self._color_sliders["ymax"], v.references[v.yref][1], self._color_sliders["target"].managed_color, ) def _update_refval(combo): ref = combo.get_active_text() if ref in self.__refs: oldv = self.get_value() newv = oldv if ref not in oldv.references: for xr in self.__refs[ref].references.keys(): if xr != ref: newv = self.__refs[ref]( ref, oldv.target, xr, oldv.xrange, oldv.yrange, oldv.targetdelta, ) break else: newv.refval = ref for xr in newv.references.keys(): if xr != ref: newv.xref = xr break self._set_value(newv) v = self.get_value() activeid = 0 refs = list(v.references.keys()) self.xref.remove_all() for r in range(len(refs)): if refs[r] != v.refval: self.xref.append_text(refs[r]) if refs[r] == v.xref: activeid = r self.xref.set_active(activeid) _setup_slider( self._color_sliders["target"], v.references[v.refval][1], v.base_color, ) _update_xref(self.xref) rvbox = Gtk.ComboBoxText() rvbox.connect("changed", _update_refval) activeid = 0 refs = list(self.__refs.keys()) for r in range(len(refs)): rvbox.append_text(refs[r]) if refs[r] == self.get_value().refval: activeid = r rvbox.set_active(activeid) grid.attach(rvbox, 0, 0, 1, 1) grid.attach(self._color_sliders["target"], 1, 0, 2, 1) self.xref.connect("changed", _update_xref) _update_refval(rvbox) grid.attach(self.xref, 0, 1, 1, 1) grid.attach(self._color_sliders["xmin"], 1, 1, 1, 1) grid.attach(self._color_sliders["xmax"], 2, 1, 1, 1) grid.attach(self.yref, 0, 2, 1, 1) grid.attach(self._color_sliders["ymin"], 1, 2, 1, 1) grid.attach(self._color_sliders["ymax"], 2, 2, 1, 1) grid.attach(self._cube, 1, 3, 2, 3) return grid
def _init_ui(self): # Dialog for editing dimensions (width, height, DPI) app = self.app buttons = (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT) self._size_dialog = windowing.Dialog( app, _("Frame Size"), app.drawWindow, buttons=buttons ) unit = _('px') height_label = self._new_key_label(_('Height:')) width_label = self._new_key_label(_('Width:')) dpi_label1 = self._new_key_label(_('Resolution:')) dpi_label2 = Gtk.Label(label=_('DPI')) dpi_label2.set_alignment(0.0, 0.5) dpi_label2.set_hexpand(False) dpi_label2.set_vexpand(False) dpi_label2.set_tooltip_text( _("Dots Per Inch (really Pixels Per Inch)") ) color_label = Gtk.Label(label=_('Color:')) color_label.set_alignment(0.0, 0.5) height_entry = Gtk.SpinButton( adjustment=self.height_adj, climb_rate=0.25, digits=0 ) height_entry.set_vexpand(False) height_entry.set_hexpand(True) self.height_adj.set_spin_button(height_entry) width_entry = Gtk.SpinButton( adjustment=self.width_adj, climb_rate=0.25, digits=0 ) width_entry.set_vexpand(False) width_entry.set_hexpand(True) self.width_adj.set_spin_button(width_entry) dpi_entry = Gtk.SpinButton( adjustment=self.dpi_adj, climb_rate=0.0, digits=0 ) dpi_entry.set_vexpand(False) dpi_entry.set_hexpand(True) color_button = Gtk.ColorButton() color_rgba = self.app.preferences.get("frame.color_rgba") color_rgba = [min(max(c, 0), 1) for c in color_rgba] color_gdk = uicolor.to_gdk_color(RGBColor(*color_rgba[0:3])) color_alpha = int(65535 * color_rgba[3]) color_button.set_color(color_gdk) color_button.set_use_alpha(True) color_button.set_alpha(color_alpha) color_button.set_title(_("Frame Color")) color_button.connect("color-set", self._color_set_cb) color_align = Gtk.Alignment.new(0, 0.5, 0, 0) color_align.add(color_button) size_grid = Gtk.Grid() size_grid.set_border_width(12) size_grid.set_row_spacing(6) size_grid.set_column_spacing(6) unit_combobox = Gtk.ComboBoxText() for unit in UnitAdjustment.CONVERT_UNITS.keys(): unit_combobox.append_text(unit) for i, key in enumerate(UnitAdjustment.CONVERT_UNITS): if key == _('px'): unit_combobox.set_active(i) unit_combobox.connect('changed', self.on_unit_changed) unit_combobox.set_hexpand(False) unit_combobox.set_vexpand(False) self._unit_combobox = unit_combobox row = 0 label = self._new_header_label(_("<b>Frame dimensions</b>")) label.set_margin_top(0) size_grid.attach(label, 0, row, 3, 1) row += 1 size_grid.attach(width_label, 0, row, 1, 1) size_grid.attach(width_entry, 1, row, 1, 1) size_grid.attach(unit_combobox, 2, row, 1, 1) row += 1 size_grid.attach(height_label, 0, row, 1, 1) size_grid.attach(height_entry, 1, row, 1, 1) row += 1 label = self._new_header_label(_("<b>Pixel density</b>")) size_grid.attach(label, 0, row, 3, 1) row += 1 size_grid.attach(dpi_label1, 0, row, 1, 1) size_grid.attach(dpi_entry, 1, row, 1, 1) size_grid.attach(dpi_label2, 2, row, 1, 1) # Options panel UI opts_table = Gtk.Table(3, 3) opts_table.set_border_width(3) xopts = Gtk.AttachOptions.FILL | Gtk.AttachOptions.EXPAND yopts = Gtk.AttachOptions.FILL xpad = ypad = 3 row = 0 size_button = Gtk.Button(label="<size-summary>") self._size_button = size_button size_button.connect("clicked", self._size_button_clicked_cb) opts_table.attach(size_button, 0, 2, row, row+1, xopts, yopts, xpad, ypad) row += 1 opts_table.attach(color_label, 0, 1, row, row+1, xopts, yopts, xpad, ypad) opts_table.attach(color_align, 1, 2, row, row+1, xopts, yopts, xpad, ypad) crop_layer_button = Gtk.Button(label=_('Set Frame to Layer')) crop_layer_button.set_tooltip_text(_("Set frame to the extents of " "the current layer")) crop_document_button = Gtk.Button(label=_('Set Frame to Document')) crop_document_button.set_tooltip_text(_("Set frame to the combination " "of all layers")) crop_layer_button.connect('clicked', self.crop_frame_cb, 'CropFrameToLayer') crop_document_button.connect('clicked', self.crop_frame_cb, 'CropFrameToDocument') trim_button = Gtk.Button() trim_action = self.app.find_action("TrimLayer") trim_button.set_related_action(trim_action) trim_button.set_label(_('Trim Layer to Frame')) trim_button.set_tooltip_text(_("Trim parts of the current layer " "which lie outside the frame")) self.enable_button = Gtk.CheckButton() frame_toggle_action = self.app.find_action("FrameToggle") self.enable_button.set_related_action(frame_toggle_action) self.enable_button.set_label(_('Enabled')) row += 1 opts_table.attach(self.enable_button, 1, 2, row, row+1, xopts, yopts, xpad, ypad) row += 1 opts_table.attach(crop_layer_button, 0, 2, row, row+1, xopts, yopts, xpad, ypad) row += 1 opts_table.attach(crop_document_button, 0, 2, row, row+1, xopts, yopts, xpad, ypad) row += 1 opts_table.attach(trim_button, 0, 2, row, row+1, xopts, yopts, xpad, ypad) content_area = self._size_dialog.get_content_area() content_area.pack_start(size_grid, True, True, 0) self._size_dialog.connect('response', self._size_dialog_response_cb) self.add(opts_table)
def __init__(self): Gtk.Grid.__init__(self) self.set_row_spacing(6) self.set_column_spacing(6) from gui.application import get_app self.app = get_app() prefs = self.app.preferences row = 0 label = Gtk.Label() label.set_markup( C_( "fill options: numeric value that determines whether tested pixels" " will be included in the fill, based on color difference", u"Tolerance:")) label.set_tooltip_text( C_( "fill options: Tolerance (tooltip) " "Note: 'the start' refers to the color of " "the starting point (pixel) of the fill", u"How much pixel colors are allowed to vary from the start\n" u"before Flood Fill will refuse to fill them")) label.set_alignment(1.0, 0.5) label.set_hexpand(False) self.attach(label, 0, row, 1, 1) value = prefs.get(self.TOLERANCE_PREF, self.DEFAULT_TOLERANCE) value = float(value) adj = Gtk.Adjustment(value=value, lower=0.0, upper=1.0, step_increment=0.05, page_increment=0.05, page_size=0) adj.connect("value-changed", self._tolerance_changed_cb) self._tolerance_adj = adj scale = Gtk.Scale() scale.set_hexpand(True) scale.set_adjustment(adj) scale.set_draw_value(False) self.attach(scale, 1, row, 1, 1) row += 1 label = Gtk.Label() label.set_markup( C_( "fill options: option category (label) " "Options under this category relate to what the fill is" "based on, not where the actual fill ends up.", u"Source:")) label.set_tooltip_text( C_("fill options: 'Source:' category (tooltip)", u"The input that the fill will be based on")) label.set_alignment(1.0, 0.5) label.set_hexpand(False) self.attach(label, 0, row, 1, 1) # Selection independent fill-basis root = self.app.doc.model.layer_stack src_list = FlatLayerList(root) self.src_list = src_list combo = Gtk.ComboBox.new_with_model(src_list) cell = Gtk.CellRendererText() cell.set_property("ellipsize", Pango.EllipsizeMode.END) combo.pack_start(cell, True) def layer_name_render(_, name_cell, model, it): """ Display layer groups in italics and child layers indented with two spaces per level """ name, path, layer = model[it][:3] if name is None: name = "Layer" if layer is None: name_cell.set_property("markup", "( <i>{text}</i> )".format(text=name)) return indented = " " * (len(path) - 1) + name if isinstance(layer, lib.layer.LayerStack): name_cell.set_property("markup", "<i>{text}</i>".format(text=indented)) else: name_cell.set_property("text", indented) def sep_func(model, it): return model[it][0] is None combo.set_row_separator_func(sep_func) combo.set_cell_data_func(cell, layer_name_render) combo.set_tooltip_text( C_("fill options: 'Source' category: Layer dropdown (tooltip)", u"Select a specific layer you want the fill to be based on")) combo.set_active(0) self._prev_src_layer = None root.layer_inserted += self._layer_inserted_cb self._src_combo_cb_id = combo.connect("changed", self._src_combo_changed_cb) self._src_combo = combo self.attach(combo, 1, row, 2, 1) row += 1 text = C_( "fill options: 'Source:' category: toggle (label)\n" "When this option is enabled, the fill is based\n" "on the combination of all visible layers", u"Sample Merged") checkbut = Gtk.CheckButton.new_with_label(text) checkbut.set_tooltip_text( C_( "fill options: Sample Merged (tooltip)", u"When considering which area to fill, use a\n" u"temporary merge of all the visible layers\n" u"underneath the current layer")) self.attach(checkbut, 1, row, 1, 1) active = bool( prefs.get(self.SAMPLE_MERGED_PREF, self.DEFAULT_SAMPLE_MERGED)) checkbut.set_active(active) checkbut.connect("toggled", self._sample_merged_toggled_cb) self._sample_merged_toggle = checkbut self._src_combo.set_sensitive(not active) row += 1 text = C_( "fill options: toggle whether the fill will be limited " "by the viewport", u"Limit to View") checkbut = Gtk.CheckButton.new_with_label(text) checkbut.set_tooltip_text( C_( "fill options: Limit to View (tooltip)\n" "Note: 'that can fit the view' is equivalent to: " "'in which the entire visible part of the canvas can fit", u"Limit the area that can be filled, based on the viewport.\n" u"If the view is rotated, the fill will be limited to the\n" u"smallest canvas-aligned rectangle that can fit the view.")) self.attach(checkbut, 1, row, 1, 1) active = bool( prefs.get(self.LIM_TO_VIEW_PREF, self.DEFAULT_LIM_TO_VIEW)) checkbut.set_active(active) checkbut.connect("toggled", self._limit_to_view_toggled_cb) self._limit_to_view_toggle = checkbut row += 1 label = Gtk.Label() label.set_markup( C_( "fill options: option category (label)\n" "Options under this category relate to where the fill " "will end up (default: the active layer) and how it " "will be combined with that layer.", u"Target:")) label.set_tooltip_text( C_("fill options: 'Target:' category (tooltip)", u"Where the output should go")) label.set_alignment(1.0, 0.5) label.set_hexpand(False) self.attach(label, 0, row, 1, 1) text = C_( "fill options: Target | toggle (label)\n" "When this option is enabled, the fill will be placed on a new\n" "layer above the active layer. Option resets after each fill.", u"New Layer (once)") checkbut = Gtk.CheckButton.new_with_label(text) checkbut.set_tooltip_text( C_( "fill options: Target | New Layer (tooltip)", u"Create a new layer with the results of the fill.\n" u"This is turned off automatically after use.")) self.attach(checkbut, 1, row, 1, 1) active = self.DEFAULT_MAKE_NEW_LAYER checkbut.set_active(active) self._make_new_layer_toggle = checkbut row += 1 label = Gtk.Label() label.set_markup(u"<b>\u26a0</b>") # unicode warning sign label.set_tooltip_text( C_("fill options: Target | Blend Mode dropdown - warning text", u"This mode does nothing when alpha locking is enabled!")) label.set_alignment(1.0, 0.5) label.set_hexpand(False) self._warning_shown = False # Not attached here, warning label is only shown for no-op combinations self._bm_warning_label = (label, 0, row, 1, 1) modes = list(lib.modes.STANDARD_MODES) modes.remove(lib.mypaintlib.CombineSpectralWGM) modes.insert(0, lib.mypaintlib.CombineSpectralWGM) combo = gui.layers.new_blend_mode_combo(modes, lib.modes.MODE_STRINGS) combo.set_tooltip_text( C_("fill options: Target | Blend Mode dropdown (tooltip)", u"Blend mode used when filling")) # Reinstate the last _mode id_ independent of mode-list order mode_type = prefs.get(self.BLEND_MODE_PREF, self.DEFAULT_BLEND_MODE) mode_dict = {mode: index for index, mode, in enumerate(modes)} # Fallback is only necessary for compat. if a mode is ever removed active = mode_dict.get(int(mode_type), self.DEFAULT_BLEND_MODE) combo.set_active(active) combo.connect("changed", self._bm_combo_changed_cb) self._blend_mode_combo = combo self.attach(combo, 1, row, 2, 1) row += 1 label = Gtk.Label() label.set_markup(_(u"Opacity:")) label.set_tooltip_text( C_("fill options: Opacity slider (tooltip)", u"Opacity of the fill")) label.set_alignment(1.0, 0.5) label.set_hexpand(False) self.attach(label, 0, row, 1, 1) value = prefs.get(self.OPACITY_PREF, self.DEFAULT_OPACITY) adj = Gtk.Adjustment(value=value, lower=0.0, upper=1.0, step_increment=0.05, page_increment=0.05, page_size=0) adj.connect("value-changed", self._opacity_changed_cb) self._opacity_adj = adj scale = Gtk.Scale() scale.set_hexpand(True) scale.set_adjustment(adj) scale.set_draw_value(False) self.attach(scale, 1, row, 1, 1) row += 1 self.attach(Gtk.Separator(), 0, row, 2, 1) row += 1 label = Gtk.Label() label.set_markup( C_("fill options: numeric option - grow/shrink fill (label)", u"Offset:")) label.set_alignment(1.0, 0.5) label.set_hexpand(False) self.attach(label, 0, row, 1, 1) TILE_SIZE = lib.floodfill.TILE_SIZE value = prefs.get(self.OFFSET_PREF, self.DEFAULT_OFFSET) adj = Gtk.Adjustment(value=value, lower=-TILE_SIZE, upper=TILE_SIZE, step_increment=1, page_increment=4) adj.connect("value-changed", self._offset_changed_cb) self._offset_adj = adj spinbut = Gtk.SpinButton() spinbut.set_tooltip_text( C_("fill options: Offset (tooltip)", u"The distance in pixels to grow or shrink the fill")) spinbut.set_hexpand(True) spinbut.set_adjustment(adj) spinbut.set_numeric(True) self.attach(spinbut, 1, row, 1, 1) row += 1 label = Gtk.Label() label.set_markup( C_("fill options: numeric option for blurring fill (label)", u"Feather:")) label.set_alignment(1.0, 0.5) label.set_hexpand(False) self.attach(label, 0, row, 1, 1) value = prefs.get(self.FEATHER_PREF, self.DEFAULT_FEATHER) adj = Gtk.Adjustment(value=value, lower=0, upper=TILE_SIZE, step_increment=1, page_increment=4) adj.connect("value-changed", self._feather_changed_cb) self._feather_adj = adj spinbut = Gtk.SpinButton() spinbut.set_tooltip_text( C_("fill options: Feather (tooltip)", u"The amount of blur to apply to the fill")) spinbut.set_hexpand(True) spinbut.set_adjustment(adj) spinbut.set_numeric(True) self.attach(spinbut, 1, row, 1, 1) row += 1 self.attach(Gtk.Separator(), 0, row, 2, 1) row += 1 gap_closing_params = Gtk.Grid() self._gap_closing_grid = gap_closing_params text = C_("fill options: gap detection toggle (label)", u'Use Gap Detection') checkbut = Gtk.CheckButton.new_with_label(text) checkbut.set_tooltip_text( C_( "fill options: Use Gap Detection (tooltip)", u"Try to detect gaps and not fill past them.\n" u"Note: This can be a lot slower than the regular fill, " u"only enable when you need it.")) self._gap_closing_toggle = checkbut checkbut.connect("toggled", self._gap_closing_toggled_cb) active = prefs.get(self.GAP_CLOSING_PREF, self.DEFAULT_GAP_CLOSING) checkbut.set_active(active) gap_closing_params.set_sensitive(active) self.attach(checkbut, 0, row, 2, 1) row += 1 self.attach(gap_closing_params, 0, row, 2, 1) gcp_row = 0 label = Gtk.Label() label.set_markup( C_( "fill options: gap-detection sub-option, numeric setting (label)", u"Max Gap Size:")) label.set_alignment(1.0, 0.5) label.set_hexpand(False) gap_closing_params.attach(label, 0, gcp_row, 1, 1) value = prefs.get(self.GAP_SIZE_PREF, self.DEFAULT_GAP_SIZE) adj = Gtk.Adjustment(value=value, lower=1, upper=int(TILE_SIZE / 2), step_increment=1, page_increment=4) adj.connect("value-changed", self._max_gap_size_changed_cb) self._max_gap_adj = adj spinbut = Gtk.SpinButton() spinbut.set_tooltip_text( C_( "fill options: Max Gap Size (tooltip)", u"The size of the largest gaps that can be detected.\n" u"Using large values can make the fill run a lot slower.")) spinbut.set_hexpand(True) spinbut.set_adjustment(adj) spinbut.set_numeric(True) gap_closing_params.attach(spinbut, 1, gcp_row, 1, 1) gcp_row += 1 text = C_( "fill options: on/off sub-option, numeric (label)\n" "When enabled, if the fill stops after going past a detected gap, " "it 'pulls' the fill back out of the gap to the other side of it.", u"Prevent seeping") checkbut = Gtk.CheckButton.new_with_label(text) active = prefs.get(self.RETRACT_SEEPS_PREF, self.DEFAULT_RETRACT_SEEPS) checkbut.set_active(active) checkbut.set_tooltip_text( C_( "fill options: Prevent seeping (tooltip)", u"Try to prevent the fill from seeping into the gaps.\n" u"If a fill starts in a detected gap, this option will do nothing." )) checkbut.connect("toggled", self._retract_seeps_toggled_cb) self._retract_seeps_toggle = checkbut gap_closing_params.attach(checkbut, 1, gcp_row, 1, 1) row += 1 align = Gtk.Alignment.new(0.5, 1.0, 1.0, 0.0) align.set_vexpand(True) button = Gtk.Button(label=_("Reset")) button.connect("clicked", self._reset_clicked_cb) button.set_tooltip_text( C_("fill options: Reset button (tooltip)", "Reset options to their defaults")) align.add(button) self.attach(align, 0, row, 2, 1) # Set up blend modifier callbacks self.bm = self.get_blend_modes() self.bm.mode_changed += self.update_blend_mode
def __init__(self): GObject.GObject.__init__(self) from gui.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) modes = list(STACK_MODES + STANDARD_MODES) modes.remove(lib.mypaintlib.CombineSpectralWGM) modes.insert(0, lib.mypaintlib.CombineSpectralWGM) combo = layers.new_blend_mode_combo(modes, MODE_STRINGS) self._layer_mode_combo = combo grid.attach(combo, 0, row, 5, 1) # Opacity widgets adj = Gtk.Adjustment(lower=0, upper=100, step_increment=1, page_increment=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 _accel_editing_started_cb(self, cell, editable, treepath): """Begin editing by showing a key capture dialog""" it = self._filter.get_iter(treepath) accel_path = self._filter.get_value(it, self._PATH_COLUMN) accel_label = self._accel_labels[accel_path] action_label = self._action_labels[accel_path] editable.set_sensitive(False) dialog = Gtk.Dialog() dialog.set_modal(True) # TRANSLATORS: Window title for the keybinding dialog. The %s is # TRANSLATORS: replaced with the name of the action that the key # TRANSLATORS: combination is being bound to, e.g. "Fit to View". dialog.set_title(_("Edit Key for '%s'") % action_label) dialog.set_transient_for(self.get_toplevel()) dialog.set_position(Gtk.WindowPosition.CENTER_ON_PARENT) dialog.add_buttons( Gtk.STOCK_DELETE, Gtk.ResponseType.REJECT, Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK, ) dialog.set_default_response(Gtk.ResponseType.OK) dialog.connect("response", self._edit_dialog_response_cb, editable, accel_path) evbox = Gtk.EventBox() evbox.set_border_width(12) dialog.connect("key-press-event", self._edit_dialog_key_press_cb, editable) grid = Gtk.Grid() grid.set_row_spacing(12) grid.set_column_spacing(12) row = 0 label = Gtk.Label() label.set_alignment(0, 0.5) label.set_text(_("Action:")) grid.attach(label, 0, row, 1, 1) label = Gtk.Label() label.set_alignment(0, 0.5) label.set_text(str(action_label)) label.set_tooltip_text(str(accel_path)) label.set_hexpand(True) grid.attach(label, 1, row, 1, 1) if self._SHOW_ACCEL_PATH: row += 1 label = Gtk.Label() label.set_alignment(0, 0.5) # TRANSLATORS: Path refers to an "action path" that is part of an # TRANSLATORS: accelerator (keybinding). Found in the dialog for # TRANSLATORS: adding new keybindings. This is a technical field # TRANSLATORS: that probably shouldn't even be part of the gui, # TRANSLATORS: so don't worry too much about the translation. label.set_text(_("Path:")) grid.attach(label, 0, row, 1, 1) label = Gtk.Label() label.set_alignment(0, 0.5) label.set_text(str(accel_path)) label.set_hexpand(True) grid.attach(label, 1, row, 1, 1) row += 1 label = Gtk.Label() label.set_alignment(0, 0.5) # TRANSLATORS: Key refers to a key on the keyboard, this is a label # TRANSLATORS: in the dialog for adding new keyboard bindings. label.set_text(_("Key:")) grid.attach(label, 0, row, 1, 1) label = Gtk.Label() label.set_alignment(0, 0.5) label.set_text(str(accel_label)) dialog.accel_label_widget = label label.set_hexpand(True) grid.attach(label, 1, row, 1, 1) row += 1 label = Gtk.Label() label.set_hexpand(True) label.set_vexpand(True) label.set_margin_top(12) label.set_margin_bottom(12) label.set_alignment(0, 0) label.set_line_wrap(True) label.set_size_request(200, 75) dialog.hint_widget = label self._edit_dialog_set_standard_hint(dialog) grid.attach(label, 0, row, 2, 1) evbox.add(grid) dialog.get_content_area().pack_start(evbox, True, True, 0) evbox.show_all() dialog.initial_accel_label = accel_label dialog.accel_path = accel_path dialog.result_keyval = None dialog.result_mods = None dialog.show()
def _init_ui(self): app = self.app # Dialog for showing and editing the axis value directly buttons = (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT) dialog = gui.windowing.Dialog( app, C_( "symmetry axis options panel: " "axis position dialog: window title", u"X axis Position", ), app.drawWindow, buttons=buttons, ) dialog.connect('response', self._axis_pos_dialog_response_cb) grid = Gtk.Grid() grid.set_border_width(gui.widgets.SPACING_LOOSE) grid.set_column_spacing(gui.widgets.SPACING) grid.set_row_spacing(gui.widgets.SPACING) label = Gtk.Label(label=self._POSITION_LABEL_X_TEXT) label.set_hexpand(False) label.set_vexpand(False) grid.attach(label, 0, 0, 1, 1) entry = Gtk.SpinButton( adjustment=self._axis_pos_adj_x, climb_rate=0.25, digits=0 ) entry.set_hexpand(True) entry.set_vexpand(False) grid.attach(entry, 1, 0, 1, 1) dialog_content_box = dialog.get_content_area() dialog_content_box.pack_start(grid, True, True, 0) self._axis_pos_x_dialog = dialog # Dialog for showing and editing the axis value directly buttons = (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT) dialog = gui.windowing.Dialog( app, C_( "symmetry axis options panel: " "axis position dialog: window title", u"Y axis Position", ), app.drawWindow, buttons=buttons, ) dialog.connect('response', self._axis_pos_dialog_response_cb) grid = Gtk.Grid() grid.set_border_width(gui.widgets.SPACING_LOOSE) grid.set_column_spacing(gui.widgets.SPACING) grid.set_row_spacing(gui.widgets.SPACING) label = Gtk.Label(label=self._POSITION_LABEL_Y_TEXT) label.set_hexpand(False) label.set_vexpand(False) grid.attach(label, 0, 0, 1, 1) entry = Gtk.SpinButton( adjustment=self._axis_pos_adj_y, climb_rate=0.25, digits=0 ) entry.set_hexpand(True) entry.set_vexpand(False) grid.attach(entry, 1, 0, 1, 1) dialog_content_box = dialog.get_content_area() dialog_content_box.pack_start(grid, True, True, 0) self._axis_pos_y_dialog = dialog # Layout grid row = 0 grid = Gtk.Grid() grid.set_border_width(gui.widgets.SPACING_CRAMPED) grid.set_row_spacing(gui.widgets.SPACING_CRAMPED) grid.set_column_spacing(gui.widgets.SPACING_CRAMPED) self.add(grid) row += 1 label = Gtk.Label(label=self._ALPHA_LABEL_TEXT) label.set_hexpand(False) label.set_halign(Gtk.Align.START) grid.attach(label, 0, row, 1, 1) scale = Gtk.Scale.new_with_range( orientation = Gtk.Orientation.HORIZONTAL, min = 0, max = 1, step = 0.1, ) scale.set_draw_value(False) line_alpha = self.app.preferences.get(_ALPHA_PREFS_KEY, _DEFAULT_ALPHA) scale.set_value(line_alpha) scale.set_hexpand(True) scale.set_vexpand(False) scale.connect("value-changed", self._scale_value_changed_cb) grid.attach(scale, 1, row, 1, 1) row += 1 store = Gtk.ListStore(int, str) sym_types = lib.tiledsurface.SYMMETRY_TYPES active_idx = 0 rootstack = self.app.doc.model.layer_stack starts_with_rotate = ( rootstack.symmetry_type in { lib.mypaintlib.SymmetryRotational, lib.mypaintlib.SymmetrySnowflake, } ) for i, sym_type in enumerate(sym_types): label = lib.tiledsurface.SYMMETRY_STRINGS.get(sym_type) store.append([sym_type, label]) if sym_type == rootstack.symmetry_type: active_idx = i self._symmetry_type_combo = Gtk.ComboBox() self._symmetry_type_combo.set_model(store) self._symmetry_type_combo.set_active(active_idx) self._symmetry_type_combo.set_hexpand(True) cell = Gtk.CellRendererText() self._symmetry_type_combo.pack_start(cell, True) self._symmetry_type_combo.add_attribute(cell, "text", 1) self._symmetry_type_combo.connect( 'changed', self._symmetry_type_combo_changed_cb ) label = Gtk.Label(label=self._SYMMETRY_TYPE_TEXT) label.set_hexpand(False) label.set_halign(Gtk.Align.START) grid.attach(label, 0, row, 1, 1) grid.attach(self._symmetry_type_combo, 1, row, 1, 1) row += 1 label = Gtk.Label(label=self._SYMMETRY_ROT_LINES_TEXT) label.set_hexpand(False) label.set_halign(Gtk.Align.START) self._axis_rot_sym_lines_entry = Gtk.SpinButton( adjustment=self._axis_rot_symmetry_lines, climb_rate=0.25 ) grid.attach(label, 0, row, 1, 1) grid.attach(self._axis_rot_sym_lines_entry, 1, row, 1, 1) row += 1 label = Gtk.Label(label=self._POSITION_LABEL_X_TEXT) label.set_hexpand(False) label.set_halign(Gtk.Align.START) button = Gtk.Button(label=self._POSITION_BUTTON_TEXT_INACTIVE) button.set_vexpand(False) button.connect("clicked", self._axis_pos_x_button_clicked_cb) button.set_hexpand(True) button.set_vexpand(False) grid.attach(label, 0, row, 1, 1) grid.attach(button, 1, row, 1, 1) self._axis_pos_x_button = button row += 1 label = Gtk.Label(label=self._POSITION_LABEL_Y_TEXT) label.set_hexpand(False) label.set_halign(Gtk.Align.START) button = Gtk.Button(label=self._POSITION_BUTTON_TEXT_INACTIVE) button.set_vexpand(False) button.connect("clicked", self._axis_pos_y_button_clicked_cb) button.set_hexpand(True) button.set_vexpand(False) grid.attach(label, 0, row, 1, 1) grid.attach(button, 1, row, 1, 1) self._axis_pos_y_button = button row += 1 button = Gtk.CheckButton() toggle_action = self.app.find_action("SymmetryActive") button.set_related_action(toggle_action) button.set_label(C_( "symmetry axis options panel: axis active checkbox", u'Enabled', )) button.set_hexpand(True) button.set_vexpand(False) grid.attach(button, 1, row, 2, 1) self._axis_active_button = button
def __init__(self): CombinedAdjusterPage.__init__(self) grid = Gtk.Grid() grid.set_size_request(150, -1) grid.set_row_spacing(6) grid.set_column_spacing(0) grid.set_border_width(6) self._sliders = [] #: List of slider widgets. grid.set_valign(0.5) grid.set_halign(0.5) grid.set_hexpand(True) grid.set_vexpand(False) row_defs = [ ( C_("color sliders panel: red/green/blue: slider label", "R"), RGBRedSlider, 0, ), ( C_("color sliders panel: red/green/blue: slider label", "G"), RGBGreenSlider, 0, ), ( C_("color sliders panel: red/green/blue: slider label", "B"), RGBBlueSlider, 0, ), ( C_("color sliders panel: hue/chroma/luma: slider label", "H"), HCYHueSlider, 12, ), ( C_("color sliders panel: hue/chroma/luma: slider label", "C"), HCYChromaSlider, 0, ), ( C_("color sliders panel: hue/chroma/luma: slider label", "Y"), HCYLumaSlider, 0, ), ] row = 0 for row_def in row_defs: label_text, adj_class, margin_top = row_def label = Gtk.Label() label.set_text(label_text) label.set_tooltip_text(adj_class.STATIC_TOOLTIP_TEXT) label.set_vexpand(True) label.set_hexpand(False) label.set_valign(0.0) label.set_margin_top(margin_top) label.set_margin_start(3) label.set_margin_end(3) adj = adj_class() adj.set_size_request(100, 22) adj.set_vexpand(False) adj.set_hexpand(True) adj.set_margin_top(margin_top) adj.set_margin_left(3) adj.set_margin_right(3) adj.set_valign(0.0) self._sliders.append(adj) grid.attach(label, 0, row, 1, 1) grid.attach(adj, 1, row, 1, 1) row += 1 align = Gtk.Alignment( xalign=0.5, yalign=0.5, xscale=1.0, yscale=0.0, ) align.add(grid) self._page_widget = align #: Page's layout widget
def _init_ui(self): # Layout grid row = 0 grid = Gtk.Grid() grid.set_border_width(gui.widgets.SPACING_CRAMPED) grid.set_row_spacing(gui.widgets.SPACING_CRAMPED) grid.set_column_spacing(gui.widgets.SPACING_CRAMPED) self.add(grid) row += 1 label = Gtk.Label(label=self._ALPHA_LABEL_TEXT) label.set_hexpand(False) label.set_halign(Gtk.Align.START) grid.attach(label, 0, row, 1, 1) scale = InputSlider() scale.set_range(0, 1) scale.set_round_digits(1) scale.set_draw_value(False) line_alpha = self.app.preferences.get(_ALPHA_PREFS_KEY, _DEFAULT_ALPHA) scale.set_value(line_alpha) scale.set_hexpand(True) scale.set_vexpand(False) scale.scale.connect("value-changed", self._scale_value_changed_cb) grid.attach(scale, 1, row, 1, 1) row += 1 store = Gtk.ListStore(int, str) rootstack = self.app.doc.model.layer_stack for _type in lib.tiledsurface.SYMMETRY_TYPES: store.append([_type, lib.tiledsurface.SYMMETRY_STRINGS[_type]]) self._symmetry_type_combo = Gtk.ComboBox() self._symmetry_type_combo.set_model(store) self._symmetry_type_combo.set_active(rootstack.symmetry_type) self._symmetry_type_combo.set_hexpand(True) cell = Gtk.CellRendererText() self._symmetry_type_combo.pack_start(cell, True) self._symmetry_type_combo.add_attribute(cell, "text", 1) self._type_cb_id = self._symmetry_type_combo.connect( 'changed', self._symmetry_type_combo_changed_cb ) label = Gtk.Label(label=self._SYMMETRY_TYPE_TEXT) label.set_hexpand(False) label.set_halign(Gtk.Align.START) grid.attach(label, 0, row, 1, 1) grid.attach(self._symmetry_type_combo, 1, row, 1, 1) row += 1 label = Gtk.Label(label=self._SYMMETRY_ROT_LINES_TEXT) label.set_hexpand(False) label.set_halign(Gtk.Align.START) self._axis_sym_lines_entry = Gtk.SpinButton( adjustment=self._axis_symmetry_lines, climb_rate=0.25 ) self._update_num_lines_sensitivity(rootstack.symmetry_type) grid.attach(label, 0, row, 1, 1) grid.attach(self._axis_sym_lines_entry, 1, row, 1, 1) row += 1 label = Gtk.Label(label=self._POSITION_LABEL_X_TEXT) label.set_hexpand(False) label.set_halign(Gtk.Align.START) entry = Gtk.SpinButton( adjustment=self._axis_pos_adj_x, climb_rate=0.25, digits=0 ) entry.set_hexpand(True) entry.set_vexpand(False) grid.attach(label, 0, row, 1, 1) grid.attach(entry, 1, row, 1, 1) row += 1 label = Gtk.Label(label=self._POSITION_LABEL_Y_TEXT) label.set_hexpand(False) label.set_halign(Gtk.Align.START) entry = Gtk.SpinButton( adjustment=self._axis_pos_adj_y, climb_rate=0.25, digits=0 ) entry.set_hexpand(True) entry.set_vexpand(False) grid.attach(label, 0, row, 1, 1) grid.attach(entry, 1, row, 1, 1) row += 1 label = Gtk.Label() label.set_hexpand(False) label.set_halign(Gtk.Align.START) self._angle_label = label self._update_angle_label() grid.attach(label, 0, row, 1, 1) scale = InputSlider(self._axis_angle) scale.set_draw_value(False) scale.set_hexpand(True) scale.set_vexpand(False) grid.attach(scale, 1, row, 1, 1) row += 1 button = Gtk.CheckButton() toggle_action = self.app.find_action("SymmetryActive") button.set_related_action(toggle_action) button.set_label(C_( "symmetry axis options panel: axis active checkbox", u'Enabled', )) button.set_hexpand(True) button.set_vexpand(False) grid.attach(button, 1, row, 2, 1)
import os import sys mgr = gui.colors.ColorManager(prefs={}, datapath='.') widget_classes = [CrossedBowl, Wash, Rings] widgets = [] for widget_class in widget_classes: widget = widget_class() widget.set_color_manager(mgr) widgets.append(widget) mgr.set_color(lib.color.RGBColor(0.3, 0.6, 0.7)) if len(sys.argv) > 1: for dir_name in sys.argv[1:]: for w in widgets: icon_name = w.__class__.__name__ w.save_icon_tree(dir_name, icon_name) else: # Interactive test window = Gtk.Window() grid = Gtk.Grid() r = 1 for w in widgets: w.set_hexpand(True) w.set_vexpand(True) grid.attach(w, 0, r, 1, 1) r += 1 window.add(grid) window.set_title(os.path.basename(sys.argv[0])) window.connect("destroy", lambda *a: Gtk.main_quit()) window.show_all() Gtk.main()