diff options
author | Sebastian Koslowski <koslowski@kit.edu> | 2016-11-17 21:20:55 +0100 |
---|---|---|
committer | Sebastian Koslowski <koslowski@kit.edu> | 2016-11-17 21:21:08 +0100 |
commit | 7f25c0120fc7bc6a6eeee87878cf387647d51614 (patch) | |
tree | ab510060a2c5625d00e7f19f4c7d699861b98cea /grc/gui | |
parent | e1acf2d27760d606cc7cba200aa380e885f2ffaf (diff) | |
parent | 1d50d70f0b990b909357a803881955623dea94d8 (diff) |
Merge remote-tracking branch 'upstream/next' into gtk3
Diffstat (limited to 'grc/gui')
-rw-r--r-- | grc/gui/Application.py | 3 | ||||
-rw-r--r-- | grc/gui/Constants.py | 10 | ||||
-rw-r--r-- | grc/gui/Dialogs.py | 2 | ||||
-rw-r--r-- | grc/gui/Executor.py | 35 | ||||
-rw-r--r-- | grc/gui/ParamWidgets.py | 4 | ||||
-rw-r--r-- | grc/gui/PropsDialog.py | 4 | ||||
-rw-r--r-- | grc/gui/Utils.py | 10 | ||||
-rw-r--r-- | grc/gui/VariableEditor.py | 10 | ||||
-rw-r--r-- | grc/gui/canvas/block.py | 3 |
9 files changed, 38 insertions, 43 deletions
diff --git a/grc/gui/Application.py b/grc/gui/Application.py index 5c643eafa1..e2290b3401 100644 --- a/grc/gui/Application.py +++ b/grc/gui/Application.py @@ -519,8 +519,9 @@ class Application(Gtk.Application): elif action == Actions.FLOW_GRAPH_NEW: main.new_page() if args: + flow_graph = main.get_flow_graph() flow_graph._options_block.get_param('generate_options').set_value(args[0]) - flow_graph_update() + flow_graph_update(flow_graph) elif action == Actions.FLOW_GRAPH_OPEN: file_paths = args if args else FileDialogs.OpenFlowGraph(main, page.file_path).run() if file_paths: # Open a new page for each file, show only the first diff --git a/grc/gui/Constants.py b/grc/gui/Constants.py index 0a555b37c9..01ea23ed3e 100644 --- a/grc/gui/Constants.py +++ b/grc/gui/Constants.py @@ -19,13 +19,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA from __future__ import absolute_import -from gi.repository import Gtk +from gi.repository import Gtk, Gdk from ..core.Constants import * # default path for the open/save dialogs -DEFAULT_FILE_PATH = os.getcwd() +DEFAULT_FILE_PATH = os.getcwd() if os.name != 'nt' else os.path.expanduser("~/Documents") FILE_EXTENSION = '.grc' # name for new/unsaved flow graphs @@ -101,6 +101,12 @@ Please consider contacting OOT module maintainer for any block in here \ and kindly ask to update their GRC Block Descriptions or Block Tree to include a module name.""" +# _SCREEN = Gdk.Screen.get_default() +# _SCREEN_RESOLUTION = _SCREEN.get_resolution() if _SCREEN else -1 +# DPI_SCALING = _SCREEN_RESOLUTION / 96.0 if _SCREEN_RESOLUTION > 0 else 1.0 +DPI_SCALING = 1.0 # todo: figure out the GTK3 way (maybe cairo does this for us + + def update_font_size(font_size): global PORT_SEPARATION, BLOCK_FONT, PORT_FONT, PARAM_FONT, FONT_SIZE diff --git a/grc/gui/Dialogs.py b/grc/gui/Dialogs.py index 0eb88952b7..09ecd48a13 100644 --- a/grc/gui/Dialogs.py +++ b/grc/gui/Dialogs.py @@ -90,7 +90,7 @@ class TextDisplay(SimpleTextDisplay): # for each \b delete one char from the buffer back_count = 0 start_iter = self.get_buffer().get_end_iter() - while line[back_count] == '\b': + while len(line) > back_count and line[back_count] == '\b': # stop at the beginning of a line if not start_iter.starts_line(): start_iter.backward_char() diff --git a/grc/gui/Executor.py b/grc/gui/Executor.py index 7168c9ef46..7c01d921bc 100644 --- a/grc/gui/Executor.py +++ b/grc/gui/Executor.py @@ -16,12 +16,11 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA from __future__ import absolute_import + import os -import threading import shlex import subprocess -import sys -import re +import threading from distutils.spawn import find_executable from gi.repository import GLib @@ -39,6 +38,7 @@ class ExecFlowGraphThread(threading.Thread): threading.Thread.__init__(self) self.page = flow_graph_page # store page and dont use main window calls in run + self.flow_graph = self.page.get_flow_graph() self.xterm_executable = xterm_executable self.update_callback = callback @@ -54,16 +54,9 @@ class ExecFlowGraphThread(threading.Thread): """ Execute this python flow graph. """ - run_command = self.page.flow_graph.get_option('run_command') generator = self.page.get_generator() - - try: - run_command = run_command.format( - python=shlex_quote(sys.executable), - filename=shlex_quote(generator.file_path)) - run_command_args = shlex.split(run_command) - except Exception as e: - raise ValueError("Can't parse run command {!r}: {}".format(run_command, e)) + run_command = self.flow_graph.get_run_command(generator.file_path) + run_command_args = shlex.split(run_command) # When in no gui mode on linux, use a graphical terminal (looks nice) xterm_executable = find_executable(self.xterm_executable) @@ -99,21 +92,3 @@ class ExecFlowGraphThread(threading.Thread): Messages.send_end_exec(self.process.returncode) self.page.process = None self.update_callback() - - -########################################################### -# back-port from python3 -########################################################### -_find_unsafe = re.compile(r'[^\w@%+=:,./-]').search - - -def shlex_quote(s): - """Return a shell-escaped version of the string *s*.""" - if not s: - return "''" - if _find_unsafe(s) is None: - return s - - # use single quotes, and put single quotes into double quotes - # the string $'b is then quoted as '$'"'"'b' - return "'" + s.replace("'", "'\"'\"'") + "'" diff --git a/grc/gui/ParamWidgets.py b/grc/gui/ParamWidgets.py index e5657c288e..b79a85623f 100644 --- a/grc/gui/ParamWidgets.py +++ b/grc/gui/ParamWidgets.py @@ -20,7 +20,7 @@ import os from gi.repository import Gtk, Gdk -from . import Colors +from . import Colors, Utils class InputParam(Gtk.HBox): @@ -35,7 +35,7 @@ class InputParam(Gtk.HBox): self._editing_callback = editing_callback self.label = Gtk.Label() - self.label.set_size_request(150, -1) + self.label.set_size_request(Utils.scale_scalar(150), -1) self.label.show() self.pack_start(self.label, False, False, 0) diff --git a/grc/gui/PropsDialog.py b/grc/gui/PropsDialog.py index 3a0f6ae6de..ca1e3c5296 100644 --- a/grc/gui/PropsDialog.py +++ b/grc/gui/PropsDialog.py @@ -51,7 +51,9 @@ class PropsDialog(Gtk.Dialog): Gtk.STOCK_APPLY, Gtk.ResponseType.APPLY, ) self.set_response_sensitive(Gtk.ResponseType.APPLY, False) - self.set_size_request(Constants.MIN_DIALOG_WIDTH, Constants.MIN_DIALOG_HEIGHT) + self.set_size_request(*Utils.scale( + (Constants.MIN_DIALOG_WIDTH, Constants.MIN_DIALOG_HEIGHT) + )) self._block = block self._hash = 0 diff --git a/grc/gui/Utils.py b/grc/gui/Utils.py index 782a7e3a01..38fde80465 100644 --- a/grc/gui/Utils.py +++ b/grc/gui/Utils.py @@ -143,3 +143,13 @@ def make_screenshot(flow_graph, file_path, transparent_bg=False): if file_path.endswith('.pdf') or file_path.endswith('.svg'): cr.show_page() psurf.finish() + + +def scale(coor, reverse=False): + factor = Constants.DPI_SCALING if not reverse else 1 / Constants.DPI_SCALING + return tuple(int(x * factor) for x in coor) + + +def scale_scalar(coor, reverse=False): + factor = Constants.DPI_SCALING if not reverse else 1 / Constants.DPI_SCALING + return int(coor * factor) diff --git a/grc/gui/VariableEditor.py b/grc/gui/VariableEditor.py index 44dd2923eb..484395be8c 100644 --- a/grc/gui/VariableEditor.py +++ b/grc/gui/VariableEditor.py @@ -21,7 +21,7 @@ from __future__ import absolute_import from gi.repository import Gtk, Gdk, GObject -from . import Actions, Constants +from . import Actions, Constants, Utils BLOCK_INDEX = 0 ID_INDEX = 1 @@ -114,9 +114,9 @@ class VariableEditor(Gtk.VBox): id_column = Gtk.TreeViewColumn("Id", self.id_cell, text=ID_INDEX) id_column.set_name("id") id_column.set_resizable(True) - id_column.set_max_width(300) - id_column.set_min_width(80) - id_column.set_fixed_width(100) + id_column.set_max_width(Utils.scale_scalar(300)) + id_column.set_min_width(Utils.scale_scalar(80)) + id_column.set_fixed_width(Utils.scale_scalar(100)) id_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED) id_column.set_cell_data_func(self.id_cell, self.set_properties) self.id_column = id_column @@ -132,7 +132,7 @@ class VariableEditor(Gtk.VBox): value_column.set_name("value") value_column.set_resizable(False) value_column.set_expand(True) - value_column.set_min_width(100) + value_column.set_min_width(Utils.scale_scalar(100)) value_column.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) value_column.set_cell_data_func(self.value_cell, self.set_value) self.value_column = value_column diff --git a/grc/gui/canvas/block.py b/grc/gui/canvas/block.py index 7e28a21fc2..fc8a533397 100644 --- a/grc/gui/canvas/block.py +++ b/grc/gui/canvas/block.py @@ -69,7 +69,7 @@ class Block(CoreBlock, Drawable): Returns: the coordinate tuple (x, y) or (0, 0) if failure """ - return self.states['_coordinate'] + return Utils.scale(self.states['_coordinate']) @coordinate.setter def coordinate(self, coor): @@ -79,6 +79,7 @@ class Block(CoreBlock, Drawable): Args: coor: the coordinate tuple (x, y) """ + coor = Utils.scale(coor, reverse=True) if Actions.TOGGLE_SNAP_TO_GRID.get_active(): offset_x, offset_y = (0, self.height / 2) if self.is_horizontal() else (self.height / 2, 0) coor = ( |