Konfigurationsmodus für Tide begonnen
This commit is contained in:
		
							parent
							
								
									9ffb28d65b
								
							
						
					
					
						commit
						cd04a5560d
					
				|  | @ -13,6 +13,8 @@ class Navtex(Page): | |||
|     def __init__(self, pageno, cfg, appdata, boatdata): | ||||
|         super().__init__(pageno, cfg, appdata, boatdata) | ||||
|         self.disabled = self.app.navtex is None | ||||
|         if self.disabled: | ||||
|             return | ||||
|         self.ids = self.app.navtex.get_ids() | ||||
|         if len(self.ids) > 0: | ||||
|             self.current = 1 | ||||
|  |  | |||
|  | @ -13,11 +13,86 @@ class Tide(Page): | |||
|     def __init__(self, pageno, cfg, appdata, boatdata): | ||||
|         super().__init__(pageno, cfg, appdata, boatdata) | ||||
| 
 | ||||
|         self.buttonlabel[1] = 'MODE' | ||||
|         self.mode = 'N' # (N)ormal, (C)onfiguration | ||||
| 
 | ||||
|         self.station = "f3c6ee73-5561-4068-96ec-364016e7d9ef" # Schulau | ||||
|         self.app.web.set_pegel('List, Sylt') | ||||
|         self.pegel = 'List, Sylt' | ||||
|         self.app.web.set_pegel(self.pegel) | ||||
|         self.app.web.refresh() | ||||
| 
 | ||||
|     def draw(self, ctx): | ||||
|         # Steuerung der Stationsliste | ||||
|         self.list_max = 10 | ||||
|         self.list_top = 0 | ||||
|         self.list_ix = 0 | ||||
|         self.list_pegel = self.pegel | ||||
|         self.list_count = len(self.app.web.pegeldata) | ||||
| 
 | ||||
|     def handle_key(self, buttonid): | ||||
|         if buttonid == 1: | ||||
|             if self.mode == 'N': | ||||
|                 self.mode = 'C' | ||||
|                 self.buttonlabel[3] = '#UP' | ||||
|                 self.buttonlabel[4] = '#DOWN' | ||||
|                 self.buttonlabel[5] = 'SET' | ||||
|             else: | ||||
|                 self.mode = 'N' | ||||
|                 self.buttonlabel[3] = '#PREV' | ||||
|                 self.buttonlabel[4] = '#NEXT' | ||||
|                 self.buttonlabel[5] = '' | ||||
|             return True | ||||
|         if self.mode == 'C': | ||||
|             if buttonid == 3: | ||||
|                 # Up | ||||
|                 self.list_ix -= 1 | ||||
|                 if self.list_ix < self.list_top: | ||||
|                     self.list_top -= 1 | ||||
|             elif buttonid == 4: | ||||
|                 # Down | ||||
|                 self.list_ix += 1 | ||||
|                 if self.list_ix > self.list_top + self.list_max: | ||||
|                     self.list_top += 1 | ||||
|             elif buttonid == 5: | ||||
|                 # Set | ||||
|                 print(self.list_pegel) | ||||
|                 self.pegel = self.list_pegel | ||||
|                 self.app.web.set_pegel(self.list_pegel) | ||||
|                 self.app.web.refresh() | ||||
|             return True | ||||
|         return False | ||||
| 
 | ||||
|     def draw_config(self, ctx): | ||||
|         # Auswahl | ||||
|         # - Station | ||||
|         # - Zeitraum | ||||
|         #    | ||||
|         ctx.select_font_face("Ubuntu", cairo.FontSlant.NORMAL, cairo.FontWeight.BOLD) | ||||
|         ctx.set_font_size(20) | ||||
| 
 | ||||
|         ctx.move_to(2, 50) | ||||
|         ctx.show_text("Tide configuration") | ||||
| 
 | ||||
|         y = 80 | ||||
|         dy = 20 | ||||
|         ctx.set_font_size(20) | ||||
|         i = 0 | ||||
|         ix = -1 | ||||
|         for pd in self.app.web.pegeldata: | ||||
|             ix += 1 | ||||
|             if ix < self.list_top: | ||||
|                 continue | ||||
|             ctx.move_to(20, y + dy * i) | ||||
|             ctx.show_text(pd) | ||||
|             self.list_pegel = pd | ||||
|             if self.list_ix == ix: | ||||
|                 ctx.show_text(' X') | ||||
|             i += 1 | ||||
|             if self.pegel == pd: | ||||
|                 ctx.show_text(' *') | ||||
|             if ix > self.list_top + self.list_max - 1: | ||||
|                 break | ||||
| 
 | ||||
|     def draw_normal(self, ctx): | ||||
|         # Title | ||||
|         ctx.select_font_face("Ubuntu", cairo.FontSlant.NORMAL, cairo.FontWeight.BOLD) | ||||
|         ctx.set_font_size(24) | ||||
|  | @ -124,3 +199,9 @@ class Tide(Page): | |||
|             else: | ||||
|                 prev_valid = False | ||||
|             x += dx | ||||
| 
 | ||||
|     def draw(self, ctx): | ||||
|         if self.mode == 'N': | ||||
|             self.draw_normal(ctx) | ||||
|         else: | ||||
|             self.draw_config(ctx) | ||||
|  |  | |||
							
								
								
									
										8
									
								
								web.py
								
								
								
								
							
							
						
						
									
										8
									
								
								web.py
								
								
								
								
							|  | @ -74,6 +74,14 @@ class WebInterface(): | |||
|                   ) | ||||
|             self.cur.execute(sql) | ||||
|             self.log.info(f"Created tide database: {dbpath}") | ||||
|         else: | ||||
|             # TODO Alte Daten aus vorhandener Datenbank bereinigen | ||||
|             ts = datetime.now().replace(minute=0, second=0, microsecond=0) - timedelta(days=2) | ||||
|             sql = "DELETE FROM data WHERE timestamp < ?" | ||||
|             self.cur.execute(sql, (ts,)) | ||||
|             self.conn.commit() | ||||
|             if self.cur.rowcount > 0: | ||||
|                 print("Tide: {} old data ponts have been deleted".format(self.cur.rowcount)) | ||||
| 
 | ||||
|         self.pegelid = 'Schulau' | ||||
|         self.bshid = self.pegeldata[self.pegelid] | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue