コード例 #1
0
def on_key_press_event(stage, event):
    scroll = stage.get_first_child()
    menu = scroll.get_first_child()
    key = event.keyval

    if key == Clutter.KEY_q:
        Clutter.main_quit()
        return True

    if key == Clutter.KEY_Up:
        item = menu.select_prev()
        if item is not None:
            pos = Clutter.Point()
            (pos.x, pos.y) = item.get_position()
            scroll.scroll_to_point(pos)
            return True

    if key == Clutter.KEY_Down:
        item = menu.select_next()
        if item is not None:
            pos = Clutter.Point()
            (pos.x, pos.y) = item.get_position()
            scroll.scroll_to_point(pos)
            return True

    if key == Clutter.KEY_Return or key == Clutter.KEY_KP_Enter:
        menu.activate_item()
        return True

    return False
コード例 #2
0
    def _startThumbnailing(self):
        if not self.pipeline:
            # Can happen if stopGeneration is called because the clip has been
            # removed from the timeline after the PreviewGeneratorManager
            # started this job.
            return
        self.debug('Now generating thumbnails for: %s',
                   filename_from_uri(self.uri))
        query_success, duration = self.pipeline.query_duration(Gst.Format.TIME)
        if not query_success or duration == -1:
            self.debug("Could not determine duration of: %s", self.uri)
            duration = self.duration
        else:
            self.duration = duration

        self.queue = list(range(0, duration, self.thumb_period))

        self._checkCPU()

        if self.bElement.props.in_point != 0:
            position = Clutter.Point()
            position.x = Zoomable.nsToPixel(self.bElement.props.in_point)
            self.scroll_to_point(position)
        self._addVisibleThumbnails()
        # Save periodically to avoid the common situation where the user exits
        # the app before a long clip has been fully thumbnailed.
        # Spread timeouts between 30-80 secs to avoid concurrent disk writes.
        random_time = randrange(30, 80)
        GLib.timeout_add_seconds(random_time, self._autosave)

        # Remove the GSource
        return False
コード例 #3
0
    def do_allocate(self, actor, allocation, flags):
        def get_visible_children(actor):
            n_visible_children = 0
            for child in actor:
                if not child.props.visible:
                    continue
                n_visible_children += 1

            return n_visible_children

        n_items = get_visible_children(actor)
        if n_items == 0:
            return

        x_offset, y_offset = allocation.get_origin()
        avail_width, avail_height = allocation.get_size()

        self.do_get_preferred_width(actor, avail_width)
        self.do_get_preferred_height(actor, avail_height)

        item_index = 0
        n_items_per_row = 0
        center = Clutter.Point()
        radius = 0
        if self._state == MultiLayout.GRID:
            n_items_per_row = self._get_items_per_row(avail_width)
            item_x = x_offset
            item_y = y_offset
        elif self._state == MultiLayout.CIRCLE:
            radius = min((avail_width - self._cell_width) / 2, (avail_height - self._cell_height) / 2)
            center.x = allocation.x2 / 2
            center.y = allocation.y2 / 2

        for child in actor:
            child_alloc = Clutter.ActorBox()

            if self._state == MultiLayout.GRID:
                if item_index == n_items_per_row:
                    item_index = 0
                    item_x = x_offset
                    item_y += self._cell_height + self._spacing

                child_alloc.x1 = item_x
                child_alloc.y1 = item_y
                item_x += self._cell_width + self._spacing
            elif self._state == MultiLayout.CIRCLE:
                theta = 2.0 * math.pi / n_items * item_index
                child_alloc.x1 = center.x + radius * math.sin(theta) - (self._cell_width / 2)
                child_alloc.y1 = center.y + radius * math.cos(theta) - (self._cell_height / 2)

            child_alloc.x2 = child_alloc.x1 + self._cell_width
            child_alloc.y2 = child_alloc.y1 + self._cell_height

            child.allocate(child_alloc, flags)

            item_index += 1
