def test_buffer(self): rgb_float = Gegl.format("RGB float") rgba_u8 = Gegl.format("RGBA u8") buf_float = Gegl.Buffer(format=rgb_float) buf_u8 = Gegl.Buffer(format=rgba_u8) self.assertEqual("RGB float", Gegl.format_get_name(buf_float.get_property("format"))) self.assertEqual("RGBA u8", Gegl.format_get_name(buf_u8.get_property("format")))
def something(): #MyPaint.init() # Create a brush, load from disk brush = MyPaint.Brush() brush_def = open("brushes/classic/brush.myb").read() brush.from_string(brush_def) # List all settings # TODO: Is there a better way to list all enums with GI? settings = [getattr(MyPaint.BrushSetting, attr) for attr in dir(MyPaint.BrushSetting) if attr.startswith("SETTING_")] print "Available settings: %s\n" % str(settings) # Get info about a given setting setting = MyPaint.BrushSetting.SETTING_RADIUS_LOGARITHMIC info = MyPaint.brush_setting_info(setting) # TODO: rename "def_" to "default" print "Setting: %s\n\t Max: %f \n\t Default: %f \n\t Min: %f" % (info.cname, info.max, info.def_, info.min) print "\t Name: %s\n\t Tooltip: '%s'\n" % (info.get_name(), info.get_tooltip()) # Use the getters so that i18n works # TODO: should be MyPaint.BrushSetting.from_cname # Same with MyPaint.Brush.input_from_cname assert (MyPaint.Brush.setting_from_cname(info.cname) == setting) # Get/Set current base value for the given setting print "Base value is: %f" % brush.get_base_value(setting) brush.set_base_value(setting, 2.0) assert brush.get_base_value(setting) == 2.0 # Get dynamics for given setting inputs = [getattr(MyPaint.BrushInput, a) for a in dir(MyPaint.BrushInput) if a.startswith('INPUT_')] if not brush.is_constant(setting): for input in inputs: mapping_points = brush.get_mapping_n(setting, input) if mapping_points > 1: # If 0, no dynamics for this input points = [brush.get_mapping_point(setting, input, i) for i in range(mapping_points)] print "Has dynamics for input %s:\n%s" % (input, str(points)) # Create a surface to paint on Gegl.init(0, "") surface = MyPaintGegl.TiledSurface() s = surface.interface() print surface.get_buffer() for x, y in [(0.0, 0.0), (100.0, 100.0), (100.0, 200.0)]: dtime = 0.1 # XXX: Important to set correctly for speed calculations s.begin_atomic() brush.stroke_to(s, x, y, pressure=1.0, xtilt=0.0, ytilt=0.0, dtime=dtime) rect = s.end_atomic() print rect.x, rect.y, rect.width, rect.height Gegl.exit()
def test_format(self): rgb_float = Gegl.format("RGB float") rgba_u8 = Gegl.format("RGBA u8") # Just ensure these don't crash str(rgb_float) repr(rgb_float) self.assertEqual("RGB float", Gegl.format_get_name(rgb_float)) self.assertEqual("RGBA u8", Gegl.format_get_name(rgba_u8))
def test_node_properties(self): graph = Gegl.Node() node = graph.create_child("gegl:nop") self.assertEqual("gegl:nop", node.get_property("operation")) node.set_property("operation", "gegl:translate") self.assertEqual("gegl:translate", node.get_property("operation")) default_x = node.get_property("x") default_sampler = node.get_property("sampler") self.assertIsNotNone(default_x) self.assertIsNotNone(default_sampler) node.set_property("x", 10) self.assertEqual(node.get_property("x"), 10) node.set_property("x", -10) self.assertEqual(node.get_property("x"), -10) node.set_property("sampler", Gegl.SamplerType.NEAREST) self.assertEqual(node.get_property("sampler"), Gegl.SamplerType.NEAREST) node.set_property("sampler", "linear") self.assertEqual(node.get_property("sampler"), Gegl.SamplerType.LINEAR) node.set_property("operation", "gegl:nop") self.assertEqual("gegl:nop", node.get_property("operation")) node.set_property("operation", "gegl:translate") self.assertEqual("gegl:translate", node.get_property("operation")) self.assertEqual(node.get_property("x"), default_x) self.assertEqual(node.get_property("sampler"), default_sampler)
def test_create_graph(self): graph = Gegl.Node() color_node = graph.create_child("gegl:color") crop_node = graph.create_child("gegl:crop") self.assertEqual(color_node.get_operation(), "gegl:color") self.assertEqual(crop_node.get_operation(), "gegl:crop") crop_rect = Gegl.Rectangle.new(10, 20, 5, 15) crop_node.set_property("x", crop_rect.x) crop_node.set_property("y", crop_rect.y) crop_node.set_property("width", crop_rect.width) crop_node.set_property("height", crop_rect.height) color_node.connect_to("output", crop_node, "input") self.assertTrue(crop_rect.equal(crop_node.get_bounding_box())) trans_node = graph.create_child("gegl:translate") crop_node.connect_to("output", trans_node, "input") self.assertTrue(crop_rect.equal(trans_node.get_bounding_box())) trans_node.set_property("x", 10) self.assertFalse(crop_rect.equal(trans_node.get_bounding_box())) trans_rect = crop_rect.dup() trans_rect.x += 10 self.assertTrue(trans_rect.equal(trans_node.get_bounding_box()))
def create_graph(self): self.graph = Gegl.Node() self.background_node = self.graph.create_child("gegl:rectangle") self.background_node.set_property('color', Gegl.Color.new("#fff")) self.over = self.graph.create_child("gegl:over") self.over2 = self.graph.create_child("gegl:over") self.opacity = self.graph.create_child("gegl:opacity") self.opacity.set_property('value', 0.5) self.over3 = self.graph.create_child("gegl:over") self.add_prev = self.graph.create_child("gegl:add") self.add_next = self.graph.create_child("gegl:add") self.color_prev = self.graph.create_child("gegl:rectangle") self.color_prev.set_property('color', Gegl.Color.new("#f00")) self.color_next = self.graph.create_child("gegl:rectangle") self.color_next.set_property('color', Gegl.Color.new("#00f")) self.background_node.connect_to("output", self.over, "input") self.over2.connect_to("output", self.over, "aux") self.opacity.connect_to("output", self.over2, "aux") self.over3.connect_to("output", self.opacity, "input") self.add_prev.connect_to("output", self.over3, "input") self.add_next.connect_to("output", self.over3, "aux") self.color_prev.connect_to("output", self.add_prev, "aux") self.color_next.connect_to("output", self.add_next, "aux") self.update_graph()
def test_buffer(self): if gi.__version__ in ("3.14.0"): print "SKIPPED! This test is known to be broken in gi version 3.14.0" print "https://bugzilla.gnome.org/show_bug.cgi?id=741291" # This gi version is known to be broken. # buf_float.get_property("format") returns an integer, # not gobject pointer to the format as it should return rgb_float = Gegl.format("RGB float") rgba_u8 = Gegl.format("RGBA u8") buf_float = Gegl.Buffer(format=rgb_float) buf_u8 = Gegl.Buffer(format=rgba_u8) self.assertEqual("RGB float", Gegl.format_get_name(buf_float.get_property("format"))) self.assertEqual("RGBA u8", Gegl.format_get_name(buf_u8.get_property("format")))
def create_graph(self): self.graph = Gegl.Node() main_over = self.graph.create_child("gegl:over") self.nodes['main_over'] = main_over layer_overs = [] for l in range(self.xsheet.layers_length): over = self.graph.create_child("gegl:over") layer_overs.append(over) self.nodes['layer_overs'] = layer_overs layer_overs[0].connect_to("output", main_over, "input") for over, next_over in zip(layer_overs, layer_overs[1:]): next_over.connect_to("output", over, "input") background_node = self.graph.create_child("gegl:rectangle") background_node.set_property('color', Gegl.Color.new("#fff")) background_node.connect_to("output", layer_overs[-1], "input") self.nodes['background'] = background_node layer_nodes = [] for l in range(self.xsheet.layers_length): nodes = {} current_cel_over = self.graph.create_child("gegl:over") current_cel_over.connect_to("output", layer_overs[l], "aux") nodes['current_cel_over'] = current_cel_over onionskin_overs = [] onionskin_opacities = [] for i in range(self.onionskin_length): over = self.graph.create_child("gegl:over") onionskin_overs.append(over) opacity = self.graph.create_child("gegl:opacity") opacity.set_property('value', 1 - self.onionskin_falloff) onionskin_opacities.append(opacity) over.connect_to("output", opacity, "input") for over, next_opacity in zip(onionskin_overs, onionskin_opacities[1:]): next_opacity.connect_to("output", over, "aux") onionskin_opacities[0].connect_to("output", current_cel_over, "aux") nodes['onionskin'] = {} nodes['onionskin']['overs'] = onionskin_overs nodes['onionskin']['opacities'] = onionskin_opacities layer_nodes.append(nodes) self.nodes['layer_nodes'] = layer_nodes self.update_graph()
def check_operations(required_ops): known_ops = Gegl.list_operations() missing_ops = [] for op in required_ops: if not op in known_ops: print("Could not find required operation:", op) missing_ops.append(op) return not missing_ops
def test_color_op(self): node = Gegl.Node() node.set_property("operation", "gegl:color") node.set_property("format", Gegl.format("RGBA u8")) self.assertEqual(Gegl.format("RGBA u8"), node.get_property("format")) self.assertEqual("RGBA u8", Gegl.format_get_name(node.get_property("format"))) node.set_property("format", Gegl.format("RGBA float")) self.assertEqual(Gegl.format("RGBA float"), node.get_property("format")) self.assertEqual("RGBA float", Gegl.format_get_name(node.get_property("format")))
def create_graph(self): self.graph = Gegl.Node() self.add = self.graph.create_child("gegl:add") self.color = self.graph.create_child("gegl:rectangle") self.color.set_property('color', Gegl.Color.new("#f00")) self.image_node = self.graph.create_child("gegl:load") self.image_node.set_property('path', 'test.png') self.color.connect_to("output", self.add, "aux") self.image_node.connect_to("output", self.add, "input")
def __init__(self): self.brush = MyPaint.Brush() self.brush.from_defaults() self.gegl_surface = MyPaintGegl.TiledSurface() self.surface = self.gegl_surface.interface() self.graph = Gegl.Node() self.button_pressed = False self.last_event = (0.0, 0.0, 0.0) # (x, y, time) self.init_ui()
def __init__(self): self.brush_info = brush.BrushInfo( open('tests/brushes/charcoal.myb').read()) self.brush_info.set_color_rgb((0.0, 0.0, 0.0)) self.brush = brush.Brush(self.brush_info) self.surface = tiledsurface.GeglSurface() self.display_node = self.surface.get_node() self.graph = Gegl.Node() self.button_pressed = False self.last_event = (0.0, 0.0, 0.0) # (x, y, time) self.init_ui()
def __init__(self): self.brush = MyPaint.Brush() self.gegl_surface = MyPaintGegl.TiledSurface() self.surface = self.gegl_surface.interface() self.graph = Gegl.Node() self.display_node = self.graph.create_child("gegl:buffer-source") # FIXME: does not seem to have any effect print self.gegl_surface.get_buffer() #self.display_node.set_property("buffer", self.gegl_surface.get_buffer()) self.button_pressed = False self.last_event = (0.0, 0.0, 0.0) # (x, y, time) self.init_ui()
def test_buffer(self): rgb_float = Gegl.format("RGB float") rgba_u8 = Gegl.format("RGBA u8") buf_float = Gegl.Buffer(format=rgb_float) buf_u8 = Gegl.Buffer(format=rgba_u8) self.assertEqual( "RGB float", Gegl.format_get_name(buf_float.get_property("format"))) self.assertEqual("RGBA u8", Gegl.format_get_name(buf_u8.get_property("format")))
def test_buffer(self): print("SKIPPED! This test is known to be broken in gi version >=3.14.0") print("https://gitlab.gnome.org/GNOME/pygobject/issues/93") return 0 # buf_float.get_property("format") returns an integer, # not gobject pointer to the format as it should rgb_float = Gegl.format("RGB float") rgba_u8 = Gegl.format("RGBA u8") buf_float = Gegl.Buffer(format=rgb_float) buf_u8 = Gegl.Buffer(format=rgba_u8) self.assertEqual("RGB float", Gegl.format_get_name(buf_float.get_property("format"))) self.assertEqual("RGBA u8", Gegl.format_get_name(buf_u8.get_property("format")))
def main(): # Parse options parser = argparse.ArgumentParser(description='An argparse snippet.') parser.add_argument("--infile", "-i", help="the input file", required=True, metavar="STRING") parser.add_argument("--outfile", "-o", help="the output file", required=True, metavar="STRING") args = parser.parse_args() infile = args.infile outfile = args.outfile # GEGL ###################################### gegl.init([]) #print(gegl.list_operations()) # Make nodes node1 = gegl.Node() node2 = gegl.Node() # png-load node3 = gegl.Node() # invert node4 = gegl.Node() # png-save # Set properties node2.set_property("operation", "gegl:png-load") node2.set_property("path", infile) node3.set_property("operation", "gegl:invert") node4.set_property("operation", "gegl:png-save") node4.set_property("path", outfile) # Make the graph node1.add_child(node2) node1.add_child(node3) node1.add_child(node4) node2.connect_to("output", node3, "input") node3.connect_to("output", node4, "input") # Process node4.process()
def create_graph(self): self.graph = Gegl.Node() self.background_node = self.graph.create_child("gegl:rectangle") self.background_node.set_property('color', Gegl.Color.new("#fff")) self.over = self.graph.create_child("gegl:over") self.over2 = self.graph.create_child("gegl:over") self.opacity_prev1 = self.graph.create_child("gegl:opacity") self.opacity_prev1.set_property('value', 0.5) self.over3 = self.graph.create_child("gegl:over") self.opacity_prev2 = self.graph.create_child("gegl:opacity") self.opacity_prev2.set_property('value', 0.5) self.background_node.connect_to("output", self.over, "input") self.over2.connect_to("output", self.over, "aux") self.opacity_prev1.connect_to("output", self.over2, "aux") self.over3.connect_to("output", self.opacity_prev1, "input") self.opacity_prev2.connect_to("output", self.over3, "aux") self.update_graph()
def test_color_get_components(self): c = Gegl.Color() c.set_components(Gegl.format("RGB float"), [1.0, 0.0, 0.0]) values = c.get_components(Gegl.format("RGB float")) self.assertAlmostEqualComps(values, [1.0, 0.0, 0.0]) values = c.get_components(Gegl.format("RGBA double")) self.assertAlmostEqualComps(values, [1.0, 0.0, 0.0, 1.0]) values = c.get_components(Gegl.format("RGBA float")) self.assertAlmostEqualComps(values, [1.0, 0.0, 0.0, 1.0]) values = c.get_components(Gegl.format("RGBA u32")) self.assertEqual(values, [float(0xFFFFFFFF), 0.0, 0.0, float(0xFFFFFFFF)]) values = c.get_components(Gegl.format("RGBA u16")) self.assertEqual(values, [float(0xFFFF), 0.0, 0.0, float(0xFFFF)]) values = c.get_components(Gegl.format("RGBA u8")) self.assertEqual(values, [float(0xFF), 0.0, 0.0, float(0xFF)]) c.set_components(Gegl.format("R'G'B' u8"), [128, 0, 128]) values = c.get_components(Gegl.format("R'G'B'A u8")) self.assertEqual(values, [float(128), 0.0, float(128), float(255)]) c.set_components(Gegl.format("YA double"), [0.5, 0.5]) values = c.get_components(Gegl.format("RGBA double")) self.assertAlmostEqualComps(values, [0.5, 0.5, 0.5, 0.5]) values = c.get_components(Gegl.format("RaGaBaA double")) self.assertAlmostEqualComps(values, [0.25, 0.25, 0.25, 0.5])
def test_number_of_children(self): children = self.graph.get_children() self.assertEqual(len(children), 2) def test_child_operation(self): children = self.graph.get_children() self.assertEqual(children[0].get_operation(), "gegl:crop") self.assertEqual(children[1].get_operation(), "gegl:invert") class TestGeglNodeSaveXml(unittest.TestCase): def setUp(self): self.graph = Gegl.Node.new() # Easiest way to test to_xml when we can't yet build graphs programatically def test_load_save_roundtrip(self): graph = Gegl.Node.new_from_xml(invert_crop_xml, "") output = graph.to_xml("") self.assertEqual(output, invert_crop_xml) if __name__ == '__main__': Gegl.init(0, ""); #print dir(Gegl.Node) unittest.main()
def test_init_exit(self): Gegl.init(0, "") Gegl.exit()
# Get/Set current base value for the given setting print "Base value is: %f" % brush.get_base_value(setting) brush.set_base_value(setting, 2.0) assert brush.get_base_value(setting) == 2.0 # Get dynamics for given setting inputs = [getattr(MyPaint.BrushInput, a) for a in dir(MyPaint.BrushInput) if a.startswith("INPUT_")] if not brush.is_constant(setting): for input in inputs: mapping_points = brush.get_mapping_n(setting, input) if mapping_points > 1: # If 0, no dynamics for this input points = [brush.get_mapping_point(setting, input, i) for i in range(mapping_points)] print "Has dynamics for input %s:\n%s" % (input, str(points)) # Create a surface to paint on Gegl.init(0, "") surface = MyPaintGegl.TiledSurface() s = surface.interface() print surface.get_buffer() for x, y in [(0.0, 0.0), (100.0, 100.0), (100.0, 200.0)]: dtime = 0.1 # XXX: Important to set correctly for speed calculations s.begin_atomic() brush.stroke_to(s, x, y, pressure=1.0, xtilt=0.0, ytilt=0.0, dtime=dtime) rect = s.end_atomic() print rect.x, rect.y, rect.width, rect.height Gegl.exit()
def test_300_exit(self): Gegl.exit()
# this binding would itself just import things using GI # This is a very minimal example, that doesnt even construct the graph and # instantiate the nodes, but cheats and uses XML to get at an intial graph. # it expect a file /tmp/lena.png to exist def locate_by_type(self, opname): for i in self.get_children(): if i.get_operation() == opname: return i Gegl.Node.locate_by_type = locate_by_type if __name__ == '__main__': Gegl.init(0,"") # < that is rather ugly node = Gegl.Node.new_from_xml(""" <gegl> <gegl:save path='/tmp/output.png'/> <gegl:crop width='512' height='512'/> <gegl:over > <gegl:translate x='30' y='30'/> <gegl:dropshadow radius='1.5' x='3' y='3'/> <gegl:text size='80' color='white' ><params><param name='string'>GEGL I R</param></params></gegl:text> </gegl:over> <gegl:unsharp-mask std-dev='30'/> <gegl:load path='/tmp/lena.png'/>
Intended as bootstrap for building larger scripts. License: Creative Commons - Atribution required. Author: João S. O. Bueno """ import sys from gi.repository import Gegl as gegl try: origin, target = sys.argv[1:3] except IndexError: sys.stderr.write("Usage: %s origin_png target_png" % __file__) sys.exit(1) gegl.init([]) ops = gegl.list_operations() x = gegl.Node() y = gegl.Node() y.set_property("operation", "gegl:png-load") y.set_property("path", origin) x.add_child(y) z = gegl.Node() z.set_property("operation", "gegl:invert") x.add_child(z) w = gegl.Node()
def test_100_init(self): Gegl.init(None)
def list_operations(filter=""): ops = _gegl.list_operations() return [op for op in ops if filter in op]
# TODO: should be MyPaint.BrushSetting.from_cname # Same with MyPaint.Brush.input_from_cname assert (MyPaint.Brush.setting_from_cname(info.cname) == setting) # Get/Set current base value for the given setting print("Base value is: %f" % brush.get_base_value(setting)) brush.set_base_value(setting, 2.0) assert brush.get_base_value(setting) == 2.0 # Get dynamics for given setting inputs = [getattr(MyPaint.BrushInput, a) for a in dir(MyPaint.BrushInput) if a.startswith('INPUT_')] if not brush.is_constant(setting): for input in inputs: mapping_points = brush.get_mapping_n(setting, input) if mapping_points > 1: # If 0, no dynamics for this input points = [brush.get_mapping_point(setting, input, i) for i in range(mapping_points)] print("Has dynamics for input %s:\n%s" % (input, str(points))) if __name__ == '__main__': Gegl.init([]) Gtk.init([]) app = Application() list_settings() app.run() Gegl.exit()
def test_init(self): Gegl.init(0, "")
#!/usr/bin/env python from gi.repository import Gegl import sys if __name__ == '__main__': Gegl.init(sys.argv) ptn = Gegl.Node() # Disable caching on all child nodes ptn.set_property("dont-cache", True) # Create our background buffer. A gegl:color node would # make more sense, we just use a buffer here as an example. background_buffer = Gegl.Buffer.new("RGBA float", 246, -10, 276, 276) white = Gegl.Color.new("#FFF") background_buffer.set_color(background_buffer.get_extent(), white) src = ptn.create_child("gegl:load") src.set_property("path", "data/surfer.png") crop = ptn.create_child("gegl:crop") crop.set_property("x", 256) crop.set_property("y", 0) crop.set_property("width", 256) crop.set_property("height", 256) buffer_src = ptn.create_child("gegl:buffer-source") buffer_src.set_property("buffer",background_buffer)
# coding: utf-8 # Author: João S. O. Bueno import sys import gi gi.require_version("Gegl", "0.4") from gi.repository import Gegl as _gegl from .path import Path DEFAULT_OP_NAMESPACE = "gegl" _gegl.init(sys.argv[1:]) def list_operations(filter=""): ops = _gegl.list_operations() return [op for op in ops if filter in op] class OpNode(object): """ Wrapper for a GEGL node with an operation You can access OpNode._node attribute for raw access to the GEGL node as exposed by pygobject """ def __init__(self, operation, **kw): object.__setattr__(self, "_node", _gegl.Node()) # cyclic - TODO: replace with weakref self._node._wrapper = self self.operation = operation for key, value in kw.items(): setattr(self, key, value)
def run(self, procedure, run_mode, image, drawable, args, run_data): if run_mode == Gimp.RunMode.INTERACTIVE: gi.require_version('Gtk', '3.0') from gi.repository import Gtk gi.require_version('Gdk', '3.0') from gi.repository import Gdk GimpUi.ui_init("palette-offset.py") dialog = GimpUi.Dialog(use_header_bar=True, title=_("Exercise a goat (Python 3)"), role="goat-exercise-Python3") dialog.add_button("_Cancel", Gtk.ResponseType.CANCEL) dialog.add_button("_Source", Gtk.ResponseType.APPLY) dialog.add_button("_OK", Gtk.ResponseType.OK) geometry = Gdk.Geometry() geometry.min_aspect = 0.5 geometry.max_aspect = 1.0 dialog.set_geometry_hints(None, geometry, Gdk.WindowHints.ASPECT) box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2) dialog.get_content_area().add(box) box.show() # XXX We use printf-style string for sharing the localized # string. You may just use recommended Python format() or # any style you like in your plug-ins. head_text = ("This plug-in is an exercise in '%s' to " "demo plug-in creation.\nCheck out the last " "version of the source code online by clicking " "the \"Source\" button." % ("Python 3")) label = Gtk.Label(label=head_text) box.pack_start(label, False, False, 1) label.show() contents = None # Get the file contents Python-style instead of using # GLib.file_get_contents() which returns bytes result, and # when converting to string, get newlines as text contents. # Rather than wasting time to figure this out, use Python # core API! with open(os.path.realpath(__file__), 'r') as f: contents = f.read() if contents is not None: scrolled = Gtk.ScrolledWindow() scrolled.set_vexpand(True) box.pack_start(scrolled, True, True, 1) scrolled.show() view = Gtk.TextView() view.set_wrap_mode(Gtk.WrapMode.WORD) view.set_editable(False) buffer = view.get_buffer() buffer.set_text(contents, -1) scrolled.add(view) view.show() while (True): response = dialog.run() if response == Gtk.ResponseType.OK: dialog.destroy() break elif response == Gtk.ResponseType.APPLY: url = "https://gitlab.gnome.org/GNOME/gimp/-/blob/master/plug-ins/goat-exercises/goat-exercise-py3.py" Gio.app_info_launch_default_for_uri(url, None) continue else: dialog.destroy() return procedure.new_return_values( Gimp.PDBStatusType.CANCEL, GLib.Error()) intersect, x, y, width, height = drawable.mask_intersect() if intersect: Gegl.init(None) buffer = drawable.get_buffer() shadow_buffer = drawable.get_shadow_buffer() graph = Gegl.Node() input = graph.create_child("gegl:buffer-source") input.set_property("buffer", buffer) invert = graph.create_child("gegl:invert") output = graph.create_child("gegl:write-buffer") output.set_property("buffer", shadow_buffer) input.link(invert) invert.link(output) output.process() # This is extremely important in bindings, since we don't # unref buffers. If we don't explicitly flush a buffer, we # may left hanging forever. This step is usually done # during an unref(). shadow_buffer.flush() drawable.merge_shadow(True) drawable.update(x, y, width, height) Gimp.displays_flush() return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error())
def run(self, procedure, args, data): runmode = args.index(0) if runmode == Gimp.RunMode.INTERACTIVE: gi.require_version('Gtk', '3.0') from gi.repository import Gtk gi.require_version('Gdk', '3.0') from gi.repository import Gdk Gimp.ui_init("palette-offset.py", False) dialog = Gimp.Dialog(use_header_bar=True, title=_("Exercise a goat (Python 3)"), role="goat-exercise-Python3") dialog.add_button("_Cancel", Gtk.ResponseType.CANCEL) dialog.add_button("_Source", Gtk.ResponseType.APPLY) dialog.add_button("_OK", Gtk.ResponseType.OK) geometry = Gdk.Geometry(); geometry.min_aspect = 0.5; geometry.max_aspect = 1.0; dialog.set_geometry_hints(None, geometry, Gdk.WindowHints.ASPECT); box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2) dialog.get_content_area().add(box) box.show() # XXX We use printf-style string for sharing the localized # string. You may just use recommended Python format() or # any style you like in your plug-ins. head_text=("This plug-in is an exercise in '%s' to " "demo plug-in creation.\nCheck out the last " "version of the source code online by clicking " "the \"Source\" button." % ("Python 3")) label = Gtk.Label(label=head_text) box.pack_start(label, False, False, 1) label.show() contents = None # Get the file contents Python-style instead of using # GLib.file_get_contents() which returns bytes result, and # when converting to string, get newlines as text contents. # Rather than wasting time to figure this out, use Python # core API! with open(os.path.realpath(__file__), 'r') as f: contents = f.read() if contents is not None: scrolled = Gtk.ScrolledWindow() scrolled.set_vexpand (True) box.pack_start(scrolled, True, True, 1) scrolled.show() view = Gtk.TextView() view.set_wrap_mode(Gtk.WrapMode.WORD) view.set_editable(False) buffer = view.get_buffer() buffer.set_text(contents, -1) scrolled.add(view) view.show() while (True): response = dialog.run() if response == Gtk.ResponseType.OK: dialog.destroy() break elif response == Gtk.ResponseType.APPLY: Gio.app_info_launch_default_for_uri(url, None) continue else: dialog.destroy() return procedure.new_return_values(Gimp.PDBStatusType.CANCEL, GLib.Error()) # Parameters are not working fine yet because properties should # be Gimp.ImageID/Gimp.DrawableID but we can't make these with # pygobject. Until I figure out how to make it work, you could # uncomment the following lines instead of using the args value. #images = Gimp.image_list() #image_id = images[0] #drawable_id = Gimp.image_get_active_drawable(image_id) drawable_id = args.index(2) success, x, y, width, height = Gimp.drawable_mask_intersect(drawable_id); if success: Gegl.init(None); buffer = Gimp.drawable_get_buffer(drawable_id) shadow_buffer = Gimp.drawable_get_shadow_buffer(drawable_id) graph = Gegl.Node() input = graph.create_child("gegl:buffer-source") input.set_property("buffer", buffer) invert = graph.create_child("gegl:invert") output = graph.create_child("gegl:write-buffer") output.set_property("buffer", shadow_buffer) input.link(invert) invert.link(output) output.process() # This is extremely important in bindings, since we don't # unref buffers. If we don't explicitly flush a buffer, we # may left hanging forever. This step is usually done # during an unref(). shadow_buffer.flush() Gimp.drawable_merge_shadow(drawable_id, True) Gimp.drawable_update(drawable_id, x, y, width, height) Gimp.displays_flush() else: retval = procedure.new_return_values(Gimp.PDBStatusType.CALLING_ERROR, GLib.Error("No pixels to process in the selected area.")) return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error())
def test_200_config_defaults(self): gegl_config = Gegl.config() # Some default that are unlikely to change self.assertEqual(gegl_config.props.quality, 1.0)
chooser.set_current_folder("brushes/deevad") response = chooser.run() if response == Gtk.ResponseType.OK: brush_settings = open(chooser.get_filename()).read() self.brush_info.load_from_string(brush_settings) chooser.destroy() def color_change_handler(self, widget): c = widget.get_current_color() rgb = (c.red/65535.0, c.green/65535.0, c.blue/65535.0) self.brush_info.set_color_rgb(rgb) if __name__ == '__main__': Gegl.init(0, "") Gtk.init([]) app = MyPaintGeglApplication() #draw_test_data(app.surface, app.brush) # TEMP: #app.save_as_png("mypaint-gegl.png") app.run()
def test_200_config_defaults(self): gegl_config = Gegl.config() # Some default that are unlikely to change self.assertEqual(gegl_config.props.quality, 1.0) self.assertEqual(gegl_config.get_property('tile-width'), 128) self.assertEqual(gegl_config.get_property('tile-height'), 64)
# TODO: should be MyPaint.BrushSetting.from_cname # Same with MyPaint.Brush.input_from_cname assert (MyPaint.Brush.setting_from_cname(info.cname) == setting) # Get/Set current base value for the given setting print "Base value is: %f" % brush.get_base_value(setting) brush.set_base_value(setting, 2.0) assert brush.get_base_value(setting) == 2.0 # Get dynamics for given setting inputs = [getattr(MyPaint.BrushInput, a) for a in dir(MyPaint.BrushInput) if a.startswith('INPUT_')] if not brush.is_constant(setting): for input in inputs: mapping_points = brush.get_mapping_n(setting, input) if mapping_points > 1: # If 0, no dynamics for this input points = [brush.get_mapping_point(setting, input, i) for i in range(mapping_points)] print "Has dynamics for input %s:\n%s" % (input, str(points)) if __name__ == '__main__': Gegl.init([]) Gtk.init([]) app = Application() list_settings() app.run() Gegl.exit()
#!/usr/bin/env python from gi.repository import Gegl from gi.repository import Gtk from application import Application Gegl.init([]) Gtk.init([]) application = Application() application.run()
def test_new_color_string(self): Gegl.Color(string="rgba(0.6, 0.6, 0.6, 1.0)")
self.assertFalse(crop_rect.equal(trans_node.get_bounding_box())) trans_rect = crop_rect.dup() trans_rect.x += 10 self.assertTrue(trans_rect.equal(trans_node.get_bounding_box())) class TestGeglXml(unittest.TestCase): def test_load_xml(self): graph = Gegl.Node.new_from_xml(invert_crop_xml, "") children = graph.get_children() self.assertEqual(len(children), 2) self.assertEqual(children[0].get_operation(), "gegl:crop") self.assertEqual(children[1].get_operation(), "gegl:invert-linear") def test_load_save_roundtrip(self): graph = Gegl.Node.new_from_xml(invert_crop_xml, "") output = graph.to_xml("") self.assertEqual(output, invert_crop_xml) if __name__ == '__main__': Gegl.init(None); unittest.main() Gegl.exit()
# This is a very minimal example, that doesnt even construct the graph and # instantiate the nodes, but cheats and uses XML to get at an intial graph. # it expect a file /tmp/lena.png to exist def locate_by_type(self, opname): for i in self.get_children(): if i.get_operation() == opname: return i Gegl.Node.locate_by_type = locate_by_type if __name__ == '__main__': Gegl.init(0, "") # < that is rather ugly node = Gegl.Node.new_from_xml( """ <gegl> <gegl:save path='/tmp/output.png'/> <gegl:crop width='512' height='512'/> <gegl:over > <gegl:translate x='30' y='30'/> <gegl:dropshadow radius='1.5' x='3' y='3'/> <gegl:text size='80' color='white' ><params><param name='string'>GEGL I R</param></params></gegl:text> </gegl:over> <gegl:unsharp-mask std-dev='30'/>
self.assertFalse(crop_rect.equal(trans_node.get_bounding_box())) trans_rect = crop_rect.dup() trans_rect.x += 10 self.assertTrue(trans_rect.equal(trans_node.get_bounding_box())) class TestGeglXml(unittest.TestCase): def test_load_xml(self): graph = Gegl.Node.new_from_xml(invert_crop_xml, "") children = graph.get_children() self.assertEqual(len(children), 2) self.assertEqual(children[0].get_operation(), "gegl:crop") self.assertEqual(children[1].get_operation(), "gegl:invert-linear") def test_load_save_roundtrip(self): graph = Gegl.Node.new_from_xml(invert_crop_xml, "") output = graph.to_xml("") self.assertEqual(output, invert_crop_xml) if __name__ == '__main__': Gegl.init(None) unittest.main() Gegl.exit()
def test_number_of_children(self): children = self.graph.get_children() self.assertEqual(len(children), 2) def test_child_operation(self): children = self.graph.get_children() self.assertEqual(children[0].get_operation(), "gegl:crop") self.assertEqual(children[1].get_operation(), "gegl:invert") class TestGeglNodeSaveXml(unittest.TestCase): def setUp(self): self.graph = Gegl.Node.new() # Easiest way to test to_xml when we can't yet build graphs programatically def test_load_save_roundtrip(self): graph = Gegl.Node.new_from_xml(invert_crop_xml, "") output = graph.to_xml("") self.assertEqual(output, invert_crop_xml) if __name__ == '__main__': Gegl.init(0, "") #print dir(Gegl.Node) unittest.main()
def init_ui(self): window = Gtk.Window() window.connect("destroy", self.destroy_cb) window.connect("size-allocate", self.size_allocate_cb) view_widget = GeglGtk.View() view_widget.set_node(self.add) view_widget.set_autoscale_policy(GeglGtk.ViewAutoscale.DISABLED) view_widget.set_size_request(800, 400) window.add(view_widget) window.show_all() def run(self): return Gtk.main() def destroy_cb(self, *ignored): Gtk.main_quit() def size_allocate_cb(self, widget, allocation): self.color.set_property("width", allocation.width) self.color.set_property("height", allocation.height) if __name__ == '__main__': Gegl.init([]) Gtk.init([]) app = TintApp() app.run()
def test_100_init(self): Gegl.init(None);