Generic mass rewrite of stuff.

- Menus up to about 98% working
- Much experimental code in for gstreamer playback
- So much stuff I forget
This commit is contained in:
noisymime 2007-08-26 13:15:05 +00:00
parent 72ac4c6fdd
commit 9c24b4b3d3
12 changed files with 224 additions and 58 deletions

View File

@ -19,10 +19,7 @@ class DvdPlayer:
self.pause()
if event.keyval == clutter.keysyms.q:
clutter.main_quit()
if event.keyval == clutter.keysyms.left:
clutter.main_quit()
if event.keyval == clutter.keysyms.right:
clutter.main_quit()
def begin(self, MenuMgr):
self.stage.add(self.video)
@ -41,7 +38,19 @@ class DvdPlayer:
def stop(self):
pass
if self.video.get_playing():
self.video.set_playing(False)
#self.myConn.stop()
timeline = clutter.Timeline(15, 25)
timeline.connect('completed', self.end_video_event)
alpha = clutter.Alpha(timeline, clutter.ramp_inc_func)
behaviour = clutter.BehaviourOpacity(alpha, 255,0)
behaviour.apply(self.video)
timeline.start()
def end_video_event(self, data):
self.stage.remove(self.video)
def pause(self):
self.paused = True

87
Menu.py
View File

