Skip to content

utils_gui

Tom SF Haines edited this page Mar 30, 2016 · 1 revision

GUI Utilities

Overview

utils_gui

Bunch of helpers for making GUIs - basically just a Viewer widget for use in GTK that provides a suitably sexy image viewer, with zooming, overlays etc.

viewer.py - The actual viewer object, to be used as a widget.

viewport_layer.py - Some helper classes used by the Viewer object, most importantly the Layer interface that everything that can draw to the image has to impliment.

tile_image.py - Layer object for use with a Viewer that draws an actual image; can do alpha matting.

tile_mask.py - Layer object that draws a colour for each label in a binary mask; alpha is supported.

tile_value.py - Layer object that does the same as the above but for an arbitrary set of labels.

reticle_overlay.py - Draws a reticle over the image, identifying the center.

readme.txt - This file, which is copied into the html documentation.

make_doc.py - Code that generates the html documentation.


Classes

Viewer(DrawingArea, Widget, Widget, InitiallyUnowned, Object, Object, GObject, ImplementorIface, Buildable, GInterface, object)

:Constructors:

::

DrawingArea(**properties)
new()

_unsupported_data_method(self, *args, **kargs) None

_unsupported_method(self, *args, **kargs) None

add_layer(self, layer) Adds a layer to the end of the layer list, returns an id you can use to delete it.

bind_property(?) bind_property(self, source_property:str, target:GObject.Object, target_property:str, flags:GObject.BindingFlags)

bind_property_full(self, *args, **kargs) bind_property_full(self, source_property:str, target:GObject.Object, target_property:str, flags:GObject.BindingFlags, transform_to:GObject.Closure, transform_from:GObject.Closure)

chain(?) None

clear_layers(self) Removes all existing layers, so you can create a new stack.

compat_control(self, *args, **kargs) compat_control(what:int, data)

connect(?) None

connect_after(?) None

connect_object(?) None

connect_object_after(?) None

del_layer(self, ident) Terminates a layer given an ident.

disconnect(*args, **kwargs) None

disconnect_by_func(?) None

drag_dest_set_target_list(self, target_list) drag_dest_set_target_list(self, target_list:Gtk.TargetList=None)

drag_source_set_target_list(self, target_list) drag_source_set_target_list(self, target_list:Gtk.TargetList=None)

emit(?) None

emit_stop_by_name(self, detailed_signal) Deprecated, please use stop_emission_by_name.

force_floating(self, *args, **kargs) force_floating(self)

freeze_notify(self) Freezes the object's property-changed notification queue.

:returns: A context manager which optionally can be used to automatically thaw notifications.

This will freeze the object so that "notify" signals are blocked until the thaw_notify() method is called.

.. code-block:: python

with obj.freeze_notify():
    pass

get_bg(self) Returns None if no background colour is selected, or a tuple (r,g,b) if it is.

get_data(self, *args, **kargs) get_data(self, key:str)

get_properties(?) None

get_property(?) get_property(self, property_name:str, value:GObject.Value)

get_qdata(self, *args, **kargs) get_qdata(self, quark:int)

get_viewport(self) Returns the current viewport, or None if it is not defined.

handler_block(obj, handler_id) Blocks the signal handler from being invoked until handler_unblock() is called.

:param GObject.Object obj: Object instance to block handlers for. :param int handler_id: Id of signal to block. :returns: A context manager which optionally can be used to automatically unblock the handler:

.. code-block:: python

with GObject.signal_handler_block(obj, id):
    pass

handler_block_by_func(?) None

handler_disconnect(*args, **kwargs) None

handler_is_connected(*args, **kwargs) None

handler_unblock(*args, **kwargs) None

handler_unblock_by_func(?) None

interface_find_property(self, *args, **kargs) interface_find_property(g_iface, property_name:str)

interface_install_property(self, *args, **kargs) interface_install_property(g_iface, pspec:GObject.ParamSpec)

interface_list_properties(self, *args, **kargs) interface_list_properties(g_iface) -> n_properties_p:int

move(self, off_x, off_y) Moves the view, with the offset in view pixels.

notify_by_pspec(self, *args, **kargs) notify_by_pspec(self, pspec:GObject.ParamSpec)

