def updateActiveStats(self, itself): if not self.active: try: if self.rng: stat = self.func(int(self.master.rngEntry.text)) else: stat = self.func() if not stat: raise Exception if type(stat[0]) == list: for s in stat: if not s: raise Exception self.activity.stockGraph.addActiveStats(self.text, stat) self.active = True self.draw() except Exception as e: # print(e) errorPopup = ErrorPopup( "There aren't enough data points to materialize this statistic!" ) errorPopup.open() elif self.active: self.active = False self.draw() self.activity.stockGraph.removeActiveStats(self.text)
def end_call(self, instance): end = self.phone.hang_up() if isinstance(end, bool): self.log_text += "Call ended \n" print("Call ended") else: error = ErrorPopup(end) error.open()
def start_call(self, instance): call = self.phone.call(self.display_text) if isinstance(call, bool): self.log_text += "Started Call \n" print("Started Call") else: error = ErrorPopup(call) error.open()
def update_gps(self): gps2uart = self.phone.toggle_gps_uart() if gps2uart == True: time.sleep(0.5) self.gps_data += self.phone.readGPS() + "\n" time.sleep(0.5) gps2uart = self.phone.toggle_gps_uart() else: error = ErrorPopup(gps2uart) error.open()
def toggle_gps_read(self): gps2uart = self.phone.toggle_gps_uart() if gps2uart == True: Clock.schedule_once( Clock.schedule_interval(self.toggle_gps_read, 1), 2) else: error = ErrorPopup(gps2uart) error.open() if self.phone.gps == True: time.sleep(0.01) self.read_gps()
def updateGraph(self, *args): try: for stat in self.statLayouts: stat.statButton.active = False stat.statButton.draw() self.stockGraph.updateTicker(self.ticker) self.tickerTitle.text = self.ticker self.updateInfo(self.ticker) except BadTickerException as e: errmsg = str(e.ticker) + " does not exist or has been delisted!" self.errorPopup = ErrorPopup(errmsg) self.errorPopup.open() self.loading.dismiss()
def toggle_gps(self): gps = self.phone.toggle_gps() if isinstance(gps, bool): gps_switch = "OFF" if self.phone.gps == True else "ON" self.gps_power = "Turn GPS " + gps_switch self.log_text += "Turn GPS " + gps_switch + "\n" if self.phone.gps == True: time.sleep(1) print("Display GPS Info...") self.log_text += "Display GPS Info...\n" self.show_gps() else: print("GPS Clean Up") self.log_text += "GPS Clean UP...\n" self.gps_baudrate = "" self.gps_gnss = "" self.gps_status = "" else: error = ErrorPopup( "GPS Toggle Error. Please Check the GPS Module (is it on?)") self.log_text += "GPS Toggle Error. Please Check the GPS Module (is it on?) \n" error.open()
def button_callback(self, button_str): valid_chars = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "#", "*"] if button_str in [str(x) for x in valid_chars]: if self.display_text == 'Enter Tel Number': self.display_text = button_str else: self.display_text = self.display_text + button_str # maximum_value = self.maximum_value # if maximum_value != None: # if self.display_value > maximum_value: # self.display_value = maximum_value elif button_str == 'del': # test = IncomingPopup(self.phone) # test.open() if len(self.display_text) == 1: self.display_text = "Enter Tel Number" elif self.display_text != "Enter Tel Number": self.display_text = self.display_text[:-1] elif button_str == 'dial': try: if "Enter Tel" in self.display_text: error = ErrorPopup( "Please Enter a valid telephone number!") self.log_text += "Error: Please Enter a valid telephone number!\n" error.open() else: check = self.phone.service_check() if isinstance(check, bool): print("Phone ready!") self.log_text += "Phone ready!\n" dial_popup = DialPopup(self.display_text) dial_popup.bind(on_open=self.start_call) dial_popup.bind(on_dismiss=self.end_call) dial_popup.open() else: error = ErrorPopup(check) error.open() except SerialException: error = ErrorPopup( "No connection to the SIM Module could be established") self.log_text += "No connection to the SIM Module could be established!\n" error.open() elif button_str == 'answer': if self.phone.is_ringing(): print("The Phone is ringing!") answer = self.phone.answer() if isinstance(answer, bool): call_popup = DialPopup("with incoming calling partner") call_popup.bind(on_dismiss=self.end_call) call_popup.open() else: error = ErrorPopup(answer) error.open() else: error = ErrorPopup("No Incoming Call") error.open()
class StatsActivity(GridLayout): def __init__(self, app, searchDB, abbr="GE"): super().__init__(cols=1, size_hint_y=None) ####################################### ############ Housekeeping ############# ####################################### self.app = app self.searchDB = searchDB self.abbr = abbr self.stockGraph = None self.coloredWidgets = [] self.color = (255 / 255, 255 / 255, 255 / 255, 1) self.bind(minimum_height=self.setter('height')) #[red, orange, yellow, green, blue, purple] self.colorPallete = [(255 / 255, 0 / 255, 0 / 255, 1), (255 / 255, 165 / 255, 0 / 255, 1), (255 / 255, 255 / 255, 0 / 255, 1), (0 / 255, 255 / 255, 0 / 255, 1), (0 / 255, 0 / 255, 255 / 255, 1), (255 / 255, 0 / 255, 255 / 255, 1)] ####################################### ############ Search Layout ############ ####################################### self.searchLayout = BoxLayout(orientation='horizontal') self.searchText = SearchBar(self, self.searchDB) self.searchText.width = Window.width * .8 self.searchText.bind(on_text_validate=self.updateLoader) self.searchLayout.add_widget(self.searchText) self.searchButton = Button(text="Cancel", font_name="res/Aldrich", font_hinting="light", bold=True) self.searchButton.width = Window.width * .2 self.searchButton.bind(on_press=self.removeText) self.searchLayout.add_widget(self.searchButton) self.add_widget(self.searchLayout) ####################################### ############# Data Layout ############# ####################################### self.dataLayout = BoxLayout(orientation="vertical") self.currentLayout = self.dataLayout ####################################### ############ Ticker Layout ############ ####################################### self.tickerLayout = BoxLayout(orientation='horizontal') self.tickerTitle = Label(text=self.abbr, color=self.color, font_name="res/Aldrich", font_hinting="light", bold=True, halign="center", valign="center") def tickerTitleScale(*args): self.tickerTitle.text_size = self.tickerTitle.size self.tickerTitle.bind(size=tickerTitleScale) self.coloredWidgets.append(self.tickerTitle) self.tickerLayout.add_widget(self.tickerTitle) self.tickerDisplay = Label(text="", halign="center", color=self.color, font_name="res/Aldrich", font_hinting="light", bold=True) self.coloredWidgets.append(self.tickerDisplay) self.tickerLayout.add_widget(self.tickerDisplay) self.dataLayout.add_widget(self.tickerLayout) ####################################### ############# Stock Graph ############# ####################################### self.stockGraph = StatsGraph(self.abbr, self, False) self.dataLayout.add_widget(self.stockGraph) # for i in range(len(self.stockGraph.AIKB)): # button = ####################################### ############ Range Options ############ ####################################### self.rangeLayout = BoxLayout(orientation='horizontal') ranges = [("1W", "1wk", "1d"), ("2W", "2wk", "1d"), ("1M", "1mo", "1d"), ("3M", "3mo", "1d"), ("YTD", "YTD", "1d"), ("1Y", "1y", "1d"), ("2Y", "2y", "1d")] self.rangeButtons = [] for r in ranges: rangeButton = RangeButton(r[0], self, r[1], r[2]) self.rangeLayout.add_widget(rangeButton) if r[0] == "YTD": rangeButton.active = True self.rangeButtons.append(rangeButton) self.dataLayout.add_widget(self.rangeLayout) self.signalLineGrid = GridLayout(rows=1, size_hint_y=None, height=Window.height * .1) self.signalButtons = [] # No Signals, Sell Signals, Buy Signals, All Signals combos = [("No\nSignals", self, False, False), ("Sell\nSignals", self, False, True), ("Buy\nSignals", self, True, False), ("Both\nSignals", self, True, True)] for combo in combos: sb = SignalButton(*combo) self.signalButtons.append(sb) self.signalLineGrid.add_widget(sb) self.signalButtons[0].active = True self.signalButtons[0].drawSelected() self.dataLayout.add_widget(self.signalLineGrid) self.updateColors() self.updateInfo(self.abbr) self.statGrid = GridLayout(cols=2, size_hint_y=None, height=Window.height * .5) self.statLayouts = [] for k, v in self.stockGraph.stats.items(): rng = False default = 0 if k in [ "Bollinger Bands", "Exponential Moving Average", "Simple Moving Average", "Relative Strength Index", "Average True Range", "Triple EMA" ]: rng = True default = 10 statLayout = StatLayout(k, v[1], self, v[0], rng, default) self.statGrid.add_widget(statLayout) self.statLayouts.append(statLayout) self.dataLayout.add_widget(self.statGrid) self.add_widget(self.dataLayout) ####################################### ############# Ratio Setup ############# ####################################### self.searchLayout.size_hint_y = None self.searchLayout.height = Window.height * .1 self.tickerLayout.size_hint_y = None self.tickerLayout.height = Window.height * .1 self.stockGraph.size_hint_y = None self.stockGraph.height = Window.height * .5 self.rangeLayout.size_hint_y = None self.rangeLayout.height = Window.height * .1 self.dataLayout.size_hint_y = None self.dataLayout.height = (self.tickerLayout.height + self.stockGraph.height + self.rangeLayout.height + Window.height * .6) # self.bind(size = self.scale) def scale(self, *args): Clock.schedule_once(self.continuousHeight, 0) def continuousHeight(self, *args): self.dataLayout.height = (self.tickerLayout.height + self.stockGraph.height + self.rangeLayout.height + Window.height * .6) def removeText(self, *args): # if not self.searchText.text: # return self.searchText.text = "" self.swap() def updateColors(self): if not self.stockGraph: return self.color = self.stockGraph.color for widget in self.coloredWidgets: widget.color = self.color for button in self.rangeButtons: button.updateColor() def updateLoader(self, *args): if not self.searchText.text: return self.ticker = self.searchText.text.upper() self.searchText.text = "" self.loading = LoadingPopup() self.loading.open() Clock.schedule_once(self.updateGraph) def updateGraph(self, *args): try: for stat in self.statLayouts: stat.statButton.active = False stat.statButton.draw() self.stockGraph.updateTicker(self.ticker) self.tickerTitle.text = self.ticker self.updateInfo(self.ticker) except BadTickerException as e: errmsg = str(e.ticker) + " does not exist or has been delisted!" self.errorPopup = ErrorPopup(errmsg) self.errorPopup.open() self.loading.dismiss() def updateInfo(self, newTicker): try: self.stockInfo = self.stockGraph.ticker.info except: print("Unable to load info for", newTicker) try: self.tickerTitle.text = newTicker + "\n" + self.stockInfo[ "longName"] except: print("longName failed") def artificialUpdateGraph(self, ticker): if not ticker: return self.ticker = ticker self.loading = LoadingPopup() self.loading.open() Clock.schedule_once(self.updateGraph) def swap(self, new=None): if not new: new = self.dataLayout self.remove_widget(self.currentLayout) self.currentLayout = new self.add_widget(self.currentLayout)