Back to index

system-config-printer  1.3.9+20120706
Public Member Functions | Private Attributes
gtkinklevel.GtkInkLevel Class Reference

List of all members.

Public Member Functions

def __init__
def set_level
def get_level
def expose_event
def draw

Private Attributes

 _level
 _color

Detailed Description

Definition at line 24 of file gtkinklevel.py.


Constructor & Destructor Documentation

def gtkinklevel.GtkInkLevel.__init__ (   self,
  color,
  level = 0 
)

Definition at line 25 of file gtkinklevel.py.

00025 
00026     def __init__ (self, color, level=0):
00027         gtk.DrawingArea.__init__ (self)
00028         self.connect ('expose-event', self.expose_event)
00029         self._level = level
00030         try:
00031             self._color = gtk.gdk.color_parse (color)
00032         except (ValueError, TypeError):
00033             self._color = gtk.gdk.color_parse ('#cccccc')
00034 
00035         self.set_size_request (30, 45)

Here is the call graph for this function:


Member Function Documentation

def gtkinklevel.GtkInkLevel.draw (   self,
  ctx,
  thickness 
)

Definition at line 62 of file gtkinklevel.py.

00062 
00063     def draw (self, ctx, thickness):
00064         r = self._color.red / 65535.0
00065         g = self._color.green / 65535.0
00066         b = self._color.blue / 65535.0
00067         fill_point = self._level / 100.0
00068 
00069         ctx.move_to (0.5, 0.0)
00070         ctx.curve_to (0.5, 0.33, 1.0, 0.5, 1.0, 0.67)
00071         ctx.curve_to (1.0, 0.85, 0.85, 1.0, 0.5, 1.0)
00072         ctx.curve_to (0.15, 1.0, 0.0, 0.85, 0.0, 0.67)
00073         ctx.curve_to (0.0, 0.5, 0.1, 0.2, 0.5, 0.0)
00074         ctx.close_path ()
00075         ctx.set_source_rgb (r, g, b)
00076         ctx.set_line_width (thickness)
00077         ctx.stroke_preserve ()
00078         if fill_point > 0.0:
00079             grad_width = 0.10
00080             grad_start = fill_point - (grad_width / 2)
00081             if grad_start < 0:
00082                 grad_start = 0
00083 
00084             pat = cairo.LinearGradient (0, 1, 0, 0)
00085             pat.add_color_stop_rgba (0, r, g, b, 1)
00086             pat.add_color_stop_rgba ((self._level - 5) / 100.0, r, g, b, 1)
00087             pat.add_color_stop_rgba ((self._level + 5)/ 100.0, 1, 1, 1, 1)
00088             pat.add_color_stop_rgba (1.0, 1, 1, 1, 1)
00089             ctx.set_source (pat)
00090             ctx.fill ()
00091         else:
00092             ctx.set_source_rgb (1, 1, 1)
00093             ctx.fill ()
00094 
00095         ctx.set_line_width (thickness / 2)
00096 
00097         ctx.move_to (0.5, 0.0)
00098         ctx.line_to (0.5, 1.0)
00099         ctx.set_source_rgb (r, g, b)
00100         ctx.stroke ()
00101 
00102         # 50% marker
00103         ctx.move_to (0.4, 0.5)
00104         ctx.line_to (0.6, 0.5)
00105         ctx.set_source_rgb (r, g, b)
00106         ctx.stroke ()
00107 
00108         # 25% marker
00109         ctx.move_to (0.45, 0.75)
00110         ctx.line_to (0.55, 0.75)
00111         ctx.set_source_rgb (r, g, b)
00112         ctx.stroke ()
00113 
00114         # 75% marker
00115         ctx.move_to (0.45, 0.25)
00116         ctx.line_to (0.55, 0.25)
00117         ctx.set_source_rgb (r, g, b)
00118         ctx.stroke ()

Here is the caller graph for this function:

def gtkinklevel.GtkInkLevel.expose_event (   self,
  widget,
  event 
)

Definition at line 43 of file gtkinklevel.py.

00043 
00044     def expose_event (self, widget, event):
00045         ctx = self.window.cairo_create ()
00046         ctx.rectangle (event.area.x, event.area.y,
00047                        event.area.width,
00048                        event.area.height)
00049         ctx.clip ()
00050 
00051         (w, h) = self.window.get_size ()
00052         ratio = 1.0 * h / w
00053         if ratio < 1.5:
00054             w = h * 2.0 / 3.0
00055         else:
00056             h = w * 3.0 / 2.0
00057         thickness = 1
00058         ctx.translate (thickness, thickness)
00059         ctx.scale (w - 2 * thickness, h - 2 * thickness)
00060         thickness = max (ctx.device_to_user_distance (thickness, thickness))
00061         self.draw (ctx, thickness)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 40 of file gtkinklevel.py.

00040 
00041     def get_level (self):
00042         return self._level

Here is the caller graph for this function:

def gtkinklevel.GtkInkLevel.set_level (   self,
  level 
)

Definition at line 36 of file gtkinklevel.py.

00036 
00037     def set_level (self, level):
00038         self._level = level
00039         self.queue_resize ()


Member Data Documentation

Definition at line 30 of file gtkinklevel.py.

Definition at line 28 of file gtkinklevel.py.


The documentation for this class was generated from the following file: