Beispiel #1
0
	def playFile(self, file, stop=True):
		## Plays the file 'file' (Could also be a URI).
		# Stop the player if requested. (Required for playbin2 and
		# changing streams midway through another).
		if stop: player.stop()
		if (file == None):
			# If no file is to be played, set the URI to None, and the file to ""
			file = ""
		# Set the now playing label to the file to be played.
		self.nowPlyLbl.set_label(os.path.basename(urllib.url2pathname(file)))
		if (os.path.exists(file) or '://' in file):
			# If it's not already a uri, make it one.
			# Also escape any # characters in the filename
			file = useful.filenameToUri(file).replace('#', '%23')
			# Set the URI to the file's one.
			player.setURI(file)
			# Try to set the subtitle track if requested.
			if cfg.getBool('video/autosub'): subtitles.trySubs(file)
			# Add the file to recently opened files.
			gtk.recent_manager_get_default().add_item(file)
			# Start the player, if it isn't already running.
			if (not player.isPlaying()): player.play()
		
		elif (file != ""):
			# If none of the above, a bad filename was passed.
			print _("Something's stuffed up, no such file: %s") % (file)
			self.playFile(None)
Beispiel #2
0
	def setPlayingTitle(self, tags):
		# If the tags passed aren't 'None'.
		if (tags):
			# If we don't want to set it, return.
			if (not cfg.getBool('gui/fileastitle')): return
			# Set the title name.
			dispTitle = tagger.getDispTitle(tags)
			if (dispTitle):
				# Update the currently displayed titles URI.
				self.titlesURI = player.uri
			else:
				# Use the filename if no tags were found.
				if not (self.titlesURI == player.uri):
					# Make sure we haven't already used tags for this file.
					# If we have, we may as well continue using them.
					# Certain files send 4 or more tag signals, and
					# only one contains useful information.
					dispTitle = useful.uriToFilename(player.uri, ext=False)
				else:
					dispTitle = None
				
			titlename = dispTitle + ' - ' + useful.lName if dispTitle else None
		
		else:
			# Otherwise, the default title.
			titlename = useful.lName
			
		# Set the title.
		if titlename: self.mainWindow.set_title(titlename)
Beispiel #3
0
	def minuteTimer(self):
		## A timer that runs every minute while playing.
		# Disable ScreenSaver (if option is enabled).
		if (cfg.getBool("misc/disablescreensaver") and player.player.get_property('n-video') > 0):
			# Inhibit hte screensaver, technically we only have to do this once.
			## FIXME: Only do this once
			useful.suspendScr()
		
		return player.isPlaying()
Beispiel #4
0
	def __init__(self):
		## Creates and prepares a player.
		# Create the player.
		self.player = gst.element_factory_make("playbin2", "player")
		
		# Make the program emit signals.
		bus = self.player.get_bus()
		bus.add_signal_watch()
		bus.enable_sync_message_emission()
		# Enable the visualisation if requested.
		self.setVisualisation(cfg.getBool("gui/enablevisualisation"))
		# Set the font for subtitles.
		self.setSubFont(cfg.get('video/subfont'))
Beispiel #5
0
	def loadPreferences(self):
		## Reads the preferences from the config and displays them.
		for x in self.chkDic:
			# Set all the checkboxes to their appropriate settings.
			x.set_active(cfg.getBool(self.chkDic[x][CFGS]))
		
		for x in self.adjDic:
			x.set_value(cfg.getFloat(self.adjDic[x][CFGS]))
		
		for x in self.entDic:
			x.set_text(cfg.getStr(self.entDic[x][CFGS]))
		
		self.wTree.get_object('cmbOnExtNewFile').set_active(cfg.getInt('misc/onextnewfile'))
Beispiel #6
0
	def onPlayerSyncMessage(self, bus, message):
		if (message.structure is None):
			return
		
		if (message.structure.get_name() == 'prepare-xwindow-id'):
			# If it's playing a video, set the video properties.
			# Get the properties of the video.(Brightness etc)
			far = cfg.getBool("video/force-aspect-ratio")
			b = cfg.getInt("video/brightness")
			c = cfg.getInt("video/contrast")
			h = cfg.getInt("video/hue")
			s = cfg.getInt("video/saturation")
			player.prepareImgSink(bus, message, far, b, c, h, s)
			# Set the image sink.
			self.setImageSink()
