[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 12/18: grc-refactor: remove (hopefully) all
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 12/18: grc-refactor: remove (hopefully) all deps to GR in core/ and gui/ |
Date: |
Sun, 24 Apr 2016 19:19:37 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch master
in repository gnuradio.
commit c285036f5674ee54c16b46c3088ed86503d63d83
Author: Sebastian Koslowski <address@hidden>
Date: Wed Mar 16 16:25:09 2016 +0100
grc-refactor: remove (hopefully) all deps to GR in core/ and gui/
---
grc/core/CMakeLists.txt | 1 +
grc/core/Config.py | 55 ++++++++++++++++++++++++++++++
grc/core/FlowGraph.py | 2 +-
grc/core/Param.py | 34 ++++++++++---------
grc/core/Platform.py | 58 +++-----------------------------
grc/core/generator/Generator.py | 9 +++--
grc/core/utils/epy_block_io.py | 15 +++++----
grc/gui/ActionHandler.py | 28 ++++++++--------
grc/gui/CMakeLists.txt | 1 +
grc/gui/Config.py | 74 +++++++++++++++++++++++++++++++++++++++++
grc/gui/Constants.py | 63 ++++++++++++-----------------------
grc/gui/Dialogs.py | 17 +++-------
grc/gui/Executor.py | 4 +--
grc/gui/FlowGraph.py | 9 +++--
grc/gui/Param.py | 6 ++--
grc/gui/Platform.py | 27 ++++++++-------
grc/scripts/gnuradio-companion | 7 +++-
17 files changed, 241 insertions(+), 169 deletions(-)
diff --git a/grc/core/CMakeLists.txt b/grc/core/CMakeLists.txt
index 623d912..8aee811 100644
--- a/grc/core/CMakeLists.txt
+++ b/grc/core/CMakeLists.txt
@@ -20,6 +20,7 @@
########################################################################
GR_PYTHON_INSTALL(FILES
Block.py
+ Config.py
Connection.py
Constants.py
Element.py
diff --git a/grc/core/Config.py b/grc/core/Config.py
new file mode 100644
index 0000000..ac38d99
--- /dev/null
+++ b/grc/core/Config.py
@@ -0,0 +1,55 @@
+"""
+Copyright 2016 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
+"""
+
+import os
+from os.path import expanduser, normpath, expandvars, exists
+
+
+class Config(object):
+
+ key = 'grc'
+ name = 'GNU Radio Companion (no gui)'
+ license = __doc__.strip()
+ website = 'http://gnuradio.org'
+
+ hier_block_lib_dir = os.environ.get('GRC_HIER_PATH',
expanduser('~/.grc_gnuradio'))
+
+ def __init__(self, prefs_file, version, version_parts=None):
+ self.prefs = prefs_file
+ self.version = version
+ self.version_parts = version_parts or version[1:].split('-',
1)[0].split('.')[:3]
+
+ @property
+ def block_paths(self):
+ path_list_sep = {'/': ':', '\\': ';'}[os.path.sep]
+
+ paths_sources = (
+ self.hier_block_lib_dir,
+ os.environ.get('GRC_BLOCKS_PATH', ''),
+ self.prefs.get_string('grc', 'local_blocks_path', ''),
+ self.prefs.get_string('grc', 'global_blocks_path', ''),
+ )
+
+ collected_paths = sum((paths.split(path_list_sep)
+ for paths in paths_sources), [])
+
+ valid_paths = [normpath(expanduser(expandvars(path)))
+ for path in collected_paths if exists(path)]
+
+ return valid_paths
diff --git a/grc/core/FlowGraph.py b/grc/core/FlowGraph.py
index 3d744f7..af6d35f 100644
--- a/grc/core/FlowGraph.py
+++ b/grc/core/FlowGraph.py
@@ -370,7 +370,7 @@ class FlowGraph(Element):
n['block'] = [b.export_data() for b in blocks]
n['connection'] = [c.export_data() for c in connections]
instructions = odict({
- 'created': '.'.join(self.get_parent().config.version2),
+ 'created': '.'.join(self.get_parent().config.version_parts),
'format': FLOW_GRAPH_FILE_FORMAT_VERSION,
})
return odict({'flow_graph': n, '_instructions': instructions})
diff --git a/grc/core/Param.py b/grc/core/Param.py
index 0be3097..99106de 100644
--- a/grc/core/Param.py
+++ b/grc/core/Param.py
@@ -20,7 +20,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA
import ast
import re
-from gnuradio import eng_notation, gr
from . import Constants
from .Constants import VECTOR_TYPES, COMPLEX_TYPES, REAL_TYPES, INT_TYPES
@@ -31,8 +30,12 @@ from .utils import odict
import __builtin__
-ID_BLACKLIST = ['self', 'options', 'gr', 'blks2', 'wxgui', 'wx', 'math',
'forms', 'firdes'] + \
- filter(lambda x: not x.startswith('_'), dir(gr.top_block())) +
dir(__builtin__)
+ID_BLACKLIST = ['self', 'options', 'gr', 'blks2', 'wxgui', 'wx', 'math',
'forms', 'firdes'] + dir(__builtin__)
+try:
+ from gnuradio import gr
+ ID_BLACKLIST.extend(attr for attr in dir(gr.top_block()) if not
attr.startswith('_'))
+except ImportError:
+ pass
_check_id_matcher = re.compile('^[a-z|A-Z]\w*$')
_show_id_matcher = re.compile('^(variable\w*|parameter|options|notebook)$')
@@ -51,22 +54,23 @@ def _get_elem(lst, key):
def num_to_str(num):
""" Display logic for numbers """
+ def eng_notation(value, fmt='g'):
+ """Convert a number to a string in engineering notation. E.g., 5e-9
-> 5n"""
+ template = '{:' + fmt + '}{}'
+ magnitude = abs(value)
+ for exp, symbol in zip(range(9, -15-1, -3), 'GMk munpf'):
+ factor = 10 ** exp
+ if magnitude >= factor:
+ return template.format(value / factor, symbol.strip())
+ return template.format(value, '')
+
if isinstance(num, COMPLEX_TYPES):
num = complex(num) # Cast to python complex
if num == 0:
return '0'
- elif num.imag == 0:
- # Value is real
- return '{}'.format(eng_notation.num_to_str(num.real))
- elif num.real == 0:
- # Value is imaginary
- return '{}j'.format(eng_notation.num_to_str(num.imag))
- elif num.imag < 0:
- return '{}-{}j'.format(eng_notation.num_to_str(num.real),
- eng_notation.num_to_str(abs(num.imag)))
- else:
- return '{}+{}j'.format(eng_notation.num_to_str(num.real),
- eng_notation.num_to_str(num.imag))
+ output = eng_notation(num.real) if num.real else ''
+ output += eng_notation(num.imag, '+g' if output else 'g') + 'j' if
num.imag else ''
+ return output
else:
return str(num)
diff --git a/grc/core/Platform.py b/grc/core/Platform.py
index 97e2b38..4c1e6f4 100644
--- a/grc/core/Platform.py
+++ b/grc/core/Platform.py
@@ -19,10 +19,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA
import os
import sys
-from gnuradio import gr
from . import ParseXML, Messages, Constants
+from .Config import Config
from .Element import Element
from .generator import Generator
from .FlowGraph import FlowGraph
@@ -34,59 +34,9 @@ from .Param import Param
from .utils import odict, extract_docs
-from os.path import expanduser, normpath, expandvars, dirname, exists
-
-
-class Config(object):
-
- key = 'grc'
- name = 'GNU Radio Companion'
- license = __doc__.strip()
- website = 'http://gnuradio.org'
- version = gr.version()
- version2 = (gr.major_version(), gr.api_version(), gr.minor_version())
-
- hier_block_lib_dir = os.environ.get('GRC_HIER_PATH',
expanduser('~/.grc_gnuradio'))
-
- def __init__(self):
- self.prefs = self._get_prefs()
-
- if not exists(self.hier_block_lib_dir):
- os.mkdir(self.hier_block_lib_dir)
-
- @staticmethod
- def _get_prefs():
- try:
- from gnuradio import gr
- prefs = gr.prefs()
- except ImportError:
- import ConfigParser
- prefs = ConfigParser.ConfigParser()
-
- return prefs
-
- @property
- def block_paths(self):
- path_list_sep = {'/': ':', '\\': ';'}[os.path.sep]
-
- paths_sources = (
- self.hier_block_lib_dir,
- os.environ.get('GRC_BLOCKS_PATH', ''),
- self.prefs.get_string('grc', 'local_blocks_path', ''),
- self.prefs.get_string('grc', 'global_blocks_path', ''),
- )
-
- collected_paths = sum((paths.split(path_list_sep)
- for paths in paths_sources), [])
-
- valid_paths = [normpath(expanduser(expandvars(path)))
- for path in collected_paths if exists(path)]
-
- return valid_paths
-
-
class Platform(Element):
+ Config = Config
Generator = Generator
FlowGraph = FlowGraph
Connection = Connection
@@ -96,11 +46,11 @@ class Platform(Element):
is_platform = True
- def __init__(self):
+ def __init__(self, *args, **kwargs):
""" Make a platform for GNU Radio """
Element.__init__(self)
- self.config = Config()
+ self.config = self.Config(*args, **kwargs)
self.block_docstrings = {}
self.block_docstrings_loaded_callback = lambda: None # dummy to be
replaced by BlockTreeWindow
diff --git a/grc/core/generator/Generator.py b/grc/core/generator/Generator.py
index 5c2fa6e..9167107 100644
--- a/grc/core/generator/Generator.py
+++ b/grc/core/generator/Generator.py
@@ -259,9 +259,12 @@ class HierBlockGenerator(TopBlockGenerator):
TopBlockGenerator.__init__(self, flow_graph, file_path)
platform = flow_graph.get_parent()
+ hier_block_lib_dir = platform.config.hier_block_lib_dir
+ if not os.path.exists(hier_block_lib_dir):
+ os.mkdir(hier_block_lib_dir)
+
self._mode = HIER_BLOCK_FILE_MODE
- self.file_path = os.path.join(platform.config.hier_block_lib_dir,
- self._flow_graph.get_option('id') +
'.py')
+ self.file_path = os.path.join(hier_block_lib_dir,
self._flow_graph.get_option('id') + '.py')
self._file_path_xml = self.file_path + '.xml'
def get_file_path_xml(self):
@@ -388,4 +391,4 @@ class QtHierBlockGenerator(HierBlockGenerator):
"\n#set $win = 'self.%s' % $id"
"\n${gui_hint()($win)}"
)
- return n
\ No newline at end of file
+ return n
diff --git a/grc/core/utils/epy_block_io.py b/grc/core/utils/epy_block_io.py
index c070e1c..df3a4bb 100644
--- a/grc/core/utils/epy_block_io.py
+++ b/grc/core/utils/epy_block_io.py
@@ -2,9 +2,6 @@
import inspect
import collections
-from gnuradio import gr
-import pmt
-
TYPE_MAP = {
'complex64': 'complex', 'complex': 'complex',
@@ -31,21 +28,27 @@ def _ports(sigs, msgs):
return ports
-def _blk_class(source_code):
+def _find_block_class(source_code, cls):
ns = {}
try:
exec source_code in ns
except Exception as e:
raise ValueError("Can't interpret source code: " + str(e))
for var in ns.itervalues():
- if inspect.isclass(var) and issubclass(var, gr.gateway.gateway_block):
+ if inspect.isclass(var) and issubclass(var, cls):
return var
raise ValueError('No python block class found in code')
def extract(cls):
+ try:
+ from gnuradio import gr
+ import pmt
+ except ImportError:
+ raise EnvironmentError("Can't import GNU Radio")
+
if not inspect.isclass(cls):
- cls = _blk_class(cls)
+ cls = _find_block_class(cls, gr.gateway.gateway_block)
spec = inspect.getargspec(cls.__init__)
defaults = map(repr, spec.defaults or ())
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index 139bbed..24add27 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -23,8 +23,7 @@ import gtk
import os
import subprocess
-from . import Dialogs, Preferences, Actions, Executor
-from .Constants import DEFAULT_CANVAS_SIZE, IMAGE_FILE_EXTENSION, GR_PREFIX,
XTERM_EXECUTABLE
+from . import Dialogs, Preferences, Actions, Executor, Constants
from .FileDialogs import (OpenFlowGraphFileDialog, SaveFlowGraphFileDialog,
SaveReportsFileDialog, SaveScreenShotDialog,
OpenQSSFileDialog)
@@ -32,8 +31,7 @@ from .MainWindow import MainWindow
from .ParserErrorsDialog import ParserErrorsDialog
from .PropsDialog import PropsDialog
-from ..core import Constants, ParseXML
-from ..core import Messages
+from ..core import ParseXML, Messages
gobject.threads_init()
@@ -487,12 +485,13 @@ class ActionHandler:
self.main_window.menu_bar.refresh_submenus()
elif action == Actions.FLOW_GRAPH_OPEN_QSS_THEME:
- file_paths = OpenQSSFileDialog(GR_PREFIX +
'/share/gnuradio/themes/').run()
+ file_paths = OpenQSSFileDialog(self.platform.config.install_prefix
+
+ '/share/gnuradio/themes/').run()
if file_paths:
try:
- from gnuradio import gr
- gr.prefs().set_string("qtgui", "qss", file_paths[0])
- gr.prefs().save()
+ prefs = self.platform.config.prefs
+ prefs.set_string("qtgui", "qss", file_paths[0])
+ prefs.save()
except Exception as e:
Messages.send("Failed to save QSS preference: " + str(e))
elif action == Actions.FLOW_GRAPH_CLOSE:
@@ -522,7 +521,7 @@ class ActionHandler:
file_path, background_transparent =
SaveScreenShotDialog(self.get_page().get_file_path()).run()
if file_path is not None:
pixbuf =
self.get_flow_graph().get_drawing_area().get_screenshot(background_transparent)
- pixbuf.save(file_path, IMAGE_FILE_EXTENSION[1:])
+ pixbuf.save(file_path, Constants.IMAGE_FILE_EXTENSION[1:])
##################################################
# Gen/Exec/Stop
##################################################
@@ -540,10 +539,11 @@ class ActionHandler:
elif action == Actions.FLOW_GRAPH_EXEC:
if not self.get_page().get_proc():
Actions.FLOW_GRAPH_GEN()
- if Preferences.xterm_missing() != XTERM_EXECUTABLE:
- if not os.path.exists(XTERM_EXECUTABLE):
- Dialogs.MissingXTermDialog(XTERM_EXECUTABLE)
- Preferences.xterm_missing(XTERM_EXECUTABLE)
+ xterm = self.platform.config.xterm_executable
+ if Preferences.xterm_missing() != xterm:
+ if not os.path.exists(xterm):
+ Dialogs.MissingXTermDialog(xterm)
+ Preferences.xterm_missing(xterm)
if self.get_page().get_saved() and
self.get_page().get_file_path():
Executor.ExecFlowGraphThread(self)
elif action == Actions.FLOW_GRAPH_KILL:
@@ -634,7 +634,7 @@ class ActionHandler:
self.main_window.update()
try: #set the size of the flow graph area (if changed)
new_size = (self.get_flow_graph().get_option('window_size') or
- DEFAULT_CANVAS_SIZE)
+ self.platform.config.default_canvas_size)
if self.get_flow_graph().get_size() != tuple(new_size):
self.get_flow_graph().set_size(*new_size)
except: pass
diff --git a/grc/gui/CMakeLists.txt b/grc/gui/CMakeLists.txt
index 7e43553..e9c4f71 100644
--- a/grc/gui/CMakeLists.txt
+++ b/grc/gui/CMakeLists.txt
@@ -22,6 +22,7 @@ GR_PYTHON_INSTALL(FILES
external_editor.py
Block.py
Colors.py
+ Config.py
Constants.py
Connection.py
Element.py
diff --git a/grc/gui/Config.py b/grc/gui/Config.py
new file mode 100644
index 0000000..9b0c5d4
--- /dev/null
+++ b/grc/gui/Config.py
@@ -0,0 +1,74 @@
+"""
+Copyright 2016 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
+"""
+
+import sys
+import os
+from ..core.Config import Config as _Config
+from . import Constants
+
+
+class Config(_Config):
+
+ name = 'GNU Radio Companion'
+
+ gui_prefs_file = os.environ.get(
+ 'GRC_PREFS_PATH', os.path.expanduser('~/.gnuradio/grc.conf'))
+
+ def __init__(self, install_prefix, *args, **kwargs):
+ _Config.__init__(self, *args, **kwargs)
+ self.install_prefix = install_prefix
+ Constants.update_font_size(self.font_size)
+
+ @property
+ def editor(self):
+ return self.prefs.get_string('grc', 'editor', '')
+
+ @editor.setter
+ def editor(self, value):
+ self.prefs.get_string('grc', 'editor', value)
+ self.prefs.save()
+
+ @property
+ def xterm_executable(self):
+ return self.prefs.get_string('grc', 'xterm_executable', 'xterm')
+
+ @property
+ def default_canvas_size(self):
+ try: # ugly, but matches current code style
+ raw = self.prefs.get_string('grc', 'canvas_default_size', '1280,
1024')
+ value = tuple(int(x.strip('() ')) for x in raw.split(','))
+ if len(value) != 2 or not all(300 < x < 4096 for x in value):
+ raise Exception()
+ return value
+ except:
+ print >> sys.stderr, "Error: invalid 'canvas_default_size'
setting."
+ return Constants.DEFAULT_CANVAS_SIZE_DEFAULT
+
+ @property
+ def font_size(self):
+ try: # ugly, but matches current code style
+ font_size = self.prefs.get_long('grc', 'canvas_font_size',
+ Constants.DEFAULT_FONT_SIZE)
+ if font_size <= 0:
+ raise Exception()
+ except:
+ font_size = Constants.DEFAULT_FONT_SIZE
+ print >> sys.stderr, "Error: invalid 'canvas_font_size' setting."
+
+ return font_size
diff --git a/grc/gui/Constants.py b/grc/gui/Constants.py
index b891c5b..e267c6c 100644
--- a/grc/gui/Constants.py
+++ b/grc/gui/Constants.py
@@ -17,28 +17,10 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
"""
-import os
-import sys
-
-import pygtk
-pygtk.require('2.0')
import gtk
-from gnuradio import gr
-
-prefs = gr.prefs()
-GR_PREFIX = gr.prefix()
-EDITOR = prefs.get_string('grc', 'editor', '')
-XTERM_EXECUTABLE = prefs.get_string('grc', 'xterm_executable', 'xterm')
+from ..core.Constants import *
-PREFS_FILE = os.environ.get(
- 'GRC_PREFS_PATH',
- os.path.expanduser('~/.gnuradio/grc.conf')
-)
-PREFS_FILE_OLD = os.environ.get(
- 'GRC_PREFS_PATH',
- os.path.expanduser('~/.grc')
-)
# default path for the open/save dialogs
DEFAULT_FILE_PATH = os.getcwd()
@@ -60,28 +42,12 @@ MIN_DIALOG_HEIGHT = 500
DEFAULT_BLOCKS_WINDOW_WIDTH = 100
DEFAULT_REPORTS_WINDOW_WIDTH = 100
-try: # ugly, but matches current code style
- raw = prefs.get_string('grc', 'canvas_default_size', '1280, 1024')
- DEFAULT_CANVAS_SIZE = tuple(int(x.strip('() ')) for x in raw.split(','))
- if len(DEFAULT_CANVAS_SIZE) != 2 or not all(300 < x < 4096 for x in
DEFAULT_CANVAS_SIZE):
- raise Exception()
-except:
- DEFAULT_CANVAS_SIZE = 1280, 1024
- print >> sys.stderr, "Error: invalid 'canvas_default_size' setting."
-
-# flow-graph canvas fonts
-try: # ugly, but matches current code style
- FONT_SIZE = prefs.get_long('grc', 'canvas_font_size', 8)
- if FONT_SIZE <= 0:
- raise Exception()
-except:
- FONT_SIZE = 8
- print >> sys.stderr, "Error: invalid 'canvas_font_size' setting."
-FONT_FAMILY = "Sans"
-BLOCK_FONT = "%s %f" % (FONT_FAMILY, FONT_SIZE)
-PORT_FONT = BLOCK_FONT
-PARAM_FONT = "%s %f" % (FONT_FAMILY, FONT_SIZE - 0.5)
+DEFAULT_CANVAS_SIZE_DEFAULT = 1280, 1024
+FONT_SIZE = DEFAULT_FONT_SIZE = 8
+FONT_FAMILY = "Sans"
+BLOCK_FONT = PORT_FONT = "Sans 8"
+PARAM_FONT = "Sans 7.5"
# size of the state saving cache in the flow graph (undo/redo functionality)
STATE_CACHE_SIZE = 42
@@ -100,8 +66,7 @@ CANVAS_GRID_SIZE = 8
# port constraint dimensions
PORT_BORDER_SEPARATION = 8
PORT_SPACING = 2 * PORT_BORDER_SEPARATION
-PORT_SEPARATION = PORT_SPACING + 2 * PORT_LABEL_PADDING + int(1.5 * FONT_SIZE)
-PORT_SEPARATION += -PORT_SEPARATION % (2 * CANVAS_GRID_SIZE) # even multiple
+PORT_SEPARATION = 32
PORT_MIN_WIDTH = 20
PORT_LABEL_HIDDEN_WIDTH = 10
@@ -130,3 +95,17 @@ SCROLL_DISTANCE = 15
# How close the mouse click can be to a line and register a connection select.
LINE_SELECT_SENSITIVITY = 5
+
+
+def update_font_size(font_size):
+ global PORT_SEPARATION, BLOCK_FONT, PORT_FONT, PARAM_FONT, FONT_SIZE
+
+ FONT_SIZE = font_size
+ BLOCK_FONT = "%s %f" % (FONT_FAMILY, font_size)
+ PORT_FONT = BLOCK_FONT
+ PARAM_FONT = "%s %f" % (FONT_FAMILY, font_size - 0.5)
+
+ PORT_SEPARATION = PORT_SPACING + 2 * PORT_LABEL_PADDING + int(1.5 *
font_size)
+ PORT_SEPARATION += -PORT_SEPARATION % (2 * CANVAS_GRID_SIZE) # even
multiple
+
+update_font_size(DEFAULT_FONT_SIZE)
diff --git a/grc/gui/Dialogs.py b/grc/gui/Dialogs.py
index c5b4d8b..6cfdd50 100644
--- a/grc/gui/Dialogs.py
+++ b/grc/gui/Dialogs.py
@@ -22,7 +22,7 @@ import gtk
import sys
from distutils.spawn import find_executable
-from . import Utils, Actions, Constants
+from . import Utils, Actions
from ..core import Messages
@@ -238,7 +238,7 @@ def MissingXTermDialog(xterm):
)
-def ChooseEditorDialog():
+def ChooseEditorDialog(config):
# Give the option to either choose an editor or use the default
# Always return true/false so the caller knows it was successful
buttons = (
@@ -264,10 +264,7 @@ def ChooseEditorDialog():
file_dialog.set_current_folder('/usr/bin')
try:
if file_dialog.run() == gtk.RESPONSE_OK:
- file_path = file_dialog.get_filename()
- Constants.prefs.set_string('grc', 'editor', file_path)
- Constants.prefs.save()
- Constants.EDITOR = file_path
+ config.editor = file_path = file_dialog.get_filename()
file_dialog.destroy()
return file_path
finally:
@@ -285,16 +282,12 @@ def ChooseEditorDialog():
if process is None:
raise ValueError("Can't find default editor executable")
# Save
- Constants.prefs.set_string('grc', 'editor', process)
- Constants.prefs.save()
- Constants.EDITOR = process
+ config.editor = process
return process
except Exception:
Messages.send('>>> Unable to load the default editor. Please
choose an editor.\n')
# Just reset of the constant and force the user to select an
editor the next time
- Constants.prefs.set_string('grc', 'editor', '')
- Constants.prefs.save()
- Constants.EDITOR = ""
+ config.editor = ''
return
Messages.send('>>> No editor selected.\n')
diff --git a/grc/gui/Executor.py b/grc/gui/Executor.py
index 96b95f4..f75f514 100644
--- a/grc/gui/Executor.py
+++ b/grc/gui/Executor.py
@@ -25,7 +25,6 @@ import re
from distutils.spawn import find_executable
from ..core import Messages
-from .Constants import XTERM_EXECUTABLE
class ExecFlowGraphThread(threading.Thread):
@@ -41,6 +40,7 @@ class ExecFlowGraphThread(threading.Thread):
threading.Thread.__init__(self)
self.update_exec_stop = action_handler.update_exec_stop
self.flow_graph = action_handler.get_flow_graph()
+ self.xterm_executable = action_handler.platform.config.xterm_executable
#store page and dont use main window calls in run
self.page = action_handler.get_page()
#get the popen
@@ -70,7 +70,7 @@ class ExecFlowGraphThread(threading.Thread):
raise ValueError("Can't parse run command {!r}:
{}".format(run_command, e))
# When in no gui mode on linux, use a graphical terminal (looks nice)
- xterm_executable = find_executable(XTERM_EXECUTABLE)
+ xterm_executable = find_executable(self.xterm_executable)
if generator.generate_options == 'no_gui' and xterm_executable:
run_command_args = [xterm_executable, '-e', run_command]
diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py
index 25fb157..2f8ca00 100644
--- a/grc/gui/FlowGraph.py
+++ b/grc/gui/FlowGraph.py
@@ -88,8 +88,9 @@ class FlowGraph(Element, _Flowgraph):
if target in self._external_updaters:
editor = self._external_updaters[target]
else:
- editor = (find_executable(Constants.EDITOR) or
- Dialogs.ChooseEditorDialog())
+ config = self.get_parent().config
+ editor = (find_executable(config.editor) or
+ Dialogs.ChooseEditorDialog(config))
if not editor:
return
updater = functools.partial(
@@ -106,9 +107,7 @@ class FlowGraph(Element, _Flowgraph):
# Problem launching the editor. Need to select a new editor.
Messages.send('>>> Error opening an external editor. Please select
a different editor.\n')
# Reset the editor to force the user to select a new one.
- Constants.prefs.set_string('grc', 'editor', '')
- Constants.prefs.save()
- Constants.EDITOR = ""
+ self.get_parent().config.editor = ''
def handle_external_editor_change(self, new_value, target):
try:
diff --git a/grc/gui/Param.py b/grc/gui/Param.py
index 647e817..bf0a59b 100644
--- a/grc/gui/Param.py
+++ b/grc/gui/Param.py
@@ -23,7 +23,7 @@ import pygtk
pygtk.require('2.0')
import gtk
-from . import Colors, Utils, Constants, Dialogs
+from . import Colors, Utils, Constants
from .Element import Element
from ..core.Param import Param as _Param
@@ -319,7 +319,9 @@ class FileParam(EntryParam):
if self.param.get_key() == 'qt_qss_theme':
dirname = os.path.dirname(dirname) # trim filename
if not os.path.exists(dirname):
- dirname = os.path.join(Constants.GR_PREFIX,
'/share/gnuradio/themes')
+ platform = self.param.get_parent().get_parent().get_parent()
+ dirname = os.path.join(platform.config.install_prefix,
+ '/share/gnuradio/themes')
if not os.path.exists(dirname):
dirname = os.getcwd() # fix bad paths
diff --git a/grc/gui/Platform.py b/grc/gui/Platform.py
index cfd5ae3..500df1c 100644
--- a/grc/gui/Platform.py
+++ b/grc/gui/Platform.py
@@ -22,9 +22,9 @@ import sys
from ..core.Platform import Platform as _Platform
+from .Config import Config as _Config
from .Block import Block as _Block
from .Connection import Connection as _Connection
-from .Constants import PREFS_FILE, PREFS_FILE_OLD
from .Element import Element
from .FlowGraph import FlowGraph as _FlowGraph
from .Param import Param as _Param
@@ -33,28 +33,30 @@ from .Port import Port as _Port
class Platform(Element, _Platform):
- def __init__(self):
+ def __init__(self, *args, **kwargs):
Element.__init__(self)
- _Platform.__init__(self)
+ _Platform.__init__(self, *args, **kwargs)
# Ensure conf directories
- if not os.path.exists(os.path.dirname(PREFS_FILE)):
- os.mkdir(os.path.dirname(PREFS_FILE))
+ gui_prefs_file = self.config.gui_prefs_file
+ if not os.path.exists(os.path.dirname(gui_prefs_file)):
+ os.mkdir(os.path.dirname(gui_prefs_file))
self._move_old_pref_file()
- self._prefs_file = PREFS_FILE
def get_prefs_file(self):
- return self._prefs_file
+ return self.config.gui_prefs_file
- @staticmethod
- def _move_old_pref_file():
- if PREFS_FILE == PREFS_FILE_OLD:
+ def _move_old_pref_file(self):
+ gui_prefs_file = self.config.gui_prefs_file
+ old_gui_prefs_file = os.environ.get(
+ 'GRC_PREFS_PATH', os.path.expanduser('~/.grc'))
+ if gui_prefs_file == old_gui_prefs_file:
return # prefs file overridden with env var
- if os.path.exists(PREFS_FILE_OLD) and not os.path.exists(PREFS_FILE):
+ if os.path.exists(old_gui_prefs_file) and not
os.path.exists(gui_prefs_file):
try:
import shutil
- shutil.move(PREFS_FILE_OLD, PREFS_FILE)
+ shutil.move(old_gui_prefs_file, gui_prefs_file)
except Exception as e:
print >> sys.stderr, e
@@ -66,3 +68,4 @@ class Platform(Element, _Platform):
Block = _Block
Port = _Port
Param = _Param
+ Config = _Config
diff --git a/grc/scripts/gnuradio-companion b/grc/scripts/gnuradio-companion
index 3a3bf50..0452989 100755
--- a/grc/scripts/gnuradio-companion
+++ b/grc/scripts/gnuradio-companion
@@ -123,7 +123,12 @@ def main():
except:
pass
- ActionHandler(args, Platform())
+ ActionHandler(args, Platform(
+ prefs_file=gr.prefs(),
+ version=gr.version(),
+ version_parts=(gr.major_version(), gr.api_version(),
gr.minor_version()),
+ install_prefix=gr.prefix()
+ ))
if __name__ == '__main__':
- [Commit-gnuradio] [gnuradio] branch master updated (bdf8517 -> a03a390), git, 2016/04/24
- [Commit-gnuradio] [gnuradio] 15/18: grc-refactoring: fix gui mode errors, no empty import on fg init, some renames, git, 2016/04/24
- [Commit-gnuradio] [gnuradio] 06/18: grc-refactor: rename grc/model/ to grc/core/, git, 2016/04/24
- [Commit-gnuradio] [gnuradio] 08/18: grc-refactor: Platform.py fixes, FlowGraphProxy, git, 2016/04/24
- [Commit-gnuradio] [gnuradio] 02/18: grc-refactor: clean-up grc directory, git, 2016/04/24
- [Commit-gnuradio] [gnuradio] 09/18: grc-refactor: move Messages to core, git, 2016/04/24
- [Commit-gnuradio] [gnuradio] 07/18: grc-refactor: cmake fixes and more reorganizing, git, 2016/04/24
- [Commit-gnuradio] [gnuradio] 13/18: grc-refactoring: move template arg to param, git, 2016/04/24
- [Commit-gnuradio] [gnuradio] 14/18: grc-refactor: fix fg load, git, 2016/04/24
- [Commit-gnuradio] [gnuradio] 12/18: grc-refactor: remove (hopefully) all deps to GR in core/ and gui/,
git <=
- [Commit-gnuradio] [gnuradio] 18/18: Merge branch 'maint_grcwg' into refactoring, git, 2016/04/24
- [Commit-gnuradio] [gnuradio] 11/18: grc-refactor: move gui prefs to gui, git, 2016/04/24
- [Commit-gnuradio] [gnuradio] 05/18: grc-refactor: fixes, type-testing-flags, FlowGraph.py, (more), git, 2016/04/24
- [Commit-gnuradio] [gnuradio] 01/18: grc-refactor: move grc.base to grc.python.base, git, 2016/04/24
- [Commit-gnuradio] [gnuradio] 10/18: grc-refactor: Platform.py, git, 2016/04/24
- [Commit-gnuradio] [gnuradio] 17/18: grc-refactor: CMake fixes, start-up script cleaned up, git, 2016/04/24
- [Commit-gnuradio] [gnuradio] 16/18: Merge remote-tracking branch 'upstream/master' into refactoring, git, 2016/04/24
- [Commit-gnuradio] [gnuradio] 04/18: grc-refactor: Cleaning up code style to match PEP8., git, 2016/04/24
- [Commit-gnuradio] [gnuradio] 03/18: grc-refactor: Moved code from grc.model.base to grc.model, git, 2016/04/24