@ -50,7 +50,6 @@ class Menu:
if self.displayMax > len(self.menuItems):
self.displayMax = len(self.menuItems)
self.displaySize = self.displayMax - self.displayMin
print self.displayMax
for i in range(self.displaySize):
self.menuItems[i].show()
@ -104,14 +103,15 @@ class Menu:
self.moveQueue = self.moveQueue + 1
#self.timeline.set_speed(1000) # Nasty hack to make sure the timeline finishes
return None
self.timeline = clutter.Timeline (15,85)
self.timeline.connect('completed', self.completeMove)
#Check if we're at the last item in the list
if (self.selected) != (len(self.menuItems)-1):
if (self.selected) != (len(self.menuItems)-1):
self.timeline = clutter.Timeline (15,85)
self.timeline.connect('completed', self.completeMove)
if not self.moveQueue == 0:
self.selected = self.selected + self.moveQueue
self.selected = self.selected +1 #+ self.moveQueue
self.moveQueue = self.moveQueue - 1 #0
if self.selected > (len(self.menuItems)-1):
self.selected = (len(self.menuItems)-1)
else:
@ -130,7 +130,7 @@ class Menu:
self.menuItems[i].scaleLabel(2, self.timeline)
#Check we're at the bottom of the viewable list
if self.selected >= self.displayMax:
if self.selected >= (self.displayMax):
#If yes, move the menu, leave the selection bar where is
self.menuItems[self.selected].set_opacity(0)
self.menuItems[self.selected].show()
@ -139,25 +139,26 @@ class Menu:
#move the selection bar
self.menuMgr.get_selector_bar().selectItem(self.menuItems[self.selected], self.timeline)
self.timeline.start()
self.moveQueue = 0
self.timeline.start()
self.moveQueue = 0
#Returns the newly selected item
def selectPrevious(self):
#Initially check whether the last animation is still going
#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
return None
self.timeline = clutter.Timeline (15,85)
self.timeline.connect('completed', self.completeMove)
#Check if we're at the first item in the list
if (self.selected) != 0:
if (self.selected) != 0:
self.timeline = clutter.Timeline (15,85)
self.timeline.connect('completed', self.completeMove)
if not self.moveQueue == 0:
self.selected = self.selected + self.moveQueue
self.selected = self.selected -1 #+ self.moveQueue
self.moveQueue = self.moveQueue + 1 # 0
if self.selected < 0:
self.selected = 0
else:
@ -165,7 +166,8 @@ class Menu:
#This horrible loop does all the scaling
#This includes, the selected item and the ones on either side of it
for i in range(len(self.menuItems)):
for i in range(len(self.menuItems)-1):
#print str(i)
if i == self.selected:
self.menuItems[i].scaleLabel(0, self.timeline)
elif (i == self.selected-1) and (i >= self.displayMin+1):
@ -174,9 +176,15 @@ class Menu:
self.menuItems[i].scaleLabel(1, self.timeline)
else:
self.menuItems[i].scaleLabel(2, self.timeline)
#This is a hack but it seems to fix a wierd bug (If rmeoving this, remove the -1 from the for loop above
if (self.selected == (len(self.menuItems)-2) ):
self.menuItems[len(self.menuItems)-1].scaleLabel(1, self.timeline)
if (self.selected == (len(self.menuItems)-3) ):
self.menuItems[len(self.menuItems)-1].scaleLabel(2, self.timeline)
#Check we're at the top of the viewable list
if self.selected < self.displayMin:
if self.selected < (self.displayMin):
#If yes, move the menu, leave the selection bar where is
#self.menuItems[self.selected].set_opacity(0)
#self.menuItems[self.selected].show()
@ -185,16 +193,20 @@ class Menu:
#move the selection bar
self.menuMgr.get_selector_bar().selectItem(self.menuItems[self.selected], self.timeline)
self.timeline.start()
self.moveQueue = 0
self.timeline.start()
self.moveQueue = 0
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!"
self.timeline = clutter.Timeline(1, 75)
self.selected = 0
for i in range(0,len(self.menuItems)):
@ -211,31 +223,43 @@ class Menu:
self.timeline.start()
#When the menu needs to display a new item from the top or bottom, it rolls
# The distance the menu moves is the distance (in pixels) between the incoming item and the selector bar
def rollMenu(self, incomingMenuItem, outgoingMenuItem, timeline):
(group_x, group_y) = self.itemGroup.get_abs_position()
(bar_x, bar_y) = incomingMenuItem.get_menu().getMenuMgr().get_selector_bar().get_abs_position()
(incoming_x, incoming_y) = incomingMenuItem.get_abs_position()
#print self.itemGroup.get_abs_position()
#print "Starting group position: " + self.itemGroup.get_abs_position()
if incoming_y > bar_y:
#Then the incoming item is below the selector bar
gap = (incoming_y - bar_y) * -1
gap = (incoming_y - bar_y - (self.item_gap/2)) * -1
#gap = -65
self.displayMin = self.displayMin+1
self.displayMax = self.displayMax+1
else:
#Then the incoming item is above the selector bar
gap = bar_y - incoming_y + (self.item_gap/2)
#gap = 65
self.displayMin = self.displayMin-1
self.displayMax = self.displayMax-1
#print "Gap: " + str(gap)
new_y = (group_y+gap)
knots = (\
(group_x, group_y),\
(group_x, group_y+gap)\
(group_x, new_y )\
)
alpha = clutter.Alpha(timeline, clutter.ramp_inc_func)
behaviour = clutter.BehaviourPath(alpha, knots)
behaviour1 = clutter.BehaviourPath(alpha, knots)
behaviour2 = clutter.BehaviourOpacity(alpha, outgoingMenuItem.get_opacity(), 0)
behaviour.apply(self.itemGroup)
#print "Going to: "+ str(new_y)
#print behaviour1.get_knots()
behaviour1.apply(self.itemGroup)
behaviour2.apply(outgoingMenuItem)
def get_item_gap(self):
@ -264,8 +288,7 @@ class ListItem (clutter.Label):
#Text is actually scaled down in 'regular' position so that it doesn't get jaggies when zoomed in
self.set_scale(self.zoomLevel, self.zoomLevel)
self.currentZoom = self.zoomLevel
self.currentZoom = 0
#(label_width, label_height) = self.label.get_size()
label_x = 0 #x #self.stage.get_width() - label_width - 50
@ -278,9 +301,7 @@ class ListItem (clutter.Label):
self.itemTexturesGroup.hide_all()
def scaleLabel(self, level, timeline):
self.timeline = timeline
self.timeline.set_loop(False)
#Determine the zooming level
zoomTo=0
opacityTo = 255
@ -300,16 +321,14 @@ class ListItem (clutter.Label):
if zoomTo == self.currentZoom:
return None
alpha = clutter.Alpha(self.timeline, clutter.ramp_inc_func)
alpha = clutter.Alpha(timeline, clutter.ramp_inc_func)
self.behaviour1 = clutter.BehaviourScale(alpha, self.currentZoom, zoomTo, clutter.GRAVITY_WEST)
self.behaviour2 = clutter.BehaviourOpacity(alpha, self.currentOpacity, opacityTo)
self.behaviour1.apply(self)
self.behaviour2.apply(self)
self.currentZoom = zoomTo
self.currentOpacity = opacityTo
return self.timeline
def get_zoom_level(self):
return self.zoomLevel

BIN
Menu.pyc

Binary file not shown.

View File

