[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 05/13: grc: add user settings for canvas de
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 05/13: grc: add user settings for canvas default size and canvas font size (+ clean-ups) |
Date: |
Fri, 24 Jul 2015 15:33:49 +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 b05c650a8c2645a0354f9176f8112cd6a67e0996
Author: Sebastian Koslowski <address@hidden>
Date: Sun Jun 21 22:51:01 2015 +0200
grc: add user settings for canvas default size and canvas font size (+
clean-ups)
---
grc/blocks/options.xml | 10 +++----
grc/grc.conf.in | 2 ++
grc/gui/ActionHandler.py | 4 ++-
grc/gui/Constants.py | 74 ++++++++++++++++++++++++++++++++----------------
grc/gui/Platform.py | 2 +-
grc/gui/Port.py | 20 +++++--------
grc/python/FlowGraph.py | 1 -
7 files changed, 68 insertions(+), 45 deletions(-)
diff --git a/grc/blocks/options.xml b/grc/blocks/options.xml
index 6588dc7..9ec9494 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 <= $(window_size)[0] <= 4096</check>
- <check>300 <= $(window_size)[1] <= 4096</check>
+ <check>not $window_size or len($window_size) == 2</check>
+ <check>not $window_size or 300 <= $(window_size)[0] <=
4096</check>
+ <check>not $window_size or 300 <= $(window_size)[1] <=
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 99ae9ca..71c4f63 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 584b412..5dbfea0 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 0dc6279..a8395f6 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 db77ff2..eda28a0 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 9abda87..5310c1f 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 d7337b8..49530af 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*)$')
- [Commit-gnuradio] [gnuradio] branch master updated (cc973de -> 65d6523), git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 12/13: Merge branch 'maint', git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 13/13: Merge remote-tracking branch 'gnuradio-wg-grc/master_grcwg', git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 06/13: grc: align default flowgraph block with canvas grid, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 11/13: grc: clean-up Block port counters, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 02/13: grc: show preview of generated code in each blocks properties dialog, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 07/13: grc: fix bus ports spacing in gui, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 03/13: grc: add default value to ToggleActions, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 04/13: grc: only show code preview tab after user enables it, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 01/13: grc: refactor Preferences.py, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 05/13: grc: add user settings for canvas default size and canvas font size (+ clean-ups),
git <=
- [Commit-gnuradio] [gnuradio] 08/13: grc: add QT GUI hier blocks (#727), git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 09/13: grc: add support for dynamic param names, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 10/13: grc: add struct variable block, git, 2015/07/24