def add(self, fid): if fid not in self.id_list(): self.flist.append(FilterElement(fid)) get_app().post_message("filter_rack_added", {"page_name" : self.name, "id": fid, "pos": len(self.flist) - 1}, self.m_id) else: raise ValueError("Filter ID already in the list")
def add_page(self, name, in_color, out_color): if name in self.pages: raise KeyError("Page '{}' already exists".format(name)) self.pages[name] = FilterPage(name, in_color, out_color) get_app().post_message("filter_page_added", {"name" : name}, self.m_id) return self.pages[name]
def down(self, fid): pos = self.filter_pos(fid) if pos < len(self.flist) - 1: self.flist[pos + 1], self.flist[pos] = self.flist[pos], self.flist[pos + 1] get_app().post_message("filter_rack_down", {"page_name": self.name, "id": fid, "old_pos": pos, "new_pos": pos+1}, self.m_id) return pos + 1 else: raise IndexError("Cannot down filter at end of the list")
def up(self, fid): pos = self.filter_pos(fid) if pos > 0: self.flist[pos - 1], self.flist[pos] = self.flist[pos], self.flist[pos - 1] get_app().post_message("filter_rack_up", {"page_name": self.name, "id": fid, "old_pos": pos, "new_pos": pos-1}, self.m_id) return pos - 1 else: raise IndexError("Cannot up filter at the beggining of the list")
def __init__(self): """Initialize, called by the LayerMode FactoryAction making a menu""" Gtk.ImageMenuItem.__init__(self) menu = Gtk.Menu() self._menu_items = [] prev_item = None spec_separator = (None,) modes_menu_spec = (STACK_MODES + spec_separator + STANDARD_MODES) for mode in modes_menu_spec: if mode is None: menu.append(Gtk.SeparatorMenuItem()) continue label, tooltip = MODE_STRINGS.get(mode) if prev_item is None: item = Gtk.RadioMenuItem() else: item = Gtk.RadioMenuItem(group=prev_item) item.set_label(label) item.set_tooltip_text(tooltip) item.connect("activate", self._item_activated_cb, mode) menu.append(item) self._menu_items.append((mode, item)) prev_item = item self._submenu = menu self.set_submenu(self._submenu) self._submenu.show_all() from gui.application import get_app app = get_app() self._model = app.doc.model rootstack = self._model.layer_stack rootstack.layer_properties_changed += self._update_actions rootstack.current_path_updated += self._update_actions self._updating = False self._update_actions()
def __init__(self, page_name, in_color, out_color): self.name = page_name self.flist = [] self.in_color = in_color self.out_color = out_color self.m_id = get_app().register_message_listener(self)
def _new_color_adjusters_menu(): from gui.application import get_app app = get_app() menu = Gtk.Menu() action_names = [ "HCYWheelTool", "HSVWheelTool", "PaletteTool", "HSVSquareTool", "HSVCubeTool", "ComponentSlidersTool", None, "CrossedBowlColorChangerTool", "WashColorChangerTool", "RingsColorChangerTool", ] for an in action_names: if an is None: item = Gtk.SeparatorMenuItem() else: action = app.find_action(an) item = Gtk.MenuItem() item.set_use_action_appearance(True) item.set_related_action(action) menu.append(item) return menu
def __init__(self): """Construct a tool widget with subwidgets from self.PAGE_CLASS.""" # Superclass setup Gtk.VBox.__init__(self) self.set_spacing(3) self.set_border_width(3) # Fields for Workspace's use self.tool_widget_icon_name = self.PAGE_CLASS.get_page_icon_name() self.tool_widget_title = self.PAGE_CLASS.get_page_title() self.tool_widget_description = self.PAGE_CLASS.get_page_description() # Main adjuster widget page = self.PAGE_CLASS() page_widget = page.get_page_widget() self.pack_start(page_widget, True, True, 0) self._adjusters = [] self._adjusters.append(page) # Properties button properties_desc = self.PAGE_CLASS.get_properties_description() if properties_desc is not None: show_props = lambda *a: page.show_properties() # noqa: E731 self.tool_widget_properties = show_props # Adjuster setup from gui.application import get_app self._app = get_app() self.set_color_manager(self._app.brush_color_manager) # Sizing. size = workspace.TOOL_WIDGET_MIN_WIDTH self.set_size_request(size, size*0.9)
def __init__(self, fid, name, title, page_name, parent=None): super(FilterUI, self).__init__(parent) app = get_app() app.load_ui("", "ICFilterUI.ui", self) self.parameters = {} self.lbl_fid.setNum(fid) self.title.setText(title) self.title.setToolTip(title) self.pb_up.setEnabled(False) self.pb_down.setEnabled(False) self.name = name self.fid = fid self.frm_parameters.setVisible(False) self.populate_parameters() self.pb_up.clicked.connect(self.pb_up_clicked) self.pb_down.clicked.connect(self.pb_down_clicked) self.pb_remove.clicked.connect(self.pb_remove_clicked) self.pb_ignore.clicked.connect(self.pb_ignore_clicked) self.page_name = page_name page = engine.get_component("filter_rack").get_page(page_name) filter_ = page.get_filter(fid) self.filter_in.setText(filter_.in_color) self.filter_out.setText(filter_.out_color)
def clicked_cb(self, tdw, event): """Flood-fill with the current settings where clicked If the current layer is not fillable, a new layer will always be created for the fill. """ from gui.application import get_app self.app = get_app() try: self.EOTF = self.app.preferences['display.colorspace_EOTF'] except: self.EOTF = 2.2 x, y = tdw.display_to_model(event.x, event.y) self._x = x self._y = y self._tdws.add(tdw) self._update_ui() color = self.doc.app.brush_color_manager.get_color() opts = self.get_options_widget() make_new_layer = opts.make_new_layer rootstack = tdw.doc.layer_stack if not rootstack.current.get_fillable(): make_new_layer = True rgb = color.get_rgb() rgb = (rgb[0]**self.EOTF, rgb[1]**self.EOTF, rgb[2]**self.EOTF) tdw.doc.flood_fill(x, y, rgb, tolerance=opts.tolerance, sample_merged=opts.sample_merged, make_new_layer=make_new_layer) opts.make_new_layer = False return False
def __init__(self): from gui.application import get_app self.app = get_app() CurveWidget.__init__(self, npoints=4, ylockgroups=((1, 2),), changed_cb=self._changed_cb) self.app.line_mode_settings.observers.append(self._adjs_changed_cb) self._update()
def __init__(self): super(_SimpleAdjusterAdapter, self).__init__() adjuster = self.ADJUSTER_CLASS() from gui.application import get_app self._app = get_app() adjuster.set_color_manager(self._app.brush_color_manager) self.pack_start(adjuster, True, True, 0) self._adjuster = adjuster
def __init__(self): Gtk.VBox.__init__(self) from gui.application import get_app app = get_app() color_hist_view = ColorHistoryView(app) self.pack_start(color_hist_view, True, False, 0) brush_hist_view = BrushHistoryView(app) self.pack_start(brush_hist_view, True, False, 0)
def get_toolbar_icon_size(): from gui.application import get_app app = get_app() size = str(app.preferences.get("ui.toolbar_icon_size", "large")) if size.lower() == 'small': return ICON_SIZE_SMALL else: return ICON_SIZE_LARGE
def __init__(self): from gui.application import get_app app = get_app() super(InputTestWindow, self).__init__(app) self.last_selected_brush = None self.set_title(_('Input Device Test')) self.set_role('Test') self.connect('map', self.map_cb) self.connect('unmap', self.unmap_cb) self._timer_id = 0 self.motion_reports = [] self.motion_event_counter = 0 self.motion_dtime_sample = [] self.last_device = None self.last_motion_time = 0 # main container vbox = Gtk.VBox() self.add(vbox) table = Gtk.Table(2, 4) vbox.pack_start(table, False, True, 0) def add(row, name, value_widget): l1 = Gtk.Label(name) l1.set_justify(Gtk.Justification.LEFT) l1.set_alignment(0.0, 0.5) l2 = value_widget l2.set_alignment(0.0, 0.5) table.attach(l1, 0, 1, row, row+1, Gtk.AttachOptions.FILL, 0, 5, 0) table.attach(l2, 1, 2, row, row+1, Gtk.AttachOptions.FILL, 0, 5, 0) label = self.pressure_label = Gtk.Label(_('(no pressure)')) add(0, _('Pressure:'), label) label = self.tilt_label = Gtk.Label(_('(no tilt)')) add(1, _('Tilt:'), label) label = self.motion_event_counter_label = Gtk.Label() add(2, 'Motion:', label) label = self.device_label = Gtk.Label(_('(no device)')) add(3, _('Device:'), label) l = self.barrel_rotation_label = Gtk.Label(_('(No Barrel Rotation)')) add(4, _('Barrel Rotation:'), l) vbox.pack_start(Gtk.HSeparator(), False, False, 0) tv = self.tv = Gtk.TextView() tv.set_editable(False) tv.modify_font(Pango.FontDescription("Monospace")) tv.set_cursor_visible(False) vbox.pack_start(tv, True, True, 0) self.log = []
def apply_filters(self, frame): if self.get_flow_errors(): raise FilterPageFlowError() if frame.color_space != self.in_color: raise WrongColorSpace("Frame should be {} and not {}".format(self.in_color, frame.color_space)) for i in range(0, len(self.flist)): if self.flist[i].ignore: continue p = engine.get_plugin(self.flist[i].fid) frame = p.instance.apply_filter(frame) if get_app().user_options["preview_source"] == get_app().OPT_PREVIEW_FILTER_PAGE: if self.name == get_app().user_options["filter_group"]: fs = engine.get_component("frame_stream") fs.preview_queue.put(frame.copy()) return frame
def __init__(self): from gui.application import get_app app = get_app() self._app = app windowing.SubWindow.__init__(self, app) self._editor = BrushIconEditor() self._editor.mode_changed += self._editor_mode_changed self.add(self._editor) self.set_title(self._TITLE_PREVIEWING)
def _list_plugins(self, plugin_type = PLUGIN_TYPE_ANY): join = os.path.join listdir = os.listdir isdir = os.path.isdir isfile = os.path.isfile app = get_app() # A plugin folder should contain the following structure # # Plugin_Folder -> info.xml # -> main.py # -> ui -> [.ui files only] # Get the path to the directory that will contain the plugin folders plugins_path = app.settings["plugins_dir"] # List all the folders inside the directory folders = listdir(plugins_path) # The list of plugin loadeds plugin_list = [] # Iterate over the folders and extract the plugin info for folder in folders: full_path = join(plugins_path, folder) try: # Open the xml file to extract its info doc = minidom.parse(join(full_path, "info.xml")) # The correspondent plugin_type value for each node Name type_list = { "VideoInput" : PLUGIN_TYPE_VIDEO_INPUT, "VideoAnalysis" : PLUGIN_TYPE_ANALYSIS, "Filter": PLUGIN_TYPE_FILTER } # Get the tag name of the root element type_tag = doc.documentElement.localName # Go to the next folder if the type is not the specified if (plugin_type != PLUGIN_TYPE_ANY and type_list[type_tag] != plugin_type): continue # List of tags to be extracted tags = ["Title", "Description", "Author", "Version"] # List of text nodes extracted from the xml file infos = {t: [i.nodeValue for i in doc.getElementsByTagName(t)[0].childNodes if i.nodeType == Node.TEXT_NODE][0] for t in tags} # (type: int, name: str, path: str, info: dict) plugin_list.append( (type_list[type_tag], folder, full_path, infos) ) except: log.error("Plugin {} raised exception, ignoring it.".format(folder), exc_info=True) #Return the list containing the found plugins return plugin_list
def _init_input(self, plugin_id): try: video_source = get_component("video_source") app = get_app() # Check if the plugin_id is valid new_plugin = self._get_plugin(plugin_id) if not new_plugin.plugin_type == PLUGIN_TYPE_VIDEO_INPUT: raise TypeError("Wrong Plugin Type {}".format(new_plugin.plugin_type)) # Close the current input plugin if there is one if self.input_plugin is not None: current_id = self.input_plugin["plugin_id"] current_plugin = get_plugin(current_id) #Call the plugin close method try: current_plugin.instance.close_plugin() except: log.error("Error when closing the plugin", exc_info=True) #Release the gui interface try: current_plugin.gui_interface.release() current_plugin.gui_interface = None except: log.error("Error when releasing the gui interface", exc_info=True) #Clean the input plugin info self.input_plugin = None #Close the VideoSource bridge video_source.close_bridge() #Post the message signaling that the video input was closed app.post_message("video_input_closed", {"plugin_id": current_id}, -1) #Get a input bridge to the video source object video_source_bridge = video_source.get_input_bridge() #Object that provides gui access to the plugin interface = GUI_Interface(plugin_id) #Init the plugin try: ret = new_plugin.instance.init_plugin(gui_interface=interface, video_source_bridge=video_source_bridge) if ret: #Init the VideoSource bridge video_source.init_bridge(new_plugin) new_plugin.gui_interface = interface self.input_plugin= {"plugin_id": plugin_id} app.post_message("video_input_changed", {"plugin_id": plugin_id}, -1) else: interface.release() raise PluginInitError("init_plugin returned False") except: log.error("Error when initialiazing input plugin", exc_info=True) #raise PluginInitError("Plugin init. raised exception") interface.release() video_source.close_bridge() except: log.error("Could not init input plugin", exc_info=True)
def __init__(self): super(SymmetryEditOptionsWidget, self).__init__( xalign=0.5, yalign=0.5, xscale=1.0, yscale=1.0, ) self._axis_pos_x_dialog = None self._axis_pos_x_button = None self._axis_pos_y_dialog = None self._axis_pos_y_button = None self._symmetry_type_combo = None self._axis_rot_sym_lines_entry = None from gui.application import get_app self.app = get_app() rootstack = self.app.doc.model.layer_stack self._axis_pos_adj_x = Gtk.Adjustment( rootstack.symmetry_x, upper=32000, lower=-32000, step_incr=1, page_incr=100, ) self._axis_pos_adj_x.connect( 'value-changed', self._axis_pos_adj_x_changed, ) self._axis_pos_adj_y = Gtk.Adjustment( rootstack.symmetry_y, upper=32000, lower=-32000, step_incr=1, page_incr=100, ) self._axis_pos_adj_y.connect( 'value-changed', self._axis_pos_adj_y_changed, ) self._axis_rot_symmetry_lines = Gtk.Adjustment( rootstack.rot_symmetry_lines, upper=50, lower=2, step_incr=1, page_incr=3, ) self._axis_rot_symmetry_lines.connect( 'value-changed', self._axis_rot_symmetry_lines_changed, ) self._init_ui() rootstack.symmetry_state_changed += self._symmetry_state_changed_cb self._update_axis_pos_x_button_label(rootstack.symmetry_x) self._update_axis_pos_y_button_label(rootstack.symmetry_y)
def __init__(self): from gui import application app = application.get_app() assert app is not None self._current_background_pixbuf = None # set when changed flags = Gtk.DialogFlags.DESTROY_WITH_PARENT buttons = [ _('Save as Default'), RESPONSE_SAVE_AS_DEFAULT, Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT, ] windowing.Dialog.__init__( self, app=app, title=_('Background'), parent=app.drawWindow, flags=flags, buttons=buttons, ) # Set up window. self.connect('response', self._response_cb) notebook = self.nb = Gtk.Notebook() self.vbox.pack_start(notebook, True, True, 0) # Set up patterns tab. patterns_scroll = Gtk.ScrolledWindow() patterns_scroll.set_policy( Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC, ) notebook.append_page(patterns_scroll, Gtk.Label(_('Pattern'))) self.bgl = BackgroundList(self) patterns_scroll.add_with_viewport(self.bgl) self.connect("realize", self._realize_cb) self.connect("show", self._show_cb) self.connect("hide", self._hide_cb) # Set up colors tab. color_vbox = Gtk.VBox() notebook.append_page(color_vbox, Gtk.Label(_('Color'))) self.cs = Gtk.ColorSelection() self.cs.connect('color-changed', self._color_changed_cb) color_vbox.pack_start(self.cs, True, True, 0) b = Gtk.Button(_('Add color to Patterns')) b.connect('clicked', self._add_color_to_patterns_cb) color_vbox.pack_start(b, False, True, 0)
def __init__(self, group): """Construct, to show a named group""" SizedVBoxToolWidget.__init__(self) self._group = group self._scrolls = Gtk.ScrolledWindow() self._dialog = None self._brush_list = None from gui.application import get_app self._app = get_app() if group not in self._app.brushmanager.groups: raise ValueError("No group named %r" % group) self.pack_start(self._scrolls, True, True, 0) self._update_brush_list()
def _unload_plugin(self, plugin_id): app = get_app() if plugin_id in self._loaded_plugins: #The the Plugin instance plugin = self._loaded_plugins[plugin_id] #Call the plugins release method plugin.instance.release() #Post a message signaling that the plugin is about to be unloaded app.post_message("plugin_unloaded", {"id": plugin_id, "type": plugin.plugin_type, "plugin": plugin}, -1) #Delete from the list del self._loaded_plugins[plugin_id] else: raise ValueError("No plugin with id '{}'".format(plugin_id))
def __init__(self): super(FrameEditOptionsWidget, self).__init__( xalign=0.5, yalign=0.5, xscale=1.0, yscale=1.0, ) from gui.application import get_app self.app = get_app() self.callbacks_active = False docmodel = self.app.doc.model x, y, w, h = docmodel.get_frame() dpi = docmodel.get_resolution() self.width_adj = UnitAdjustment(w, upper=32000, lower=1, step_increment=1, page_increment=128, dpi=dpi) self.height_adj = UnitAdjustment(h, upper=32000, lower=1, step_increment=1, page_increment=128, dpi=dpi) self.dpi_adj = Gtk.Adjustment( value=dpi, upper=9600, lower=1, step_increment=76, # hack: 3 clicks 72->300 page_increment=dpi) docmodel.frame_updated += self._frame_updated_cb self._init_ui() self.width_adj.connect('value-changed', self.on_size_adjustment_changed) self.height_adj.connect('value-changed', self.on_size_adjustment_changed) self.dpi_adj.connect('value-changed', self.on_dpi_adjustment_changed) self._update_size_button()
def __init__(self): Gtk.Grid.__init__(self) self.set_row_spacing(6) self.set_column_spacing(12) from gui.application import get_app app = get_app() self._app = app self._bm = app.brushmanager self.set_border_width(12) self._bm.brush_selected += self._brush_selected_cb self._brush_to_edit = None self._preview_modified = False self._model = lib.document.Document(self._app.brush, painting_only=True) self._model.layer_stack.ensure_populated() self._model.canvas_area_modified += self._preview_area_modified_cb self._init_widgets()
def __init__(self): super(FrameEditOptionsWidget, self).__init__() from gui.application import get_app self.app = get_app() self.callbacks_active = False docmodel = self.app.doc.model x, y, w, h = docmodel.get_frame() dpi = docmodel.get_resolution() self.width_adj = UnitAdjustment(w, upper=32000, lower=1, step_increment=1, page_increment=128, dpi=dpi) self.height_adj = UnitAdjustment(h, upper=32000, lower=1, step_increment=1, page_increment=128, dpi=dpi) self.dpi_adj = Gtk.Adjustment( value=dpi, upper=9600, lower=1, step_increment=76, # hack: 3 clicks 72->300 page_increment=dpi) frame_overlays = list( filter(lambda o: isinstance(o, FrameOverlay), self.app.doc.tdw.display_overlays)) assert len(frame_overlays) == 1, "Should be exactly 1 frame overlay!" self._overlay = frame_overlays[0] docmodel.frame_updated += self._frame_updated_cb self._init_ui() self.width_adj.connect('value-changed', self.on_size_adjustment_changed) self.height_adj.connect('value-changed', self.on_size_adjustment_changed) self.dpi_adj.connect('value-changed', self.on_dpi_adjustment_changed)
def __init__(self): from gui import application app = application.get_app() assert app is not None windowing.Dialog.__init__(self, app=app, title=_('Background'), modal=True) self.add_button(_('Save as Default'), RESPONSE_SAVE_AS_DEFAULT) self.add_button(Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT) self._current_background_pixbuf = None # set when changed # Set up window. self.connect('response', self._response_cb) notebook = self.nb = Gtk.Notebook() self.vbox.pack_start(notebook, True, True, 0) # Set up patterns tab. patterns_scroll = Gtk.ScrolledWindow() patterns_scroll.set_policy( Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC, ) notebook.append_page(patterns_scroll, Gtk.Label(label=_('Pattern'))) self.bgl = BackgroundList(self) patterns_scroll.add(self.bgl) self.connect("realize", self._realize_cb) self.connect("show", self._show_cb) self.connect("hide", self._hide_cb) # Set up colors tab. color_vbox = Gtk.VBox() notebook.append_page(color_vbox, Gtk.Label(label=_('Color'))) self.cs = Gtk.ColorSelection() self.cs.connect('color-changed', self._color_changed_cb) color_vbox.pack_start(self.cs, True, True, 0) b = Gtk.Button(label=_('Add color to Patterns')) b.connect('clicked', self._add_color_to_patterns_cb) color_vbox.pack_start(b, False, True, 0)
def __init__(self): Gtk.Grid.__init__(self) self.set_row_spacing(6) self.set_column_spacing(12) from gui.application import get_app app = get_app() self._app = app self._bm = app.brushmanager self.set_border_width(12) self._bm.brush_selected += self._brush_selected_cb self._brush_to_edit = None self._preview_modified = False self._model = lib.document.Document(self._app.brush, painting_only=True) self._model.layer_stack.ensure_populated() self._model.canvas_area_modified += self._preview_area_modified_cb self._init_widgets()
def __init__(self): assert Engine._INSTANCE is None Engine._INSTANCE = self # Dictionary containing all loaded engine components self.components = {} # Dictionary containing the currently initialized input plugin and it's # GUI_Interface object among other informations about the plugin. self.input_plugin = None # Dictionary containing the currently initialized analy. plugin and it's # GUI_Interface object mong other informations about the plugin. self.analysis_plugin = None # This dictionary holds all the plugin objects loaded using the # load_plugin method, all plugin objects have a unique id. They can be # retrivied by calling the method get_plugin self._loaded_plugins = {} self.identifier = get_app().register_message_listener(self)
def __init__(self, **kwds): """Initialize.""" super(SymmetryEditMode, self).__init__(**kwds) from gui.application import get_app app = get_app() self.app = app statusbar_cid = app.statusbar.get_context_id(self._STATUSBAR_CONTEXT) self._statusbar_context_id = statusbar_cid self._drag_start_x = None self._drag_start_y = None self._drag_start_model_x = None self._drag_start_model_y = None self.zone = _EditZone.UNKNOWN self._last_msg_zone = None self._click_info = None self.button_pos = None self._entered_before = False self.line_alphafrac = 0.0
def __init__(self, **kwds): """Initialize.""" super(SymmetryEditMode, self).__init__(**kwds) from gui.application import get_app app = get_app() self.app = app statusbar_cid = app.statusbar.get_context_id(self._STATUSBAR_CONTEXT) self._statusbar_context_id = statusbar_cid self._drag_start_x = None self._drag_start_y = None self._drag_start_model_x = None self._drag_start_model_y = None self.zone = _EditZone.UNKNOWN self._last_msg_zone = None self._click_info = None self.button_pos = None self._entered_before = False self.line_alphafrac = 0.0
def __init__(self): app = None if __name__ != '__main__': from gui.application import get_app app = get_app() self._brush = app.brush bm = app.brushmanager bm.brush_selected += self.brush_selected_cb else: self._brush = lib.brush.BrushInfo() self._brush.load_defaults() SubWindow.__init__(self, app, key_input=True) # Tracking vars for updating the treestore in response to # brush setting changes and loading new brushes. self._treestore = None self._setting_treepath = {} # {cname: Gtk.TreePath}, path for setting self._group_treepath = {} # {groupid: Gtk.TreePath}, path for group self._setting_group = {} # {cname: groupid}, group containing setting # Adjusters: may be shared with those of the app self._base_adj = {} #: setting cname => base value adj self._input_y_adj = {} #: input name => scale y range (+-) adj self._input_xmin_adj = {} #: input name => scale x min adj self._input_xmax_adj = {} #: input name => scale x min adj self._disable_input_adj_changed_cb = False self._init_adjustments() self.set_title( C_( "brush settings editor: subwindow title", "Brush Settings Editor", )) self._scales = [] self._setting = None self._builder = Gtk.Builder() self._builder.set_translation_domain("mypaint") self._build_ui() self._base_value_scale = self._builder.get_object("base_value_scale") self.connect_after("show", self._post_show_cb) self.connect('button-press-event', self._clear_focus) editor = self._builder.get_object("brush_editor") self.add(editor) self._brush.observers.append(self.brush_modified_cb) self._live_update_idle_cb_id = None self._updating_metadata_ui = False self.set_default_size(1000, 800)
def __init__(self): super(FrameEditOptionsWidget, self).__init__( xalign=0.5, yalign=0.5, xscale=1.0, yscale=1.0, ) from gui.application import get_app self.app = get_app() self.callbacks_active = False docmodel = self.app.doc.model x, y, w, h = docmodel.get_frame() dpi = docmodel.get_resolution() self.width_adj = UnitAdjustment( w, upper=32000, lower=1, step_incr=1, page_incr=128, dpi=dpi ) self.height_adj = UnitAdjustment( h, upper=32000, lower=1, step_incr=1, page_incr=128, dpi=dpi ) self.dpi_adj = Gtk.Adjustment(dpi, upper=9600, lower=1, step_incr=76, # hack: 3 clicks 72->300 page_incr=dpi) docmodel.frame_updated += self._frame_updated_cb self._init_ui() self.width_adj.connect('value-changed', self.on_size_adjustment_changed) self.height_adj.connect('value-changed', self.on_size_adjustment_changed) self.dpi_adj.connect('value-changed', self.on_dpi_adjustment_changed) self._update_size_button()
def __init__(self, string=None): """Construct a BrushInfo object, optionally parsing it.""" super(BrushInfo, self).__init__() self.settings = {} self.cache_str = None self.observers = [] for s in brushsettings.settings: self.reset_setting(s.cname) self.observers.append(self.settings_changed_cb) self.observers_hidden = [] self.pending_updates = set() if string: self.load_from_string(string) from gui.application import get_app self.app = get_app() try: self.EOTF = self.app.preferences['display.colorspace_EOTF'] except: self.EOTF = 2.2
def __init__(self): super(SizedVBoxToolWidget, self).__init__() from gui.application import get_app app = get_app() self.app = app toolbar = inline_toolbar(app, [ ("ScratchNew", "mypaint-add-symbolic"), ("ScratchLoad", None), ("ScratchSaveAs", "mypaint-document-save-symbolic"), ("ScratchRevert", "mypaint-document-revert-symbolic"), ]) scratchpad_view = app.scratchpad_doc.tdw scratchpad_view.set_size_request(64, 64) self.connect("destroy-event", self._save_cb) self.connect("delete-event", self._save_cb) scratchpad_box = Gtk.EventBox() scratchpad_box.add(scratchpad_view) self.pack_start(scratchpad_box, True, True, 0) self.pack_start(toolbar, False, True, 0)
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 __init__(self): assert VideoSource._INSTANCE is None VideoSource._INSTANCE = self #Is the video source open? self._source_open = False #List of bridged methods (Since they have the same behaviour, they will #be dynamically generated when the bridge is initialized) self._bridge_methods = ["seek", "tell", "get_length", "get_fps", "get_size", "next"] #Create the bridge object that will be provided to the VideoInput self._input_bridge = InputBridge(self) #The current bridge plugin instance self._plugin_instance = None self.mid = get_app().register_message_listener(self) self.color_space = None
def __init__(self): super(BrushGroupsMenu, self).__init__() from gui.application import get_app self.app = get_app() # Static items item = Gtk.SeparatorMenuItem() self.append(item) item = Gtk.MenuItem(C_("brush groups menu", u"New Group…")) item.connect("activate", self._new_brush_group_cb) self.append(item) item = Gtk.MenuItem(C_("brush groups menu", u"Import Brushes…")) item.connect("activate", self.app.drawWindow.import_brush_pack_cb) self.append(item) item = Gtk.MenuItem(C_("brush groups menu", u"Get More Brushes…")) item.connect("activate", self.app.drawWindow.download_brush_pack_cb) self.append(item) # Dynamic items bm = self.app.brushmanager self._items = {} self._update(bm) bm.groups_changed += self._update
def __init__(self): super(BrushGroupsMenu, self).__init__() from gui.application import get_app self.app = get_app() # Static items item = Gtk.SeparatorMenuItem() self.append(item) item = Gtk.MenuItem(C_("brush groups menu", "New Group...")) item.connect("activate", self._new_brush_group_cb) self.append(item) item = Gtk.MenuItem(C_("brush groups menu", "Import Brushes...")) item.connect("activate", self.app.drawWindow.import_brush_pack_cb) self.append(item) item = Gtk.MenuItem(C_("brush groups menu", "Get More Brushes...")) item.connect("activate", self.app.drawWindow.download_brush_pack_cb) self.append(item) # Dynamic items bm = self.app.brushmanager self._items = {} self._update(bm) bm.groups_changed += self._update
def get_background_validity(self): from gui.application import get_app app = get_app() cm = self.get_color_manager() prefs = cm.get_prefs() try: if app.brush.get_setting('cie_v') == '': return True limit_purity = prefs['color.limit_purity'] vsh = ( int(app.brush.get_setting('cie_v') * 100), int(app.brush.get_setting('cie_s') * 100), int(app.brush.get_setting('cie_h') * 100)) cieaxes = app.brush.get_setting('cieaxes'), lightsource = ( app.brush.get_setting('lightsource_X'), app.brush.get_setting('lightsource_Y'), app.brush.get_setting('lightsource_Z')) except KeyError: return True return vsh, cieaxes, lightsource, limit_purity
def __init__(self, mipmap_level=0, mipmap_surfaces=None, looped=False, looped_size=(0, 0)): super(MyPaintSurface, self).__init__() # TODO: pass just what it needs access to, not all of self self._backend = mypaintlib.TiledSurface(self) self.tiledict = {} self.observers = [] # Used to implement repeating surfaces, like Background if looped_size[0] % N or looped_size[1] % N: raise ValueError('Looped size must be multiples of tile size') self.looped = looped self.looped_size = looped_size self.mipmap_level = mipmap_level if mipmap_level == 0: assert mipmap_surfaces is None self._mipmaps = self._create_mipmap_surfaces() else: assert mipmap_surfaces is not None self._mipmaps = mipmap_surfaces # Forwarding API self.set_symmetry_state = self._backend.set_symmetry_state self.begin_atomic = self._backend.begin_atomic self.get_color = self._backend.get_color self.get_alpha = self._backend.get_alpha self.draw_dab = self._backend.draw_dab from gui.application import get_app self.app = get_app() try: self.EOTF = self.app.preferences['display.colorspace_EOTF'] except: self.EOTF = 2.2
def __init__(self): """Construct, and connect internal signals & callbacks""" SizedVBoxToolWidget.__init__(self) from gui.application import get_app self._app = get_app() self._app.doc.modes.changed += self._modestack_changed_cb self.set_border_width(3) self.set_spacing(6) # Placeholder in case a mode has no options label = Gtk.Label() label.set_markup(self.NO_OPTIONS_MARKUP) self._no_options_label = label # Container for an options widget exposed by the current mode self._mode_icon = Gtk.Image() label = Gtk.Label() label.set_text("<options-label>") self._options_label = label label.set_alignment(0.0, 0.5) label_hbox = Gtk.HBox() label_hbox.set_spacing(3) label_hbox.set_border_width(3) label_hbox.pack_start(self._mode_icon, False, False, 0) label_hbox.pack_start(self._options_label, True, True, 0) align = Gtk.Alignment.new(0.5, 0.5, 1.0, 1.0) align.set_padding(0, 0, 0, 0) align.set_border_width(3) self._options_bin = align self.pack_start(label_hbox, False, False, 0) self.pack_start(align, True, True, 0) self.connect("show", lambda *a: self._update_ui()) # Fallback self._update_ui_with_options_widget( self._no_options_label, self.tool_widget_title, self.tool_widget_icon_name, )
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(_("Tolerance:")) label.set_tooltip_text( _("How much pixel colors are allowed to vary from the start\n" "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(_("Source:")) label.set_tooltip_text(_("Which visible layers should be filled")) 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 option (not saved): Specific fill source choice", "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 = _("Sample Merged") checkbut = Gtk.CheckButton.new_with_label(text) checkbut.set_tooltip_text( _("When considering which area to fill, use a\n" "temporary merge of all the visible layers\n" "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 = _("Limit to view") checkbut = Gtk.CheckButton.new_with_label(text) checkbut.set_tooltip_text( C_("fill option: fill does not reach beyond view when active", "Constrain the area that may be filled to the view area")) 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(_("Target:")) label.set_tooltip_text(_("Where the output should go")) label.set_alignment(1.0, 0.5) label.set_hexpand(False) self.attach(label, 0, row, 1, 1) text = _("New Layer (once)") checkbut = Gtk.CheckButton.new_with_label(text) checkbut.set_tooltip_text( _("Create a new layer with the results of the fill.\n" "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_( "floodfill options warning text", "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.modes.DEFAULT_MODE) modes.insert(0, lib.modes.DEFAULT_MODE) combo = gui.layers.new_blend_mode_combo(modes, lib.modes.MODE_STRINGS) combo.set_tooltip_text(C_( "floodfill option tooltip text - blend modes", "Blend mode used when filling")) active = prefs.get(self.BLEND_MODE_PREF, self.DEFAULT_BLEND_MODE) active = int(active) 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(_("Opacity:")) label.set_tooltip_text( _("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: offset (grow/shrink) 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 (grow/shrink) description", 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: feather (blur) 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 (blur) description", 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 on/off label", u'Use gap detection' ) checkbut = Gtk.CheckButton.new_with_label(text) checkbut.set_tooltip_text(C_( "fill options: gap closing on/off description", 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 really 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: maximum size of gaps 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 description", u"The size of the largest gaps that can be detected" )) 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 to gap closing fill; " "When enabled, the fill will stay outside of detected " "gaps, when disabled, they will seep into them", 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_( "gui/fill.py - description of (Retract seeps) option", u"Try to prevent the fill from seeping into the gaps" )) 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(_("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 __init__(self): from gui.application import get_app app = get_app() super(InputTestWindow, self).__init__(app) self.last_selected_brush = None self.set_title(_('Input Device Test')) self.set_role('Test') self.connect('map', self.map_cb) self.connect('unmap', self.unmap_cb) self._timer_id = 0 self.motion_reports = [] self.motion_event_counter = 0 self.motion_dtime_sample = [] self.last_device = None self.last_motion_time = 0 # main container vbox = Gtk.VBox() self.add(vbox) table = Gtk.Table(2, 4) vbox.pack_start(table, False, True, 0) def add(row, name, value_widget): l1 = Gtk.Label(label=name) l1.set_justify(Gtk.Justification.LEFT) l1.set_alignment(0.0, 0.5) l2 = value_widget l2.set_alignment(0.0, 0.5) table.attach(l1, 0, 1, row, row + 1, Gtk.AttachOptions.FILL, 0, 5, 0) table.attach(l2, 1, 2, row, row + 1, Gtk.AttachOptions.FILL, 0, 5, 0) label = self.pressure_label = Gtk.Label(label=_('(no pressure)')) add(0, _('Pressure:'), label) label = self.tilt_label = Gtk.Label(label=_('(no tilt)')) add(1, _('Tilt:'), label) label = self.motion_event_counter_label = Gtk.Label() add(2, 'Motion:', label) label = self.device_label = Gtk.Label(label=_('(no device)')) add(3, _('Device:'), label) label = Gtk.Label(label=_('(No Barrel Rotation)')) self.barrel_rotation_label = label add(4, _('Barrel Rotation:'), label) vbox.pack_start(Gtk.HSeparator(), False, False, 0) tv = self.tv = Gtk.TextView() tv.set_editable(False) tv.modify_font(Pango.FontDescription("Monospace")) tv.set_cursor_visible(False) vbox.pack_start(tv, True, True, 0) self.log = []
def __init__(self, monitor=None): """Initialize :param Monitor monitor: monitor instance (for testing) By default, the central app's `device_monitor` is used to permit parameterless construction. """ super(SettingsEditor, self).__init__() if monitor is None: from gui.application import get_app app = get_app() monitor = app.device_monitor self._monitor = monitor self._devices_store = Gtk.ListStore(object) self._devices_view = Gtk.TreeView(self._devices_store) # Device info column col = Gtk.TreeViewColumn(_("Device")) col.set_min_width(250) col.set_expand(True) col.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) self._devices_view.append_column(col) cell = Gtk.CellRendererText() cell.set_property("ellipsize", Pango.EllipsizeMode.MIDDLE) col.pack_start(cell, expand=True) col.set_cell_data_func(cell, self._device_name_datafunc) col = Gtk.TreeViewColumn(_("Axes")) col.set_min_width(30) col.set_expand(False) col.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) self._devices_view.append_column(col) cell = Gtk.CellRendererText() col.pack_start(cell, expand=True) col.set_cell_data_func(cell, self._device_axes_datafunc) col = Gtk.TreeViewColumn(_("Type")) col.set_min_width(30) col.set_expand(False) col.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) self._devices_view.append_column(col) cell = Gtk.CellRendererText() col.pack_start(cell, expand=True) col.set_cell_data_func(cell, self._device_type_datafunc) # Usage config value => string store (dropdowns) store = Gtk.ListStore(str, str) for config, flag, string in _USAGE_CONFVAL_INFO: store.append([config, string]) self._usage_store = store # Mode setting & current value column col = Gtk.TreeViewColumn(_("Allow...")) col.set_min_width(150) col.set_resizable(False) col.set_expand(True) self._devices_view.append_column(col) cell = Gtk.CellRendererCombo() cell.set_property("model", self._usage_store) cell.set_property("text-column", self._USAGE_STRING_COL) cell.set_property("mode", Gtk.CellRendererMode.EDITABLE) cell.set_property("editable", True) cell.set_property("has-entry", False) cell.connect("changed", self._usage_config_cell_changed_cb) col.pack_start(cell, expand=True) col.set_cell_data_func(cell, self._usage_config_string_datafunc) # Pretty borders view_scroll = Gtk.ScrolledWindow() view_scroll.set_shadow_type(Gtk.ShadowType.ETCHED_IN) pol = Gtk.PolicyType.AUTOMATIC view_scroll.set_policy(pol, pol) view_scroll.add(self._devices_view) view_scroll.set_hexpand(True) view_scroll.set_vexpand(True) self.attach(view_scroll, 0, 0, 1, 1) self._update_devices_store() self._monitor.devices_updated += self._update_devices_store
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(_("Tolerance:")) label.set_tooltip_text( _("How much pixel colors are allowed to vary from the start\n" "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(_("Source:")) label.set_tooltip_text(_("Which visible layers should be filled")) label.set_alignment(1.0, 0.5) label.set_hexpand(False) self.attach(label, 0, row, 1, 1) text = _("Sample Merged") checkbut = Gtk.CheckButton.new_with_label(text) checkbut.set_tooltip_text( _("When considering which area to fill, use a\n" "temporary merge of all the visible layers\n" "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 row += 1 label = Gtk.Label() label.set_markup(_("Target:")) label.set_tooltip_text(_("Where the output should go")) label.set_alignment(1.0, 0.5) label.set_hexpand(False) self.attach(label, 0, row, 1, 1) text = _("New Layer (once)") checkbut = Gtk.CheckButton.new_with_label(text) checkbut.set_tooltip_text( _("Create a new layer with the results of the fill.\n" "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 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(_("Reset options to their defaults")) align.add(button) self.attach(align, 0, row, 2, 1)
def _init_color_manager(self, widget): from gui.application import get_app self._app = get_app() mgr = self._app.brush_color_manager assert mgr is not None self.set_color_manager(mgr)
def analyse(exctyp, value, tb): import tokenize import keyword import platform from gui import application from gui.meta import get_libs_version_string app = application.get_app() trace = StringIO() nlines = 3 frecs = inspect.getinnerframes(tb, nlines) trace.write('Mypaint version: %s\n' % app.version) trace.write('System information: %s\n' % platform.platform()) trace.write('Using: %s\n' % (get_libs_version_string(),)) trace.write('Traceback (most recent call last):\n') for frame, fname, lineno, funcname, context, cindex in frecs: trace.write(' File "%s", line %d, ' % (fname, lineno)) args, varargs, varkw, lcls = inspect.getargvalues(frame) def readline(lno=[lineno], *args): if args: print(args) try: return linecache.getline(fname, lno[0]) finally: lno[0] += 1 all, prev, name, scope = {}, None, '', None for ttype, tstr, stup, etup, line in tokenize.generate_tokens(readline): if ttype == tokenize.NAME and tstr not in keyword.kwlist: if name: if name[-1] == '.': try: val = getattr(prev, tstr) except AttributeError: # XXX skip the rest of this identifier only break name += tstr else: assert not name and not scope scope, val = lookup(tstr, frame, lcls) name = tstr if val is not None: prev = val elif tstr == '.': if prev: name += '.' else: if name: all[name] = (scope, prev) prev, name, scope = None, '', None if ttype == tokenize.NEWLINE: break try: details = inspect.formatargvalues(args, varargs, varkw, lcls, formatvalue=lambda v: '=' + pydoc.text.repr(v)) except: # seen that one on Windows (actual exception was KeyError: self) details = '(no details)' trace.write(funcname + details + '\n') if context is None: context = ['<source context missing>\n'] trace.write(''.join([' ' + x.replace('\t', ' ') for x in filter(lambda a: a.strip(), context)])) if len(all): trace.write(' variables: %s\n' % str(all)) trace.write('%s: %s' % (exctyp.__name__, value)) return trace
def __init__(self): super(SizedVBoxToolWidget, self).__init__() from gui.application import get_app app = get_app() self.app = app self._main_tdw = app.doc.tdw self._model = app.doc.model self.tdw = tileddrawwidget.TiledDrawWidget( idle_redraw_priority=REDRAW_PRIORITY, ) self.tdw.set_model(self._model) self.tdw.zoom_min = 1 / 50.0 self.tdw.set_size_request(64, 64) self.pack_start(self.tdw, True, True, 0) self._cursor = None # Cursors for states self._cursor_move_here = app.cursors.get_icon_cursor( "mypaint-view-zoom-symbolic", cursor_name=gui.cursor.Name.ARROW, ) self._cursor_drag_ready = app.cursors.get_icon_cursor( "mypaint-view-pan-symbolic", cursor_name=gui.cursor.Name.HAND_OPEN, ) self._cursor_drag_active = app.cursors.get_icon_cursor( "mypaint-view-pan-symbolic", cursor_name=gui.cursor.Name.HAND_CLOSED, ) self._cursor_no_op = app.cursors.get_icon_cursor( None, cursor_name=gui.cursor.Name.ARROW, ) # Overlay shapes (used by the overlay) self.viewport_overlay_shapes = [] self.viewport_overlay_topleft = None self.viewport_is_rotated = False self.viewport_is_mirrored = False # TRANSLATORS: The preview panel shows where the "camera" of the # TRANSLATORS: main view is pointing. checkbtn = Gtk.CheckButton(label=_("Show Viewfinder")) checkbtn.set_active(self.show_viewfinder) self.pack_start(checkbtn, False, False, 0) checkbtn.connect("toggled", self._show_viewfinder_toggled_cb) self._overlay = VisibleAreaOverlay(self) self.tdw.display_overlays.append(self._overlay) if self.SUPPORTED_ZOOMLEVELS_ONLY: self._zoomlevel_values = [ 1.0 / 128, 1.5 / 128, 1.0 / 64, 1.5 / 64, 1.0 / 32, 1.5 / 32, 1.0 / 16, 1.0 / 8, 2.0 / 11, 0.25, 1.0 / 3, 0.50, 2.0 / 3, 1.0 ] self.tdw.zoom_min = 1.0 / 128 self.tdw.zoom_max = float(app.preferences.get('view.default_zoom', 1)) # Used for detection of potential effective bbox changes during # canvas modify events self._x_min = self._x_max = None self._y_min = self._y_max = None # Used for determining if a potential bbox change is a real one self._last_bbox = None # Watch various objects for updates docmodel = self._model layerstack = docmodel.layer_stack observed_events = { self._canvas_area_modified_cb: [ docmodel.canvas_area_modified, ], self._recreate_preview_transformation: [ layerstack.layer_inserted, layerstack.layer_deleted, ], } for observer_method, events in observed_events.items(): for event in events: event += observer_method # Watch the main model's frame for scale and zoom docmodel.frame_updated += self._frame_modified_cb docmodel.frame_enabled_changed += self._frame_modified_cb # Main controller observers, for updating our overlay self.app.doc.view_changed_observers.append(self._main_view_changed_cb) # Click and drag tracking self._zone = _EditZone.OUTSIDE self._drag_start = None self._button_pressed = None # Events for the preview widget self.tdw.add_events(Gdk.EventMask.BUTTON1_MOTION_MASK | Gdk.EventMask.SCROLL_MASK) preview_tdw_events = { # Clicks and drags "button-press-event": self._button_press_cb, "button-release-event": self._button_release_cb, "motion-notify-event": self._motion_notify_cb, "scroll-event": self._scroll_event_cb, "leave-notify-event": self._leave_notify_cb, # Handle resizes "size-allocate": self._recreate_preview_transformation, } for signal, callback in preview_tdw_events.items(): self.tdw.connect(signal, callback)
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): from gui.application import get_app self.app = get_app() 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/saturation/value: slider label", "H"), 'HSVHueSlider', 12, ), ( C_("color sliders panel: hue/saturation/value: slider label", "S"), 'HSVSaturationSlider', 0, ), ( C_("color sliders panel: hue/saturation/value: slider label", "V"), 'HSVValueSlider', 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, ), ( C_("color sliders panel: hue/chroma/luma: slider label", "cHue"), 'CIECAMHueNormSlider', 12, ), ( C_("color sliders panel: hue/chroma/luma: slider label", "cH"), 'CIECAMHueSlider', 0, ), ( C_("color sliders panel: hue/chroma/luma: slider label", "cS"), 'CIECAMChromaSlider', 0, ), ( C_("color sliders panel: hue/chroma/luma: slider label", "cV"), 'CIECAMLumaSlider', 0, ), ( C_("color sliders panel: Temperature: slider label", "cT"), 'CIECAMTempSlider', 0, ), ( C_("color sliders panel: Limit Purity: slider label", "cLim"), 'CIECAMLimitChromaSlider', 0, ), ] row = 0 for row_def in row_defs: label_text, adj_class, margin_top = row_def active = self.app.preferences["ui.sliders_enabled"].get(adj_class, True) if active: self.app.preferences["ui.sliders_enabled"][adj_class] = True adj_class = globals()[adj_class] 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_left(3) label.set_margin_right(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__(self, monitor=None): """Initialize :param Monitor monitor: monitor instance (for testing) By default, the central app's `device_monitor` is used to permit parameterless construction. """ super(SettingsEditor, self).__init__() if monitor is None: from gui.application import get_app app = get_app() monitor = app.device_monitor self._monitor = monitor self._devices_store = Gtk.ListStore(object) self._devices_view = Gtk.TreeView(self._devices_store) # TRANSLATORS: Column's data is the device's name col = Gtk.TreeViewColumn( C_( "prefs: devices table: column header", "Device", )) col.set_min_width(200) col.set_expand(True) col.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) self._devices_view.append_column(col) cell = Gtk.CellRendererText() cell.set_property("ellipsize", Pango.EllipsizeMode.MIDDLE) col.pack_start(cell, True) col.set_cell_data_func(cell, self._device_name_datafunc) # TRANSLATORS: Column's data is an integer count of the number of axes col = Gtk.TreeViewColumn( C_( "prefs: devices table: column header", "Axes", )) col.set_min_width(30) col.set_resizable(True) col.set_expand(False) col.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) self._devices_view.append_column(col) cell = Gtk.CellRendererText() col.pack_start(cell, True) col.set_cell_data_func(cell, self._device_axes_datafunc) # TRANSLATORS: Column shows type labels ("Touchscreen", "Pen" etc.) col = Gtk.TreeViewColumn( C_( "prefs: devices table: column header", "Type", )) col.set_min_width(120) col.set_resizable(True) col.set_expand(False) col.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) self._devices_view.append_column(col) cell = Gtk.CellRendererText() cell.set_property("ellipsize", Pango.EllipsizeMode.END) col.pack_start(cell, True) col.set_cell_data_func(cell, self._device_type_datafunc) # Usage config value => string store (dropdowns) store = Gtk.ListStore(str, str) for conf_val in AllowedUsage.VALUES: string = AllowedUsage.DISPLAY_STRING[conf_val] store.append([conf_val, string]) self._usage_store = store # TRANSLATORS: Column's data is a dropdown allowing the allowed # TRANSLATORS: tasks for the row's device to be configured. col = Gtk.TreeViewColumn( C_( "prefs: devices table: column header", "Use for...", )) col.set_min_width(100) col.set_resizable(True) col.set_expand(False) self._devices_view.append_column(col) cell = Gtk.CellRendererCombo() cell.set_property("model", self._usage_store) cell.set_property("text-column", self._USAGE_STRING_COL) cell.set_property("mode", Gtk.CellRendererMode.EDITABLE) cell.set_property("editable", True) cell.set_property("has-entry", False) cell.set_property("ellipsize", Pango.EllipsizeMode.END) cell.connect("changed", self._usage_cell_changed_cb) col.pack_start(cell, True) col.set_cell_data_func(cell, self._device_usage_datafunc) # Scroll action config value => string store (dropdowns) store = Gtk.ListStore(str, str) for conf_val in ScrollAction.VALUES: string = ScrollAction.DISPLAY_STRING[conf_val] store.append([conf_val, string]) self._scroll_store = store # TRANSLATORS: Column's data is a dropdown for how the device's # TRANSLATORS: scroll wheel or scroll-gesture events are to be # TRANSLATORS: interpreted normally. col = Gtk.TreeViewColumn( C_( "prefs: devices table: column header", "Scroll...", )) col.set_min_width(100) col.set_resizable(True) col.set_expand(False) self._devices_view.append_column(col) cell = Gtk.CellRendererCombo() cell.set_property("model", self._scroll_store) cell.set_property("text-column", self._USAGE_STRING_COL) cell.set_property("mode", Gtk.CellRendererMode.EDITABLE) cell.set_property("editable", True) cell.set_property("has-entry", False) cell.set_property("ellipsize", Pango.EllipsizeMode.END) cell.connect("changed", self._scroll_cell_changed_cb) col.pack_start(cell, True) col.set_cell_data_func(cell, self._device_scroll_datafunc) # Pretty borders view_scroll = Gtk.ScrolledWindow() view_scroll.set_shadow_type(Gtk.ShadowType.ETCHED_IN) pol = Gtk.PolicyType.AUTOMATIC view_scroll.set_policy(pol, pol) view_scroll.add(self._devices_view) view_scroll.set_hexpand(True) view_scroll.set_vexpand(True) self.attach(view_scroll, 0, 0, 1, 1) self._update_devices_store() self._monitor.devices_updated += self._update_devices_store
def cursor(self): name = self._current_cursor from gui.application import get_app app = get_app() return app.cursors.get_action_cursor(self.ACTION_NAME, name)