pygtkdrawingwindow package

Submodules

pygtkdrawingwindow.base module

class pygtkdrawingwindow.base.DrawingWindow[source]

Bases: gtk.ScrolledWindow

Drawing widget.

__gsignals__

GObject signals:

render(widget : DrawingWindow, ctx: cairo.Context)
Image draw signal.
screen

gtk.DrawingArea – Drawing area.

pointer

(float, float) or None – Pointer coordinates on drawing area.

pointer_root

(float, float) or None – Pointer coordinates on root window.

_scrollbar_size

int – Scrollbar size.

_fit_offset

int – Fit offset.

_size

(int, int) – Image size.

_rotate

float – Image rotation angle.

_scale

float – Zoom ratio.

_prev_scale

float – Previous zoom ratio.

_fit

FitType – Fit type.

_do_fit

function – Fit function.

_do_fit_funcs

tuple of function – Fit functions by type.

Examples

>>> def render(widget, ctx):
...     width, height = widget.get_size()
...     ctx.set_source_rgb(1.0, 0.5, 1.0)
...     ctx.rectangle(0, 0, width, height)
...     ctx.stroke()
...
>>> widget = DrawingWindow()
>>> widget.set_size(200, 200)
>>> widget.connect('render', render)
BUTTON_MASK = <flags GDK_BUTTON1_MASK | GDK_BUTTON2_MASK of type GdkModifierType>

ModifierType – Pointer motion button mask.

EVENTS = <flags GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK of type GdkEventMask>

EventMask – Drawing area event mask.

POLICY = <enum GTK_POLICY_AUTOMATIC of type GtkPolicyType>

PolicyType – Scrollbar policy type.

SHADOW = <enum GTK_SHADOW_NONE of type GtkShadowType>

ShadowType – Shadow type.

__init__()[source]
draw_event(_, ctx)[source]

Handle drawing area draw event.

Parameters:
  • _ (gtk.DrawingArea) –
  • ctx (cairo.Context) –
expose_event(_, event)[source]

Handle drawing area expose event.

Parameters:
  • _ (gtk.DrawingArea) –
  • event (gtk.gdk.Event) –
get_angle()[source]

Get image rotation angle.

Returns:Angle in radians.
Return type:float
get_fit()[source]

Get fit type.

Returns:
Return type:FitType
get_screen_size()[source]

Get drawing area size.

Returns:Drawing area width and height.
Return type:(int, int)
get_size()[source]

Get image size.

Returns:Image width and height.
Return type:(int, int)
get_window_size()[source]

Get widget size.

Returns:Widget width and height.
Return type:(int, int)
get_zoom()[source]

Get zoom ratio.

Returns:
Return type:float
leave_notify_event(_, ev_)[source]

Handle drawing area leave-notify event.

Parameters:
  • _ (gtk.DrawingArea) –
  • ev (gtk.gdk.Event) –
Returns:

True to stop event propagation.

Return type:

bool

motion_notify_event(_, event)[source]

Handle drawing area motion-notify event.

Parameters:
  • _ (gtk.DrawingArea) –
  • event (gtk.gdk.Event) –
Returns:

True to stop event propagation.

Return type:

bool

queue_draw()[source]

Queue drawing area redraw.

scroll_event(_, event)[source]

Handle scroll event.

Parameters:
Returns:

True to stop event propagation.

Return type:

bool

set_angle(angle)[source]

Set image rotation angle.

Parameters:angle (float) – Angle in radians.
set_fit(fit)[source]

Set fit type.

Parameters:fit (FitType) –
set_size(width, height)[source]

Set image size.

Parameters:
  • width (int) – Image width.
  • height (int) – Image height.
set_zoom(ratio)[source]

Set zoom ratio.

Parameters:ratio (float) –
size_allocate_event(_, ev_)[source]

Handle drawing area size-allocate event.

Parameters:
  • _ (gtk.DrawingArea) –
  • ev (gtk.gdk.Event) –
update_fit()[source]

Update zoom to fit resized widget.

zoom_fit()[source]

Zoom to fit width and height.

zoom_fit_height()[source]

Zoom to fit height.

zoom_fit_or_1to1()[source]

Zoom to fit or 1:1.

zoom_fit_width()[source]

Zoom to fit width.

zoom_in()[source]

Zoom in.

zoom_out()[source]

Zoom out.

pygtkdrawingwindow.deps module

class pygtkdrawingwindow.deps.IconSize[source]

Bases: enum.IntEnum

PyGTK icon sizes.

DIALOG = 6
class pygtkdrawingwindow.deps.ImageType[source]

Bases: enum.IntEnum

PyGTK image types.

ANIMATION = 6
EMPTY = 0
ICON_SET = 5
IMAGE = 2
PIXBUF = 3
PIXMAP = 1
STOCK = 4
class pygtkdrawingwindow.deps.NoRsvg[source]

Bases: object

Missing rsvg module class.

Examples

>>> rsvg = NoRsvg
>>> rsvg.Handle('image.svg')
glib.GError: missing rsvg module
>>> rsvg.Handle.new_from_file('image.svg')
glib.GError: missing rsvg module
class Handle(*_)[source]

Bases: object

rsvg handle class.

__init__(*_)[source]

Throw missing module error.

Parameters:*_ – Unused.
Raises:glib.GError
static error()[source]

Throw missing module error.

Raises:glib.GError
classmethod new_from_file(*_)[source]

Throw missing module error.

Parameters:*_ – Unused.
Raises:glib.GError
class pygtkdrawingwindow.deps.PolicyType[source]

Bases: enum.IntEnum

PyGTK scrollbar policy types.

ALWAYS = 0
AUTOMATIC = 1
NEVER = 2
class pygtkdrawingwindow.deps.ScrollDirection[source]