one_to_one(self) Adjusts the viewport such that it is a one to one between the viewing region and the actual window.

ref(self, *args, **kargs) ref(self)

ref_sink(self, *args, **kargs) ref_sink(self)

replace_data(self, *args, **kargs) replace_data(self, key:str, oldval=None, newval=None, destroy:GLib.DestroyNotify=None, old_destroy:GLib.DestroyNotify=None)

replace_qdata(self, *args, **kargs) replace_qdata(self, quark:int, oldval=None, newval=None, destroy:GLib.DestroyNotify=None, old_destroy:GLib.DestroyNotify=None)

reset_view(self) Resets the zoom and pan, so that it reverts to the default.

run_dispose(self, *args, **kargs) run_dispose(self)

set_bg(self, r, g, b) Sets a background colour to be drawn before all the layers - whilst usually reuired this defaults to off. You provide a colour as the usual three channels in the rnage [0,1], or None to disable.

set_data(self, *args, **kargs) set_data(self, key:str, data)

set_drag_col(self, r, g, b) Sets a colour for a line to be drawn when dragging; if no colour is provided (The default) then no line is drawn. Standard three channels, in range [0,1]. Only works if there is a dragging function, set with set_on_drag.

set_on_click(self, func) Sets a function (Pass None if you want to disable it) that will be called when the user clicks in the viewport with the lmb. It will receive two parameters - the x and y (floating point) coordinates of where was clicked. All will be in the unscaled coordinate system.

set_on_drag(self, func) Sets a function (Pass None if you want to disable it) that will be called when the user drags from one point in the viewport to another with the lmb down. It will receive four parameters - the x and y of the start and then the x and y of the end (All floating point). All will be in the unscaled coordinate system.

set_on_draw(self, func) Sets a function (Pass None if you want to disable it) that will be called when the display is redrawn - it gets no parameters.

set_on_move(self, func) Sets a function (Pass None if you want to disable it) that will be called when the user moves their mouse. It will be given (x,y) in the unscaled coordinate system as inputs; it should return True if it wants the screen to redrawn as a result of the movement.

set_on_paint(self, func) Sets a function (Pass None to disable) that is called when dragging across the image with the lmb down for each on move sample. Input will be (start x, start y, end x, end y) in the unscaled coordinate system; return True to redraw the screen, False to not.

set_properties(?) None

set_property(?) set_property(self, property_name:str, value:GObject.Value)

steal_data(self, *args, **kargs) steal_data(self, key:str)

steal_qdata(self, *args, **kargs) steal_qdata(self, quark:int)

stop_emission(self, detailed_signal) Deprecated, please use stop_emission_by_name.

stop_emission_by_name(*args, **kwargs) None

translate_coordinates(*args, **kwargs) translate_coordinates(self, dest_widget:Gtk.Widget, src_x:int, src_y:int) -> dest_x:int, dest_y:int

unref(self, *args, **kargs) unref(self)

watch_closure(self, *args, **kargs) watch_closure(self, closure:GObject.Closure)

weak_ref(?) None

zoom(self, way) True to zoom in, False to zoom out, or a number for fine control - positive to zoom in.

Layer()

Defines an interface that layers have to impliment - basically this allows them to render to the drawing area, and influence things such as its default size.

draw(self, ctx, vp) Draws to the provided cairo context (ctx) the contents defined by the provided viewport (vp). Note that it could be in a stack with other layers - it probably shouldn't be clearing the background.

get_size(self) Returns the tuple (height, width), the default size of the layer (Origin is assumed to be (0,0)). This basically defines the area in which a Viewport can be expected to show something interesting.

Viewport()

Defines a view onto a renderable region. You have the width and height of the window into which to render - these are always integers; and the start and end coordinates of a viewport for you to render into that window. This exists to be provided to a draw method with a cairo context. Tradition dictates that the aspect ratio of the window and viewport be identical - a renderer is allowed to operate under that assumption.

original_to_view(self, x, y) None

original_to_view_scale(self, scale) None

view_to_original(self, x, y) None

TileImage(Layer)

A wrapper around an image, that breaks it into tiles for accelerated rendering. Has full support for scaling, so you can get tiles at any scale you desire.

