- Implemented the InputQueue controller on the cover_viewer, damn thing worked first time

This commit is contained in:
noisymime 2008-01-13 10:45:43 +00:00
parent 242a62a50f
commit 5904a77c52
5 changed files with 109 additions and 53 deletions

View File

@ -87,9 +87,11 @@ class GlossMgr:
# If none of these things, the menu needs to do something
if event.keyval == clutter.keysyms.Up: #Up button pressed
self.currentMenu.selectPrevious()
self.currentMenu.input_queue.input(event)
#self.currentMenu.selectPrevious()
if event.keyval == clutter.keysyms.Down: #Down button pressed
self.currentMenu.selectNext()
self.currentMenu.input_queue.input(event)
#self.currentMenu.selectNext()
if event.keyval == clutter.keysyms.q:
self.stage.show_cursor()
clutter.main_quit()

View File

@ -1,3 +1,5 @@
import clutter
#########################################################
# The input queue controls fast user input by queing up
# signals and processing them one by one once any timelines
@ -7,7 +9,7 @@
class InputQueue:
NORTH, EAST, SOUTH, WEST = range(4)
def __init__(self, timeline):
def __init__(self):
self.queue_north = 0
self.queue_east = 0
self.queue_south = 0
@ -18,14 +20,58 @@ class InputQueue:
self.action_south = None
self.action_west = None
def set_timeline(self, timeline):
self.timeline = timeline
self.timeline.connect('completed', self.flush_queue)
def flush_queue(self):
def input(self, event):
if not self.timeline.is_playing():
if (event.keyval == clutter.keysyms.Left) and (not self.action_west is None): self.action_west()
if (event.keyval == clutter.keysyms.Right) and (not self.action_east is None): self.action_east()
if (event.keyval == clutter.keysyms.Up) and (not self.action_north is None): self.action_north()
if (event.keyval == clutter.keysyms.Down) and (not self.action_south is None): self.action_south()
return True
if event.keyval == clutter.keysyms.Left:
self.queue_west = self.queue_west + 1
return True
elif event.keyval == clutter.keysyms.Right:
self.queue_east = self.queue_east + 1
return True
elif event.keyval == clutter.keysyms.Down:
self.queue_south = self.queue_south + 1
return True
elif event.keyval == clutter.keysyms.Up:
self.queue_north = self.queue_north + 1
return True
#If we get to this point, we haven't handled the input, so return False
return False
def set_action(self, direction, function):
if (direction == self.NORTH): self.action_north = function
if (direction == self.EAST): self.action_east = function
if (direction == self.SOUTH): self.action_south = function
if (direction == self.WEST): self.action_west = function
def flush_queue(self, data):
#Consolodate north/south, east/west volumes
self.queue_north = self.queue_north - self.queue_south
self.queue_south = self.queue_south - self.queue_north
self.queue_east = self.queue_east - self.queue_west
self.queue_west = self.queue_west - self.queue_east
if self.queue_north > 0:
self.selectNext()
elif self.moveQueue < 0:
self.selectPrevious()
self.action_north()
if self.queue_east > 0:
self.action_east()
if self.queue_south > 0:
self.action_south()
if self.queue_west > 0:
self.action_west()
self.moveQueue = 0
self.queue_east = 0
self.queue_south = 0
self.queue_west = 0
self.queue_north = 0

35
Menu.py
View File

