Exemplo n.º 1
0
    def drawTimes(self, context, offset, spacing, interval_seconds):
        # figure out what the optimal offset is
        interval = int(Gst.SECOND * interval_seconds)
        current_time = self.pixelToNs(self.pixbuf_offset)
        paintpos = TIMES_LEFT_MARGIN_PIXELS
        if offset > 0:
            current_time = current_time - (current_time % interval) + interval
            paintpos += spacing - offset

        set_cairo_color(context, self._color_normal)
        y_bearing = context.text_extents("0")[1]

        def split(x):
            # Seven elements: h : mm : ss . mmm
            # Using negative indices because the first element (hour)
            # can have a variable length.
            return x[:-10], x[-10], x[-9:-7], x[-7], x[-6:-4], x[-4], x[-3:]

        previous = split(time_to_string(max(0, current_time - interval)))
        width = context.get_target().get_width()
        while paintpos < width:
            context.move_to(int(paintpos), 1 - y_bearing)
            current = split(time_to_string(int(current_time)))
            millis = current_time % Gst.SECOND > 0
            self._drawTime(context, current, previous, millis)
            previous = current
            paintpos += spacing
            current_time += interval
Exemplo n.º 2
0
    def drawTimes(self, context, offset, spacing, interval_seconds):
        # figure out what the optimal offset is
        interval = int(Gst.SECOND * interval_seconds)
        current_time = self.pixelToNs(self.pixbuf_offset)
        paintpos = TIMES_LEFT_MARGIN_PIXELS
        if offset > 0:
            current_time = current_time - (current_time % interval) + interval
            paintpos += spacing - offset

        set_cairo_color(context, self._color_normal)
        y_bearing = context.text_extents("0")[1]

        def split(x):
            # Seven elements: h : mm : ss . mmm
            # Using negative indices because the first element (hour)
            # can have a variable length.
            return x[:-10], x[-10], x[-9:-7], x[-7], x[-6:-4], x[-4], x[-3:]

        previous = split(time_to_string(max(0, current_time - interval)))
        width = context.get_target().get_width()
        while paintpos < width:
            context.move_to(int(paintpos), 1 - y_bearing)
            current = split(time_to_string(int(current_time)))
            millis = current_time % Gst.SECOND > 0
            self._drawTime(context, current, previous, millis)
            previous = current
            paintpos += spacing
            current_time += interval
Exemplo n.º 3
0
 def _getSpacing(self, context):
     textwidth = context.text_extents(time_to_string(0))[2]
     zoom = Zoomable.zoomratio
     for scale in self.scales:
         spacing = scale * zoom
         if spacing >= textwidth * 1.5:
             return spacing, scale
     raise Exception("Failed to find an interval size for textwidth:%s, zoomratio:%s" % (textwidth, Zoomable.zoomratio))
Exemplo n.º 4
0
 def _getSpacing(self, context):
     textwidth = context.text_extents(time_to_string(0))[2]
     zoom = Zoomable.zoomratio
     for scale in self.scales:
         spacing = scale * zoom
         if spacing >= textwidth * 1.5:
             return spacing, scale
     raise Exception("Failed to find an interval size for textwidth:%s, zoomratio:%s" % (textwidth, Zoomable.zoomratio))
Exemplo n.º 5
0
    def drawRuler(self, cr):
        # FIXME use system defaults
        cr.set_font_face(cairo.ToyFontFace("Cantarell"))
        cr.set_font_size(13)
        textwidth = cr.text_extents(time_to_string(0))[2]

        for scale in self.scale:
            spacing = Zoomable.zoomratio * scale
            if spacing >= textwidth * 1.5:
                break

        offset = self.pixbuf_offset % spacing
        self.drawFrameBoundaries(cr)
        self.drawTicks(cr, offset, spacing, scale)
        self.drawTimes(cr, offset, spacing, scale)
Exemplo n.º 6
0
    def drawTimes(self, cr, offset, spacing, scale):
        # figure out what the optimal offset is
        interval = long(gst.SECOND * scale)
        seconds = self.pixelToNs(self.pixbuf_offset)
        paintpos = float(self.border) + 2
        if offset > 0:
            seconds = seconds - (seconds % interval) + interval
            paintpos += spacing - offset

        while paintpos < cr.get_target().get_width():
            if paintpos < self.nsToPixel(gst.CLOCK_TIME_NONE):
                state = gtk.STATE_ACTIVE
            else:
                state = gtk.STATE_NORMAL
            timevalue = time_to_string(long(seconds))
            setCairoColor(cr, self.style.fg[state])
            x_bearing, y_bearing = cr.text_extents("0")[:2]
            cr.move_to(int(paintpos), 1 - y_bearing)
            cr.show_text(timevalue)
            paintpos += spacing
            seconds += interval
Exemplo n.º 7
0
    def drawTimes(self, cr, offset, spacing, scale):
        # figure out what the optimal offset is
        interval = long(Gst.SECOND * scale)
        seconds = self.pixelToNs(self.pixbuf_offset)
        paintpos = float(self.border) + 2
        if offset > 0:
            seconds = seconds - (seconds % interval) + interval
            paintpos += spacing - offset

        while paintpos < cr.get_target().get_width():
            if paintpos < self.nsToPixel(Gst.CLOCK_TIME_NONE):
                state = Gtk.StateType.ACTIVE
            else:
                state = Gtk.StateType.NORMAL
            timevalue = time_to_string(long(seconds))
            style = self.get_style_context()
            setCairoColor(cr, style.get_color(state))
            x_bearing, y_bearing = cr.text_extents("0")[:2]
            cr.move_to(int(paintpos), 1 - y_bearing)
            cr.show_text(timevalue)
            paintpos += spacing
            seconds += interval
Exemplo n.º 8
0
 def setWidgetValue(self, timeNanos, send_signal=True):
     timecode = time_to_string(timeNanos)
     if timecode.startswith("0:"):
         timecode = timecode[2:]
     TextWidget.setWidgetValue(self, timecode, send_signal=send_signal)
Exemplo n.º 9
0
 def setWidgetValue(self, value, send_signal=True):
     TextWidget.setWidgetValue(self,
                               time_to_string(value),
                               send_signal=send_signal)
Exemplo n.º 10
0
 def setWidgetValue(self, value, send_signal=True):
     TextWidget.setWidgetValue(self, time_to_string(value), send_signal=send_signal)
Exemplo n.º 11
0
 def setWidgetValue(self, timeNanos, send_signal=True):
     timecode = time_to_string(timeNanos)
     if timecode.startswith("0:"):
         timecode = timecode[2:]
     TextWidget.setWidgetValue(self, timecode, send_signal=send_signal)