def home(page): # Speedometer Display speed = candisplay.can_number(",\nkm/h,0,0,0,0,0") speed.set_position(700,422) speed.set_size(100,100) speed.set_font_name("Futura 50") page.append(speed) # State of Charge Display soc = candisplay.can_number("SOC: ,%,0,0,0,0,0") soc.set_position(10,10) soc.set_size(100,100) page.append(soc) # Some Other Display soc = candisplay.can_number("Something: ,%,0,0,0,0,0") soc.set_position(10,80) soc.set_size(100,100) page.append(soc) # Dial Display dial = candisplay.can_dial(1,241,8,8,0.392157) dial.set_position(25,210) page.append(dial) diallabel = candisplay.can_label("H2 level, none") diallabel.set_position(80,230) diallabel.set_font_name("Helvetica 15") page.append(diallabel)
def build_display(self,config): config_file = open(config, "r+") # get the number of pages self.numpages = 0 for line in config_file.readlines(): # ignore comments and blank lines if line[0] == "#" or line[0] == "\n": continue # check this line's page number newnumber = int(line.split(',')[0]) # if it's the greatest so far, make that the number of pages if newnumber > self.numpages: self.numpages = newnumber # set the position back to the top of file config_file.seek(0) # The current page number (-1 for none) self.curpage = -1 # store the pages and number of elements on each page self.pages = [] elcount = [] #populate the pages and page counts for i in range(0,self.numpages): self.pages.append([]) # each count is [columns, rows] elcount.append([0,0]) # iterate through the config and create the elements for line in config_file.readlines(): # ignore comments and blank lines if line[0] == "#" or line[0] == "\n": continue page,disptype,args = line.strip().split(',',2) # pages are 1 indexed, convert page = int(page)-1 # entire page display if disptype == 'p': if hasattr(pages, args): # call the builder function and pass the page to build getattr(pages, args)(self.pages[page]) # boolean display if disptype == 'b': # create a constant label (no handler) newlabel = candisplay.can_label(args) # find the position for element y = 5+65*elcount[page][1] if y > ysize-50: # go to next column y = 5 elcount[page][0] = elcount[page][0]+1 elcount[page][1] = 0 # each column has width 320 x = 40 + elcount[page][0]*320 newlabel.set_position(x,y) self.pages[page].append(newlabel) # create the boolean display newbool = candisplay.can_bool(args) # just position relative to the label newbool.set_position(x + 220, y+7) self.pages[page].append(newbool) elcount[page][1] = elcount[page][1] + 1 # text display if disptype == 't': newlabel = candisplay.can_label(args) y = 5+65*elcount[page][1] if y > ysize-50: y = 5 elcount[page][0] = elcount[page][0]+1 elcount[page][1] = 0 x = 40 + elcount[page][0]*320 newlabel.set_position(x,y) self.pages[page].append(newlabel) elcount[page][1] = elcount[page][1] + 1 # number display if disptype == 'n': newlabel = candisplay.can_number(args) y = 5+65*elcount[page][1] if y > ysize-50: y = 5 elcount[page][0] = elcount[page][0]+1 elcount[page][1] = 0 x = 40 + elcount[page][0]*320 newlabel.set_position(x,y) self.pages[page].append(newlabel) elcount[page][1] = elcount[page][1] + 1 config_file.close()