Commit 1270f0fb authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Selective stash/pop of graph filter state

Individual filters can be stashed and popped by passing keyword
arguments to the respective functions. Additionally the filter state can
be obtained and set directly, with the get_filter_state() and
set_filter_state() functions.
parent 6f223eaa
......@@ -24,7 +24,7 @@ import io # sets up libcore io routines
import sys, os, os.path, re, struct, fcntl, termios, gzip, bz2, string,\
textwrap, time, signal, traceback, shutil, time, math, inspect, \
functools, types, weakref
functools, types, weakref, copy
from StringIO import StringIO
from decorators import _wraps, _require, _attrs, _handle_exceptions, _limit_args
......@@ -657,16 +657,6 @@ class Graph(object):
# Directedness
# ============
@_handle_exceptions
def directed(self):
"""Treat graph as directed (default)."""
self.__graph.SetDirected(True)
@_handle_exceptions
def undirected(self):
"""Treat graph as undirected."""
self.__graph.SetDirected(False)
@_handle_exceptions
def set_directed(self, is_directed):
"""Set the directedness of the graph"""
......@@ -680,11 +670,6 @@ class Graph(object):
# Reversedness
# ============
@_handle_exceptions
def reversed(self):
"""Reverse the direction of the edges."""
self.__graph.SetReversed(not self.__graph.GetReversed())
@_handle_exceptions
def set_reversed(self, is_reversed):
"""Reverse the direction of the edges, if 'reversed' is True, or
......@@ -736,19 +721,47 @@ class Graph(object):
self.__graph.SetEdgeFilterProperty(None)
@_handle_exceptions
def stash_filter(self):
"""Stash current filter state and recover unfiltered graph"""
def stash_filter(self, edge=True, vertex=True,
directed=False, reversed=False, all=False):
"""Stash current filter state and recover unfiltered graph. The optional
keyword arguments specify which type of filter should be stashed."""
self.__stashed_filter_state.append(self.__filter_state)
if libcore.graph_filtering_enabled():
self.set_vertex_filter(None)
self.set_edge_filter(None)
self.directed()
self.set_reversed(False)
if vertex or all:
self.set_vertex_filter(None)
if edge or all:
self.set_edge_filter(None)
if directed or all:
self.set_directed(True)
if reversed or all:
self.set_reversed(False)
@_handle_exceptions
def pop_filter(self, edge=True, vertex=True,
directed=False, reversed=False, all=False):
"""Pop last stashed filter state. The optional keyword arguments specify
which type of filter should be recovered."""
state = self.__stashed_filter_state.pop()
if libcore.graph_filtering_enabled():
if vertex or all:
self.set_vertex_filter(state["vertex_filter"][0],
state["vertex_filter"][1])
if edge or all:
self.set_edge_filter(state["edge_filter"][0],
state["edge_filter"][1])
if directed or all:
self.set_directed(state["directed"])
if reversed or all:
self.set_reversed(state["reversed"])
@_handle_exceptions
def pop_filter(self):
"""Pop last stashed filter state"""
state = self.__stashed_filter_state.pop()
def get_filter_state(self):
"""Return a copy of the filter state of the graph."""
return copy.copy(self.__filter_state)
@_handle_exceptions
def set_filter_state(self, state):
"""Set the filter state of the graph."""
if libcore.graph_filtering_enabled():
self.set_vertex_filter(state["vertex_filter"][0],
state["vertex_filter"][1])
......@@ -757,7 +770,6 @@ class Graph(object):
self.set_directed(state["directed"])
self.set_reversed(state["reversed"])
# Basic graph statistics
# ======================
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment