[meld] ui.cellrenderers: New helper for small cellrenderer conveniences
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] ui.cellrenderers: New helper for small cellrenderer conveniences
- Date: Sat, 16 Dec 2017 02:37:42 +0000 (UTC)
commit 821bb753d56532ccd541eae3eb44f0778492b6dd
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sun Oct 23 12:49:10 2016 +1000
ui.cellrenderers: New helper for small cellrenderer conveniences
meld/dirdiff.py | 13 +++++--------
meld/ui/cellrenderers.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 53 insertions(+), 8 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index 61581cdc..da86c31c 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -18,7 +18,6 @@
import collections
import copy
-import datetime
import errno
import functools
import os
@@ -46,6 +45,7 @@ from meld.misc import all_same
from meld.recent import RecentType
from meld.settings import bind_settings, meldsettings, settings
from meld.treehelpers import refocus_deleted_path
+from meld.ui.cellrenderers import CellRendererDate
################################################################################
@@ -210,7 +210,7 @@ COL_EMBLEM, COL_SIZE, COL_TIME, COL_PERMS, COL_END = \
class DirDiffTreeStore(tree.DiffTreeStore):
def __init__(self, ntree):
- tree.DiffTreeStore.__init__(self, ntree, [str, str, str, str])
+ tree.DiffTreeStore.__init__(self, ntree, [str, str, object, str])
class CanonicalListing(object):
@@ -398,9 +398,9 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
# Create date-time CellRenderer
column = Gtk.TreeViewColumn(_("Modification time"))
column.set_resizable(True)
- rentext = Gtk.CellRendererText()
+ rentext = CellRendererDate()
column.pack_start(rentext, True)
- column.set_attributes(rentext, markup=col_index(COL_TIME, i))
+ column.set_attributes(rentext, timestamp=col_index(COL_TIME, i))
self.treeview[i].append_column(column)
self.columns_dict[i]["modification time"] = column
# Create permissions CellRenderer
@@ -1311,11 +1311,8 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
it, self.model.column_index(COL_EMBLEM, j), emblem)
one_isdir[j] = isdir
- # A DateCellRenderer would be nicer, but potentially very slow
TIME = self.model.column_index(COL_TIME, j)
- mod_datetime = datetime.datetime.fromtimestamp(mod_times[j])
- time_str = mod_datetime.strftime("%a %d %b %Y %H:%M:%S")
- self.model.set_value(it, TIME, time_str)
+ self.model.set_value(it, TIME, mod_times[j])
def natural_size(bytes):
suffixes = (
diff --git a/meld/ui/cellrenderers.py b/meld/ui/cellrenderers.py
new file mode 100644
index 00000000..ccd9f901
--- /dev/null
+++ b/meld/ui/cellrenderers.py
@@ -0,0 +1,48 @@
+# Copyright (C) 2016 Kai Willadsen <kai willadsen gmail com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or (at
+# your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import datetime
+
+from gi.repository import GObject
+from gi.repository import Gtk
+
+
+class CellRendererDate(Gtk.CellRendererText):
+
+ __gtype_name__ = "CellRendererDate"
+
+ DATETIME_FORMAT = "%a %d %b %Y %H:%M:%S"
+
+ def get_timestamp(self):
+ return getattr(self, '_datetime', None)
+
+ def set_timestamp(self, value):
+ if value == self.get_timestamp():
+ return
+ if value is None:
+ time_str = ''
+ else:
+ mod_datetime = datetime.datetime.fromtimestamp(value)
+ time_str = mod_datetime.strftime(self.DATETIME_FORMAT)
+ self.props.markup = time_str
+ self._datetime = value
+
+ timestamp = GObject.property(
+ type=object,
+ nick="Unix timestamp to display",
+ getter=get_timestamp,
+ setter=set_timestamp,
+ )
+ )
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]