From bc4e0b3ba71250d92a7f45a036bcae7f5589e1a6 Mon Sep 17 00:00:00 2001
From: Ben Hilburn <ben.hilburn@ettus.com>
Date: Fri, 14 Oct 2016 14:21:07 -0400
Subject: Backport GRC Python code for Python-2.6.6+

---
 grc/gui/PropsDialog.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'grc/gui/PropsDialog.py')

diff --git a/grc/gui/PropsDialog.py b/grc/gui/PropsDialog.py
index 7c66a77a54..0e7005d7a7 100644
--- a/grc/gui/PropsDialog.py
+++ b/grc/gui/PropsDialog.py
@@ -265,7 +265,7 @@ class PropsDialog(gtk.Dialog):
             insert('\n\n# Variables\n', block.get_var_make())
         insert('\n\n# Blocks\n', block.get_make())
         if src:
-            insert('\n\n# External Code ({}.py)\n'.format(block.get_id()), src)
+            insert('\n\n# External Code ({0}.py)\n'.format(block.get_id()), src)
 
     def _handle_key_press(self, widget, event):
         """
-- 
cgit v1.2.3


From ea3eaa5f930062fa57568c6132a5930b7399f5f7 Mon Sep 17 00:00:00 2001
From: Sebastian Koslowski <koslowski@kit.edu>
Date: Wed, 12 Oct 2016 15:17:09 +0200
Subject: grc: respect display scaling for block positions, canvas size and
 props dialog

---
 grc/gui/ActionHandler.py |  8 +++++---
 grc/gui/Block.py         | 15 +++++++--------
 grc/gui/Constants.py     |  2 ++
 grc/gui/FlowGraph.py     |  2 +-
 grc/gui/PropsDialog.py   |  5 +++--
 grc/gui/Utils.py         |  7 ++++++-
 6 files changed, 24 insertions(+), 15 deletions(-)

(limited to 'grc/gui/PropsDialog.py')

diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index f18fcea3e1..ec5ac7c574 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -23,7 +23,7 @@ import gtk
 import os
 import subprocess
 
-from . import Dialogs, Preferences, Actions, Executor, Constants
+from . import Dialogs, Preferences, Actions, Executor, Constants, Utils
 from .FileDialogs import (OpenFlowGraphFileDialog, SaveFlowGraphFileDialog,
                           SaveConsoleFileDialog, SaveScreenShotDialog,
                           OpenQSSFileDialog)
@@ -688,8 +688,10 @@ class ActionHandler:
         Actions.FLOW_GRAPH_SAVE.set_sensitive(not page.get_saved())
         main.update()
         try: #set the size of the flow graph area (if changed)
-            new_size = (flow_graph.get_option('window_size') or
-                        self.platform.config.default_canvas_size)
+            new_size = Utils.scale(
+                flow_graph.get_option('window_size') or
+                self.platform.config.default_canvas_size
+            )
             if flow_graph.get_size() != tuple(new_size):
                 flow_graph.set_size(*new_size)
         except: pass
diff --git a/grc/gui/Block.py b/grc/gui/Block.py
index 55c8805fae..b90ea485ee 100644
--- a/grc/gui/Block.py
+++ b/grc/gui/Block.py
@@ -95,9 +95,8 @@ class Block(Element, _Block):
         """
         proximity = Constants.BORDER_PROXIMITY_SENSITIVITY
         try: #should evaluate to tuple
-            coor = eval(self.get_param('_coordinate').get_value())
-            x, y = map(int, coor)
-            fgW,fgH = self.get_parent().get_size()
+            x, y = Utils.scale(eval(self.get_param('_coordinate').get_value()))
+            fgW, fgH = self.get_parent().get_size()
             if x <= 0:
                 x = 0
             elif x >= fgW - proximity:
@@ -124,7 +123,7 @@ class Block(Element, _Block):
                 Utils.align_to_grid(coor[0] + offset_x) - offset_x,
                 Utils.align_to_grid(coor[1] + offset_y) - offset_y
             )
