Parcourir la source

Change: SongTitle

Satoshi Yoneda il y a 6 ans
Parent
commit
2674f8161e
1 fichiers modifiés avec 48 ajouts et 20 suppressions
  1. 48 20
      tree/usr/local/bin/superdac.py

+ 48 - 20
tree/usr/local/bin/superdac.py

@@ -612,6 +612,8 @@ class LCD(Worker, threading.Thread):
 	
 	BOTTOM_HEIGHT = 12
 	INDICATE_HEIGHT = 10
+	TOP_HEIGHT = 138
+	
 	
 	term = False
 	
@@ -664,12 +666,12 @@ class LCD(Worker, threading.Thread):
 				if item.getWidth() != self.WIDTH:
 					scale = float(float(self.WIDTH)/float(item.getWidth()))
 					image = item.getImage().resize((int(item_width * scale), int(item_height*scale)), Image.BILINEAR)
-				if image.size[1] > self.HEIGHT:
-					image = image.crop( box=(0,0,self.WIDTH, self.HEIGHT) )
 				
 				# Display TOP
 				if item.getPos() == LCDItem.TOP:
-					self.disp.display(image, x0=left, y0=upper, x1=self.WIDTH-1, y1=image.size[1]-1 )
+					topimg = Image.new('RGB', (LCD.WIDTH, LCD.TOP_HEIGHT), 0)
+					topimg.paste(image)
+					self.disp.display(topimg, x0=left, y0=upper, x1=self.WIDTH-1, y1=topimg.size[1]-1 )
 			
 				# Display Bottom
 				elif item.getPos() == LCDItem.BOTTOM:
@@ -859,28 +861,13 @@ class AlbumArt(Worker, threading.Thread):
 		
 		# Display AlbumArt
 		if imgfile is not None:
-			# LCD clear
-			param = LCDItem(None, clear=True)
-			msg = Message(self,Message.DISPLAY, param)
-			self.sendMessage(msg)
-			#
 			image = Image.open(imgfile)
 			param = LCDItem(image, pos=LCDItem.TOP)
 			msg = Message(self, Message.DISPLAY, param)
 			self.sendMessage(msg)
 			# インジケータ再描画
-			self.sendMessage(Message(self, Message.INDICATOR, None))
+#			self.sendMessage(Message(self, Message.INDICATOR, None))
 		
-		# Display Title
-		if 'title' in current:
-			title = current['title']
-			jpfont = ImageFont.truetype(DEFAULT_FONT, LCD.BOTTOM_HEIGHT, encoding="unic");
-			image = Image.new('RGB', (LCD.WIDTH, LCD.BOTTOM_HEIGHT), 0)
-			draw = ImageDraw.Draw(image)
-			draw.text((0,0) , title, font=jpfont, fill='#FFFFFF')
-			param = LCDItem(image, pos=LCDItem.BOTTOM)
-			msg = Message(self, Message.DISPLAY, param)
-			self.sendMessage(msg)
 		return
 	
 	def receiveMessage(self,message):
@@ -900,6 +887,42 @@ class AlbumArt(Worker, threading.Thread):
 			except queue.Empty:
 				sleep(0.05)
 		return
+		
+		
+class SongTitle(Worker, threading.Thread):
+	
+	term = False
+	
+	def __init__(self, pm):
+		threading.Thread.__init__(self)
+		Worker.__init__(self, pm)
+		self.messageq = queue.Queue()
+	
+	def receiveMessage(self, message):
+		if message.getMessage() == Message.MPD:
+			self.messageq.put(message.getParam())
+		elif message.getMessage() == Message.TERM:
+			self.term = True
+		return True
+	
+	def draw(self, title):
+		jpfont = ImageFont.truetype(DEFAULT_FONT, LCD.BOTTOM_HEIGHT, encoding="unic");
+		image = Image.new('RGB', (LCD.WIDTH, LCD.BOTTOM_HEIGHT), 0)
+		draw = ImageDraw.Draw(image)
+		draw.text((0,0) , title, font=jpfont, fill='#FFFFFF')
+		param = LCDItem(image, pos=LCDItem.BOTTOM)
+		msg = Message(self, Message.DISPLAY, param)
+		self.sendMessage(msg)
+	
+	def run(self):
+		while self.term == False:
+			try:
+				param = self.messageq.get_nowait()
+				if 'title' in param['current']:
+					self.draw(param['current']['title'])
+			except queue.Empty:
+				sleep(0.05)
+		return
 			
 
 # Indicator worker
@@ -1131,7 +1154,6 @@ class MPC(Worker, threading.Thread):
 
 		
 
-
 # lirc remote control worker
 class Remote(Worker, threading.Thread):
 
@@ -1237,6 +1259,12 @@ class PlayerMain(Master, threading.Thread):
 		self.mpc.start()
 		self.workers.append(self.mpc)
 		
+		# SongTitle
+		st = SongTitle(self)
+		st.setDaemon(True)
+		st.start()
+		self.workers.append(st)
+		
 		# Indicator
 		id = Indicator(self)
 		id.setDaemon(True)