def filter_data(self, _): def validate_date(date_text): try: year, month, day = date_text.split("-") datetime(int(year), int(month), int(day)) except ValueError: raise ValueError("Incorrect data format, should be YYYY-MM-DD") try: date1 = ask(self.parent, "Enter start date or leave empty") if date1: validate_date(date1) else: date1 = "1980-01-01" date2 = ask(self.parent, "Enter end date or leave empty") if date2: validate_date(date2) else: date2 = "2050-01-01" df = self.parent.data_frame self.parent.data_frame = df[(df['date'] > date1) & (df['date'] < date2)] except ValueError as exc: error(self.parent, str(exc))
def load_image(self, filename): try: image = wx.Image(filename, wx.BITMAP_TYPE_ANY) self.image_control.SetBitmap(wx.Bitmap(image)) self.Refresh() except IOError: error(self, "Image file %s not found" % filename)
def onCrawlerDone(self, event): if event.aborted: error(message="Crawler aborted", caption="Warning") else: notify(message="Crawler finished") self.settings.last_crawl = date.today() self.settings.save()
def load_image(self, filename): try: image = wx.Image(filename, wx.BITMAP_TYPE_ANY) self.image_control.SetBitmap(wx.Bitmap(image)) self.parent.SetSize(image.GetWidth(), image.GetHeight() + 100) self.Refresh() except IOError: error(self, "Image file %s not found" % filename)
def start_background_task( self, function: typing.Callable, message: str = "Operation in progress...") -> None: if self.background_thread and self.background_thread.is_alive(): error(self, "Background operation already running.") else: self.background_thread = threading.Thread(target=function) self.background_thread.start() window.display([None, message]) self.update_menubar(False)
def dynamic_crawl(self, _): if self.parent.is_background_task_running(): error(self.parent, "Background task already running") return dialog = wx.MessageDialog( self.parent, "Are you sure you want to start dynamic crawl? It might take a while.", "Start dynamic crawl", wx.YES_NO | wx.ICON_QUESTION) if dialog.ShowModal() == wx.ID_YES: self.crawler_change(True) events.connect_event(self, self.on_crawler_done, events.CRAWLER_DONE_ID) self.parent.background_thread = start_append_crawl( self.settings.data_folder, self.settings.last_crawl, self) self.parent.background_thread.start() self.parent.display([None, "Downloading forum data..."])
def save_to_file(self, _): dlg = wx.DirDialog(self.parent, "Choose save directory", style=wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST) if not dlg.ShowModal() == wx.ID_OK: error(message="Chosen file must be a directory") return path = dlg.GetPath() dlg.Destroy() name = ask(message="How should I name this file?") if not name: error(message="Empty file name is not a valid name") if self.parent.image_on_top: copyfile(self.parent.settings.temp_folder + "/plot.png", path + "/%s.png" % name) else: if self.parent.data_frame_cache: self.parent.data_frame_cache.to_csv(path + "/%s.csv" % name) else: with open(path + "/%s.csv" % name, "wb") as text_file: text_file.write( self.parent.raw_save.replace(", ", "\n").encode('UTF8'))