diff options
author | Johnathan Corgan <johnathan@corganlabs.com> | 2015-08-28 12:06:07 -0700 |
---|---|---|
committer | Johnathan Corgan <johnathan@corganlabs.com> | 2015-08-28 12:06:07 -0700 |
commit | e1bdd3c8eff488aa5de91cd1a8b474779b7054d7 (patch) | |
tree | e929da3ad5f90a7473e626a2c80d59ac347efadc | |
parent | 5e645075ebaeb1d32a0a4c7b2e99a4bed8220163 (diff) | |
parent | 26b6cf4d645b68279b23467dc77d442c4b9720ec (diff) |
Merge remote-tracking branch 'gnuradio-wg-grc/master_grcwg'
-rw-r--r-- | grc/CMakeLists.txt | 17 | ||||
-rw-r--r-- | grc/gui/ActionHandler.py | 30 | ||||
-rw-r--r-- | grc/gui/Actions.py | 7 | ||||
-rw-r--r-- | grc/gui/Dialogs.py | 31 | ||||
-rw-r--r-- | grc/gui/Messages.py | 2 | ||||
-rw-r--r-- | grc/gui/Preferences.py | 91 | ||||
-rw-r--r-- | grc/python/Constants.py | 25 | ||||
-rw-r--r-- | grc/python/Generator.py | 1 | ||||
-rw-r--r-- | grc/python/Platform.py | 37 |
9 files changed, 145 insertions, 96 deletions
diff --git a/grc/CMakeLists.txt b/grc/CMakeLists.txt index 3714401bbb..859b9e9045 100644 --- a/grc/CMakeLists.txt +++ b/grc/CMakeLists.txt @@ -72,13 +72,16 @@ if(CMAKE_INSTALL_PREFIX STREQUAL "/usr") set(blocksdir ${blocksdir}:/usr/local/${GRC_BLOCKS_DIR}) endif(CMAKE_INSTALL_PREFIX STREQUAL "/usr") -if (APPLE) - set(GRC_XTERM_EXE "xterm") -elseif(CYGWIN) - set(GRC_XTERM_EXE "xterm") -elseif(UNIX) - set(GRC_XTERM_EXE "x-terminal-emulator") -else() +if(UNIX) + find_program(GRC_XTERM_EXE + NAMES xterminal-emulator gnome-terminal konsole xterm + HINTS ENV PATH + DOC "graphical terminal emulator used in GRC's no-gui-mode" + ) + if(NOT GRC_XTERM_EXE) + set(GRC_XTERM_EXE "") + endif() +else() # APPLE CYGWIN set(GRC_XTERM_EXE "xterm") endif() diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py index 15565127e3..19c6edc914 100644 --- a/grc/gui/ActionHandler.py +++ b/grc/gui/ActionHandler.py @@ -18,23 +18,24 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA """ import os -from Constants import IMAGE_FILE_EXTENSION -import Actions +import subprocess +from threading import Thread + import pygtk pygtk.require('2.0') import gtk import gobject -import subprocess -import Preferences -from threading import Thread -import Messages + from .. base import ParseXML, Constants -from MainWindow import MainWindow -from PropsDialog import PropsDialog -from ParserErrorsDialog import ParserErrorsDialog -import Dialogs -from FileDialogs import OpenFlowGraphFileDialog, SaveFlowGraphFileDialog, SaveReportsFileDialog, SaveImageFileDialog -from . Constants import DEFAULT_CANVAS_SIZE +from .. python.Constants import XTERM_EXECUTABLE + +from . import Dialogs, Messages, Preferences, Actions +from .ParserErrorsDialog import ParserErrorsDialog +from .MainWindow import MainWindow +from .PropsDialog import PropsDialog +from .FileDialogs import (OpenFlowGraphFileDialog, SaveFlowGraphFileDialog, + SaveReportsFileDialog, SaveImageFileDialog) +from .Constants import DEFAULT_CANVAS_SIZE, IMAGE_FILE_EXTENSION gobject.threads_init() @@ -511,6 +512,10 @@ 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) if self.get_page().get_saved() and self.get_page().get_file_path(): ExecFlowGraphThread(self) elif action == Actions.FLOW_GRAPH_KILL: @@ -634,7 +639,6 @@ class ExecFlowGraphThread(Thread): self.flow_graph = action_handler.get_flow_graph() #store page and dont use main window calls in run self.page = action_handler.get_page() - Messages.send_start_exec(self.page.get_generator().get_file_path()) #get the popen try: self.p = self.page.get_generator().get_popen() diff --git a/grc/gui/Actions.py b/grc/gui/Actions.py index d864db7e16..ce1f2cf873 100644 --- a/grc/gui/Actions.py +++ b/grc/gui/Actions.py @@ -150,13 +150,12 @@ class ToggleAction(gtk.ToggleAction, _ActionBase): def load_from_preferences(self): if self.preference_name is not None: - self.set_active(Preferences.bool_entry(self.preference_name, - default=self.default)) + self.set_active(Preferences.entry( + self.preference_name, default=bool(self.default))) def save_to_preferences(self): if self.preference_name is not None: - Preferences.bool_entry(self.preference_name, - value=self.get_active()) + Preferences.entry(self.preference_name, value=self.get_active()) ######################################################################## # Actions diff --git a/grc/gui/Dialogs.py b/grc/gui/Dialogs.py index 61d677af85..6c01219dee 100644 --- a/grc/gui/Dialogs.py +++ b/grc/gui/Dialogs.py @@ -160,6 +160,8 @@ ERRORS_MARKUP_TMPL="""\ $encode($err_msg.replace('\t', ' ')) #end for""" + + def ErrorsDialog(flowgraph): MessageDialogHelper( type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_CLOSE, @@ -167,6 +169,7 @@ def ErrorsDialog(flowgraph): MessageDialogHelper( markup=Utils.parse_template(ERRORS_MARKUP_TMPL, errors=flowgraph.get_error_messages()), ) + class AboutDialog(gtk.AboutDialog): """A cute little about dialog.""" @@ -181,6 +184,7 @@ class AboutDialog(gtk.AboutDialog): self.run() self.destroy() + def HelpDialog(): MessageDialogHelper( type=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_CLOSE, @@ -208,8 +212,25 @@ COLORS_DIALOG_MARKUP_TMPL = """\ #end if """ -def TypesDialog(platform): MessageDialogHelper( - type=gtk.MESSAGE_INFO, - buttons=gtk.BUTTONS_CLOSE, - title='Types', - markup=Utils.parse_template(COLORS_DIALOG_MARKUP_TMPL, colors=platform.get_colors())) + +def TypesDialog(platform): + MessageDialogHelper( + type=gtk.MESSAGE_INFO, + buttons=gtk.BUTTONS_CLOSE, + title='Types', + markup=Utils.parse_template(COLORS_DIALOG_MARKUP_TMPL, + colors=platform.get_colors()) + ) + + +def MissingXTermDialog(xterm): + MessageDialogHelper( + type=gtk.MESSAGE_WARNING, + buttons=gtk.BUTTONS_OK, + title='Warning: missing xterm executable', + markup=("The xterm executable {0!r} is missing.\n\n" + "You can change this setting in your gnuradio.conf, in " + "section [grc], 'xterm_executable'.\n" + "\n" + "(This message is shown only once)").format(xterm) + ) diff --git a/grc/gui/Messages.py b/grc/gui/Messages.py index 4bce9967ed..61692b45dc 100644 --- a/grc/gui/Messages.py +++ b/grc/gui/Messages.py @@ -102,7 +102,7 @@ def send_fail_gen(error): ################# functions for executing flow graphs ######################################## def send_start_exec(file_path): - send('\nExecuting: "%s"'%file_path + '\n') + send('\nExecuting: ' + repr(file_path) + '\n') def send_verbose_exec(verbose): send(verbose) diff --git a/grc/gui/Preferences.py b/grc/gui/Preferences.py index 109fe5e85e..a5a7fa91b5 100644 --- a/grc/gui/Preferences.py +++ b/grc/gui/Preferences.py @@ -17,11 +17,20 @@ 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 ConfigParser +HEADER = """\ +# This contains only GUI settings for GRC and is not meant for users to edit. +# +# GRC settings not accessible through the GUI are in gnuradio.conf under +# section [grc]. + +""" + _platform = None -_config_parser = ConfigParser.ConfigParser() +_config_parser = ConfigParser.SafeConfigParser() def file_extension(): @@ -36,15 +45,34 @@ def load(platform): _config_parser.add_section('files_open') try: _config_parser.read(_platform.get_prefs_file()) - except: - pass + except Exception as err: + print >> sys.stderr, err def save(): try: - _config_parser.write(open(_platform.get_prefs_file(), 'w')) - except: - pass + with open(_platform.get_prefs_file(), 'w') as fp: + fp.write(HEADER) + _config_parser.write(fp) + except Exception as err: + print >> sys.stderr, err + + +def entry(key, value=None, default=None): + if value is not None: + _config_parser.set('main', key, str(value)) + result = value + else: + _type = type(default) if default is not None else str + getter = { + bool: _config_parser.getboolean, + int: _config_parser.getint, + }.get(_type, _config_parser.get) + try: + result = getter('main', key) + except ConfigParser.Error: + result = _type() if default is None else default + return result ########################################################################### @@ -52,26 +80,15 @@ def save(): ########################################################################### def main_window_size(size=None): - if size is not None: - _config_parser.set('main', 'main_window_width', size[0]) - _config_parser.set('main', 'main_window_height', size[1]) - else: - try: - w = _config_parser.getint('main', 'main_window_width') - h = _config_parser.getint('main', 'main_window_height') - except: - w, h = 1, 1 - return w, h + if size is None: + size = [None, None] + w = entry('main_window_width', size[0], default=1) + h = entry('main_window_height', size[1], default=1) + return w, h def file_open(filename=None): - if filename is not None: - _config_parser.set('main', 'file_open', filename) - else: - try: - return _config_parser.get('main', 'file_open') - except: - return '' + return entry('file_open', filename, default='') def files_open(files=None): @@ -85,36 +102,18 @@ def files_open(files=None): try: files = [value for name, value in _config_parser.items('files_open') if name.startswith('file_open_')] - except: + except ConfigParser.Error: files = [] return files def reports_window_position(pos=None): - if pos is not None: - _config_parser.set('main', 'reports_window_position', pos) - else: - try: - return _config_parser.getint('main', 'reports_window_position') or 1 #greater than 0 - except: - return -1 + return entry('reports_window_position', pos, default=-1) or 1 def blocks_window_position(pos=None): - if pos is not None: - _config_parser.set('main', 'blocks_window_position', pos) - else: - try: - return _config_parser.getint('main', 'blocks_window_position') or 1 #greater than 0 - except: - return -1 + return entry('blocks_window_position', pos, default=-1) or 1 -def bool_entry(key, value=None, default=True): - if value is not None: - _config_parser.set('main', key, value) - else: - try: - return _config_parser.getboolean('main', key) - except: - return default +def xterm_missing(cmd=None): + return entry('xterm_missing', cmd, default='INVALID_XTERM_SETTING') diff --git a/grc/python/Constants.py b/grc/python/Constants.py index 1df1fc492b..02be22a441 100644 --- a/grc/python/Constants.py +++ b/grc/python/Constants.py @@ -18,18 +18,21 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA """ import os +from os.path import expanduser import stat from gnuradio import gr _gr_prefs = gr.prefs() -#setup paths -PATH_SEP = {'/':':', '\\':';'}[os.path.sep] -HIER_BLOCKS_LIB_DIR = os.environ.get('GRC_HIER_PATH', - os.path.expanduser('~/.grc_gnuradio')) -PREFS_FILE = os.environ.get('GRC_PREFS_PATH', - os.path.join(os.path.expanduser('~/.grc'))) -BLOCKS_DIRS = filter( #filter blank strings +# setup paths +PATH_SEP = {'/': ':', '\\': ';'}[os.path.sep] + +HIER_BLOCKS_LIB_DIR = os.environ.get('GRC_HIER_PATH', expanduser('~/.grc_gnuradio')) + +PREFS_FILE = os.environ.get('GRC_PREFS_PATH', expanduser('~/.gnuradio/grc.conf')) +PREFS_FILE_OLD = os.environ.get('GRC_PREFS_PATH', expanduser('~/.grc')) + +BLOCKS_DIRS = filter( # filter blank strings lambda x: x, PATH_SEP.join([ os.environ.get('GRC_BLOCKS_PATH', ''), _gr_prefs.get_string('grc', 'local_blocks_path', ''), @@ -37,14 +40,14 @@ BLOCKS_DIRS = filter( #filter blank strings ]).split(PATH_SEP), ) + [HIER_BLOCKS_LIB_DIR] -#user settings +# user settings XTERM_EXECUTABLE = _gr_prefs.get_string('grc', 'xterm_executable', 'xterm') -#file creation modes +# file creation modes TOP_BLOCK_FILE_MODE = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH HIER_BLOCK_FILE_MODE = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IROTH -#data files +# data files DATA_DIR = os.path.dirname(__file__) FLOW_GRAPH_TEMPLATE = os.path.join(DATA_DIR, 'flow_graph.tmpl') BLOCK_DTD = os.path.join(DATA_DIR, 'block.dtd') @@ -74,7 +77,7 @@ GRC_COLOR_GREY = '#BDBDBD' GRC_COLOR_WHITE = '#FFFFFF' -CORE_TYPES = ( #name, key, sizeof, color +CORE_TYPES = ( # name, key, sizeof, color ('Complex Float 64', 'fc64', 16, GRC_COLOR_BROWN), ('Complex Float 32', 'fc32', 8, GRC_COLOR_BLUE), ('Complex Integer 64', 'sc64', 16, GRC_COLOR_LIGHT_GREEN), diff --git a/grc/python/Generator.py b/grc/python/Generator.py index f807b59ad1..98fbd0c360 100644 --- a/grc/python/Generator.py +++ b/grc/python/Generator.py @@ -140,6 +140,7 @@ class TopBlockGenerator(object): if self._generate_options == 'no_gui' and xterm_executable: cmds = [xterm_executable, '-e', args_to_string(cmds)] + Messages.send_start_exec(args_to_string(cmds)) p = subprocess.Popen( args=cmds, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False, universal_newlines=True) diff --git a/grc/python/Platform.py b/grc/python/Platform.py index feea81dae1..1497099f3f 100644 --- a/grc/python/Platform.py +++ b/grc/python/Platform.py @@ -18,7 +18,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA """ import os +import sys + from gnuradio import gr + from .. base.Platform import Platform as _Platform from .. gui.Platform import Platform as _GUIPlatform from FlowGraph import FlowGraph as _FlowGraph @@ -27,21 +30,26 @@ from Block import Block as _Block from Port import Port as _Port from Param import Param as _Param from Generator import Generator -from Constants import \ - HIER_BLOCKS_LIB_DIR, BLOCK_DTD, \ - DEFAULT_FLOW_GRAPH, BLOCKS_DIRS, PREFS_FILE -import Constants +from Constants import ( + HIER_BLOCKS_LIB_DIR, BLOCK_DTD, DEFAULT_FLOW_GRAPH, BLOCKS_DIRS, + PREFS_FILE, PREFS_FILE_OLD, CORE_TYPES +) + + +COLORS = [(name, color) for name, key, sizeof, color in CORE_TYPES] -COLORS = [(name, color) for name, key, sizeof, color in Constants.CORE_TYPES] class Platform(_Platform, _GUIPlatform): def __init__(self): """ Make a platform for gnuradio. """ - #ensure hier dir - if not os.path.exists(HIER_BLOCKS_LIB_DIR): os.mkdir(HIER_BLOCKS_LIB_DIR) - #init + # ensure hier and conf directories + if not os.path.exists(HIER_BLOCKS_LIB_DIR): + os.mkdir(HIER_BLOCKS_LIB_DIR) + if not os.path.exists(os.path.dirname(PREFS_FILE)): + os.mkdir(os.path.dirname(PREFS_FILE)) + # init _Platform.__init__( self, name='GNU Radio Companion', @@ -55,12 +63,23 @@ class Platform(_Platform, _GUIPlatform): generator=Generator, colors=COLORS, ) - + self._move_old_pref_file() _GUIPlatform.__init__( self, prefs_file=PREFS_FILE ) + @staticmethod + def _move_old_pref_file(): + if PREFS_FILE == PREFS_FILE_OLD: + return # prefs file overridden with env var + if os.path.exists(PREFS_FILE_OLD) and not os.path.exists(PREFS_FILE): + try: + import shutil + shutil.move(PREFS_FILE_OLD, PREFS_FILE) + except Exception as e: + print >> sys.stderr, e + ############################################## # Constructors ############################################## |