-        self.get_param('_coordinate').set_value(str(coor))
+        self.get_param('_coordinate').set_value(str(Utils.scale(coor, reverse=True)))
 
     def bound_move_delta(self, delta_coor):
         """
@@ -141,11 +140,11 @@ class Block(Element, _Block):
 
         try:
             fgW, fgH = self.get_parent().get_size()
-            x, y = map(int, eval(self.get_param("_coordinate").get_value()))
+            x, y = Utils.scale(eval(self.get_param('_coordinate').get_value()))
             if self.is_horizontal():
-               sW, sH = self.W, self.H
+                sW, sH = self.W, self.H
             else:
-               sW, sH = self.H, self.W
+                sW, sH = self.H, self.W
 
             if x + dX < 0:
                 dX = -x
@@ -154,7 +153,7 @@ class Block(Element, _Block):
             if y + dY < 0:
                 dY = -y
             elif dY + y + sH >= fgH:
-               dY = fgH - y - sH
+                dY = fgH - y - sH
         except:
             pass
 
diff --git a/grc/gui/Constants.py b/grc/gui/Constants.py
index 022564cd77..f3a6df1802 100644
--- a/grc/gui/Constants.py
+++ b/grc/gui/Constants.py
@@ -96,6 +96,8 @@ SCROLL_DISTANCE = 15
 # How close the mouse click can be to a line and register a connection select.
 LINE_SELECT_SENSITIVITY = 5
 
+DPI_SCALING = gtk.gdk.screen_get_default().get_resolution() / 96.0
+
 
 def update_font_size(font_size):
     global PORT_SEPARATION, BLOCK_FONT, PORT_FONT, PARAM_FONT, FONT_SIZE
diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py
index f98aec41d5..5bcf018120 100644
--- a/grc/gui/FlowGraph.py
+++ b/grc/gui/FlowGraph.py
@@ -407,7 +407,7 @@ class FlowGraph(Element, _Flowgraph):
         Draw the pixmap to the drawable window of this flow graph.
         """
 
-        W,H = self.get_size()
+        W, H = self.get_size()
         hide_disabled_blocks = Actions.TOGGLE_HIDE_DISABLED_BLOCKS.get_active()
         hide_variables = Actions.TOGGLE_HIDE_VARIABLES.get_active()
 
diff --git a/grc/gui/PropsDialog.py b/grc/gui/PropsDialog.py
index 7c66a77a54..907eff7c68 100644
--- a/grc/gui/PropsDialog.py
+++ b/grc/gui/PropsDialog.py
@@ -23,7 +23,7 @@ import gtk
 
 import Actions
 from Dialogs import SimpleTextDisplay
-from Constants import MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT, FONT_SIZE
+from Constants import MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT, FONT_SIZE, DPI_SCALING
 import Utils
 import pango
 
@@ -72,7 +72,8 @@ class PropsDialog(gtk.Dialog):
                      gtk.STOCK_APPLY, gtk.RESPONSE_APPLY)
         )
         self.set_response_sensitive(gtk.RESPONSE_APPLY, False)
-        self.set_size_request(MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT)
+        self.set_size_request(MIN_DIALOG_WIDTH +DPI_SCALING,
+                              MIN_DIALOG_HEIGHT * DPI_SCALING)
         self._block = block
 
         vpaned = gtk.VPaned()
diff --git a/grc/gui/Utils.py b/grc/gui/Utils.py
index 51b9b19e9f..7d15d47142 100644
--- a/grc/gui/Utils.py
+++ b/grc/gui/Utils.py
@@ -24,7 +24,7 @@ import gobject
 
 from Cheetah.Template import Template
 
-from Constants import POSSIBLE_ROTATIONS, CANVAS_GRID_SIZE
+from Constants import POSSIBLE_ROTATIONS, CANVAS_GRID_SIZE, DPI_SCALING
 
 
 def rotate_pixmap(gc, src_pixmap, dst_pixmap, angle=gtk.gdk.PIXBUF_ROTATE_COUNTERCLOCKWISE):
@@ -131,3 +131,8 @@ def align_to_grid(coor, mode=round):
     except TypeError:
         x = coor
         return align(coor)
+
+
+def scale(coor, reverse=False):
+    factor = DPI_SCALING if not reverse else 1 / DPI_SCALING
+    return tuple(int(x * factor) for x in coor)
-- 
cgit v1.2.3


From a4514d5c172b2631b856d7bd543c491a02a5c553 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan <johnathan@corganlabs.com>
Date: Tue, 25 Oct 2016 14:08:09 -0700
Subject: Revert "Merge remote-tracking branch 'skoslowski/dpi_fix' into maint"

This reverts commit afadc5cb5564cb9b6136db046adccde5856edf57, reversing
changes made to 915f1b02408a6a4f2ce2ffb2d9336643745aa939.
---
 grc/gui/ActionHandler.py |  8 +++-----
 grc/gui/Block.py         | 15 ++++++++-------
 grc/gui/Constants.py     |  2 --
 grc/gui/FlowGraph.py     |  2 +-
 grc/gui/PropsDialog.py   |  5 ++---
 grc/gui/Utils.py         |  7 +------
 6 files changed, 15 insertions(+), 24 deletions(-)

