Пример #1
0
	def handle(self, msg):
		from dwite import get_dm, get_cm, msg_reg

		if type(msg) in [Play, Add]:
			#print 'ui Play/Add %s' % msg
			match = re.match(
				'(?P<scheme>^.+?)://(?P<cm>.+?)/(?P<guid>.+)', msg.url
			)
			if not match:
				errstr = u'Invalid URL format: %s' % msg.url
				msg.respond(1, errstr, 0, False, False)
				return
			scheme = match.group('scheme')
			label  = match.group('cm')
			guid   = match.group('guid')
			if scheme != u'cm':
				errstr = u'Invalid URL scheme: %s' % msg.url
				msg.respond(2, errstr, 0, False, False)
				return
			cm = get_cm(label)
			if not cm:
				errstr = u'No such CM: %s' % label
				msg.respond(3, errstr, 0, False, False)
				return
			get = GetItem(msg_reg.make_guid(), guid)

			# warning: handler executed by CM thread:
			def handle_get_item(msg_reg, msg, orig_msg, cm):
				if msg.errno:
					orig_msg.respond(msg.errno, msg.errstr, 0, False, False)
					return
				item = make_item(cm.label, **msg.result)
				for dm in get_dm(None):
					if type(orig_msg) == Play:
						cmd = PlayItem(
							orig_msg.guid, orig_msg.wire, item, orig_msg.seek
						)
					elif type(orig_msg) == Add:
						cmd = AddItem(orig_msg.guid, orig_msg.wire, item)
					dm.in_queue.put(cmd)

			msg_reg.set_handler(get, handle_get_item, cm, msg)
			cm.wire.send(get.serialize())
			return

		msg.sender = self.label
		try:
			msg_reg.run_handler(msg)
			msg_str = unicode(msg)
			if len(msg_str) > 200:
				msg_str = msg_str[:200]
		except:
			owner = msg_reg.get_owner(msg)
			assert owner != self
			print 'UI: owner %s: %s' % (type(msg), owner.name)
			owner.in_queue.put(msg)
Пример #2
0
	def play(self):
		#print 'play + %s' % self.dump()
		if type(self.focused()) == SearcherResults:
			return None # let menu handle DOWN key
		from dwite import msg_reg, get_cm, get_dm
		if self.query:
			# check for existing results container for the same query to reuse:
			results = self.get_results(self.query)
			if not results:
				results = SearcherResults(self.query, u'', self)
				self.children.append(results)
			waiting = SearcherSearching(self.get_query(), results)
			results.children = [waiting] # TODO: preserve currently playing item
			results.set_focus(waiting)

			for cm in get_cm(None):
				search = Search(msg_reg.make_guid(), self.query)

				def handle_search(msg_reg, response, orig_msg, user):
					#print 'response: %s' % response
					(self, cm) = user
					assert type(self) == Searcher
					parent = self.get_results(orig_msg.terms)
					assert parent != None # not possible because added above
					please_curry = False
					if type(parent.children[0]) == SearcherSearching:
						parent.children = []
						please_curry = True

					if response.errno:
						parent.children = [SearcherNotice(
							u'<%s>' % response.errstr, u'', parent
						)]
						return TRANSITION.NONE
					
					for r in response.result:
						item = make_item(cm, **r)
						link = Link(item, parent)
						parent.children.append(link)
					if please_curry:
						firstborn = parent.children[0]
						firstborn.render.curry(firstborn.target)

				msg_reg.set_handler(search, handle_search, (self, cm.label))
				cm.wire.send(search.serialize())

			self.query = []
			self.notify(default_notice)
			return TRANSITION.SCROLL_LEFT
		return TRANSITION.BOUNCE_LEFT
Пример #3
0
	def cm(self):
		from dwite import get_cm
		return get_cm(self.cm_label)