Bases: enum.IntEnum

PyGTK scroll directions.

DOWN = 1
LEFT = 2
RIGHT = 3
SMOOTH = -1
UP = 0

pygtkdrawingwindow.image module

class pygtkdrawingwindow.image.ImageWindow[source]

Bases: pygtkdrawingwindow.base.DrawingWindow

Drawing widget with background image.

image_filter

Cairo filter for image scaling.

new_image_fit

FitType – Fit type to set on image change.

_image

None or gtk.gdk.Pixbuf or gtk.gdk.PixbufAnimation or rsvg.Handle – Background image.

_animation

gtk.gdk.PixbufAnimationIter – Animation iterator.

_animation_time

float or None – Animation start/stop time.

_animation_timeout

int or None – Animation timeout id.

_prev_delay

int – Previous frame delay in milliseconds.

EVENTS = <flags GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_STRUCTURE_MASK of type GdkEventMask>

EventMask – Drawing area event mask.

MIN_ANIMATION_DELAY = 10

int – Minimum animation frame delay in milliseconds.

__init__()[source]

Drawing widget constructor.

animation_step()[source]

Animation timeout.

do_render(ctx)[source]

Handle render signal.

Parameters:ctx (cairo.Context) –
get_animation()[source]
Returns:True if animation is started.
Return type:bool
get_image()[source]

Get background image.

Returns:Background image.
Return type:None or gtk.gdk.Pixbuf or gtk.gdk.PixbufAnimation or rsvg.Handle
has_animation()[source]
Returns:True if background image is animated.
Return type:bool
reset_animation()[source]

Restart animation.

set_animation(enable)[source]

Set animation state.

Parameters:enable (bool) – True to start animation, False to stop.
set_image(img)[source]

Set background image.

Parameters:img (None or str or gtk.Image or gtk.gdk.Pixbuf or gtk.gdk.PixbufAnimation or rsvg.Handle) – Background image.
start_animation()[source]

Start animation.

stop_animation()[source]

Stop animation.

pygtkdrawingwindow.util module

class pygtkdrawingwindow.util.FitType[source]

Bases: enum.IntEnum

Zoom fit types.

FIT = 1
FIT_OR_1TO1 = 4
HEIGHT = 3
LAST = -1
NONE = 0
WIDTH = 2
pygtkdrawingwindow.util.freeze(*args, **kwds)[source]

Widget update freezing context manager.

Parameters:widget (gtk.Widget) – Widget to freeze.
pygtkdrawingwindow.util.get_gtk_image_size(img)[source]

Get GTK size.

Parameters:img (gtk.Image) –
Raises:ValueError – If image storage type is invalid.
Returns:Image width and height.
Return type:(int, int)
pygtkdrawingwindow.util.get_image_size(img)[source]

Get image size.

Parameters:img (None or rsvg.Handle or gtk.gdk.Pixbuf or gtk.gdk.PixbufAnimation or gtk.Image) –
Raises:TypeError – If image type is invalid.
Returns:Image width and height.
Return type:(int, int)
pygtkdrawingwindow.util.get_pixbuf_size(pixbuf)[source]

Get GTK pixbuf size.

Parameters:img (gtk.gdk.Pixbuf or gtk.gdk.PixbufAnimation) –
Returns:Pixbuf width and height.
Return type:(int, int)
pygtkdrawingwindow.util.get_scroll_direction(event)[source]

Get scroll event direction.

Parameters:event (gtk.gdk.Event) – Scroll event.
Returns:
Return type:ScrollDirection
pygtkdrawingwindow.util.get_timeval(time_)[source]

Get time value.

Parameters:time (float) – Time from time.time()
Returns:Time value for gtk.gdk.PixbufAnimation.get_iter().
Return type:gi.repository.GLib.TimeVal or float
pygtkdrawingwindow.util.ignore_args(func)[source]

Create a function that ignores its arguments.

Parameters:func (function) – Function to decorate.
Returns:
Return type:function

Examples

>>> @ignore_args
... def f(*args):
...     print(args)
...
>>> f(1, 2, x=3)
()
pygtkdrawingwindow.util.load_gtk_image(img, widget=None)[source]

Load GTK image.

Parameters:
  • img (gtk.Image) – Image to load.
  • widget (gtk.Widget, optional) – Widget for icon rendering (default: gtk.Label()).
Raises:

ValueError – If image storage type not in (EMPTY, PIXBUF, ANIMATION, STOCK).

Returns:

Loaded image or None if image is empty.

Return type:

gtk.gdk.Pixbuf or gtk.gdk.PixbufAnimation or None

pygtkdrawingwindow.util.load_image(img, widget=None)[source]

Load an image.

Parameters:
  • img (str or gtk.Image or gtk.gdk.Pixbuf or gtk.gdk.PixbufAnimation or rsvg.Handle) – Image to load.
  • widget (gtk.Widget, optional) – Widget for icon rendering (default: gtk.Label()).
Returns:

Loaded image or None if image is empty.

Return type:

gtk.gdk.Pixbuf or gtk.gdk.PixbufAnimation or rsvg.Handle or None

pygtkdrawingwindow.util.load_image_file(path)[source]

Load image from file.

Parameters:path (str) – Image file path.
Returns:Loaded image.
Return type:rsvg.Handle or gtk.Image
pygtkdrawingwindow.util.log(msg)[source]

Log function calls.

Parameters:msg (str) – Message to print before each function call.
Returns:Decorator.
Return type:function

Examples

>>> @log('called')
... def f(x):
...   return x
...
>>> f(0)
called
0
pygtkdrawingwindow.util.nop(*_, **kw_)[source]

Do nothing.

Parameters:
  • *_ – Unused.
  • **kw_ – Unused.

Module contents