def _on_edit_ok(self, e): assert (self._edited_row is not None) user, bookmark, fudge_amount = None, None, None try: user = self._edit_user_field.GetValue() if (len(user) == 0 or user == "@"): user = None bookmark = common.delta_from_str(self._edit_bookmark_field.GetValue()) fudge_amount = common.delta_from_str(self._edit_fudge_field.GetValue()) except (ValueError) as err: pass proceed = True for x,noun in [(user, "user"), (bookmark, "time"), (fudge_amount, "fudge amount")]: if (x is None): self.statusbar.SetStatusText("Error: Bad %s." % noun, self.STATUS_HELP) proceed = False break if (proceed is True): prev_row_count = self.fudge_table.GetNumberRows() self._snarks_wrapper.checkout(self.__class__.__name__) config = self._snarks_wrapper.get_config() if (self._edited_row != -1): # Remove the old user fudge that had been edited. doomed_user = self.fudge_table.GetValue(self._edited_row, self.fudge_table.COL_USER) doomed_bookmark = common.delta_from_str(self.fudge_table.GetValue(self._edited_row, self.fudge_table.COL_GLOBALLY_FUDGED_TIME)) snarkutils.config_remove_user_fudge(config, doomed_user, doomed_bookmark) snarkutils.config_add_user_fudge(config, user, (bookmark, fudge_amount)) snarkutils.gui_fudge_users(config, self._snarks_wrapper.get_snarks()) self._snarks_wrapper.commit() new_event = common.SnarksEvent([common.SnarksEvent.FLAG_CONFIG_FUDGES, common.SnarksEvent.FLAG_SNARKS]) self._snarks_wrapper.fire_snarks_event(new_event) self._on_edit_cancel(None) if (prev_row_count == 0): self.fudge_grid.AutoSizeColumn(self.fudge_table.COL_GLOBALLY_FUDGED_TIME) self.fudge_grid.AutoSizeColumn(self.fudge_table.COL_USER_FUDGE) if (e is not None): e.Skip(False) # Consume the event.
def _on_delete(self, e): rows = self.fudge_grid.GetSelectedRows() if (not rows): self.statusbar.SetStatusText("No fudge selected.", self.STATUS_HELP) else: self._snarks_wrapper.checkout(self.__class__.__name__) config = self._snarks_wrapper.get_config() rows.reverse() for row in rows: doomed_user = self.fudge_table.GetValue(row, self.fudge_table.COL_USER) doomed_bookmark = common.delta_from_str(self.fudge_table.GetValue(row, self.fudge_table.COL_GLOBALLY_FUDGED_TIME)) snarkutils.config_remove_user_fudge(config, doomed_user, doomed_bookmark) snarkutils.gui_fudge_users(config, self._snarks_wrapper.get_snarks()) self._snarks_wrapper.commit() new_event = common.SnarksEvent([common.SnarksEvent.FLAG_CONFIG_FUDGES, common.SnarksEvent.FLAG_SNARKS]) self._snarks_wrapper.fire_snarks_event(new_event) if (e is not None): e.Skip(False) # Consume the event.
def _on_place_snark(self, e): """Adds a new fudge_users value to make the grabbed snark visible at the current video time. All config and snarks listeners will be notified of changes. """ if (self._grabbed_snark is None): self.statusbar.SetStatusText("Error: No snark was grabbed.", self.STATUS_HELP) else: vlc_milliseconds = wx.GetApp().player_frame.get_vlc_time() if (vlc_milliseconds == -1): self.statusbar.SetStatusText("Error: VLC reported a bad time. Aborting placement.", self.STATUS_HELP) if (e is not None): e.Skip(False) # Consume the event. return grabbed_snark = self._grabbed_snark self._grabbed_snark = None current_time = timedelta(seconds=(vlc_milliseconds//1000)) fudge_delta = current_time - grabbed_snark["_globally fudged time"] fudge_tuple = (grabbed_snark["_globally fudged time"], fudge_delta) self._snarks_wrapper.checkout(self.__class__.__name__) snarkutils.config_add_user_fudge(self._snarks_wrapper.get_config(), grabbed_snark["user"], fudge_tuple) snarkutils.gui_fudge_users(self._snarks_wrapper.get_config(), self._snarks_wrapper.get_snarks()) self._snarks_wrapper.commit() new_event = common.SnarksEvent([common.SnarksEvent.FLAG_CONFIG_FUDGES, common.SnarksEvent.FLAG_SNARKS]) self._snarks_wrapper.fire_snarks_event(new_event) # Reselect the grabbed snark. for i in range(len(self._snarks)): snark = self._snarks[i] if (snark["user"] == grabbed_snark["user"] and snark["date"] == grabbed_snark["date"]): self.snark_grid.SelectRow(i, False) break self.grab_btn.Enable(True) self.place_btn.Enable(False) self.drop_btn.Enable(False) if (e is not None): e.Skip(False) # Consume the event.
def threaded_code(snarks_wrapper=self._snarks_wrapper, config=config, keep_alive_func=None, sleep_func=None): # Don't touch snarks_wrapper until back in the main thread. try: logging.info("Calling %s parser..." % config.parser_name) wx.GetApp().invoke_later(wx.GetApp().ACTION_WARN, {"message":"Calling %s parser..." % config.parser_name}) snarks = snarkutils.parse_snarks(config, keep_alive_func=keep_alive_func, sleep_func=sleep_func) if (len(snarks) == 0): raise common.CompileSubsException("No messages were parsed.") snarkutils.gui_preprocess_snarks(config, snarks) snarkutils.gui_fudge_users(config, snarks) if (len(snarks) == 0): raise common.CompileSubsException("After preprocessing, no messages were left.") logging.info("Parsing succeeded.") wx.GetApp().invoke_later(wx.GetApp().ACTION_WARN, {"message":"Parsing succeeded."}) def main_code(snarks_wrapper=snarks_wrapper, snarks=snarks): snarks_wrapper.checkout(self.__class__.__name__) snarks_wrapper.set_snarks(snarks) snarks_wrapper.commit() event = common.SnarksEvent([common.SnarksEvent.FLAG_SNARKS]) snarks_wrapper.fire_snarks_event(event) wx.CallAfter(main_code) except (common.CompileSubsException) as err: # Parser failed in an uninteresting way. logging.error(str(err)) wx.GetApp().invoke_later(wx.GetApp().ACTION_WARN, {"message":"Error: %s" % str(err)}) except (Exception) as err: logging.exception(err) wx.GetApp().invoke_later(wx.GetApp().ACTION_WARN, {"message":"Error: The parser failed in an unexpected way."})
def config_subsection_callback(values_dict): self._snarks_wrapper.checkout(self.__class__.__name__) old_config = self._snarks_wrapper.clone_config() config = self._snarks_wrapper.get_config() snarks = self._snarks_wrapper.get_snarks() for (k,v) in values_dict.items(): setattr(config, k, v) # Determine what changed, assuming everything, at first. # Each section flag may be removed, but we'll keep ANY to be safe. event_flags = [] for section_list in common.SnarksEvent.SECTION_FLAGS: if (section_list[0] == common.SnarksEvent.FLAG_CONFIG_ALL): for f in section_list[2]: if (f not in event_flags): event_flags.append(f) # Add section flag. if (section_list[1] not in event_flags): event_flags.append(section_list[1]) # Add *_ANY. break def toggle_flag(event_flags, flag, expression): # Sets a flag if expression is True, unsets otherwise. if (expression): if (flag not in event_flags): event_flags.append(flag) else: if (flag in event_flags): event_flags.remove(flag) if (config.ignore_users != old_config.ignore_users or config.ignore_regexes != old_config.ignore_regexes): for snark in snarks: if (snark["user"] in config.ignore_users): snark["_ignored"] = True else: snark["_ignored"] = False for ptn in config.ignore_regexes: if (re.search(ptn, snark["msg"])): snark["_ignored"] = True break toggle_flag(event_flags, common.SnarksEvent.FLAG_SNARKS, True) if (config.fudge_time != old_config.fudge_time): diff = config.fudge_time - old_config.fudge_time for user in config.fudge_users: fudge_list = config.fudge_users[user] fudge_list[:] = [(ft[0]+diff, ft[1]) for ft in fudge_list] toggle_flag(event_flags, common.SnarksEvent.FLAG_CONFIG_FUDGES, True) # Strip cached globally fudged time. for snark in snarks: snark.pop("_globally fudged time", None) snarkutils.gui_fudge_users(config, snarks) toggle_flag(event_flags, common.SnarksEvent.FLAG_SNARKS, True) else: toggle_flag(event_flags, common.SnarksEvent.FLAG_CONFIG_FUDGES, False) toggle_flag(event_flags, common.SnarksEvent.FLAG_CONFIG_SHOW_TIME, (config.show_time != old_config.show_time)) toggle_flag(event_flags, common.SnarksEvent.FLAG_CONFIG_PARSERS, (config.parser_name != old_config.parser_name)) toggle_flag(event_flags, common.SnarksEvent.FLAG_CONFIG_EXPORTERS, (config.exporter_name != old_config.exporter_name)) self._snarks_wrapper.commit() event = common.SnarksEvent(event_flags) self._snarks_wrapper.fire_snarks_event(event)