Beispiel #7
0
	def progressBarMotion(self, widget, event):
		## when the mouse moves over the progress bar.
		# If we're not seeking, cancel.
		if (not self.seeking): return
		# Check if the mouse button is still down, just in case we missed it.
		x, y, state = event.window.get_pointer()
		if (not state & gtk.gdk.BUTTON1_MASK): self.seekEnd(widget, event)
		if (cfg.getBool("gui/instantseek")):
			# If instantaneous seek is set, seek!
			self.seekFromProgress(widget, event)
			return
		
		# Get the mouse co-ordinates, the width of the bar and the file duration.
		x, y = event.get_coords()
		maxX = widget.get_allocation().width
		dur = player.getDurationSec()
		# Convert the information to a fraction, and make sure 0 <= frac <= 1
		frac = useful.toRange(float(x) / maxX, 0, 1)
		
		# Set the progress bar to the new data.
		self.progressUpdate((frac * dur), dur)
Beispiel #8
0
	def progressUpdate(self, pld=None, tot=None):
		## Updates the progress bar.
		if (player.isStopped()):
			# If the player is stopped, played time and total should 
			# be 0, and the progress should be 0.
			pld = tot = 0
			self.progressBar.set_fraction(0)
		else:
			# Otherwise (playing or paused), get the track time data, set
			# the progress bar fraction.
			if (pld == None or tot == None): pld, tot = player.getTimesSec()
			self.progressBar.set_fraction(pld / tot if (tot > 0) else 0)
		
		# Convert played & total time to integers
		p, t = int(pld), int(tot)
		# Add the data to the progress bar's text.
		text = ""
		text += useful.secToStr(p)
		if (tot > 0):
			text += " / "
			text += useful.secToStr(t - (cfg.getBool('gui/showtimeremaining') * p))
		self.progressBar.set_text(text)
