Skip to content

Commit

Permalink
Added support for custom DateColumn timestamp formats
Browse files Browse the repository at this point in the history
  • Loading branch information
Meriipu committed Apr 25, 2017
1 parent 0f30e75 commit 3b9d3de
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
3 changes: 3 additions & 0 deletions quodlibet/quodlibet/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ def _config_text(text):

# the pattern for the main window title
"window_title_pattern": "~title~version~~people",

# the format of the timestamps in DateColumn
"datecolumn_timestamp_format": "",
},
"rename": {
"spaces": "false",
Expand Down
6 changes: 6 additions & 0 deletions quodlibet/quodlibet/ext/events/advanced_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ def changed(entry, name, section="settings"):
("A (tied) tag for the main window title, e.g. ~title~~people "
"(restart required)")))

rows.append(
text_config(
"settings", "datecolumn_timestamp_format",
"DateColumn timestamp format",
"A timestamp format, e.g. %Y%m%d %X "))

for (row, (label, entry, button)) in enumerate(rows):
label.set_alignment(1.0, 0.5)
table.attach(label, 0, 1, row, row + 1,
Expand Down
18 changes: 13 additions & 5 deletions quodlibet/quodlibet/qltk/songlistcolumns.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,20 @@ def _apply_value(self, model, iter_, cell, stamp):
date = datetime.datetime.fromtimestamp(stamp).date()
today = datetime.datetime.now().date()
days = (today - date).days
if days == 0:
format_ = "%X"
elif days < 7:
format_ = "%A"
format_setting = config.gettext("settings",
"datecolumn_timestamp_format")

# default behaviour
if format_setting == "":
if days == 0:
format_ = "%X"
elif days < 7:
format_ = "%A"
else:
format_ = "%x"
else:
format_ = "%x"
format_ = format_setting

stamp = time.localtime(stamp)
text = time.strftime(format_, stamp)
cell.set_property('text', text)
Expand Down

0 comments on commit 3b9d3de

Please sign in to comment.