@ -4,6 +4,7 @@ import gtk
import pango
import time
from ReflectionTexture import Texture_Reflection
from InputQueue import InputQueue
class Menu(clutter.Group):
font = ""
@ -18,6 +19,11 @@ class Menu(clutter.Group):
self.itemGroup = clutter.Group()
self.glossMgr.themeMgr.setup_menu("main", self)
#Setup input queue controller
self.input_queue = InputQueue()
self.input_queue.set_action(InputQueue.NORTH, self.selectPrevious)
self.input_queue.set_action(InputQueue.SOUTH, self.selectNext)
self.menuItems = []
self.selected = 0
self.displayMin = 0 #The number of menu items that will be shown at a time
@ -27,6 +33,7 @@ class Menu(clutter.Group):
self.stage.add(self.itemGroup)
self.timeline = clutter.Timeline(15, 75) #This timeline is used on any movements that occur when changing items
self.input_queue.set_timeline(self.timeline)
self.timeline_completed=True
self.glossMgr.addMenu(self)
self.stage.add(self)
@ -104,17 +111,12 @@ class Menu(clutter.Group):
#Returns the newly selected item
def selectNext(self):
#Initially check whether the last animation is still going
if self.timeline.is_playing():
self.moveQueue = self.moveQueue + 1
#self.timeline.set_speed(1000) # Nasty hack to make sure the timeline finishes
return None
#Check if we're at the last item in the list
if (self.selected) != (len(self.menuItems)-1):
self.timeline = clutter.Timeline (15,85)
self.timeline.connect('completed', self.completeMove)
self.input_queue.set_timeline(self.timeline)
#self.timeline.connect('completed', self.completeMove)
if not self.moveQueue == 0:
self.selected = self.selected +1 #+ self.moveQueue
@ -158,17 +160,12 @@ class Menu(clutter.Group):
#Returns the newly selected item
def selectPrevious(self):
#Initially check whether the last animation is still going
if self.timeline.is_playing():
self.moveQueue = self.moveQueue - 1
#self.timeline.set_speed(1000) # Nasty hack to make sure the timeline finishes
return None
#Check if we're at the first item in the list
if (self.selected) != 0:
self.timeline = clutter.Timeline (15,85)
self.timeline.connect('completed', self.completeMove)
self.input_queue.set_timeline(self.timeline)
#self.timeline.connect('completed', self.completeMove)
if not self.moveQueue == 0:
self.selected = self.selected -1 #+ self.moveQueue
@ -209,15 +206,7 @@ class Menu(clutter.Group):
self.glossMgr.get_selector_bar().selectItem(self.menuItems[self.selected], self.timeline)
self.timeline.start()
def completeMove(self, data):
#print self.itemGroup.get_abs_position()
if self.moveQueue > 0:
self.selectNext()
elif self.moveQueue < 0:
self.selectPrevious()
def selectFirst(self, moveBar):
if self.timeline.is_playing:
"ERROR: Timeline should NOT be playing here!"

View File

@ -175,6 +175,7 @@ class Module:
self.newFilename = self.textures[self.rand1]
pixbuf = gtk.gdk.pixbuf_new_from_file(self.newFilename)
self.nextTexture.set_pixbuf(pixbuf)
#self.nextTexture.set_anchor_point_from_gravity(clutter.GRAVITY_CENTER)
#Make sure we don't show the same photo twice
if (self.newFilename == self.currentFilename) and (len(self.textures) > 1):
self.nextTexture = None
@ -185,7 +186,7 @@ class Module:
#Zooming stuff
rand_zoom = random.uniform(1,1.3) # Zoom somewhere between 1 and 1.3 times
self.behaviour1 = clutter.BehaviourScale(scale_start=1, scale_end=rand_zoom, alpha=self.alpha)
self.behaviour1.set_property("scale-gravity", clutter.GRAVITY_CENTER) #As at Clutter r1807 you cannot set the gravity on the line above.
#self.behaviour1.set_property("scale-gravity", clutter.GRAVITY_CENTER) #As at Clutter r1807 you cannot set the gravity on the line above.
#panning stuff
x_pos = self.currentTexture.get_x() + random.randint(-100, 100)
@ -221,12 +222,14 @@ class Module:
#Pick a random spot for the next image
x_pos = random.randint(0, abs(self.stage.get_width() - self.nextTexture.get_width()) ) #Somewhere between 0 and (stage_width-image_width)
y_pos = random.randint(0, abs(self.stage.get_height() - self.nextTexture.get_height()) )
self.nextTexture.set_position(x_pos, y_pos)
#print "pic pos: " + str(x_pos) + ":" + str(y_pos)
self.oldTexture = self.currentTexture
self.currentTexture = self.nextTexture
self.currentFilename = self.newFilename
self.stage.add(self.currentTexture)
self.nextTexture.set_position(x_pos, y_pos)
self.nextTexture.show()
self.timeline_dissolve.start()
self.nextImage(self.currentTexture)
@ -312,7 +315,7 @@ class Module:
#Fade everything out
timeline_stop = clutter.Timeline(10,30)
alpha = clutter.Alpha(timeline_stop, clutter.ramp_inc_func)
self.stop_behaviour = clutter.BehaviourOpacity(alpha, 255, 0)
self.stop_behaviour = clutter.BehaviourOpacity(opacity_start=255, opacity_end=0, alpha=alpha)
self.stop_behaviour.apply(self.currentTexture)
self.stop_behaviour.apply(self.backdrop)
self.stop_behaviour.apply(self.overlay)

