Permalink
Browse files

Port to GTK3

  • Loading branch information...
1 parent 16d7be4 commit c95699da386d34af6693529e4f8775f903df69f1 @placidrage committed Jun 8, 2012
Showing with 146 additions and 100 deletions.
  1. +17 −11 liblarch/__init__.py
  2. +16 −8 liblarch/filteredtree.py
  3. +18 −9 liblarch/processqueue.py
  4. +45 −38 liblarch_gtk/__init__.py
  5. +9 −4 liblarch_gtk/treemodel.py
  6. +40 −29 main.py
  7. +1 −1 setup.py
View
@@ -226,28 +226,34 @@ def register_cllbck(self, event, func):
return key
def deregister_cllbck(self, event, key):
- """ Remove the callback identifed by key (from register_cllbck) """
+ """
+ Remove the callback identifed by key (from register_cllbck)
+ """
try:
del self.__cllbcks[event][key]
- except KeyError:
- pass
-
+ except KeyError, exc:
+ print(str(exc))
+
@izidormatusov

izidormatusov Jun 9, 2012

We want to be benevolent to the user and don't punish (by an error output) him for removing non-existent callback. Could you let it to be "pass"?

Btw: I was thinking why we don't check it directly through if event in self.__cllbck and key in self.__cllbck[event]: but this looks more easier to understand :)

def __emit(self, event, node_id, path=None, neworder=None):
- """ Handle a new event from MainTree or FilteredTree
- by passing it to other objects, e.g. TreeWidget """
+ """
+ Handle a new event from MainTree or FilteredTree
+ by passing it to other objects, e.g. TreeWidget
+ """
callbacks = dict(self.__cllbcks.get(event, {}))
-# print "ViewTree __emit for %s" %str(node_id)
+ print("ViewTree __emit for {0}".format(str(node_id)))
for func in callbacks.itervalues():
-# print " -> func = %s - %s" %(func,str(path))
+ print(" -> func = {0} - {1}".format(func, str(path)))
if neworder:
func(node_id, path, neworder)
else:
- func(node_id,path)
+ func(node_id, path)
def get_node(self, node_id):
- """ Get a node from MainTree """
+ """
+ Get a node from MainTree
+ """
return self.__maintree.get_node(node_id)
-
+
#FIXME Remove this method from public interface
def get_root(self):
return self.__maintree.get_root()
View
@@ -17,10 +17,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------
-import gobject
+from gi.repository import GObject
-class FilteredTree():
- """ FilteredTree is the most important and also the most buggy part of
+
+class FilteredTree(object):
+ """
+ FilteredTree is the most important and also the most buggy part of
LibLarch.
FilteredTree transforms general changes in tree like creating/removing
@@ -35,14 +37,16 @@ class FilteredTree():
"""
def __init__(self, tree, filtersbank, name=None, refresh=True):
- """ Construct a layer where filters could by applied
+ """
+ Construct a layer where filters could by applied
@param tree: Original tree to filter.
@param filtersbank: Filter bank which stores filters
@param refresh: Requests all nodes in the beginning? Additional
filters can be added and refresh can be done later
- _flat defines whether only nodes without children can be shown. For example WorkView filter.
+ _flat defines whether only nodes without children can be shown.
+ For example WorkView filter.
"""
self.cllbcks = {}
@@ -76,7 +80,8 @@ def __init__(self, tree, filtersbank, name=None, refresh=True):
def set_callback(self, event, func,node_id=None, param=None):
- """ Register a callback for an event.
+ """
+ Register a callback for an event.
It is possible to have just one callback for event.
@param event: one of added, modified, deleted, reordered
@@ -87,7 +92,7 @@ def set_callback(self, event, func,node_id=None, param=None):
raise Exception('runonce callback should come with a node_id')
if self.is_displayed(node_id):
#it is essential to idle_add to avoid hard recursion
- gobject.idle_add(func,param)
+ GObject.idle_add(func,param)
else:
if not self.cllbcks.has_key(node_id):
self.cllbcks[node_id] = []
@@ -711,7 +716,8 @@ def apply_filter(self, filter_name, parameters=None, \
return toreturn
def unapply_filter(self, filter_name, refresh=True):
- """ Removes a filter from the tree.
+ """
+ Removes a filter from the tree.
@param filter_name: The name of an already added filter to remove
@param refresh: Should be refereshed the whole tree?
@@ -745,3 +751,5 @@ def reset_filters(self, refresh=True, transparent_only=False):
self.applied_filters = []
if refresh:
self.refilter()
+
+# -----------------------------------------------------------------------------
View
@@ -18,15 +18,19 @@
# -----------------------------------------------------------------------------
import threading
-import gobject
+from gi.repository import GObject
-class SyncQueue:
- """ Synchronized queue for processing requests"""
+class SyncQueue(object):
+ """
+ Synchronized queue for processing requests
+ """
def __init__(self):
- """ Initialize synchronized queue.
+ """
+ Initialize synchronized queue.
- @param callback - function for processing requests"""
+ @param callback - function for processing requests
+ """
self._low_queue = []
self._queue = []
self._vip_queue = []
@@ -37,15 +41,18 @@ def __init__(self):
self.count = 0
def process_queue(self):
- """ Process requests from queue """
+ """
+ Process requests from queue
+ """
for action in self.process():
func = action[0]
func(*action[1:])
# return True to process other requests as well
return True
def push(self, *element, **kwargs):
- """ Add a new element to the queue.
+ """
+ Add a new element to the queue.
Process actions from the same thread as the thread which created
this queue immediately. What does it mean? When I use liblarch
@@ -77,7 +84,7 @@ def push(self, *element, **kwargs):
if element not in queue:
queue.append(element)
if self._handler is None:
- self._handler = gobject.idle_add(self.process_queue)
+ self._handler = GObject.idle_add(self.process_queue)
self._lock.release()
@@ -102,7 +109,9 @@ def process(self):
if len(self._queue) == 0 and len(self._vip_queue) == 0 and\
len(self._low_queue) == 0 and\
self._handler is not None:
- gobject.source_remove(self._handler)
+ GObject.source_remove(self._handler)
self._handler = None
self._lock.release()
return toreturn
+
+# -----------------------------------------------------------------------------
Oops, something went wrong.

2 comments on commit c95699d

Nice job!

Owner

placidrage replied Jun 9, 2012

Thanks!

Please sign in to comment.