draw(self, ctx, vp) Draws the image into the provided context, matching the provided viewport.

fetch_tile(self, scale, bx, by, extra = 0) Fetches a tile, given a scale (Multiplication of original dimensions.) and base coordinates (bx, by) - the tile will be the size provided on class initialisation. This request is going through a caching layer, which will hopefuly have the needed tile. If not it will be generated and the tile that has been used the least recently thrown away.

from_array(self, image) Replaces the current image, after being given an array of uint8, [y, x, c], where alpha is c=3, blue is c=0, green is c=1 and red is c=2.

get_interpolate(self) Returns True if the image is interpolated, False if it is not.

get_original(self) Returns the original image, as an ImageSurface.

get_size(self) Returns the tuple (height, width) for the original size.

get_tint(self) Returns the tint strength used when drawing the image.

load(self, fn) Replaces the current image with a new one. You can provide none to get a default image, as standin until you load a real image.

set_blank(self, width = 640, height = 480, r = 1.0, g = 1.0, b = 1.0, a = 1.0) Allows you to set it up to contain a blank image, with the given colours and alpha.

set_interpolate(self, interpolate) True to interpolate, False to not. Defaults to True

set_tint(self, t) Sets a tint, that is only used during drawing - essentially fades out the image by interpolating it towards white, with the original image at t=0.0, and just white at t=1.0

TileMask(Layer)

A wrapper for rendering a mask, represented as a boolean numpy array. Allows you to select a colour for True and a colour for False, or allow the background to show through for either. Has a tile cache, to make it suitably fast to render.

draw(self, ctx, vp) Draws the mask into the provided context, matching the provided viewport.

fetch_tile(self, scale, bx, by, extra = 0) Fetches a tile, given a scale (Multiplication of original dimensions.) and base coordinates (bx, by) - the tile will be the size provided on class initialisation. This request is going through a caching layer, which will hopefuly have the needed tile. If not it will be generated and the tile that has been used the least recently thrown away.

get_false(self) Returns the colour used for the False region of the mask, or None if it is transparent.

get_interpolate(self) Returns True if the mask is interpolated, False if it is not.

get_mask(self) Returns the mask, as an ImageSurface with format A8.

get_size(self) Returns the tuple (height, width) for the original size.

get_true(self) Returns the colour used for the True region of the mask, or None if it is transparent.

set_false(self, col) Sets the colour associated with the False regions of the mask. A 3-tuple of rgb, in 0-1, or None if you want to show through the layer below.

set_interpolate(self, interpolate) True to interpolate, False to not. Defaults to True

set_mask(self, mask) Replaces the current mask with a new one.

set_true(self, col) Sets the colour associated with the True regions of the mask. A 3-tuple of rgb, in 0-1, or None if you want to show through the layer below.

TileValue(Layer)

A wrapper for rendering an image of uint8, where you can choose a colour for each, or show through the background if you want. Has a tile cache, to make it suitably fast to render.

draw(self, ctx, vp) Draws the image into the provided context, matching the provided viewport.

fetch_tile(self, scale, bx, by, extra = 0) Fetches a tile, given a scale (Multiplication of original dimensions.) and base coordinates (bx, by) - the tile will be the size provided on class initialisation. This request is going through a caching layer, which will hopefuly have the needed tile. If not it will be generated and the tile that has been used the least recently thrown away.

get_colour(self, value) Returns the colour used for the given part of the mask, as 4 tuple with the last element alpha, or None if it is transparent.

get_interpolate(self) Returns True if the mask is interpolated, False if it is not.

get_size(self) Returns the tuple (height, width) for the original size.

set_colour(self, value, col) Sets the colour for a value, as a 4-tuple (r,g,b,a), or None for totally transparent.

set_interpolate(self, interpolate) True to interpolate, False to not. Defaults to True

set_values(self, values) Replaces the current values array with a new one.

ReticleOverlay(Layer)

Draws a reticle on the drawing area - good for zooming.

draw(self, ctx, vp) Draws a simple reticle.

get_size(self) To satisfy the interface for a Layer object

set_render(self, render) True to draw the reticle, False to not draw it.

Clone this wiki locally