View File

@ -7,6 +7,7 @@ import pango
import clutter
import os
from modules.video_player.CoverItem import cover_item
from InputQueue import InputQueue
class coverViewer(clutter.Group):
scaleFactor = 1.4
@ -33,6 +34,13 @@ class coverViewer(clutter.Group):
self.num_columns = columns
self.cover_size = int(self.covers_width / self.num_columns) #A cover will be cover_size * cover_size (X * Y)
#Setup input queue controller
self.input_queue = InputQueue()
self.input_queue.set_action(InputQueue.NORTH, self.move_up)
self.input_queue.set_action(InputQueue.SOUTH, self.move_down)
self.input_queue.set_action(InputQueue.EAST, self.move_right)
self.input_queue.set_action(InputQueue.WEST, self.move_left)
#Setup the current min and max viewable rows
self.min_visible_rows = 0
@ -106,6 +114,7 @@ class coverViewer(clutter.Group):
def select_item(self, incomingItem, outgoingItem):
self.timeline = clutter.Timeline(10,35)
self.input_queue.set_timeline(self.timeline)
numFolders = len(self.folderLibrary)
if incomingItem >= numFolders:
incomingItemVideo = incomingItem - numFolders
@ -169,6 +178,7 @@ class coverViewer(clutter.Group):
def select_first(self):
self.timeline = clutter.Timeline(20,80)
self.input_queue.set_timeline(self.timeline)
if not len(self.folderLibrary) == 0:
pass
else:
@ -294,24 +304,30 @@ class coverViewer(clutter.Group):
return self.textureLibrary
def on_key_press_event(self, event):
newItem = None
if event.keyval == clutter.keysyms.Left:
#Make sure we're not already on the first cover
if not self.currentSelection == 0:
newItem = self.currentSelection - 1
elif event.keyval == clutter.keysyms.Right:
#This check makes sure that we're not on the last cover already
if not self.currentSelection == (self.num_covers-1):
newItem = self.currentSelection + 1
elif event.keyval == clutter.keysyms.Down:
#Check if we're already on the bottom row
if not (self.currentSelection > (len(self.textureLibrary)-1 - self.num_columns)):
newItem = self.currentSelection + self.num_columns
elif event.keyval == clutter.keysyms.Up:
#Check if we're already on the top row
if not (self.currentSelection < self.num_columns):
newItem = self.currentSelection - self.num_columns
self.input_queue.input(event)
#These are the basic movement functions
def move_left(self):
#Make sure we're not already on the first cover
if not self.currentSelection == 0:
newItem = self.currentSelection - 1
self.move_common(newItem)
def move_right(self):
#This check makes sure that we're not on the last cover already
if not self.currentSelection == (self.num_covers-1):
newItem = self.currentSelection + 1
self.move_common(newItem)
def move_up(self):
#Check if we're already on the top row
if not (self.currentSelection < self.num_columns):
newItem = self.currentSelection - self.num_columns
self.move_common(newItem)
def move_down(self):
#Check if we're already on the bottom row
if not (self.currentSelection > (len(self.textureLibrary)-1 - self.num_columns)):
newItem = self.currentSelection + self.num_columns
self.move_common(newItem)
def move_common(self, newItem):
#Final sanity check
if (newItem < 0) and (not newItem == None):
newItem = self.currentSelection