def GetValue(self, row, col): if (col == self.COL_USER): return self._data[row]["user"] elif (col == self.COL_GLOBALLY_FUDGED_TIME): return common.delta_str(self._data[row]["bookmark"]) elif (col == self.COL_USER_FUDGE): return common.delta_str(self._data[row]["fudge"]) else: return "(%s,%s)" % (row, col)
def write_snarks(dest_file, snarks, show_time, options={}, keep_alive_func=None, sleep_func=None): """Writes snarks as tab-separated text. Columns: In-Movie Time, Original Date, Color, User, Msg. Newlines in "msg" are represented with \n. :param dest_file: A binary-mode file-like object to write into. :param snarks: A list of processed snark dicts. :param show_time: Timedelta duration each msg appears on-screen. :param options: A dict of extra options specific to this exporter. Not used. :param keep_alive_func: Optional replacement to get an abort boolean. :param sleep_func: Optional replacement to sleep N seconds. """ if (keep_alive_func is None): keep_alive_func = global_config.keeping_alive if (sleep_func is None): sleep_func = global_config.nap dest_file.write("\t".join(["In-Movie Time", "Original Date", "Color", "User", "Msg"])) dest_file.write("\r\n") for snark in snarks: snark_start = common.delta_str(snark["time"]) snark_date = snark["date"].strftime("%Y-%m-%d %H:%M:%S") snark_color = "" if ("color" in snark and snark["color"] is not None): snark_color = common.rgb_to_hex(snark["color"]) # Represent newlines with \n. snark_msg = snark["msg"].replace("\n", "\\n") dest_file.write("\t".join([snark_start, snark_date, snark_color, snark["user"], snark_msg])) dest_file.write("\r\n")
def srt_delta_str(delta): """Formats a timedelta as an srt string. A millisecond suffix is appended to make SubRip happy. :return: The string. """ return ("%s,000" % common.delta_str(delta))
def _set_field_value(self, field, value): if (self._arg.choices is not None): field.SetSelection(self._arg.choices.index(value)) elif (self._arg.type == arginfo.TIMEDELTA): field.SetValue(common.delta_str(value)) elif (self._arg.type == arginfo.DATETIME): field.SetValue(value.strftime("%Y-%m-%d")) elif (self._arg.type in [arginfo.STRING, arginfo.HIDDEN_STRING, arginfo.FILE, arginfo.URL]): field.SetValue(value) elif (self._arg.type == arginfo.FILE_OR_URL): field.SetValue(value, 0) elif (self._arg.type in [arginfo.INTEGER, arginfo.BOOLEAN]): field.SetValue(repr(value))
def GetValue(self, row, col): snark = self._snarks[row] if (col == self.COL_FINAL_TIME): return common.delta_str(snark["time"]) elif (col == self.COL_USER): return snark["user"] elif (col == self.COL_MSG): return snark["msg"] elif (col == self.COL_GLOBALLY_FUDGED_TIME): return common.delta_str(snark["_globally fudged time"]) elif (col == self.COL_USER_FUDGE): # Search backward through a user's delays for one in the recent past. if (snark["user"] in self._config.fudge_users): for (bookmark, fudge_value) in reversed(self._config.fudge_users[snark["user"]]): if (snark["_globally fudged time"] >= bookmark): return common.delta_str(fudge_value) return common.delta_str(timedelta(0)) else: return common.delta_str(timedelta(0)) elif (col == self.COL_DATE): return snark["date"].strftime("%Y-%m-%d %H:%M:%S") else: return "(%s,%s)" % (row, col)
def _on_add_field(self, e): if (self._arg.choices is not None): value_field = wx.Choice(self._value_panel, wx.ID_ANY) for x in self._arg.choices: value_field.Append(str(x), x) if (self._arg.default is not None): value_field.SetSelection(self._arg.choices.index(self._arg.default)) elif (self._arg.type == arginfo.TIMEDELTA): default_str = common.delta_str(timedelta(0)) if (self._arg.default is not None): default_str = common.delta_str(self._arg.default) value_field = wx.TextCtrl(self._value_panel, wx.ID_ANY, size=(self._textfield_width,-1), value=default_str) elif (self._arg.type == arginfo.DATETIME): default_str = "0000-00-00" if (self._arg.default is not None): default_str = self._arg.default.strftime("%Y-%m-%d") value_field = wx.TextCtrl(self._value_panel, wx.ID_ANY, size=(self._textfield_width,-1), value=default_str) elif (self._arg.type == arginfo.FILE): default_str = "" if (self._arg.default is not None): default_str = self._arg.default value_field = wx.lib.filebrowsebutton.FileBrowseButton(self._value_panel, wx.ID_ANY, labelText="", buttonText="File...") value_field.textControl.SetInitialSize((self._browsefield_width,-1)) value_field.browseButton.SetWindowStyleFlag(value_field.browseButton.GetWindowStyleFlag()|wx.BU_EXACTFIT) value_field.SetValue(default_str, 0) elif (self._arg.type == arginfo.FILE_OR_URL): def file_callback(e): source = e.GetEventObject() if (isinstance(source, wx.TextCtrl)): ipoint = source.GetInsertionPoint() old_value = source.GetValue() new_value = re.sub("\\\\", "/", old_value) has_schema = False if (re.match("^file:", new_value) is not None): has_schema = True elif (re.match("(?i)^[a-z]{2,}:/($|/)", new_value) is not None): has_schema = True if (has_schema is False): m = re.search("(?i)^[a-z]:/", new_value) if (m is not None): new_value = new_value[0:m.start(0)] + m.expand("file:///\g<0>") + new_value[m.end(0):] ipoint += 8 has_schema = True if (has_schema is False): m = re.search("^[^/]*/", new_value) if (m is not None): new_value = "file:"+ new_value ipoint += 5 has_schema = True if (new_value != old_value): source.SetValue(new_value) source.SetInsertionPoint(ipoint) default_str = "" if (self._arg.default is not None): default_str = self._arg.default value_field = wx.lib.filebrowsebutton.FileBrowseButton(self._value_panel, wx.ID_ANY, labelText="", buttonText="File...", changeCallback=file_callback) value_field.textControl.SetInitialSize((self._browsefield_width,-1)) value_field.browseButton.SetWindowStyleFlag(value_field.browseButton.GetWindowStyleFlag()|wx.BU_EXACTFIT) value_field.SetValue(default_str, 0) elif (self._arg.type == arginfo.HIDDEN_STRING): default_str = "" if (self._arg.default is not None): default_str = self._arg.default value_field = wx.TextCtrl(self._value_panel, wx.ID_ANY, style=wx.TE_PASSWORD, size=(self._textfield_width,-1), value=default_str) elif (self._arg.type == arginfo.STRING): default_str = "" if (self._arg.default is not None): default_str = self._arg.default value_field = wx.TextCtrl(self._value_panel, wx.ID_ANY, size=(self._textfield_width,-1), value=default_str) else: # boolean, integer, url default_str = "" if (self._arg.default is not None): default_str = self._arg.default if (isinstance(default_str, basestring) is False): default_str = repr(default_str) value_field = wx.TextCtrl(self._value_panel, wx.ID_ANY, size=(self._textfield_width,-1), value=default_str) self._value_fields.append(value_field) self._fields_sizer.Add(value_field, flag=wx.ALIGN_RIGHT) self._relayout_parent() if (e is not None): e.Skip(False) # Consume the event.