def update_image(self): size = self.backend.get_size() pixbuf = gtk2compat.gdk.pixbuf.new(gdk.COLORSPACE_RGB, True, 8, size, size) arr = gdkpixbuf2numpy(pixbuf) self.backend.set_brush_color(*self.app.brush.get_color_hsv()) self.backend.render(arr) if gtk2compat.USE_GTK3: # This seems to work, but is pointless until we can get shaped # windows working. Might need a NumPy RGBA => ARGB oneliner. # # rowstride = arr.strides[0] # surf = cairo.ImageSurface.create_for_data(arr.data, # cairo.FORMAT_ARGB32, # size, size, rowstride) # TODO:FUTURE: Want to be able to do: # # region = gdk.cairo_region_create_from_surface(surf) # # and then use self.shape_combine_region(), but some Cairo structs # aren't wrapped: http://stackoverflow.com/questions/6133622 is # happening as of python-gi-cairo 3.2.2-1~precise and pass else: pixmap, mask = pixbuf.render_pixmap_and_mask() self.image.set_from_pixmap(pixmap, mask) self.shape_combine_mask(mask, 0, 0) self.image.set_from_pixbuf(pixbuf)
def update_image(self): size = self.backend.get_size() pixbuf = gtk2compat.gdk.pixbuf.new(gdk.COLORSPACE_RGB, True, 8, size, size) arr = gdkpixbuf2numpy(pixbuf) self.backend.set_brush_color(*self.app.brush.get_color_hsv()) self.backend.render(arr) if gtk2compat.USE_GTK3: # This seems to work, but is pointless until we can get shaped # windows working. Might need a NumPy RGBA => ARGB oneliner. # # rowstride = arr.strides[0] # surf = cairo.ImageSurface.create_for_data(arr.data, # cairo.FORMAT_ARGB32, # size, size, rowstride) # TODO:FUTURE: Want to be able to do: # # region = gdk.cairo_region_create_from_surface(surf) # # and then use self.shape_combine_region(), but some Cairo structs # aren't wrapped: http://stackoverflow.com/questions/6133622 is # happening as of python-gi-cairo 3.2.2-1~precise and pass else: pixmap, mask = pixbuf.render_pixmap_and_mask() self.image.set_from_pixmap(pixmap, mask) self.shape_combine_mask(mask,0,0) self.image.set_from_pixbuf(pixbuf)
def color_changed_cb(self, widget): rgb = self.cs.get_current_color() rgb = rgb.red, rgb.green, rgb.blue rgb = [int(x / 65535.0 * 255.0) for x in rgb] pixbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, N, N) arr = helpers.gdkpixbuf2numpy(pixbuf) arr[:,:] = rgb self.set_background(pixbuf)
def color_changed_cb(self, widget): rgb = self.cs.get_current_color() rgb = rgb.red, rgb.green, rgb.blue rgb = [int(x / 65535.0 * 255.0) for x in rgb] pixbuf = gui.gtk2compat.gdk.pixbuf.new(gdk.COLORSPACE_RGB, False, 8, N, N) arr = helpers.gdkpixbuf2numpy(pixbuf) arr[:, :] = rgb self.set_background(pixbuf)
def update_image(self): size = self.backend.get_size() pixbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, True, 8, size, size) arr = gdkpixbuf2numpy(pixbuf) self.backend.set_brush_color(*self.app.brush.get_color_hsv()) self.backend.render(arr) pixmap, mask = pixbuf.render_pixmap_and_mask() self.image.set_from_pixmap(pixmap, mask) self.shape_combine_mask(mask,0,0)
def render_background_cb(self, cr, wd, ht, icon_border=None): size = self._backend.get_size() pixbuf = GdkPixbuf.Pixbuf.new( GdkPixbuf.Colorspace.RGB, True, 8, size, size, ) arr = gdkpixbuf2numpy(pixbuf) self._backend.render(arr) self._dx = (wd-size)/2 self._dy = (ht-size)/2 cr.translate(self._dx, self._dy) Gdk.cairo_set_source_pixbuf(cr, pixbuf, 0, 0) cr.paint()
def __init__(self, app, tdw, model, leader=None): self.app = app self.model = model self.ani = animation.Animation(self) CanvasController.__init__(self, tdw) # Current mode observation self.modes.observers.append(self.mode_stack_changed_cb) # Pass on certain actions to other gui.documents. self.followers = [] self.model.frame_observers.append(self.frame_changed_cb) self.model.symmetry_observers.append(self.update_symmetry_toolitem) # Deferred until after the app starts (runs in the first idle- # processing phase) as a workaround for https://gna.org/bugs/?14372 # ([Windows] crash when moving the pen during startup) gobject.idle_add(self.init_pointer_events) gobject.idle_add(self.init_scroll_events) # Input stroke observers self.input_stroke_ended_observers = [] """Callbacks interested in the end of an input stroke. Observers are called with the GTK event as their only argument. This is a good place to listen for "just painted something" events in some cases; app.brush will contain everything needed about the input stroke which is ending. An input stroke is a single button-down, move, button-up action. This sort of stroke is not the same as a brush engine stroke (see ``lib.document``). It is possible that the visible stroke starts earlier and ends later, depending on how the operating system maps pressure to button up/down events. """ self.input_stroke_started_observers = [] """See `self.input_stroke_ended_observers`""" # FIXME: hack, to be removed fname = os.path.join(self.app.datapath, 'backgrounds', '03_check1.png') pixbuf = gdk.pixbuf_new_from_file(fname) self.tdw.neutral_background_pixbuf = tiledsurface.Background( helpers.gdkpixbuf2numpy(pixbuf)) self.zoomlevel_values = [ 1.0 / 16, 1.0 / 8, 2.0 / 11, 0.25, 1.0 / 3, 0.50, 2.0 / 3, # micro 1.0, 1.5, 2.0, 3.0, 4.0, 5.5, 8.0, # normal 11.0, 16.0, 23.0, 32.0, 45.0, 64.0 ] # macro default_zoom = self.app.preferences['view.default_zoom'] self.tdw.scale = default_zoom self.tdw.zoom_min = min(self.zoomlevel_values) self.tdw.zoom_max = max(self.zoomlevel_values) # Device-specific brushes: save at end of stroke self.input_stroke_ended_observers.append(self.input_stroke_ended_cb) self.init_stategroups() if leader is not None: # This is a side controller (e.g. the scratchpad) which plays # follow-the- leader for some events. assert isinstance(leader, Document) leader.followers.append(self) self.action_group = leader.action_group # hack, but needed by tdw else: # This doc owns the Actions which are (sometimes) passed on to # followers to perform. Its model is also the main 'document' # being worked on by the user. self.init_actions() self.init_context_actions() for action in self.action_group.list_actions(): self.app.kbm.takeover_action(action) for action in self.modes_action_group.list_actions(): self.app.kbm.takeover_action(action) self.init_extra_keys() toggle_action = self.app.builder.get_object('ContextRestoreColor') toggle_action.set_active( self.app.preferences['misc.context_restores_color']) #: Saved transformation to allow FitView to be toggled. self.saved_view = None #: Viewport change/manipulation observers. self.view_changed_observers = [] self.view_changed_observers.append(self._view_changed_cb) self._view_changed_notification_srcid = None do_notify = lambda *a: self.notify_view_changed() self.tdw.connect_after("size-allocate", do_notify)
def __init__(self, app, leader=None): self.app = app self.model = lib.document.Document(self.app.brush) self.ani = animation.Animation(self) tdw = tileddrawwidget.TiledDrawWidget(self.app, self.model) CanvasController.__init__(self, tdw) self.modes.observers.append(self.mode_stack_changed_cb) # Pass on certain actions to other gui.documents. self.followers = [] self.model.frame_observers.append(self.frame_changed_cb) self.model.symmetry_observers.append(self.update_symmetry_toolitem) # Deferred until after the app starts (runs in the first idle- # processing phase) as a workaround for https://gna.org/bugs/?14372 # ([Windows] crash when moving the pen during startup) gobject.idle_add(self.init_pointer_events) gobject.idle_add(self.init_scroll_events) # Input stroke observers self.input_stroke_ended_observers = [] """Callbacks interested in the end of an input stroke. Observers are called with the GTK event as their only argument. This is a good place to listen for "just painted something" events in some cases; app.brush will contain everything needed about the input stroke which is ending. An input stroke is a single button-down, move, button-up action. This sort of stroke is not the same as a brush engine stroke (see ``lib.document``). It is possible that the visible stroke starts earlier and ends later, depending on how the operating system maps pressure to button up/down events. """ self.input_stroke_started_observers = [] """See `self.input_stroke_ended_observers`""" # FIXME: hack, to be removed fname = os.path.join(self.app.datapath, "backgrounds", "03_check1.png") pixbuf = gdk.pixbuf_new_from_file(fname) self.tdw.neutral_background_pixbuf = tiledsurface.Background(helpers.gdkpixbuf2numpy(pixbuf)) self.zoomlevel_values = [ 1.0 / 16, 1.0 / 8, 2.0 / 11, 0.25, 1.0 / 3, 0.50, 2.0 / 3, # micro 1.0, 1.5, 2.0, 3.0, 4.0, 5.5, 8.0, # normal 11.0, 16.0, 23.0, 32.0, 45.0, 64.0, ] # macro default_zoom = self.app.preferences["view.default_zoom"] self.tdw.scale = default_zoom self.tdw.zoom_min = min(self.zoomlevel_values) self.tdw.zoom_max = max(self.zoomlevel_values) # Device-specific brushes: save at end of stroke self.input_stroke_ended_observers.append(self.input_stroke_ended_cb) self.init_stategroups() if leader is not None: # This is a side controller (e.g. the scratchpad) which plays # follow-the- leader for some events. assert isinstance(leader, Document) leader.followers.append(self) self.action_group = leader.action_group # hack, but needed by tdw else: # This doc owns the Actions which are (sometimes) passed on to # followers to perform. It's model is also the main 'document' # being worked on by the user. self.init_actions() self.init_context_actions() for action in self.action_group.list_actions(): self.app.kbm.takeover_action(action) for action in self.modes_action_group.list_actions(): self.app.kbm.takeover_action(action) self.init_extra_keys() toggle_action = self.app.builder.get_object("ContextRestoreColor") toggle_action.set_active(self.app.preferences["misc.context_restores_color"]) #: Saved transformation to allow FitView to be toggled. self.saved_view = None #: Viewport change/manipulation observers. self.view_changed_observers = [] self.view_changed_observers.append(self._view_changed_cb) self._view_changed_notification_srcid = None do_notify = lambda *a: self.notify_view_changed() self.tdw.connect_after("size-allocate", do_notify)