viewgit/index.php:465 Only variables should be passed by reference [2048]

viewgit/index.php:466 Non-static method GeSHi::get_language_name_from_extension() should not be called statically [2048]

  1. #
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Implementazione del Widget per gestire il video
  5. #
  6.  
  7. import pygtk, gtk, gst, cairo, threading, time
  8.  
  9. class GstPlayer(threading.Thread):
  10.  
  11. def __init__(self, xid, video):
  12. threading.Thread.__init__(self)
  13. self.xid = xid
  14. self.video = video
  15.  
  16. self.exit_required = False
  17. self.loading = False
  18.  
  19. self.daemon = True
  20.  
  21. def set_sink(self, sink):
  22. assert self.xid
  23. self.imagesink = sink
  24. self.imagesink.set_xwindow_id(self.xid)
  25.  
  26. def on_sync_message(self, bus, message):
  27.  
  28. if message.structure is None:
  29. return
  30. if message.structure.get_name() == 'prepare-xwindow-id':
  31. gtk.gdk.threads_enter()
  32.  
  33. self.set_sink(message.src)
  34. message.src.set_property("force-aspect-ratio", True)
  35. gtk.gdk.threads_leave()
  36.  
  37. def on_message(self, bus, message):
  38. if message.type == gst.MESSAGE_ERROR:
  39. err, debug = message.parse_error()
  40. print err, debug
  41. elif message.type == gst.MESSAGE_LATENCY:
  42. print message.parse_latency()
  43. elif message.type == gst.MESSAGE_BUFFERING:
  44. if message.parse_buffering() is 100:
  45. self.play()
  46. self.loading = False
  47.  
  48.  
  49. def is_loading(self):
  50. return self.loading
  51.  
  52. def run(self):
  53. self.player = gst.element_factory_make("playbin", "player")
  54.  
  55. self.player.set_property
  56. bus = self.player.get_bus()
  57. bus.enable_sync_message_emission()
  58. bus.add_signal_watch()
  59. bus.connect("sync-message::element", self.on_sync_message)
  60. bus.connect("message", self.on_message)
  61.  
  62. self.loading = True
  63.  
  64. self.player.set_property("uri", self.video)
  65.  
  66. self.pause()
  67.  
  68. while not self.exit_required:
  69. pass
  70.  
  71. self.player.set_state(gst.STATE_NULL)
  72.  
  73. def exit(self):
  74. self.player.set_state(gst.STATE_NULL)
  75. self.exit_required = True
  76.  
  77. def pause(self):
  78. self.player.set_state(gst.STATE_PAUSED)
  79.  
  80. def play(self):
  81. self.player.set_state(gst.STATE_PLAYING)
  82. self.loading = False
  83.  
  84.  
  85. class VideoWidget(gtk.DrawingArea):
  86.  
  87. def __init__(self):
  88.  
  89. ## Creo la drawing area e la coloro
  90. ## di nero
  91. gtk.DrawingArea.__init__(self)
  92.  
  93. self.set_size_request(240,240)
  94. self.unset_flags(gtk.DOUBLE_BUFFERED)
  95.  
  96. ## Connetto l'expose-event
  97. self.connect("expose-event", self.colorize)
  98.  
  99. self.playing = False
  100. self.player = None
  101.  
  102.  
  103. def colorize(self, widget, event):
  104. """Quando la finestra viene creata la coloriamo di
  105. nero. Poi sarà tutto lavoro per gstreamer"""
  106.  
  107. ## Ci permettiamo di disegnare sopra il filmato
  108. ## se e solo se non c'è un filmato che sta andando! :)
  109.  
  110. print self.playing
  111.  
  112. if not self.playing:
  113. cr = self.window.cairo_create()
  114. ## Non facciamo lavoro extra e coloriamo solo ciò
  115. ## che è stato scoperto
  116. cr.rectangle(event.area.x, event.area.y,
  117. event.area.width, event.area.height)
  118.  
  119. cr.clip()
  120.  
  121. width, height = self.window.get_size()
  122.  
  123. cr.set_source_rgb(0,0,0)
  124. cr.rectangle(0,0,width,height)
  125. cr.fill()
  126.  
  127. pixbuf = gtk.gdk.pixbuf_new_from_file("ui/rai_logo.png")
  128. x = pixbuf.get_width()
  129. y = pixbuf.get_height()
  130. cr.set_source_pixbuf(pixbuf,max((width-x)/2,0),max((height-y)/2,0))
  131.  
  132.  
  133. cr.rectangle(max((width - x)/2,0),max((height-y)/2,0),x,y)
  134. cr.fill()
  135.  
  136. return
  137.  
  138. cr.set_source_rgb(0.5,0,0)
  139. st = "RaiTV :)"
  140. cr.set_font_size(height/20)
  141. cr.select_font_face("Comic Sans MS")
  142. xbearing , ybearing, twidth, theight, xadvance, yadvance = cr.text_extents(st)
  143.  
  144. cr.move_to(width/2 - twidth/2, 1.6*height/3 - theight/5)
  145. cr.show_text(st)
  146.  
  147. cr.set_line_width(3)
  148. cr.move_to(width/2 - twidth/2 - 5 , 1.6* height/3)
  149. cr.rel_line_to(twidth + 10,0)
  150. cr.stroke()
  151.  
  152.  
  153. def load_video(self, uri):
  154. """Start video playing with the specified URI"""
  155. ## Stoppiamo ogni video
  156. if self.playing:
  157. self.stop()
  158.  
  159. print " => Buono, video stoppati"
  160.  
  161. self.player = GstPlayer(self.window.xid, uri)
  162. print " => Player creato"
  163. self.player.start()
  164. self.player.pause()
  165. print " => Player avviato"
  166. self.playing = True
  167.  
  168.  
  169. ## Aspettiamo 5 secondi
  170.  
  171.  
  172.  
  173. def pause(self):
  174. self.player.pause()
  175.  
  176. def stop(self):
  177. self.playing = False
  178. if self.player is not None:
  179. self.player.exit()
  180. self.player.join(2)
  181. if self.player.isAlive():
  182. print " => Ops, l'ho ucciso brutalmente"
  183. del self.player
  184.  
  185. self.repaint()
  186.  
  187. def repaint(self):
  188.  
  189. width, height = self.window.get_size()
  190. self.queue_draw_area(0,0,width,height)
  191.  
  192.  
  193.  
  194. def play(self):
  195. if self.player is not None:
  196. self.playing = True
  197. self.player.play()
  198.  
  199.  
  200.  
  201.  
  202. def reset(self):
  203. pass