summaryrefslogtreecommitdiff
path: root/grc
diff options
context:
space:
mode:
authorSebastian Koslowski <koslowski@kit.edu>2015-06-21 22:51:01 +0200
committerSebastian Koslowski <koslowski@kit.edu>2015-07-17 15:47:50 +0200
commitb05c650a8c2645a0354f9176f8112cd6a67e0996 (patch)
tree0c7aa9b1a41386f69ead0d15456aecf3bc7e0328 /grc
parent11752ea4f6868594b511fceac05d5677670e2f1c (diff)
grc: add user settings for canvas default size and canvas font size (+ clean-ups)
Diffstat (limited to 'grc')
-rw-r--r--grc/blocks/options.xml10
-rw-r--r--grc/grc.conf.in2
-rw-r--r--grc/gui/ActionHandler.py4
-rw-r--r--grc/gui/Constants.py74
-rw-r--r--grc/gui/Platform.py2
-rw-r--r--grc/gui/Port.py20
-rw-r--r--grc/python/FlowGraph.py1
7 files changed, 68 insertions, 45 deletions
diff --git a/grc/blocks/options.xml b/grc/blocks/options.xml
index 6588dc72d0..9ec94949a3 100644
--- a/grc/blocks/options.xml
+++ b/grc/blocks/options.xml
@@ -49,9 +49,9 @@ else: self.stop(); self.wait()</callback>
<hide>#if $description() then 'none' else 'part'#</hide>
</param>
<param>
- <name>Window Size</name>
+ <name>Canvas Size</name>
<key>window_size</key>
- <value>1280, 1024</value>
+ <value></value>
<type>int_vector</type>
<hide>part</hide>
</param>
@@ -174,9 +174,9 @@ part#slurp
</option>
<tab>Advanced</tab>
</param>
- <check>len($window_size) == 2</check>
- <check>300 &lt;= $(window_size)[0] &lt;= 4096</check>
- <check>300 &lt;= $(window_size)[1] &lt;= 4096</check>
+ <check>not $window_size or len($window_size) == 2</check>
+ <check>not $window_size or 300 &lt;= $(window_size)[0] &lt;= 4096</check>
+ <check>not $window_size or 300 &lt;= $(window_size)[1] &lt;= 4096</check>
<doc>
The options block sets special parameters for the flow graph. \
Only one option block is allowed per flow graph.
diff --git a/grc/grc.conf.in b/grc/grc.conf.in
index 99ae9caff5..71c4f63bca 100644
--- a/grc/grc.conf.in
+++ b/grc/grc.conf.in
@@ -6,3 +6,5 @@
global_blocks_path = @blocksdir@
local_blocks_path =
xterm_executable = @GRC_XTERM_EXE@
+canvas_font_size = 8
+canvas_default_size = 1280, 1024
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index 584b4120e6..5dbfea024b 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -35,6 +35,7 @@ from PropsDialog import PropsDialog
from ParserErrorsDialog import ParserErrorsDialog
import Dialogs
from FileDialogs import OpenFlowGraphFileDialog, SaveFlowGraphFileDialog, SaveReportsFileDialog, SaveImageFileDialog
+from . Constants import DEFAULT_CANVAS_SIZE
gobject.threads_init()
@@ -598,7 +599,8 @@ class ActionHandler:
Actions.FLOW_GRAPH_SAVE.set_sensitive(not self.get_page().get_saved())
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')
+ new_size = (self.get_flow_graph().get_option('window_size') or
+ 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/Constants.py b/grc/gui/Constants.py
index 0dc6279fd2..a8395f631e 100644
--- a/grc/gui/Constants.py
+++ b/grc/gui/Constants.py
@@ -18,78 +18,104 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
"""
import pygtk
+
pygtk.require('2.0')
import gtk
import os
+import sys
+from gnuradio import gr
+
+_gr_prefs = gr.prefs()
+
-##default path for the open/save dialogs
+# default path for the open/save dialogs
DEFAULT_FILE_PATH = os.getcwd()
-##file extensions
+# file extensions
IMAGE_FILE_EXTENSION = '.png'
TEXT_FILE_EXTENSION = '.txt'
-##name for new/unsaved flow graphs
+# name for new/unsaved flow graphs
NEW_FLOGRAPH_TITLE = 'untitled'
-##main window constraints
+# main window constraints
MIN_WINDOW_WIDTH = 600
MIN_WINDOW_HEIGHT = 400
-##dialog constraints
+# dialog constraints
MIN_DIALOG_WIDTH = 500
MIN_DIALOG_HEIGHT = 500
-##default sizes
+# default sizes
DEFAULT_BLOCKS_WINDOW_WIDTH = 100
DEFAULT_REPORTS_WINDOW_WIDTH = 100
-## flow-graph canvas fonts
+
+try: # ugly, but matches current code style
+ raw = _gr_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 = _gr_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"
-FONT_SIZE = 8
BLOCK_FONT = "%s %f" % (FONT_FAMILY, FONT_SIZE)
PORT_FONT = BLOCK_FONT
PARAM_FONT = "%s %f" % (FONT_FAMILY, FONT_SIZE - 0.5)
-##The size of the state saving cache in the flow graph (for undo/redo functionality)
+# size of the state saving cache in the flow graph (undo/redo functionality)
STATE_CACHE_SIZE = 42
-##Shared targets for drag and drop of blocks
+# Shared targets for drag and drop of blocks
DND_TARGETS = [('STRING', gtk.TARGET_SAME_APP, 0)]
-#label constraint dimensions
+# label constraint dimensions
LABEL_SEPARATION = 3
BLOCK_LABEL_PADDING = 7
PORT_LABEL_PADDING = 2
-#port constraint dimensions
-PORT_SEPARATION = 32
-PORT_BORDER_SEPARATION = 9
+# canvas grid size
+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_MIN_WIDTH = 20
PORT_LABEL_HIDDEN_WIDTH = 10
-#minimal length of connector
+# minimal length of connector
CONNECTOR_EXTENSION_MINIMAL = 11
-#increment length for connector
+# increment length for connector
CONNECTOR_EXTENSION_INCREMENT = 11
-#connection arrow dimensions
+# connection arrow dimensions
CONNECTOR_ARROW_BASE = 13
CONNECTOR_ARROW_HEIGHT = 17
-#possible rotations in degrees
+# possible rotations in degrees
POSSIBLE_ROTATIONS = (0, 90, 180, 270)
-#How close can the mouse get to the window border before mouse events are ignored.
+# How close can the mouse get to the window border before mouse events are ignored.
BORDER_PROXIMITY_SENSITIVITY = 50
-#How close the mouse can get to the edge of the visible window before scrolling is invoked.
+# How close the mouse can get to the edge of the visible window before scrolling is invoked.
SCROLL_PROXIMITY_SENSITIVITY = 30
-#When the window has to be scrolled, move it this distance in the required direction.
+# When the window has to be scrolled, move it this distance in the required direction.
SCROLL_DISTANCE = 15
-#How close the mouse click can be to a line and register a connection select.
+# How close the mouse click can be to a line and register a connection select.
LINE_SELECT_SENSITIVITY = 5
-# canvas grid size
-CANVAS_GRID_SIZE = 8
diff --git a/grc/gui/Platform.py b/grc/gui/Platform.py
index db77ff2112..eda28a0e94 100644
--- a/grc/gui/Platform.py
+++ b/grc/gui/Platform.py
@@ -25,4 +25,4 @@ class Platform(Element):
self._prefs_file = prefs_file
- def get_prefs_file(self): return self._prefs_file \ No newline at end of file
+ def get_prefs_file(self): return self._prefs_file
diff --git a/grc/gui/Port.py b/grc/gui/Port.py
index 9abda878bf..5310c1f73b 100644
--- a/grc/gui/Port.py
+++ b/grc/gui/Port.py
@@ -104,31 +104,25 @@ class Port(Element):
#the connector length
self._connector_length = CONNECTOR_EXTENSION_MINIMAL + CONNECTOR_EXTENSION_INCREMENT*index
- def modify_height(self, start_height):
- type_dict = {'bus':(lambda a: a * 3)};
-
- if self.get_type() in type_dict:
- return type_dict[self.get_type()](start_height);
- else:
- return start_height;
-
def create_labels(self):
"""Create the labels for the socket."""
Element.create_labels(self)
self._bg_color = Colors.get_color(self.get_color())
- #create the layout
+ # create the layout
layout = gtk.DrawingArea().create_pango_layout('')
layout.set_markup(Utils.parse_template(PORT_MARKUP_TMPL, port=self, font=PORT_FONT))
self.w, self.h = layout.get_pixel_size()
- self.W, self.H = 2*PORT_LABEL_PADDING + self.w, 2*PORT_LABEL_PADDING+self.h
- self.H = self.modify_height(self.H)
- #create the pixmap
+ self.W = 2 * PORT_LABEL_PADDING + self.w
+ self.H = 2 * PORT_LABEL_PADDING + self.h * (
+ 3 if self.get_type() == 'bus' else 1)
+ self.H += self.H % 2
+ # create the pixmap
pixmap = self.get_parent().get_parent().new_pixmap(self.w, self.h)
gc = pixmap.new_gc()
gc.set_foreground(self._bg_color)
pixmap.draw_rectangle(gc, True, 0, 0, self.w, self.h)
pixmap.draw_layout(gc, 0, 0, layout)
- #create vertical and horizontal pixmaps
+ # create vertical and horizontal pixmaps
self.horizontal_label = pixmap
if self.is_vertical():
self.vertical_label = self.get_parent().get_parent().new_pixmap(self.h, self.w)
diff --git a/grc/python/FlowGraph.py b/grc/python/FlowGraph.py
index d7337b8a96..49530af8a3 100644
--- a/grc/python/FlowGraph.py
+++ b/grc/python/FlowGraph.py
@@ -20,7 +20,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
import expr_utils
from .. base.FlowGraph import FlowGraph as _FlowGraph
from .. gui.FlowGraph import FlowGraph as _GUIFlowGraph
-from .. base.odict import odict
import re
_variable_matcher = re.compile('^(variable\w*)$')