Beispiel #9
0
	def __init__(self):
		# Set the last folder to the directory from which the program was called.
		useful.lastFolder = useful.origDir
		# Set the application's name (for about dialogue etc).
		gobject.set_application_name(str(useful.lName))
		
		# Create & prepare the player for playing.
		self.preparePlayer()
		# Connect up the sigterm signal.
		signal.signal(signal.SIGTERM, self.sigterm)
		
		if msgBus.avail: self.dbus = msgBus.IntObject(self)
		
		# Set up the gtk-builder and interface.
		self.wTree = gtk.Builder()
		windowname = "main"
		self.wTree.add_from_file(useful.getBuilderFile('main'))
		
		dic = { "on_main_delete_event" : self.quit,
		        "on_mnuiQuit_activate" : self.quit,
		        "on_mnuiOpen_activate" : self.showOpenDialogue,
		        "on_mnuiOpenURI_activate" : self.showOpenURIDialogue,
		        "on_btnPlayToggle_clicked" : self.togglePlayPause,
		        "on_btnStop_clicked" : self.stopPlayer,
		        "on_btnNext_clicked" : self._cb_on_btnNext_clicked,
		        "on_btnRestart_clicked" : self.restartTrack,
		        "on_pbarProgress_button_press_event" : self.progressBarClick,
		        "on_pbarProgress_button_release_event" : self.seekEnd,
		        "on_pbarProgress_motion_notify_event" : self.progressBarMotion,
		        "on_btnVolume_value_changed" : self.changeVolume,
		        "on_mnuiFS_activate" : self.toggleFullscreen,
		        "on_btnLeaveFullscreen_clicked" : self.toggleFullscreen,
		        "on_videoWindow_expose_event" : self.videoWindowExpose,
		        "on_videoWindow_configure_event" : self.videoWindowConfigure,
		        "on_main_key_press_event" : self.windowKeyPressed,
		        "on_videoWindow_button_press_event" : self.videoWindowClicked,
		        "on_videoWindow_scroll_event" : self.videoWindowScroll,
		        "on_mnuiAbout_activate" : self.showAboutDialogue,
		        "on_main_drag_data_received" : self.openDroppedFiles,
		        "on_videoWindow_motion_notify_event" : self.videoWindowMotion,
		        "on_videoWindow_leave_notify_event" : self.videoWindowLeave,
		        "on_videoWindow_enter_notify_event" : self.videoWindowEnter,
		        "on_mnuiPreferences_activate" : self.showPreferencesDialogue,
		        "on_mnuiPlayDVD_activate" : self.showPlayDVDDialogue,
				"on_mnuiDVDMenu_activate" : self.gotoDVDMenu,
		        "on_mnuiAudioTrack_activate" : self.showAudioTracksDialogue,
				"on_mnuiSubtitleManager_activate" : self.openSubtitleManager,
		        "on_mnuiReportBug_activate" : self.openBugReporter,
		        "on_main_window_state_event" : self.onMainStateEvent,
		        "on_mnuiQueue_toggled" : self.toggleQueueWindow,
		        "on_eventNumQueued_button_release_event" : self.toggleQueueWindow,
		        "on_mnuiAdvCtrls_toggled" : self.toggleAdvControls,
		        "on_mnuiSupFeatures_activate" : self.openSupFeaturesDlg,
		        "on_spnPlaySpeed_value_changed" : self.onPlaySpeedChange }
		self.wTree.connect_signals(dic)
		
		# Add the queue to the queue box.
		self.wTree.get_object("queueBox").pack_start(queue.qwin)
		
		# Get several items for access later.
		useful.mainWin = self.mainWindow = self.wTree.get_object(windowname)
		self.progressBar = self.wTree.get_object("pbarProgress")
		self.videoWindow = self.wTree.get_object("videoWindow")
		self.nowPlyLbl = self.wTree.get_object("lblNowPlaying")
		self.volAdj = self.wTree.get_object("btnVolume").get_adjustment()
		self.hboxVideo = self.wTree.get_object("hboxVideo")
		queue.mnuiWidget = self.wTree.get_object("mnuiQueue")
		# Set gapless flag
		self.isvideo = None
		# Set the icon.
		self.mainWindow.set_icon_from_file(os.path.join(useful.dataDir, 'images', 'whaawmp48.png'))
		# Set the window to allow drops
		self.mainWindow.drag_dest_set(gtk.DEST_DEFAULT_ALL, [("text/uri-list", 0, 0)], gtk.gdk.ACTION_COPY)
		# If we drop stuff on the queue label we want it queued (bottom right)
		self.wTree.get_object('lblNumQueued').drag_dest_set(gtk.DEST_DEFAULT_ALL, [("text/uri-list", 0, 0)], gtk.gdk.ACTION_COPY)
		self.wTree.get_object('lblNumQueued').connect('drag-data-received', queue.enqueueDropped)
		# Update the progress bar.
		self.progressUpdate()
		# Get the volume from the configuration.
		volVal = cfg.getFloat("audio/volume") if (cfg.cl.volume == None) else float(cfg.cl.volume)
		self.volAdj.value = useful.toRange(volVal, 0, 1)
		# Set the quit on stop checkbox.
		self.wTree.get_object("mnuiQuitOnStop").set_active(cfg.cl.quitOnEnd)
		# Set up the default flags.
		self.controlsShown = True
		self.seeking = False
		# Call the function to change the play/pause image.
		self.playPauseChange(False)
		# Show the next button & restart track button if enabled.
		if (cfg.getBool("gui/shownextbutton")): self.wTree.get_object("btnNext").show()
		if (cfg.getBool("gui/showrestartbutton")): self.wTree.get_object("btnRestart").show()
		# Setup the signals.
		signals.connect('toggle-play-pause', self.togglePlayPause)
		signals.connect('toggle-fullscreen', self.toggleFullscreen)
		signals.connect('play-next', self.playNext, False)
		signals.connect('restart-track', self.restartTrack)
		signals.connect('toggle-queue', queue.toggle)
		signals.connect('toggle-advanced-controls', self.toggleAdvancedControls)
		signals.connect('queue-changed', self.numQueuedChanged)
		# Show the window.
		self.mainWindow.show()
		# Save the windows ID so we can use it to inhibit screensaver.
		useful.winID = self.mainWindow.get_window().xid
		# Set the queue play command, so it can play tracks.
		queue.playCommand = self.playFile
		# Play a file (if it was specified on the command line).
		if (len(cfg.args) > 0):
			# Append all tracks to the queue.
			queue.appendMany(cfg.args)
			# Then play the next track.
			gobject.idle_add(self.playNext, False)
		
		if (cfg.cl.fullscreen):
			# If the fullscreen option was passed, start fullscreen.
			self.activateFullscreen()
		
		# Connect the hooks.
		self.connectLinkHooks()
		
		# Enter the GTK main loop.
		gtk.main()
Beispiel #10
0
	def toggleForceAspect(self, widget):
		## Sets force aspect ratio to if it's set or not.
		if (player.playingVideo()):
			player.setForceAspectRatio(cfg.getBool("video/force-aspect-ratio"))
			self.main.videoWindowConfigure(self.main.videoWindow)
Beispiel #11
0
	def getCfg(self):
		# Get the config options and give it to the window.
		self.chkAutoSubs.set_active(cfg.getBool('video/autosub'))
		self.txtSubsExt.set_text(cfg.getStr('video/autosubexts'))
		self.txtSubsEnc.set_text(cfg.getStr('video/subenc'))