summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Koslowski <sebastian.koslowski@gmail.com>2017-10-03 18:47:06 +0200
committerSebastian Koslowski <sebastian.koslowski@gmail.com>2017-11-08 20:56:28 +0100
commitcd9c3479e17fbdb84918e255cf6de74edf0ceab1 (patch)
tree42919242b9ed1286e0be2ed8121ee16f4be76f8a
parent7beebab1e7957f53bdea88dd60eb2bbe75c54013 (diff)
grc: refactor: move Param cls to core.params
-rw-r--r--grc/core/blocks/block.py1
-rw-r--r--grc/core/params/__init__.py18
-rw-r--r--grc/core/params/param.py (renamed from grc/core/Param.py)82
-rw-r--r--grc/core/params/template_arg.py50
-rw-r--r--grc/core/platform.py5
-rw-r--r--grc/gui/canvas/param.py4
6 files changed, 96 insertions, 64 deletions
diff --git a/grc/core/blocks/block.py b/grc/core/blocks/block.py
index 3a3de43fce..0cb3f61237 100644
--- a/grc/core/blocks/block.py
+++ b/grc/core/blocks/block.py
@@ -19,7 +19,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
from __future__ import absolute_import
-import ast
import collections
import itertools
diff --git a/grc/core/params/__init__.py b/grc/core/params/__init__.py
new file mode 100644
index 0000000000..93663bdada
--- /dev/null
+++ b/grc/core/params/__init__.py
@@ -0,0 +1,18 @@
+# Copyright 2017 Free Software Foundation, Inc.
+# This file is part of GNU Radio
+#
+# GNU Radio Companion 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.
+#
+# GNU Radio Companion 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, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+
+from .param import Param
diff --git a/grc/core/Param.py b/grc/core/params/param.py
index 13439f43b4..787be9a19f 100644
--- a/grc/core/Param.py
+++ b/grc/core/params/param.py
@@ -1,21 +1,19 @@
-"""
-Copyright 2008-2015 Free Software Foundation, Inc.
-This file is part of GNU Radio
-
-GNU Radio Companion 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.
-
-GNU Radio Companion 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, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-"""
+# Copyright 2008-2017 Free Software Foundation, Inc.
+# This file is part of GNU Radio
+#
+# GNU Radio Companion 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.
+#
+# GNU Radio Companion 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, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
from __future__ import absolute_import
@@ -28,9 +26,11 @@ import textwrap
import six
from six.moves import builtins, range
-from . import Constants, blocks
-from .base import Element
-from .utils.descriptors import Evaluated, EvaluatedEnum, setup_names
+from .. import Constants, blocks
+from ..base import Element
+from ..utils.descriptors import Evaluated, EvaluatedEnum, setup_names
+
+from .template_arg import TemplateArg
# Blacklist certain ids, its not complete, but should help
ID_BLACKLIST = ['self', 'options', 'gr', 'math', 'firdes'] + dir(builtins)
@@ -41,38 +41,6 @@ except (ImportError, AttributeError):
pass
-class TemplateArg(str):
- """
- A cheetah template argument created from a param.
- The str of this class evaluates to the param's to code method.
- The use of this class as a dictionary (enum only) will reveal the enum opts.
- The __call__ or () method can return the param evaluated to a raw python data type.
- """
-
- def __new__(cls, param):
- value = param.to_code()
- instance = str.__new__(cls, value)
- setattr(instance, '_param', param)
- return instance
-
- def __getitem__(self, item):
- return str(self._param.get_opt(item)) if self._param.is_enum() else NotImplemented
-
- def __getattr__(self, item):
- if not self._param.is_enum():
- raise AttributeError()
- try:
- return str(self._param.get_opt(item))
- except KeyError:
- raise AttributeError()
-
- def __str__(self):
- return str(self._param.to_code())
-
- def __call__(self):
- return self._param.get_evaluated()
-
-
@setup_names
class Param(Element):
@@ -106,10 +74,6 @@ class Param(Element):
self.hostage_cells = set()
self._init = False
- @property
- def template_arg(self):
- return TemplateArg(self)
-
def _init_options(self, values, labels, attributes):
"""parse option and option attributes"""
options = collections.OrderedDict()
@@ -142,6 +106,10 @@ class Param(Element):
return options
# endregion
+ @property
+ def template_arg(self):
+ return TemplateArg(self)
+
def __str__(self):
return 'Param - {}({})'.format(self.name, self.key)
diff --git a/grc/core/params/template_arg.py b/grc/core/params/template_arg.py
new file mode 100644
index 0000000000..5c8c610b4f
--- /dev/null
+++ b/grc/core/params/template_arg.py
@@ -0,0 +1,50 @@
+# Copyright 2008-2017 Free Software Foundation, Inc.
+# This file is part of GNU Radio
+#
+# GNU Radio Companion 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.
+#
+# GNU Radio Companion 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, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+
+from __future__ import absolute_import
+
+
+class TemplateArg(str):
+ """
+ A cheetah template argument created from a param.
+ The str of this class evaluates to the param's to code method.
+ The use of this class as a dictionary (enum only) will reveal the enum opts.
+ The __call__ or () method can return the param evaluated to a raw python data type.
+ """
+
+ def __new__(cls, param):
+ value = param.to_code()
+ instance = str.__new__(cls, value)
+ setattr(instance, '_param', param)
+ return instance
+
+ def __getitem__(self, item):
+ return str(self._param.get_opt(item)) if self._param.is_enum() else NotImplemented
+
+ def __getattr__(self, item):
+ if not self._param.is_enum():
+ raise AttributeError()
+ try:
+ return str(self._param.get_opt(item))
+ except KeyError:
+ raise AttributeError()
+
+ def __str__(self):
+ return str(self._param.to_code())
+
+ def __call__(self):
+ return self._param.get_evaluated()
diff --git a/grc/core/platform.py b/grc/core/platform.py
index 54deef3455..6d02cb6441 100644
--- a/grc/core/platform.py
+++ b/grc/core/platform.py
@@ -28,7 +28,7 @@ from six.moves import range
from . import (
Messages, Constants,
- blocks, ports, errors, utils, schema_checker
+ blocks, params, ports, errors, utils, schema_checker
)
from .Config import Config
@@ -38,7 +38,6 @@ from .io import yaml
from .generator import Generator
from .FlowGraph import FlowGraph
from .Connection import Connection
-from .Param import Param
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
@@ -395,7 +394,7 @@ class Platform(Element):
'clone': ports.PortClone, # clone of ports with multiplicity > 1
}
param_classes = {
- None: Param, # default
+ None: params.Param, # default
}
def make_flow_graph(self, from_filename=None):
diff --git a/grc/gui/canvas/param.py b/grc/gui/canvas/param.py
index e2c335d9cf..845ff5a926 100644
--- a/grc/gui/canvas/param.py
+++ b/grc/gui/canvas/param.py
@@ -18,10 +18,8 @@
from __future__ import absolute_import
from .drawable import Drawable
-
from .. import ParamWidgets, Utils, Constants
-
-from ...core.Param import Param as CoreParam
+from ...core.params import Param as CoreParam
class Param(CoreParam):