def create_scroll_actor(stage): scroll = Clutter.ScrollActor(name='scroll') scroll.set_position(0, 18) scroll.add_constraint( Clutter.AlignConstraint(source=stage, align_axis=Clutter.AlignAxis.X_AXIS, factor=0.5)) scroll.add_constraint( Clutter.BindConstraint(source=stage, coordinate=Clutter.BindCoordinate.HEIGHT, offset=-36)) scroll.set_scroll_mode(Clutter.ScrollMode.VERTICALLY) scroll.set_easing_duration(250) scroll.add_child(create_menu_actor()) stage.add_child(scroll)
def create_listbox(posX, posY, sizeX, sizeY, orientation=Clutter.Orientation.HORIZONTAL, iD="listbox", pad=1, handle_mouse=_handle_lb_mouse, handle_itemclick=None): boxLayout = Clutter.BoxLayout() boxLayout.set_orientation(orientation) boxLayout.set_spacing(pad) boxList = Clutter.ScrollActor() if orientation == Clutter.Orientation.HORIZONTAL: boxList.set_scroll_mode(Clutter.ScrollMode.HORIZONTALLY) elif orientation == Clutter.Orientation.VERTICAL: boxList.set_scroll_mode(Clutter.ScrollMode.VERTICALLY) #boxList = Clutter.Actor() boxList.set_layout_manager(boxLayout) boxList.set_id(iD) boxList.set_position(posX, posY) boxList.set_size(sizeX, sizeY) boxList.set_reactive(True) gActors[iD] = { 'curIndex': 0, # index to current selection in the listbox 'startTime': None, # store time of button press 'prevPos': None, 'prevTime': None, # location and time of mouse wrt last event during scroll 'posX': 0, 'posY': 0, # Corresponds to offset wrt Viewport start 'handle_itemclick': handle_itemclick, # custom handler for handling itemclicks 'blur': False } # Tell if blur effect is currently active, for example during scroll beyond boundries if handle_mouse != None: boxList.connect("button-press-event", handle_mouse) boxList.connect("button-release-event", handle_mouse) boxList.connect("motion-event", handle_mouse) return boxList
if key == Clutter.KEY_Return or key == Clutter.KEY_KP_Enter: menu.activate_item() return True return False if __name__ == '__main__': Clutter.init(None) stage = Clutter.Stage(title='Actor Model', user_resizable=True) stage.connect('destroy', Clutter.main_quit) stage.connect('key-press-event', on_key_press_event) stage.show() scroll = Clutter.ScrollActor(name='scroll') scroll.set_position(0, 18) scroll.add_constraint( Clutter.AlignConstraint(source=stage, align_axis=Clutter.AlignAxis.X_AXIS, factor=0.5)) scroll.add_constraint( Clutter.BindConstraint(source=stage, coordinate=Clutter.BindCoordinate.HEIGHT, offset=-36)) scroll.set_scroll_mode(Clutter.ScrollMode.VERTICALLY) scroll.set_easing_duration(250) stage.add_child(scroll) menu = Menu() scroll.add_child(menu)