示例#1
0
	def prepareAudioDevCmb(self):
		## Prepares the audio device combo box.
		# Create the combo box for the selection.
		audioCmbBox = gtk.combo_box_new_text()
		self.wTree.get_object('hboxAudioDevice').pack_end(audioCmbBox)
		audioCmbBox.connect('changed', self.changeAudioDevice)
		audioCmbBox.show()
		# Get the available alsa devices.
		self.audioDevDic = msgBus.getAlsaDevices()
		# Append the non-alsa devices.
		for x in (_('Default/Auto'), _('Other (Set from config.ini)')):
			audioCmbBox.append_text(x)
		# For all the alsa devices, add them to the combo box.
		for x in self.audioDevDic:
			audioCmbBox.append_text('Alsa: %s (%s)' % (self.audioDevDic[x], x))
		# Set the preference according to the current device.
		cfgSink = cfg.getStr('audio/audiosink')
		cfgDevice = cfg.getStr('audio/audiodevice')
		if (cfgSink == 'alsasink' and cfgDevice in self.audioDevDic):
			# If we're set to use the alsa sink and the device has been detected.
			# Set that device as the one set (+1 is to account for the 'Other'
			# option at the top of the list.
			audioCmbBox.set_active(self.audioDevDic.keys().index(cfgDevice) + 2)
		elif (cfgSink in ('default', '')):
			# The 'default' option is set, corresponds to sink=default.
			audioCmbBox.set_active(0)
		else:
			# Otherwise set the 'Other' option.
			audioCmbBox.set_active(1)
示例#2
0
	def setAudioSink(self, sinkName=None):
		## Sets the player's audio sink.
		if (not sinkName):
			# Get the sink name if None was passed.
			sinkName = cfg.cl.audiosink or cfg.getStr("audio/audiosink")
		# If default is selected, just use None.
		if (sinkName == "default"): sinkName = None
		
		# If a name was passed, create the element, otherwise pass None
		sink = gst.element_factory_make(sinkName, 'audio-sink') if (sinkName) else None
		# Set the selected audio device.
		device = cfg.getStr('audio/audiodevice')
		if (device != ''): sink.set_property('device', device)
		# Set the player's sink accordingly.
		self.player.set_property('audio-sink', sink)
示例#3
0
	def showOpenDialogue(self, widget=None):
		## Shows the open file dialogue.
		# Prepare the dialogue.
		dlg = dialogues.OpenFile(self.mainWindow, useful.lastFolder, allowSub=True)

		if (dlg.files):
			# If the response is OK, play the first file, then queue the others.
			# Clear the queue first though, since it is now obsolete.
			queue.clear()
			# Set the last folder, (if it exists).
			if (dlg.dir): useful.lastFolder = dlg.dir
			
			if dlg.chkSubs.get_active():
				# If the user want's subtitles, let them choose the stream.
				dlg2 = dialogues.OpenFile(self.mainWindow, useful.lastFolder, multiple=False, useFilter=False, title=_("Choose a Subtitle Stream"))
				if dlg2.files:
					player.player.set_property('suburi', useful.filenameToUri(dlg2.files[0]))
					player.player.set_property('subtitle-encoding', cfg.getStr('video/subenc'))
				else:
					# Bail if they chose add subtitles but then clicked cancel.
					return
			
			# Play the first file and append the rest to the queue.
			self.playFile(dlg.files[0])
			queue.appendMany(dlg.files[1:])
示例#4
0
def getDispTitle(tags):
	## Gets the display title according to configuration.
	# Flag that no tags have been added.
	noneAdded = True
	# Initialise the window's title.
	winTitle = ""
	for x in useful.tagsToTuple(cfg.getStr('gui/tagsyntax')):
		# For all the items in the list produced by tagsToTuple.
		# New string = the associated tag if it's a tag, otherwise just the string.
		# Remember in each x, [0] is True if [1] is a tag, False if it's not.
		try:
			nStr = tags[x[1]] if (x[0]) else x[1]
		except KeyError:
			nStr = None
		if (nStr):
			# If there was a string.
			# Make sure we actually have a string (sometimes the tags are spat out as lists,
			# so if we have a list, just take the first one.
			if (isinstance(nStr, list)):
				nStr = nStr[0]
			if not isinstance(nStr, basestring):
				# If it's not a string, recast it as a string.
				nStr = str(nStr)
			
			# Flag that a tag has been added if it's a tag.
			if (x[0]): noneAdded = False
			# Add the string to the new window title.
			winTitle += nStr
	# If at least one tag was added, return the title, otherwise return None.
	if (not noneAdded):
		return winTitle
	else:
		return None
示例#5
0
def trySubs(file):
	# Trys to automatically set the subtitle track for a file.
	# Get rid of the file:// at the start (if it's there).
	if ('file://' in file): file = file[7:]
	# Rip off the files extension.
	(root, x) = os.path.splitext(file)
	for ext in cfg.getStr('video/autosubexts').split(','):
		# For all the extensions in the extensions list.
		subPath = '%s.%s' % (root, ext)
		if os.path.exists(subPath):
			# If the subtitle file exists DO IT!
			player.player.set_property('suburi', useful.filenameToUri(subPath))
			player.player.set_property('subtitle-encoding', cfg.getStr('video/subenc'))
			print _("Found subtitles stream %s" % subPath)
			return True
	
	return False
示例#6
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'))
示例#7
0
	def setVideoSink(self, sinkName=None):
		## Sets the player's video sink.
		if (not sinkName):
			# Get the sink name if None was passed.
			sinkName = cfg.cl.videosink or cfg.getStr("video/videosink")
		# If default is selected, just use None.
		if (sinkName == "default"): sinkName = None
		
		# Create the sink bin.
		bin =  gst.Bin()
		# Create a filter for colour balancing & add it to the bin.
		colourBalance = gst.element_factory_make('videobalance')
		bin.add(colourBalance)
		# Convert to ffmpeg colourspace to allow more video sinks.
		colourSpace = gst.element_factory_make('ffmpegcolorspace')
		bin.add(colourSpace)
		# Create a ghostpad so I can connect to it from the playbin.
		pad = colourBalance.get_pad('sink')
		ghostPad = gst.GhostPad('sink', pad)
		bin.add_pad(ghostPad)
		# If a name was passed, create the element, otherwise pass use autosink.
		sink = gst.element_factory_make(sinkName if sinkName else 'autovideosink')
		# Create a pad to send navigation information to the gstreamer backend.
		navPad = gst.Pad(name="navPad", direction=gst.PAD_SRC)
		bin.add_pad(navPad)
		bin.add(sink)
		# Link the elements.
		gst.element_link_many(colourBalance, colourSpace,  sink)
		
		# HACK: In Windows, scrap the bin and always use directdrawsink without
		# videobalance.
		if (sys.platform == 'win32'):
			bin = gst.element_factory_make('directdrawsink')
		
		# Actually set the player's sink.
		self.player.set_property('video-sink', bin)
		# Need to change colour settings externally.
		self.colourBalance = colourBalance
示例#8
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'))