summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohnathan Corgan <johnathan@corganlabs.com>2014-10-01 12:27:08 -0700
committerJohnathan Corgan <johnathan@corganlabs.com>2014-10-01 12:27:08 -0700
commita166f439d9c33165ccc0a3fee3d63cdef2040d5a (patch)
tree3df6ba5cd6b5fb8ab28e065e20256ea022d1d219
parent029079cf5cee92c64755318b4fe5d46d45b61b7a (diff)
parent1edeff17c0b11e9ab2c626a82472690318268a9a (diff)
Merge branch 'maint'
-rw-r--r--grc/base/ParseXML.py2
-rw-r--r--grc/base/Port.py15
-rw-r--r--grc/gui/ActionHandler.py8
-rw-r--r--grc/gui/Block.py3
-rw-r--r--grc/gui/BlockTreeWindow.py11
-rw-r--r--grc/gui/MainWindow.py12
-rw-r--r--grc/gui/Port.py24
-rw-r--r--grc/python/Generator.py6
8 files changed, 50 insertions, 31 deletions
diff --git a/grc/base/ParseXML.py b/grc/base/ParseXML.py
index 888272a2e1..a2cede1c86 100644
--- a/grc/base/ParseXML.py
+++ b/grc/base/ParseXML.py
@@ -121,7 +121,7 @@ def to_file(nested_data, xml_file):
instructions = nested_data.pop('_instructions', None)
if instructions:
xml_data += etree.tostring(etree.ProcessingInstruction(
- 'grc', ' '.join("{}='{}'".format(*item) for item in instructions.iteritems())
+ 'grc', ' '.join("{0}='{1}'".format(*item) for item in instructions.iteritems())
), xml_declaration=True, pretty_print=True)
xml_data += etree.tostring(_to_file(nested_data)[0], pretty_print=True)
open(xml_file, 'w').write(xml_data)
diff --git a/grc/base/Port.py b/grc/base/Port.py
index 34766bb4f8..761369d4f8 100644
--- a/grc/base/Port.py
+++ b/grc/base/Port.py
@@ -38,6 +38,8 @@ class Port(Element):
self._type = n['type']
self._hide = n.find('hide') or ''
self._dir = dir
+ self._type_evaluated = '' # updated on rewrite()
+ self._hide_evaluated = False # updated on rewrite()
def validate(self):
"""
@@ -48,6 +50,13 @@ class Port(Element):
if self.get_type() not in self.get_types():
self.add_error_message('Type "%s" is not a possible type.'%self.get_type())
+ def rewrite(self):
+ """resolve dependencies in for type and hide"""
+ Element.rewrite(self)
+ self._type_evaluated = self.get_parent().resolve_dependencies(self._type)
+ hide = self.get_parent().resolve_dependencies(self._hide).strip().lower()
+ self._hide_evaluated = False if hide in ('false', 'off', '0') else bool(hide)
+
def __str__(self):
if self.is_source():
return 'Source - %s(%s)'%(self.get_name(), self.get_key())
@@ -73,10 +82,8 @@ class Port(Element):
def get_key(self): return self._key
def is_sink(self): return self._dir == 'sink'
def is_source(self): return self._dir == 'source'
- def get_type(self): return self.get_parent().resolve_dependencies(self._type)
- def get_hide(self):
- value = self.get_parent().resolve_dependencies(self._hide).strip().lower()
- return False if value in ('false', 'off', '0') else bool(value)
+ def get_type(self): return self._type_evaluated
+ def get_hide(self): return self._hide_evaluated
def get_connections(self):
"""
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index c06dc9671f..f8963fa472 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -86,7 +86,10 @@ class ActionHandler:
false to let gtk handle the key action
"""
# prevent key event stealing while the search box is active
- if self.main_window.btwin.search_entry.has_focus(): return False
+ # .has_focus() only in newer versions 2.17+?
+ # .is_focus() seems to work, but exactly the same
+ if self.main_window.btwin.search_entry.flags() & gtk.HAS_FOCUS:
+ return False
if not self.get_focus_flag(): return False
return Actions.handle_key_press(event)
@@ -394,7 +397,8 @@ class ActionHandler:
Actions.NOTHING_SELECT()
elif action == Actions.TOGGLE_AUTO_HIDE_PORT_LABELS:
action.save_to_preferences()
- self.main_window.get_flow_graph().create_shapes()
+ for page in self.main_window.get_pages():
+ page.get_flow_graph().create_shapes()
elif action == Actions.TOGGLE_SNAP_TO_GRID:
action.save_to_preferences()
##################################################
diff --git a/grc/gui/Block.py b/grc/gui/Block.py
index 0ae624f94f..1a32f6c2ba 100644
--- a/grc/gui/Block.py
+++ b/grc/gui/Block.py
@@ -224,8 +224,7 @@ class Block(Element):
window.draw_drawable(gc, self.vertical_label, 0, 0, x+(self.H-self.label_height)/2, y+BLOCK_LABEL_PADDING, -1, -1)
#draw ports
for port in self.get_ports_gui():
- if not port.get_hide():
- port.draw(gc, window)
+ port.draw(gc, window)
def what_is_selected(self, coor, coor_m=None):
"""
diff --git a/grc/gui/BlockTreeWindow.py b/grc/gui/BlockTreeWindow.py
index b04a4dda7c..76eebdb959 100644
--- a/grc/gui/BlockTreeWindow.py
+++ b/grc/gui/BlockTreeWindow.py
@@ -58,10 +58,13 @@ class BlockTreeWindow(gtk.VBox):
# search entry
self.search_entry = gtk.Entry()
- self.search_entry.set_icon_from_stock(gtk.ENTRY_ICON_PRIMARY, gtk.STOCK_FIND)
- self.search_entry.set_icon_activatable(gtk.ENTRY_ICON_PRIMARY, False)
- self.search_entry.set_icon_from_stock(gtk.ENTRY_ICON_SECONDARY, gtk.STOCK_CLOSE)
- self.search_entry.connect('icon-release', self._handle_icon_event)
+ try:
+ self.search_entry.set_icon_from_stock(gtk.ENTRY_ICON_PRIMARY, gtk.STOCK_FIND)
+ self.search_entry.set_icon_activatable(gtk.ENTRY_ICON_PRIMARY, False)
+ self.search_entry.set_icon_from_stock(gtk.ENTRY_ICON_SECONDARY, gtk.STOCK_CLOSE)
+ self.search_entry.connect('icon-release', self._handle_icon_event)
+ except AttributeError:
+ pass # no icon for old pygtk
self.search_entry.connect('changed', self._update_search_tree)
self.search_entry.connect('key-press-event', self._handle_search_key_press)
self.pack_start(self.search_entry, False)
diff --git a/grc/gui/MainWindow.py b/grc/gui/MainWindow.py
index 75d9dce433..d1cf866ce7 100644
--- a/grc/gui/MainWindow.py
+++ b/grc/gui/MainWindow.py
@@ -209,7 +209,7 @@ class MainWindow(gtk.Window):
open_files = filter(lambda file: file, self._get_files()) #filter blank files
open_file = self.get_page().get_file_path()
#close each page
- for page in self._get_pages():
+ for page in self.get_pages():
self.page_to_be_closed = page
self.close_page(False)
if self.notebook.get_n_pages(): return False
@@ -271,7 +271,7 @@ class MainWindow(gtk.Window):
)
)
#set tab titles
- for page in self._get_pages(): page.set_markup(
+ for page in self.get_pages(): page.set_markup(
Utils.parse_template(PAGE_TITLE_MARKUP_TMPL,
#get filename and strip out file extension
title=os.path.splitext(os.path.basename(page.get_file_path()))[0],
@@ -280,13 +280,13 @@ class MainWindow(gtk.Window):
)
)
#show/hide notebook tabs
- self.notebook.set_show_tabs(len(self._get_pages()) > 1)
+ self.notebook.set_show_tabs(len(self.get_pages()) > 1)
def update_pages(self):
"""
Forces a reload of all the pages in this notebook.
"""
- for page in self._get_pages():
+ for page in self.get_pages():
success = page.get_flow_graph().reload()
if success: # Only set saved if errors occurred during import
page.set_saved(False)
@@ -351,9 +351,9 @@ class MainWindow(gtk.Window):
Returns:
list of file paths
"""
- return map(lambda page: page.get_file_path(), self._get_pages())
+ return map(lambda page: page.get_file_path(), self.get_pages())
- def _get_pages(self):
+ def get_pages(self):
"""
Get a list of all pages in the notebook.
diff --git a/grc/gui/Port.py b/grc/gui/Port.py
index 188281a95e..364ca6a5b9 100644
--- a/grc/gui/Port.py
+++ b/grc/gui/Port.py
@@ -45,7 +45,7 @@ class Port(Element):
"""
Element.__init__(self)
self.W = self.H = self.w = self.h = 0
- self._connector_coordinate = (0,0)
+ self._connector_coordinate = (0, 0)
self._connector_length = 0
self._hovering = True
self._force_label_unhidden = False
@@ -53,11 +53,15 @@ class Port(Element):
def create_shapes(self):
"""Create new areas and labels for the port."""
Element.create_shapes(self)
+ if self.get_hide():
+ return # this port is hidden, no need to create shapes
#get current rotation
rotation = self.get_rotation()
#get all sibling ports
- if self.is_source(): ports = self.get_parent().get_sources_gui()
- elif self.is_sink(): ports = self.get_parent().get_sinks_gui()
+ if self.is_source():
+ ports = self.get_parent().get_sources_gui()
+ elif self.is_sink():
+ ports = self.get_parent().get_sinks_gui()
#get the max width
self.W = max([port.W for port in ports] + [PORT_MIN_WIDTH])
W = self.W if not self._label_hidden() else PORT_LABEL_HIDDEN_WIDTH
@@ -70,7 +74,8 @@ class Port(Element):
return
length = len(filter(lambda p: not p.get_hide(), ports))
#reverse the order of ports for these rotations
- if rotation in (180, 270): index = length-index-1
+ if rotation in (180, 270):
+ index = length-index-1
offset = (self.get_parent().H - (length-1)*PORT_SEPARATION - self.H)/2
#create areas and connector coordinates
if (self.is_sink() and rotation == 0) or (self.is_source() and rotation == 180):
@@ -137,12 +142,13 @@ class Port(Element):
Element.draw(
self, gc, window, bg_color=self._bg_color,
border_color=self.is_highlighted() and Colors.HIGHLIGHT_COLOR or
- self.get_parent().is_dummy_block() and Colors.MISSING_BLOCK_BORDER_COLOR or Colors.BORDER_COLOR,
+ self.get_parent().is_dummy_block() and Colors.MISSING_BLOCK_BORDER_COLOR or
+ Colors.BORDER_COLOR,
)
- if self._label_hidden():
- return
- X,Y = self.get_coordinate()
- (x,y),(w,h) = self._areas_list[0] #use the first area's sizes to place the labels
+ if not self._areas_list or self._label_hidden():
+ return # this port is either hidden (no areas) or folded (no label)
+ X, Y = self.get_coordinate()
+ (x, y), (w, h) = self._areas_list[0] # use the first area's sizes to place the labels
if self.is_horizontal():
window.draw_drawable(gc, self.horizontal_label, 0, 0, x+X+(self.W-self.w)/2, y+Y+(self.H-self.h)/2, -1, -1)
elif self.is_vertical():
diff --git a/grc/python/Generator.py b/grc/python/Generator.py
index 92f36cf30b..caf45fa3b1 100644
--- a/grc/python/Generator.py
+++ b/grc/python/Generator.py
@@ -93,10 +93,10 @@ This is usually undesired. Consider removing the throttle block.''')
# python_exe = 'pythonw'
#setup the command args to run
- cmds = [python_exe, '-u', self.get_file_path()] #-u is unbuffered stdio
+ cmds = [python_exe, '-u', self.get_file_path()] # -u is unbuffered stdio
- #when in no gui mode on linux, use an xterm (looks nice)
- if self._generate_options == 'no_gui' and 'linux' in sys.platform.lower():
+ # when in no gui mode on linux, use a graphical terminal (looks nice)
+ if self._generate_options == 'no_gui' and os.path.exists(XTERM_EXECUTABLE):
cmds = [XTERM_EXECUTABLE, '-e'] + cmds
p = subprocess.Popen(args=cmds, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False, universal_newlines=True)