[Xfce4-commits] [apps/xfce4-panel-profiles] 45/162: Correctly sort timestamps

noreply at xfce.org noreply at xfce.org
Fri Jul 13 13:09:04 CEST 2018


This is an automated email from the git hooks/post-receive script.

o   c   h   o   s   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/xfce4-panel-profiles.

commit 58ed08fbd36e6630f2a6c36497619ae404d011cd
Author: Sean Davis <smd.seandavis at gmail.com>
Date:   Sat Sep 26 11:52:34 2015 -0400

    Correctly sort timestamps
---
 xfpanel-switch/xfpanel-switch.glade | 14 ++++---------
 xfpanel-switch/xfpanel-switch.py    | 42 +++++++++++++++++++++++++------------
 2 files changed, 33 insertions(+), 23 deletions(-)

diff --git a/xfpanel-switch/xfpanel-switch.glade b/xfpanel-switch/xfpanel-switch.glade
index fad881f..a9b3a1e 100644
--- a/xfpanel-switch/xfpanel-switch.glade
+++ b/xfpanel-switch/xfpanel-switch.glade
@@ -9,7 +9,7 @@
       <!-- column-name displayed -->
       <column type="gchararray"/>
       <!-- column-name modified -->
-      <column type="gchararray"/>
+      <column type="gint"/>
     </columns>
   </object>
   <object class="GtkWindow" id="xfpanel_switch_window">
@@ -133,7 +133,7 @@ Backup and restore your panel configuration</property>
                           <object class="GtkTreeSelection" id="treeview-selection1"/>
                         </child>
                         <child>
-                          <object class="GtkTreeViewColumn" id="treeviewcolumn1">
+                          <object class="GtkTreeViewColumn" id="filename_column">
                             <property name="title" translatable="yes">Filename</property>
                             <property name="expand">True</property>
                             <property name="sort_indicator">True</property>
@@ -149,16 +149,10 @@ Backup and restore your panel configuration</property>
                           </object>
                         </child>
                         <child>
-                          <object class="GtkTreeViewColumn" id="treeviewcolumn2">
+                          <object class="GtkTreeViewColumn" id="modified_column">
                             <property name="title" translatable="yes">Date Modified</property>
                             <property name="sort_indicator">True</property>
-                            <property name="sort_column_id">1</property>
-                            <child>
-                              <object class="GtkCellRendererText" id="cellrenderertext2"/>
-                              <attributes>
-                                <attribute name="text">2</attribute>
-                              </attributes>
-                            </child>
+                            <property name="sort_column_id">2</property>
                           </object>
                         </child>
                       </object>
diff --git a/xfpanel-switch/xfpanel-switch.py b/xfpanel-switch/xfpanel-switch.py
index 5bf84ea..c0377ae 100644
--- a/xfpanel-switch/xfpanel-switch.py
+++ b/xfpanel-switch/xfpanel-switch.py
@@ -53,11 +53,19 @@ class XfpanelSwitch:
 
         self.load_xfconf()
 
+        modified_col = self.builder.get_object('modified_column')
+        cell = Gtk.CellRendererText()
+        modified_col.pack_start(cell, False)
+        modified_col.set_cell_data_func(cell, self.cell_data_func_modified, 2)
+
         self.treeview = self.builder.get_object('saved_configurations')
         self.tree_model = self.treeview.get_model()
         for config in self.get_saved_configurations():
             self.tree_model.append(config)
-        self.tree_model.set_sort_column_id(1, Gtk.SortType.DESCENDING)
+
+        # Sort by name, then sort by date so timestamp sort is alphabetical
+        self.tree_model.set_sort_column_id(1, Gtk.SortType.ASCENDING)
+        self.tree_model.set_sort_column_id(2, Gtk.SortType.DESCENDING)
 
         if not os.path.exists(self.save_location):
             os.makedirs(self.save_location)
@@ -128,7 +136,8 @@ class XfpanelSwitch:
 
     def get_saved_configurations(self):
         results = []
-        results.append(("", _("Current Configuration"), ""))
+        now = int(datetime.datetime.now().strftime('%s'))
+        results.append(("", _("Current Configuration"), now))
         today_delta = datetime.datetime.today() - datetime.timedelta(days=1)
 
         for directory in self.get_data_dirs():
@@ -137,18 +146,25 @@ class XfpanelSwitch:
                 name, tar = os.path.splitext(name)
                 if ext in [".gz", ".bz2"]:
                     path = os.path.join(directory, filename)
-                    t = os.path.getmtime(path)
-                    datetime_o = datetime.datetime.fromtimestamp(t)
-                    if datetime_o > today_delta:
-                        modified = (_("Today"))
-                    elif datetime_o == today_delta:
-                        modified = (_("Yesterday"))
-                    else:
-                        modified = datetime_o.strftime("%x")
-                    results.append((path, name, modified))
+                    t = int(os.path.getmtime(path))
+                    results.append((path, name, int(t)))
 
         return results
 
+    def cell_data_func_modified(self, column, cell_renderer,
+                                tree_model, tree_iter, id):
+        today_delta = datetime.datetime.today() - datetime.timedelta(days=1)
+        t = tree_model.get_value(tree_iter, id)
+        datetime_o = datetime.datetime.fromtimestamp(t)
+        if datetime_o > today_delta:
+            modified = _("Today")
+        elif datetime_o == today_delta:
+            modified = _("Yesterday")
+        else:
+            modified = datetime_o.strftime("%x")
+        cell_renderer.set_property('text', modified)
+        return
+
     def get_selected(self):
         model, treeiter = self.treeview.get_selection().get_selected()
         values = model[treeiter][:]
@@ -175,7 +191,7 @@ class XfpanelSwitch:
         filename = name + ".tar.bz2"
         filename = os.path.join(self.save_location, filename)
         PanelConfig.from_xfconf(self.xfconf).to_file(filename)
-        created = datetime.datetime.now().strftime("%X")
+        created = int(datetime.datetime.now().strftime('%s'))
         if append:
             self.tree_model.append([filename, name, created])
 
@@ -216,7 +232,7 @@ class XfpanelSwitch:
                 dst = os.path.join(self.save_location, name + ".tar.bz2")
                 self._copy(filename, dst)
                 self.tree_model.append(
-                    [dst, name, datetime.datetime.now().strftime("%X")])
+                    [dst, name, int(datetime.datetime.now().strftime('%s'))])
             savedlg.destroy()
         dialog.destroy()
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list