@ -165,11 +165,7 @@ class MenuSelector(clutter.Texture):
def selectItem(self, selectee, timeline):
(x, y) = selectee.get_abs_position()
group_x = selectee.get_menu().getItemGroup().get_x()
group_y = selectee.get_menu().getItemGroup().get_y()
x = x + self.x_offset
self.timeline = timeline
#Check if we're going up or down
if y > self.get_y():
@ -179,16 +175,15 @@ class MenuSelector(clutter.Texture):
#Going up
y = int(y - selectee.get_menu().get_item_gap()/2)
self.move_to(x, y, self.timeline)
self.move_to(x, y, timeline)
def move_to(self, x, y, timeline):
self.timeline = timeline
knots = (\
(self.get_x(), self.get_y()),\
(x, y)\
)
self.alpha = clutter.Alpha(self.timeline, clutter.ramp_inc_func)
self.alpha = clutter.Alpha(timeline, clutter.ramp_inc_func)
self.behaviour = clutter.BehaviourPath(self.alpha, knots)
self.behaviour.apply(self)
@ -212,8 +207,8 @@ class MenuSelector(clutter.Texture):
self.spinner.set_size(width, height)
(x, y) = self.get_abs_position()
x = x + self.get_width() - int(self.get_width() * 0.11)
y = y + int(self.get_height() * 0.05)
x = x + self.get_width() - int(self.get_width() * 0.13)
y = y + int(self.get_height() * 0.03)
self.spinner.set_position(x, y)
self.spinner.set_opacity(0)

Binary file not shown.

View File