(limited to 'grc/gui/PropsDialog.py')

diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index ec5ac7c574..f18fcea3e1 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -23,7 +23,7 @@ import gtk
 import os
 import subprocess
 
-from . import Dialogs, Preferences, Actions, Executor, Constants, Utils
+from . import Dialogs, Preferences, Actions, Executor, Constants
 from .FileDialogs import (OpenFlowGraphFileDialog, SaveFlowGraphFileDialog,
                           SaveConsoleFileDialog, SaveScreenShotDialog,
                           OpenQSSFileDialog)
@@ -688,10 +688,8 @@ class ActionHandler:
         Actions.FLOW_GRAPH_SAVE.set_sensitive(not page.get_saved())
         main.update()
         try: #set the size of the flow graph area (if changed)
-            new_size = Utils.scale(
-                flow_graph.get_option('window_size') or
-                self.platform.config.default_canvas_size
-            )
+            new_size = (flow_graph.get_option('window_size') or
+                        self.platform.config.default_canvas_size)
             if flow_graph.get_size() != tuple(new_size):
                 flow_graph.set_size(*new_size)
         except: pass
diff --git a/grc/gui/Block.py b/grc/gui/Block.py
index 39c6993a37..b9fc12b782 100644
--- a/grc/gui/Block.py
+++ b/grc/gui/Block.py
@@ -95,8 +95,9 @@ class Block(Element, _Block):
         """
         proximity = Constants.BORDER_PROXIMITY_SENSITIVITY
         try: #should evaluate to tuple
-            x, y = Utils.scale(eval(self.get_param('_coordinate').get_value()))
-            fgW, fgH = self.get_parent().get_size()
+            coor = eval(self.get_param('_coordinate').get_value())
+            x, y = map(int, coor)
+            fgW,fgH = self.get_parent().get_size()
             if x <= 0:
                 x = 0
             elif x >= fgW - proximity:
@@ -123,7 +124,7 @@ class Block(Element, _Block):
                 Utils.align_to_grid(coor[0] + offset_x) - offset_x,
                 Utils.align_to_grid(coor[1] + offset_y) - offset_y
             )
-        self.get_param('_coordinate').set_value(str(Utils.scale(coor, reverse=True)))
+        self.get_param('_coordinate').set_value(str(coor))
 
     def bound_move_delta(self, delta_coor):
         """
@@ -140,11 +141,11 @@ class Block(Element, _Block):
 
         try:
             fgW, fgH = self.get_parent().get_size()
-            x, y = Utils.scale(eval(self.get_param('_coordinate').get_value()))
+            x, y = map(int, eval(self.get_param("_coordinate").get_value()))
             if self.is_horizontal():
-                sW, sH = self.W, self.H
+               sW, sH = self.W, self.H
             else:
-                sW, sH = self.H, self.W
+               sW, sH = self.H, self.W
 
             if x + dX < 0:
                 dX = -x
@@ -153,7 +154,7 @@ class Block(Element, _Block):
             if y + dY < 0:
                 dY = -y
             elif dY + y + sH >= fgH:
-                dY = fgH - y - sH
+               dY = fgH - y - sH
         except:
             pass
 
diff --git a/grc/gui/Constants.py b/grc/gui/Constants.py
index 7dc6d6e15b..6a7b54dffa 100644
--- a/grc/gui/Constants.py
+++ b/grc/gui/Constants.py
@@ -96,8 +96,6 @@ SCROLL_DISTANCE = 15
 # How close the mouse click can be to a line and register a connection select.
 LINE_SELECT_SENSITIVITY = 5
 
-DPI_SCALING = gtk.gdk.screen_get_default().get_resolution() / 96.0
-
 
 def update_font_size(font_size):
     global PORT_SEPARATION, BLOCK_FONT, PORT_FONT, PARAM_FONT, FONT_SIZE
diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py
index e0cd7d1441..44a8ae24a9 100644
--- a/grc/gui/FlowGraph.py
+++ b/grc/gui/FlowGraph.py
@@ -407,7 +407,7 @@ class FlowGraph(Element, _Flowgraph):
         Draw the pixmap to the drawable window of this flow graph.
         """
 
-        W, H = self.get_size()
+        W,H = self.get_size()
         hide_disabled_blocks = Actions.TOGGLE_HIDE_DISABLED_BLOCKS.get_active()
         hide_variables = Actions.TOGGLE_HIDE_VARIABLES.get_active()
 
diff --git a/grc/gui/PropsDialog.py b/grc/gui/PropsDialog.py
index 890cbb0680..0e7005d7a7 100644
--- a/grc/gui/PropsDialog.py
+++ b/grc/gui/PropsDialog.py
@@ -23,7 +23,7 @@ import gtk
 
 import Actions
 from Dialogs import SimpleTextDisplay
-from Constants import MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT, FONT_SIZE, DPI_SCALING
+from Constants import MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT, FONT_SIZE
 import Utils
 import pango
 
@@ -72,8 +72,7 @@ class PropsDialog(gtk.Dialog):
                      gtk.STOCK_APPLY, gtk.RESPONSE_APPLY)
         )
         self.set_response_sensitive(gtk.RESPONSE_APPLY, False)
-        self.set_size_request(MIN_DIALOG_WIDTH +DPI_SCALING,
-                              MIN_DIALOG_HEIGHT * DPI_SCALING)
+        self.set_size_request(MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT)
         self._block = block
 
         vpaned = gtk.VPaned()
diff --git a/grc/gui/Utils.py b/grc/gui/Utils.py
index d85b846b3a..80dcb4283a 100644
--- a/grc/gui/Utils.py
+++ b/grc/gui/Utils.py
@@ -24,7 +24,7 @@ import gobject
 
 from Cheetah.Template import Template
 
-from Constants import POSSIBLE_ROTATIONS, CANVAS_GRID_SIZE, DPI_SCALING
+from Constants import POSSIBLE_ROTATIONS, CANVAS_GRID_SIZE
 
 
 def rotate_pixmap(gc, src_pixmap, dst_pixmap, angle=gtk.gdk.PIXBUF_ROTATE_COUNTERCLOCKWISE):
@@ -131,8 +131,3 @@ def align_to_grid(coor, mode=round):
     except TypeError:
         x = coor
         return align(coor)
-
-
-def scale(coor, reverse=False):
-    factor = DPI_SCALING if not reverse else 1 / DPI_SCALING
-    return tuple(int(x * factor) for x in coor)
-- 
cgit v1.2.3


From 8ffadf88423290ad9b24a63a7d67ec36ccd5975b Mon Sep 17 00:00:00 2001
From: Sebastian Koslowski <koslowski@kit.edu>
Date: Wed, 12 Oct 2016 15:17:09 +0200
Subject: grc: respect display scaling for block positions, canvas size and
 props dialog

---
 grc/gui/ActionHandler.py |  8 +++++---
 grc/gui/Block.py         | 15 +++++++--------
 grc/gui/Constants.py     |  3 +++
 grc/gui/FlowGraph.py     |  2 +-
 grc/gui/PropsDialog.py   |  4 +++-
 grc/gui/Utils.py         |  7 ++++++-
 6 files changed, 25 insertions(+), 14 deletions(-)

(limited to 'grc/gui/PropsDialog.py')

diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index f18fcea3e1..ec5ac7c574 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -23,7 +23,7 @@ import gtk
 import os
 import subprocess
 
-from . import Dialogs, Preferences, Actions, Executor, Constants
+from . import Dialogs, Preferences, Actions, Executor, Constants, Utils
 from .FileDialogs import (OpenFlowGraphFileDialog, SaveFlowGraphFileDialog,
                           SaveConsoleFileDialog, SaveScreenShotDialog,
                           OpenQSSFileDialog)
@@ -688,8 +688,10 @@ class ActionHandler:
         Actions.FLOW_GRAPH_SAVE.set_sensitive(not page.get_saved())
         main.update()
         try: #set the size of the flow graph area (if changed)
-            new_size = (flow_graph.get_option('window_size') or
-                        self.platform.config.default_canvas_size)
+            new_size = Utils.scale(
+                flow_graph.get_option('window_size') or
+                self.platform.config.default_canvas_size
+            )
             if flow_graph.get_size() != tuple(new_size):
                 flow_graph.set_size(*new_size)
         except: pass
diff --git a/grc/gui/Block.py b/grc/gui/Block.py
index b9fc12b782..39c6993a37 100644
--- a/grc/gui/Block.py
+++ b/grc/gui/Block.py
@@ -95,9 +95,8 @@ class Block(Element, _Block):
         """
         proximity = Constants.BORDER_PROXIMITY_SENSITIVITY
         try: #should evaluate to tuple
-            coor = eval(self.get_param('_coordinate').get_value())
-            x, y = map(int, coor)
-            fgW,fgH = self.get_parent().get_size()
+            x, y = Utils.scale(eval(self.get_param('_coordinate').get_value()))
+            fgW, fgH = self.get_parent().get_size()
             if x <= 0:
                 x = 0
             elif x >= fgW - proximity:
