def display(self,msg,menu1,menu2,menu3): if self.busy: return False self.busy=True with self.canvas as draw: draw.rectangle((0, 0, self.device.width-1, self.device.height-1), outline=0, fill=0) if UI.USE_ALSA_MIXER: s1 = "%s | Vol: %d%%" % (UI.Mode(), UI.SoundVolume()) else: s1 = "Mode: %s" % (gv.sample_mode) s2=msg if s2 == '': if UI.Voice()>1: s2=str(UI.Voice())+":" if UI.Presetlist()!=[]: s2 += UI.Presetlist()[UI.getindex(UI.Preset(),UI.Presetlist())][1] #s3 = "Scale:%s" % (UI.Scalename()[UI.Scale()]) s3 = "Scale:%s | Chord:%s" % (UI.Scalename()[UI.Scale()], UI.Chordname()[UI.Chord()]) # Change menu lines if necessary if menu1 != '': self.s4=menu1 self.s5=menu2 self.s6=menu3 s6=self.s6 if self.s6!='' else UI.IP() draw.text((self.x, self.top), s1, font=self.font, fill=255) draw.rectangle((self.x, self.top+11,self.device.width, 21), outline=255, fill=255) draw.text((self.x+2, self.top+12), s2, font=self.font,fill=0) draw.text((self.x, self.top+24), s3, font=self.font, fill=255) draw.text((self.x, self.top+32), self.s4, font=self.font, fill=255) draw.text((self.x, self.top+40), self.s5, font=self.font, fill=255) draw.text((self.x, self.top+48), s6, font=self.font, fill=255) self.busy=False return True
def display(msg='', menu1='', menu2='', menu3='', *z): global busy, prevs if busy: return False busy = True # --- default behaviour for first two lines s = [''] * 4 vol = " %d%%" % UI.SoundVolume() if UI.USE_ALSA_MIXER else "" s[0] = "%s%s %s%s" % (UI.Scalename()[UI.Scale()], UI.Chordname()[UI.Chord()], UI.Mode(), vol) if UI.Voice() > 1: s[1] = str(UI.Voice()) + ":" if UI.Presetlist() != []: s[1] += UI.Presetlist()[UI.getindex(UI.Preset(), UI.Presetlist())][1] # --- menu control, fit the 3 menu lines into two/four display lines if I2C_DISPLAY_LCD_LINES == 2: if menu1 != '': if menu3 == '': s[0] = menu1 s[1] = menu2 else: s[0] = menu1 + ":" + menu2 if len( s[0] ) > I2C_DISPLAY_LCD_WIDTH: # make sure the most significant part is displayed s[0] = menu1[:I2C_DISPLAY_LCD_WIDTH - 1 - len(menu2)] + ":" + menu2 s[1] = menu3 if msg != '': s[1] = msg # a message is important, so override s[1] else: if menu1 != '': if menu3 == '': s[2] = menu1 s[3] = menu2 else: s[1] = menu1 s[2] = menu2 s[3] = menu3 else: s[2] = prevs[2] s[3] = prevs[3] # --- display the result for i in xrange(I2C_DISPLAY_LCD_LINES): if not s[i] == prevs[i]: lcd_string(i, s[i]) prevs[i] = s[i] busy = False return True
def do_POST(self): length = int(self.headers.getheader('content-length')) field_data = self.rfile.read(length) fields=parse_qs(field_data) display=True #----------------------------------------------# # Process fields with special logic first # #----------------------------------------------# if "SB_RenewMedia" in fields: if UI.RenewMedia(fields["SB_RenewMedia"]): self.do_GET() # answer the browser return if "SB_Preset" in fields: loading=UI.Preset(UI.procs["Presetlist"][1]()[int(fields["SB_Preset"][0])][0]) if loading: self.do_GET() # answer the browser return if "SB_DefinitionTxt" in fields: loading=UI.DefinitionTxt(fields["SB_DefinitionTxt"][0]) if loading: self.do_GET() # answer the browser return voicechange=False if "SB_Voice" in fields: voicechange=UI.Voice(int(fields["SB_Voice"][0])) notemapchange=False if "SB_Notemap" in fields and not voicechange: UI.Notemap(int(fields["SB_Notemap"][0])) if not (voicechange or notemapchange): if "SB_nm_inote" in fields: # inote is used as a signal: remapping requires it and html page sends it regardless of it being changed if UI.nm_inote(int(fields["SB_nm_inote"][0])): # so now we know something has changed on a screen containing remapping fields if "SB_nm_Q" in fields: UI.nm_Q(int(fields["SB_nm_Q"][0])) # needs to be before onote to get proper name2note translation if "SB_nm_unote" in fields: UI.nm_unote(int(fields["SB_nm_unote"][0])) # needs to be before onote, so onote can reset it if "SB_nm_onote" in fields: UI.nm_onote(int(fields["SB_nm_onote"][0])) if "SB_nm_retune" in fields: UI.nm_retune(int(fields["SB_nm_retune"][0])) if "SB_nm_voice" in fields: UI.nm_voice(int(fields["SB_nm_voice"][0])-1) UI.nm_consolidate() scalechange=False # Scale takes precedence over Chord if "SB_Scale" in fields: scalechange=(UI.Scale()!=UI.Scale(int(fields["SB_Scale"][0]))) if "SB_Chord" in fields and not scalechange: UI.Chord(int(fields["SB_Chord"][0])) if "SB_Button" in fields: display = not (UI.Button(fields["SB_Button"][0])) # if we had succesfull button, a display was shown already #----------------------------------------------# # Next process straightforward fields in bulk # #----------------------------------------------# for n in fields: nam=n[3:] if nam not in ["RenewMedia","Preset","DefinitionTxt","Voice","Notemap","nm_inote","nm_Q","nm_onote","nm_retune","nm_voice","Scale","Chord","Button"]: #"nm_map","nm_sav", self.set_UI_parm(nam,fields[n][0]) if display: UI.display("") # show it on the box if not done already self.do_GET() # as well as on the gui
def display(self, msg='', menu1='', menu2='', menu3='', *z): if self.busy: return False self.busy = True # --- default behaviour s1 = "" s2 = msg if msg == '': if UI.Voice() > 1: s2 = str(UI.Voice()) + ":" if UI.Presetlist() != []: s2 += UI.Presetlist()[UI.getindex(UI.Preset(), UI.Presetlist())][1] if menu1 == '': # The menu will also override s2 vol = " %d%%" % UI.SoundVolume() if UI.USE_ALSA_MIXER else "" s1 = "%s%s %s%s" % (UI.Scalename()[UI.Scale()], UI.Chordname()[UI.Chord()], UI.Mode(), vol) # --- menu control, fit the 3 menu lines into two display lines else: if menu3 == '': s1 = menu1 s2 = menu2 else: s1 = menu1 + ":" + menu2 if len( s1 ) > 16: # make sure the most significant part is displayed s1 = menu1[:15 - len(menu2)] + ":" + menu2 s2 = menu3 if not (s1 == self.prevs1 and s2 == self.prevs2): self.prevs1 = s1 self.prevs2 = s2 self.cmd(0x02) # go home first self.displayline(s1) self.cmd(0xC0) # next line self.displayline(s2) self.busy = False return True