コード例 #4
0
    def do_allocate(self, container, allocation, flags):
        n_items = MultiLayout._get_visible_children(container)
        if n_items == 0:
            return

        x_offset, y_offset = allocation.get_origin()
        avail_width, avail_height = allocation.get_size()

        self.get_preferred_width(container, avail_width)
        self.get_preferred_height(container, avail_height)

        item_index = 0

        if self.state == 0:
            n_items_per_row = MultiLayout._get_items_per_row(
                avail_width, self.cell_width, self.spacing)
            item_x = x_offset
            item_y = y_offset
        elif self.state == 1:
            center = Clutter.Point()
            center.x = allocation.x2 // 2
            center.y = allocation.y2 // 2
            radius = min((avail_width - self.cell_width) // 2,
                         (avail_height - self.cell_height) // 2)

        for child in container.get_children():
            child_allocation = Clutter.ActorBox()

            if not child.is_visible():
                continue

            if self.state == 0:
                if item_index == n_items_per_row:
                    item_index = 0
                    item_x = x_offset
                    item_y += self.cell_height + self.spacing

                child_allocation.x1 = item_x
                child_allocation.y1 = item_y
                child_allocation.x2 = child_allocation.x1 + self.cell_width
                child_allocation.y2 = child_allocation.y1 + self.cell_height

                item_x += self.cell_width + self.spacing
            elif self.state == 1:
                # Should be arythmetic operation for floating point.
                theta = 2 * math.pi / n_items * item_index
                child_allocation.x1 = center.x + radius * math.sin(theta) - (
                    self.cell_width // 2)
                child_allocation.y1 = center.y + radius * -1 * math.cos(
                    theta) - (self.cell_height // 2)
                child_allocation.x2 = child_allocation.x1 + self.cell_width
                child_allocation.y2 = child_allocation.y1 + self.cell_height

            child.allocate(child_allocation, flags)

            item_index += 1
コード例 #5
0
    def _updateScrollPosition(self, adjustment):
        self._scroll_pos_ns = Zoomable.pixelToNs(self.hadj.get_value())
        point = Clutter.Point()
        point.x = self.hadj.get_value()
        point.y = self.vadj.get_value()
        self.point = point

        self.timeline.scroll_to_point(point)
        point.x = 0
        self.controls.scroll_to_point(point)
コード例 #6
0
def listbox_select(lb,
                   offset,
                   offsetType=SelectOffsetType.START,
                   animOrientation=None,
                   colorizeEffect=None,
                   scrollToView=True):
    cnt = lb.get_n_children()
    aID = lb.get_id()
    curIndex = gActors[aID]['curIndex']
    if offsetType == SelectOffsetType.CUR:
        nxtIndex = (curIndex + offset) % cnt
    elif offsetType == SelectOffsetType.START:
        nxtIndex = offset % cnt
    #while nxtIndex < 0:
    #    nxtIndex = cnt + nxtIndex
    curActor = lb.get_child_at_index(curIndex)
    nxtActor = lb.get_child_at_index(nxtIndex)
    curActor.save_easing_state()
    nxtActor.save_easing_state()
    lb.save_easing_state()
    lb.set_easing_duration(500)
    if scrollToView:
        nxtActorPos = nxtActor.get_position()
        point = Clutter.Point()
        point.x = nxtActorPos[0]
        point.y = nxtActorPos[1]
        lb.scroll_to_point(point)
    if colorizeEffect != None:
        curActor.remove_effect(colorizeEffect)
    curActor.set_scale(1, 1)
    if (animOrientation == None):
        listOrientation = lb.get_layout_manager().get_orientation()
        if listOrientation == Clutter.Orientation.HORIZONTAL:
            animOrientation = AnimOrientation.VERTICAL
        elif listOrientation == Clutter.Orientation.VERTICAL:
            animOrientation = AnimOrientation.HORIZONTAL
        else:
            print("WARN:animate_listbox:Unknown listbox Orientation")
            animOrientation = AnimOrientation.BOTH
    if (animOrientation == AnimOrientation.HORIZONTAL):
        xScale = 1 + LB_SELSCALE_PERCENT
        yScale = 1
    elif (animOrientation == AnimOrientation.VERTICAL):
        xScale = 1
        yScale = 1 + LB_SELSCALE_PERCENT
    else:
        xScale = 1 + LB_SELSCALE_PERCENT
        yScale = 1 + LB_SELSCALE_PERCENT
    nxtActor.set_scale(xScale, yScale)
    if colorizeEffect != None:
        nxtActor.add_effect(colorizeEffect)
    curActor.restore_easing_state()
    nxtActor.restore_easing_state()
    lb.restore_easing_state()
    gActors[aID]['curIndex'] = nxtIndex
コード例 #7
0
 def __init__(self, container):
     Clutter.ScrollActor.__init__(self)
     Zoomable.__init__(self)
     self.bTimeline = None
     self._container = container
     self.elements = []
     self.ghostClips = []
     self.selection = Selection()
     self._scroll_point = Clutter.Point()
     self.lastPosition = 0  # Saved for redrawing when paused
     self._createPlayhead()
     self._createSnapIndicator()
コード例 #8
0
    def _createUi(self):
        self.embed = GtkClutter.Embed()
        self.embed.get_accessible().set_name("timeline canvas")  # for dogtail
        self.stage = self.embed.get_stage()

        self.timeline = TimelineStage(self)
        self.controls = ControlContainer(self.timeline)
        self.zoomBox = ZoomBox(self)
        self.shiftMask = False
        self.controlMask = False

        # TODO: make the bg a gradient from (0, 0, 0, 255) to (50, 50, 50, 255)
        self.stage.set_background_color(Clutter.Color.new(31, 30, 33, 255))
        self.timeline.set_position(CONTROL_WIDTH, 0)
        self.controls.set_position(0, 0)
        self.controls.set_z_position(2)

        self.stage.add_child(self.controls)
        self.stage.add_child(self.timeline)

        self.stage.connect("destroy", quit_)
        self.stage.connect("button-press-event", self._clickedCb)
        self.stage.connect("button-release-event", self._releasedCb)
        self.embed.connect("scroll-event", self._scrollEventCb)
        if self.gui:
            self.gui.connect("key-press-event", self._keyPressEventCb)
            self.gui.connect("key-release-event", self._keyReleaseEventCb)

        self.embed.connect("enter-notify-event", self._enterNotifyEventCb)

        self.point = Clutter.Point()
        self.point.x = 0
        self.point.y = 0

        self.scrolled = 0

        self.zoomed_fitted = True
        self.pressed = False

        self._packScrollbars(self)
        self.stage.show()
コード例 #9
0
ファイル: previewers.py プロジェクト: tomak-git/pitivi
 def _inpointChangedCb(self, unused_bElement, unused_value):
     position = Clutter.Point()
     position.x = Zoomable.nsToPixel(self.bElement.props.in_point)
     self.scroll_to_point(position)
     self._update()
コード例 #10
0
def _handle_lb_mouse(actor, event):
    global gLBMMCnt
    #print("INFO:LbMouse:{}:{}:{},{}:{}".format(event.time, actor, event.x, event.y, event.type))
    aID = actor.get_id()
    orientation = actor.get_layout_manager().get_orientation()
    if event.type == Clutter.EventType.BUTTON_PRESS:
        dprint(DEBUG_LBM, "DBUG:LBMouse:BtnPress", aID, gLBMMCnt,
               gActors[aID]['posX'], gActors[aID]['posY'])
        gActors[aID]['prevPos'] = (event.x, event.y)
        gActors[aID]['prevTime'] = event.time
        gActors[aID]['startTime'] = event.time
        return Clutter.EVENT_PROPAGATE
    elif event.type == Clutter.EventType.MOTION:
        gLBMMCnt += 1
        prevPos = gActors[aID]['prevPos']
        prevTime = gActors[aID]['prevTime']
        x = gActors[aID]['posX']
        y = gActors[aID]['posY']
        if prevTime != None:
            timeDelta = event.time - prevTime
        else:
            timeDelta = 54321
        if (timeDelta < LB_GESTURE_DELTATIME_MS):
            xD = event.x - prevPos[0]
            yD = event.y - prevPos[1]
            if abs(xD) > abs(yD):
                x -= xD
                bHorizScroll = True
                bVertiScroll = False
            else:
                y -= yD
                bVertiScroll = True
                bHorizScroll = False
            if (x >= 0) and (y >= 0):
                if ((orientation == Clutter.Orientation.HORIZONTAL) and
                    (x > 0) and bHorizScroll) or (
                        (orientation == Clutter.Orientation.VERTICAL) and
                        (y > 0) and bVertiScroll):
                    dprint(DEBUG_LBM_EXTRA, "DBUG:LBMouse:Motion: Will Scroll",
                           aID, gLBMMCnt, x, y)
                    actor.save_easing_state()
                    point = Clutter.Point()
                    point.x = x
                    point.y = y
                    actor.scroll_to_point(point)
                    gActors[aID]['posX'] = x
                    gActors[aID]['posY'] = y
                    actor.restore_easing_state()
                else:
                    dprint(DEBUG_LBM_NEGPATH,
                           "DBUG:LBMouse:Motion: Not my scroll", aID, gLBMMCnt)
                    return False
            else:
                if ((orientation == Clutter.Orientation.HORIZONTAL) and
                    (x < 0)) or ((orientation == Clutter.Orientation.VERTICAL)
                                 and (y < 0)):
                    dprint(DEBUG_LBM,
                           "DBUG:LBMouse:Motion: Scroll already at boundry",
                           aID, gLBMMCnt, x, y)
                    if gActors[aID]['blur'] == False:
                        actor.add_effect(blurEffect)
                        gActors[aID]['blur'] = True
                        Clutter.threads_add_timeout(GLib.PRIORITY_DEFAULT,
                                                    LB_CLEANUP_TIMEOUT,
                                                    _lb_scroll_cleanup, actor)
                else:
                    dprint(
                        DEBUG_LBM_NEGPATH,
                        "DBUG:LBMouse:Motion: Scroll Pos -ve, Not mine, just passing up",
                        aID, gLBMMCnt, x, y, xD, yD)
                return False
            gActors[aID]['prevPos'] = (event.x, event.y)
            gActors[aID]['prevTime'] = event.time
            return True
        else:
            dprint(DEBUG_LBM_NEGPATH, "DBUG:LBMouse:Motion: Stray or Delayed",
                   aID, gLBMMCnt, timeDelta)
            return False
    elif event.type == Clutter.EventType.BUTTON_RELEASE:
        dprint(DEBUG_LBM, "DBUG:LBMouse:BtnRelease", aID, gLBMMCnt,
               gActors[aID]['posX'], gActors[aID]['posY'])
        gActors[aID]['startTime'] = None
        gActors[aID]['prevPos'] = None
        gActors[aID]['prevTime'] = None
        if gActors[aID]['blur']:
            actor.remove_effect(blurEffect)
            gActors[aID]['blur'] = False
        return Clutter.EVENT_PROPAGATE
コード例 #11
0
# kaa imports
import kaa
import kaa.imlib2

# clutter imports
from gi.repository import Clutter as clutter
from gi.repository import GObject as gobject

# candy backend import
import candy

# register the thread pool for loading images
kaa.register_thread_pool('candy::photo', kaa.ThreadPool())

CENTER = clutter.Point()
CENTER.x = 0.5
CENTER.y = 0.5


class Widget(candy.Widget):
    """
    Backend widget class
    """
    def create(self):
        """
        Create the clutter object
        """
        self.obj = clutter.Group.new()
        self.obj.show()
        self.textures = {}
コード例 #12
0
ファイル: scroll-actor.py プロジェクト: xrombik/pyclutter
def scroll_to_item(scroll, item):
    pos = Clutter.Point()
    pos.x, pos.y = item.get_position()
    scroll.scroll_to_point(pos)