@ -41,6 +41,7 @@ class TVPlayer:
#self.buffer_file = open("test.mpg","r")
#fd = self.buffer_file.fileno()
#print os.read(fd, 100)
stage = self.menuMgr.get_stage()
self.menuMgr.get_selector_bar().set_spinner(False)
self.video.set_uri("fd://"+str(fd))
#self.video.set_property("fullscreen", True)
@ -57,11 +58,26 @@ class TVPlayer:
timeline.start()
return None
playbin = self.video.get_playbin() .get_by_name("decodebin0")
for element in playbin.elements():
print element.get_name()
sink = playbin.elements().next()
deinterlace = gst.element_factory_make("ffdeinterlace", "deinterlace")
playbin.add(deinterlace)
#gst.element_link_many(sink, deinterlace)
self.video.set_size(stage.get_width(), stage.get_height())
self.video.set_size(800, 600)
#self.video.set_height(stage.get_height())
"""
self.video_texture = clutter.Texture()
self.pipeline = gst.Pipeline("mypipeline")
self.pbin = gst.element_factory_make("playbin", "pbin");
self.sink = cluttergst.video_sink_new(self.video_texture)
self.pbin.set_property("uri", "fd://"+str(fd))
# add elements to the pipeline
self.pipeline.add(self.pbin)
self.pipeline.set_state(gst.STATE_PLAYING)

Binary file not shown.

View File

@ -1,6 +1,10 @@
import pygtk
import gtk
import pygst
import gst
import gobject
import clutter
from clutter import cluttergst
class VideoPlayer():
@ -14,6 +18,10 @@ class VideoPlayer():
#This block can be moved to begin() but causes a performance hit when loading the module *shrug*
results = dbMgr.get_videos()
if results == None:
print "VideoPlayer: No connection to DB or no videos found in DB"
return None
for record in results:
tempVideo = videoItem()
tempVideo.importFromMythObject(record)
@ -52,8 +60,39 @@ class VideoPlayer():
begin_behaviour.apply(self.cover_viewer)
timeline_begin.start()
"""
video = customBin()
video.get_texture().show()
video.get_texture().set_opacity(255)
self.stage.add(video.get_texture())
video.startPlayback()
self.video_texture = clutter.Texture() #cluttergst.VideoTexture()
self.pipeline = gst.Pipeline("mypipeline")
self.filesrc = gst.element_factory_make("filesrc", "file")
self.filesrc.set_property("location", "/home/josh/clutter/toys/gloss/cast1.avi")
#self.pbin.set_property("uri", "file://cast1.avi")
self.pbin = gst.element_factory_make("decodebin", "pbin")
#self.pbin = gst.element_factory_make("videotestsrc", "video")
self.sink = gst.element_factory_make("xvimagesink", "sink")
#self.sink = cluttergst.video_sink_new(self.video_texture)
#self.sink = cluttergst.VideoSink(self.video_texture)
# add elements to the pipeline
self.pipeline.add(self.pbin)
self.pipeline.add(self.sink)
self.pipeline.add(self.filesrc)
self.pbin.link(self.sink)
self.pbin.link(self.filesrc)
self.pipeline.set_state(gst.STATE_PLAYING)
self.stage.add(self.video_texture)
#self.stage.add(self.sink)
"""
def stop(self):
#Fade everything out
@ -75,7 +114,7 @@ class VideoPlayer():
pass
def unpause(self):
passnews/page2
pass
class videoItem():
def __init(self):
@ -145,8 +184,95 @@ class coverViewer(clutter.Group):
y = (i % self.num_rows) * self.cover_size
tempTexture.set_position(x, y)"""
class customBin:
def __init__(self):
self.gstInit()
def gstInit(self):
self.texture = gobject.new(cluttergst.VideoTexture, tiled=False) # , "sync-size=False"
#self.texture = clutter.Texture() #cluttergst.VideoTexture()
self.texture.set_property("sync-size", False)
# declare our pipeline and GST elements
self.pipeline = gst.Pipeline("mypipeline")
"""
self.src = gst.element_factory_make("filesrc", "src");
self.src.set_property("location", "test.mpg")
self.demux = gst.element_factory_make("ffdemux_mpegts", "demux")
self.queue1 = gst.element_factory_make("queue", "queue1")
self.queue2 = gst.element_factory_make("queue", "queue2")
self.deinterlace = gst.element_factory_make("ffdeinterlace", "deinterlace")
self.vdecode = gst.element_factory_make("mpeg2dec", "vdecode")
self.adecode = gst.element_factory_make("mad", "adecode")
#self.vsink = gst.element_factory_make("xvimagesink", "vsink")
self.vsink = cluttergst.VideoSink(self.video_texture)
self.asink = gst.element_factory_make("alsasink", "asink")
"""
self.src = gst.element_factory_make("videotestsrc", "src")
#self.warp = gst.element_factory_make ("warptv", "warp")
self.colorspace = gst.element_factory_make ("ffmpegcolorspace", "color")
self.pipeline.add(self.colorspace)
#self.demux = gst.element_factory_make("ffdemux_mpegts", "demux")
self.sink = cluttergst.VideoSink (self.texture)
#self.sink = gst.element_factory_make("autovideosink", "vsink")
self.sink.set_property("qos", True)
self.sink.set_property("sync", True)
# add elements to the pipeline
self.pipeline.add(self.src)
#self.pipeline.add(self.warp)
#self.pipeline.add(self.demux)
#self.pipeline.add(self.colorspace)
self.pipeline.add(self.sink)
"""
self.pipeline.add(self.demux)
self.pipeline.add(self.queue1)
self.pipeline.add(self.queue2)
self.pipeline.add(self.vdecode)
self.pipeline.add(self.deinterlace)
self.pipeline.add(self.adecode)
self.pipeline.add(self.vsink)
self.pipeline.add(self.asink)
# we can"t link demux until the audio and video pads are added
# we need to listen for "pad-added" signals
self.demux.connect("pad-added", self.on_pad_added)
"""
self.texture.set_width(200)
self.texture.set_height(200)
#self.pipeline.add_signal_watch()
#self.pipeline.add_many(self.pipeline, self.src, self.warp, self.colorspace, self.sink)
gst.element_link_many(self.src, self.sink) #self.warp, self.colorspace,
# link all elements apart from demux
#gst.element_link_many(self.src, self.demux)
#gst.element_link_many(self.queue1, self.vsink) #self.vdecode, self.deinterlace,
#gst.element_link_many(self.queue2, self.adecode, self.asink)
#self.pipeline.set_state(gst.STATE_PLAYING)
def on_pad_added(self, element, src_pad):
caps = src_pad.get_caps()
name = caps[0].get_name()
# link demux to vdecode when video/mpeg pad added to demux
if name == "video/mpeg":
sink_pad = self.queue1.get_pad("sink")
elif name == "audio/mpeg":
sink_pad = self.queue2.get_pad("sink")
else:
return
if not sink_pad.is_linked():
src_pad.link(sink_pad)
def startPlayback(self):
# start playback
self.pipeline.set_state(gst.STATE_PLAYING)
def get_texture(self):
return self.texture

Binary file not shown.

View File

@ -24,7 +24,9 @@ class MainApp:
self.stage.set_property("fullscreen", True)
self.stage.connect('button-press-event', self.on_button_press_event)
self.stage.show_all()
#hide the cursor
self.stage.hide_cursor()
#color = clutter.Color(0xff, 0xcc, 0xcc, 0xdd)
color = clutter.Color(0, 0, 0, 0)
@ -45,10 +47,8 @@ class MainApp:
#menu1.setListFont('Tahoma 42')
menu1.setMenuPositionByName("center")
self.menu1 = menu1
self.menu1.selectFirst(True)
self.menu1.display()
self.menu1.selectFirst(True)
self.menu2 = Menu(self.menuMgr)
self.menu2.addItem("Nothing", "ui/dvd.png")

View File

@ -19,6 +19,7 @@ class mythDB():
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
self.connected = False
return None
self.cursor = self.db.cursor()
#self.get_gallery_directory()

Binary file not shown.