[meld: 7/12] single set() call instead of the multiple set_values()
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld: 7/12] single set() call instead of the multiple set_values()
- Date: Sun, 2 Sep 2018 00:27:58 +0000 (UTC)
commit 978df6a122a37a4ff5587f726bdc20c296d3ce58
Author: hugosenari <hugosenari gmail com>
Date: Sun Aug 5 07:13:21 2018 -0300
single set() call instead of the multiple set_values()
meld/dirdiff.py | 13 +++++++------
meld/tree.py | 31 ++++++++++++++++---------------
meld/treehelpers.py | 23 ++++++++++++++---------
3 files changed, 37 insertions(+), 30 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index 6154fa84..d057be4b 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -1399,13 +1399,14 @@ class DirDiff(MeldDoc, Component):
self.model.set_path_state(
it, j, state, isdir[j], display_text=name_overrides[j])
emblem = EMBLEM_NEW if j in newest else None
- self.model.unsafe_set_value(it, column(COL_EMBLEM), emblem)
link_emblem = EMBLEM_SYMLINK if j in symlinks else None
- self.model.unsafe_set_value(
- it, column(COL_EMBLEM_SECONDARY), link_emblem)
- self.model.unsafe_set_value(it, column(COL_TIME), times[j])
- self.model.unsafe_set_value(it, column(COL_SIZE), sizes[j])
- self.model.unsafe_set_value(it, column(COL_PERMS), perms[j])
+ self.model.unsafe_set(it, {
+ column(COL_EMBLEM): emblem,
+ column(COL_EMBLEM_SECONDARY): link_emblem,
+ column(COL_TIME): times[j],
+ column(COL_SIZE): sizes[j],
+ column(COL_PERMS): perms[j],
+ })
else:
# TODO: More consistent state setting here would let us avoid
# pyobjects for column types by avoiding None use.
diff --git a/meld/tree.py b/meld/tree.py
index 1a05af53..92e7221f 100644
--- a/meld/tree.py
+++ b/meld/tree.py
@@ -115,25 +115,25 @@ class DiffTreeStore(SearchableTreeStore):
return self.ntree * col + pane
def add_entries(self, parent, names):
- child = self.append(parent)
+ it = self.append(parent)
for pane, path in enumerate(names):
column = self.column_index(COL_PATH, pane)
- self.unsafe_set_value(child, column, path)
- return child
+ self.unsafe_set(it, { column: path })
+ return it
def add_empty(self, parent, text="empty folder"):
it = self.append(parent)
for pane in range(self.ntree):
column = self.column_index(COL_PATH, pane)
- self.set_value(it, column, None)
+ self.unsafe_set(it, { column: None })
self.set_state(it, pane, STATE_EMPTY, text)
return it
def add_error(self, parent, msg, pane):
it = self.append(parent)
for i in range(self.ntree):
- self.set_value(it, self.column_index(COL_STATE, i),
- str(STATE_ERROR))
+ column = self.column_index(COL_STATE, i)
+ self.unsafe_set(it, { column: str(STATE_ERROR) })
self.set_state(it, pane, STATE_ERROR, msg)
def set_path_state(self, it, pane, state, isdir=0, display_text=None):
@@ -146,16 +146,17 @@ class DiffTreeStore(SearchableTreeStore):
col_idx = self.column_index
icon = self.icon_details[state][1 if isdir else 0]
tint = self.icon_details[state][3 if isdir else 2]
- self.unsafe_set_value(it, col_idx(COL_STATE, pane), str(state))
- self.unsafe_set_value(it, col_idx(COL_TEXT, pane), label)
- self.unsafe_set_value(it, col_idx(COL_ICON, pane), icon)
- self.unsafe_set_value(it, col_idx(COL_TINT, pane), tint)
-
fg, style, weight, strike = self.text_attributes[state]
- self.unsafe_set_value(it, col_idx(COL_FG, pane), fg)
- self.unsafe_set_value(it, col_idx(COL_STYLE, pane), style)
- self.unsafe_set_value(it, col_idx(COL_WEIGHT, pane), weight)
- self.unsafe_set_value(it, col_idx(COL_STRIKE, pane), strike)
+ self.unsafe_set(it, {
+ col_idx(COL_STATE, pane): str(state),
+ col_idx(COL_TEXT, pane): label,
+ col_idx(COL_ICON, pane): icon,
+ col_idx(COL_TINT, pane): tint,
+ col_idx(COL_FG, pane): fg,
+ col_idx(COL_STYLE, pane): style,
+ col_idx(COL_WEIGHT, pane): weight,
+ col_idx(COL_STRIKE, pane): strike,
+ })
def get_state(self, it, pane):
state_idx = self.column_index(COL_STATE, pane)
diff --git a/meld/treehelpers.py b/meld/treehelpers.py
index d10bb5a7..0183cb94 100644
--- a/meld/treehelpers.py
+++ b/meld/treehelpers.py
@@ -147,21 +147,26 @@ class SearchableTreeStore(Gtk.TreeStore):
return prev_path, next_path
- def unsafe_set_value(self, treeiter, column, value):
- """ This must be fastest than super.set_value,
+ def unsafe_set(self, treeiter, keys_values):
+ """ This must be fastest than super.set,
at the cost that may crash the application if you don't
know what your're passing here.
ie: pass treeiter or column as None crash meld
treeiter: Gtk.TreeIter
- column: Int col index
- value: Str (UTF-8), Int, Float, Double, Boolean or GObject
+ keys_values: dict<column, value>
+ column: Int col index
+ value: Str (UTF-8), Int, Float, Double, Boolean, None or GObject
return None
"""
- if value is None and hasattr(self, '_none_of_cols'):
- value = self._none_of_cols.get(column)
- if value is not None and _GIGtk and treeiter:
- _GIGtk.TreeStore.set_value(self, treeiter, column, value)
+ safe_keys_values = {
+ col: val if val is not None else self._none_of_cols.get(col)
+ for col, val in keys_values.items()
+ }
+ if _GIGtk and treeiter:
+ columns = [col for col in safe_keys_values.keys()]
+ values = [val for val in safe_keys_values.values()]
+ _GIGtk.TreeStore.set(self, treeiter, columns, values)
else:
- self.set_value(treeiter, column, value)
+ self.set(treeiter, safe_keys_values)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]