@@ -124,7 +123,7 @@ class Block(Element, _Block):
                 Utils.align_to_grid(coor[0] + offset_x) - offset_x,
                 Utils.align_to_grid(coor[1] + offset_y) - offset_y
             )
-        self.get_param('_coordinate').set_value(str(coor))
+        self.get_param('_coordinate').set_value(str(Utils.scale(coor, reverse=True)))
 
     def bound_move_delta(self, delta_coor):
         """
@@ -141,11 +140,11 @@ class Block(Element, _Block):
 
         try:
             fgW, fgH = self.get_parent().get_size()
-            x, y = map(int, eval(self.get_param("_coordinate").get_value()))
+            x, y = Utils.scale(eval(self.get_param('_coordinate').get_value()))
             if self.is_horizontal():
-               sW, sH = self.W, self.H
+                sW, sH = self.W, self.H
             else:
-               sW, sH = self.H, self.W
+                sW, sH = self.H, self.W
 
             if x + dX < 0:
                 dX = -x
@@ -154,7 +153,7 @@ class Block(Element, _Block):
             if y + dY < 0:
                 dY = -y
             elif dY + y + sH >= fgH:
-               dY = fgH - y - sH
+                dY = fgH - y - sH
         except:
             pass
 
diff --git a/grc/gui/Constants.py b/grc/gui/Constants.py
index 6a7b54dffa..f77221e52d 100644
--- a/grc/gui/Constants.py
+++ b/grc/gui/Constants.py
@@ -96,6 +96,9 @@ SCROLL_DISTANCE = 15
 # How close the mouse click can be to a line and register a connection select.
 LINE_SELECT_SENSITIVITY = 5
 
+_SCREEN_RESOLUTION = gtk.gdk.screen_get_default().get_resolution()
+DPI_SCALING = _SCREEN_RESOLUTION / 96.0 if _SCREEN_RESOLUTION > 0 else 1.0
+
 
 def update_font_size(font_size):
     global PORT_SEPARATION, BLOCK_FONT, PORT_FONT, PARAM_FONT, FONT_SIZE
diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py
index 44a8ae24a9..e0cd7d1441 100644
--- a/grc/gui/FlowGraph.py
+++ b/grc/gui/FlowGraph.py
@@ -407,7 +407,7 @@ class FlowGraph(Element, _Flowgraph):
         Draw the pixmap to the drawable window of this flow graph.
         """
 
-        W,H = self.get_size()
+        W, H = self.get_size()
         hide_disabled_blocks = Actions.TOGGLE_HIDE_DISABLED_BLOCKS.get_active()
         hide_variables = Actions.TOGGLE_HIDE_VARIABLES.get_active()
 
diff --git a/grc/gui/PropsDialog.py b/grc/gui/PropsDialog.py
index 0e7005d7a7..cfea13e1a8 100644
--- a/grc/gui/PropsDialog.py
+++ b/grc/gui/PropsDialog.py
@@ -72,7 +72,9 @@ class PropsDialog(gtk.Dialog):
                      gtk.STOCK_APPLY, gtk.RESPONSE_APPLY)
         )
         self.set_response_sensitive(gtk.RESPONSE_APPLY, False)
-        self.set_size_request(MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT)
+        self.set_size_request(*Utils.scale(
+            (MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT)
+        ))
         self._block = block
 
         vpaned = gtk.VPaned()
diff --git a/grc/gui/Utils.py b/grc/gui/Utils.py
index 80dcb4283a..d85b846b3a 100644
--- a/grc/gui/Utils.py
+++ b/grc/gui/Utils.py
@@ -24,7 +24,7 @@ import gobject
 
 from Cheetah.Template import Template
 
-from Constants import POSSIBLE_ROTATIONS, CANVAS_GRID_SIZE
+from Constants import POSSIBLE_ROTATIONS, CANVAS_GRID_SIZE, DPI_SCALING
 
 
 def rotate_pixmap(gc, src_pixmap, dst_pixmap, angle=gtk.gdk.PIXBUF_ROTATE_COUNTERCLOCKWISE):
@@ -131,3 +131,8 @@ def align_to_grid(coor, mode=round):
     except TypeError:
         x = coor
         return align(coor)
+
+
+def scale(coor, reverse=False):
+    factor = DPI_SCALING if not reverse else 1 / DPI_SCALING
+    return tuple(int(x * factor) for x in coor)
-- 
cgit v1.2.3