[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 16/23: grc: Added option to use the default
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 16/23: grc: Added option to use the default editor when opening embedded python blocks |
Date: |
Sat, 28 Nov 2015 21:18:08 +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 ba57cd0c5e7352c81e5025760d7aaecde92d083b
Author: Seth Hitefield <address@hidden>
Date: Fri Nov 13 18:51:04 2015 -0500
grc: Added option to use the default editor when opening embedded python
blocks
---
grc/gui/Dialogs.py | 80 ++++++++++++++++++++++++++++++++++++----------
grc/gui/FlowGraph.py | 18 +++++++++--
grc/gui/Param.py | 2 --
grc/gui/external_editor.py | 20 +++++-------
4 files changed, 88 insertions(+), 32 deletions(-)
diff --git a/grc/gui/Dialogs.py b/grc/gui/Dialogs.py
index 631dc0f..f294125 100644
--- a/grc/gui/Dialogs.py
+++ b/grc/gui/Dialogs.py
@@ -21,7 +21,11 @@ import pygtk
pygtk.require('2.0')
import gtk
-from . import Utils, Actions, Constants
+import sys
+from distutils.spawn import find_executable
+
+
+from . import Utils, Actions, Constants, Messages
class SimpleTextDisplay(gtk.TextView):
@@ -237,19 +241,63 @@ def MissingXTermDialog(xterm):
def ChooseEditorDialog():
- file_dialog = gtk.FileChooserDialog(
- 'Open a Data File...', None,
- gtk.FILE_CHOOSER_ACTION_OPEN,
- ('gtk-cancel', gtk.RESPONSE_CANCEL, 'gtk-open', gtk.RESPONSE_OK)
+ # Give the option to either choose an editor or use the default
+ # Always return true/false so the caller knows it was successful
+ buttons = (
+ 'Choose Editor', gtk.RESPONSE_YES,
+ 'Use Default', gtk.RESPONSE_NO,
+ gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL
)
- file_dialog.set_select_multiple(False)
- file_dialog.set_local_only(True)
- file_dialog.set_current_folder('/usr/bin')
- response = file_dialog.run()
-
- if response == gtk.RESPONSE_OK:
- file_path = file_dialog.get_filename()
- Constants.prefs.set_string('grc', 'editor', file_path)
- Constants.prefs.save()
- Constants.EDITOR = file_path
- file_dialog.destroy()
+ response = MessageDialogHelper(
+ gtk.MESSAGE_QUESTION, gtk.BUTTONS_NONE, 'Choose Editor',
+ 'Would you like to choose the editor to use?', gtk.RESPONSE_YES,
buttons
+ )
+
+ # Handle the inital default/choose/cancel response
+ # User wants to choose the editor to use
+ if response == gtk.RESPONSE_YES:
+ file_dialog = gtk.FileChooserDialog(
+ 'Select an Editor...', None,
+ gtk.FILE_CHOOSER_ACTION_OPEN,
+ ('gtk-cancel', gtk.RESPONSE_CANCEL, 'gtk-open', gtk.RESPONSE_OK)
+ )
+ file_dialog.set_select_multiple(False)
+ file_dialog.set_local_only(True)
+ 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
+ file_dialog.destroy()
+ return file_path
+ finally:
+ file_dialog.destroy()
+
+ # Go with the default editor
+ elif response == gtk.RESPONSE_NO:
+ # Determine the platform
+ try:
+ process = None
+ if sys.platform.startswith('linux'):
+ process = find_executable('xdg-open')
+ elif sys.platform.startswith('darwin'):
+ process = find_executable('open')
+ 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
+ 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 = ""
+ return
+
+ Messages.send('>>> No editor selected.\n')
+ return
diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py
index b27f015..6d712e5 100644
--- a/grc/gui/FlowGraph.py
+++ b/grc/gui/FlowGraph.py
@@ -21,10 +21,11 @@ import random
import functools
from itertools import chain
from operator import methodcaller
+from distutils.spawn import find_executable
import gobject
-from . import Actions, Colors, Utils, Messages, Bars
+from . import Actions, Colors, Constants, Utils, Messages, Bars, Dialogs
from . Element import Element
from . Constants import SCROLL_PROXIMITY_SENSITIVITY, SCROLL_DISTANCE
from . external_editor import ExternalEditor
@@ -67,14 +68,27 @@ class FlowGraph(Element):
if target in self._external_updaters:
editor = self._external_updaters[target]
else:
+ editor = (find_executable(Constants.EDITOR) or
+ Dialogs.ChooseEditorDialog())
+ if not editor:
+ return
updater = functools.partial(
self.handle_external_editor_change, target=target)
editor = self._external_updaters[target] = ExternalEditor(
+ editor=editor,
name=target[0], value=param.get_value(),
callback=functools.partial(gobject.idle_add, updater)
)
editor.start()
- editor.open_editor()
+ try:
+ editor.open_editor()
+ except Exception as e:
+ # 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 = ""
def handle_external_editor_change(self, new_value, target):
try:
diff --git a/grc/gui/Param.py b/grc/gui/Param.py
index 5f83689..515c345 100644
--- a/grc/gui/Param.py
+++ b/grc/gui/Param.py
@@ -221,8 +221,6 @@ class PythonEditorParam(InputParam):
self.pack_start(button, True)
def open_editor(self, widget=None):
- if not os.path.exists(Constants.EDITOR):
- Dialogs.ChooseEditorDialog()
flowgraph = self.param.get_parent().get_parent()
flowgraph.install_external_editor(self.param)
diff --git a/grc/gui/external_editor.py b/grc/gui/external_editor.py
index 3322556..76f2141 100644
--- a/grc/gui/external_editor.py
+++ b/grc/gui/external_editor.py
@@ -24,16 +24,15 @@ import threading
import tempfile
import subprocess
-import Constants
-
class ExternalEditor(threading.Thread):
- def __init__(self, name, value, callback):
+ def __init__(self, editor, name, value, callback):
threading.Thread.__init__(self)
self.daemon = True
self._stop_event = threading.Event()
+ self.editor = editor
self.callback = callback
self.tempfile = self._create_tempfile(name, value)
@@ -49,9 +48,7 @@ class ExternalEditor(threading.Thread):
return self.tempfile.name
def open_editor(self):
- proc = subprocess.Popen(
- args=(Constants.EDITOR, self.filename)
- )
+ proc = subprocess.Popen(args=(self.editor, self.filename))
proc.poll()
return proc
@@ -84,10 +81,9 @@ if __name__ == '__main__':
def p(data):
print data
- Constants.EDITOR = '/usr/bin/gedit'
- editor = ExternalEditor("test", "content", p)
- editor.open_editor()
- editor.start()
+ e = ExternalEditor('/usr/bin/gedit', "test", "content", p)
+ e.open_editor()
+ e.start()
time.sleep(15)
- editor.stop()
- editor.join()
+ e.stop()
+ e.join()
- [Commit-gnuradio] [gnuradio] 03/23: grc: finish doc_string extraction in the background (faster start-up), (continued)
- [Commit-gnuradio] [gnuradio] 03/23: grc: finish doc_string extraction in the background (faster start-up), git, 2015/11/28
- [Commit-gnuradio] [gnuradio] 18/23: Merge branch 'maint', git, 2015/11/28
- [Commit-gnuradio] [gnuradio] 11/23: gr-dtv: Fix Coverity issue #1327838., git, 2015/11/28
- [Commit-gnuradio] [gnuradio] 10/23: gr-dtv: Fix Coverity issue #1327858., git, 2015/11/28
- [Commit-gnuradio] [gnuradio] 20/23: Merge remote-tracking branch 'jdemel/maint', git, 2015/11/28
- [Commit-gnuradio] [gnuradio] 14/23: digital: clarify gmsk doc, git, 2015/11/28
- [Commit-gnuradio] [gnuradio] 15/23: grc: fix Action to str method, git, 2015/11/28
- [Commit-gnuradio] [gnuradio] 22/23: Merge remote-tracking branch 'gnuradio-wg-grc/master_grcwg', git, 2015/11/28
- [Commit-gnuradio] [gnuradio] 02/23: grc: move docstring extraction into subprocess, git, 2015/11/28
- [Commit-gnuradio] [gnuradio] 17/23: grc: preserve block spacing when dragging multiple blocks into canvas boundary, git, 2015/11/28
- [Commit-gnuradio] [gnuradio] 16/23: grc: Added option to use the default editor when opening embedded python blocks,
git <=
- [Commit-gnuradio] [gnuradio] 19/23: Merge remote-tracking branch 'drmpeg/dtv-coverity-clean', git, 2015/11/28
- [Commit-gnuradio] [gnuradio] 12/23: grc: added recently opened flowgraph submenu and toolbar button dropdown menu, git, 2015/11/28
- [Commit-gnuradio] [gnuradio] 06/23: grc: auto-generate missing hier_blocks, git, 2015/11/28
- [Commit-gnuradio] [gnuradio] 08/23: gr-dtv: Fix Coverity issue #1327535., git, 2015/11/28
- [Commit-gnuradio] [gnuradio] 09/23: gr-dtv: Fix Coverity issue #1327847., git, 2015/11/28
- [Commit-gnuradio] [gnuradio] 13/23: ctrlport: pc_throughput_avg registered, git, 2015/11/28
- [Commit-gnuradio] [gnuradio] 23/23: Merge branch 'maint', git, 2015/11/28
- [Commit-gnuradio] [gnuradio] 05/23: grc: refactoring Messages.py, git, 2015/11/28