commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 06/101: grc: gtk3: update props dialog


From: git
Subject: [Commit-gnuradio] [gnuradio] 06/101: grc: gtk3: update props dialog
Date: Thu, 16 Mar 2017 14:57:57 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch python3
in repository gnuradio.

commit d290917e982ba4473a03e5a7e1acaa1e50c59f3d
Author: Sebastian Koslowski <address@hidden>
Date:   Fri May 27 15:19:11 2016 +0200

    grc: gtk3: update props dialog
---
 grc/checks.py                         |   2 +
 grc/gui/ActionHandler.py              |   2 +-
 grc/gui/Block.py                      |   2 +-
 grc/gui/Constants.py                  |   2 +-
 grc/gui/Param.py                      | 149 ++++++++++----------
 grc/gui/{Param.py => ParamWidgets.py} | 258 +++++++++-------------------------
 grc/gui/PropsDialog.py                | 137 ++++++++----------
 7 files changed, 201 insertions(+), 351 deletions(-)

diff --git a/grc/checks.py b/grc/checks.py
index cfff10e..66c114d 100755
--- a/grc/checks.py
+++ b/grc/checks.py
@@ -53,6 +53,8 @@ def check_gtk():
         warnings.filterwarnings("error")
         import gi
         gi.require_version('Gtk', '3.0')
+        gi.require_version('PangoCairo', '1.0')
+
         from gi.repository import Gtk
         Gtk.init_check()
         warnings.filterwarnings("always")
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index e25fa19..7dc37cc 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -461,7 +461,7 @@ class ActionHandler:
             else:
                 selected_block = flow_graph.get_selected_block()
             if selected_block:
-                self.dialog = PropsDialog(selected_block)
+                self.dialog = PropsDialog(self.main_window, selected_block)
                 response = Gtk.ResponseType.APPLY
                 while response == Gtk.ResponseType.APPLY:  # rerun the dialog 
if Apply was hit
                     response = self.dialog.run()
diff --git a/grc/gui/Block.py b/grc/gui/Block.py
index f8687be..5e5c5c4 100644
--- a/grc/gui/Block.py
+++ b/grc/gui/Block.py
@@ -180,7 +180,7 @@ class Block(Element, _Block):
                 font=PARAM_FONT, key=self._key
             )]
         else:
-            markups = [param.get_markup() for param in self.get_params() if 
param.get_hide() not in ('all', 'part')]
+            markups = [param.format_block_surface_markup() for param in 
self.get_params() if param.get_hide() not in ('all', 'part')]
         if markups:
             layout = Gtk.DrawingArea().create_pango_layout('')
             layout.set_spacing(LABEL_SEPARATION*Pango.SCALE)
diff --git a/grc/gui/Constants.py b/grc/gui/Constants.py
index 4508efc..4ab644e 100644
--- a/grc/gui/Constants.py
+++ b/grc/gui/Constants.py
@@ -38,7 +38,7 @@ NEW_FLOGRAPH_TITLE = 'untitled'
 MIN_WINDOW_WIDTH = 600
 MIN_WINDOW_HEIGHT = 400
 # dialog constraints
-MIN_DIALOG_WIDTH = 500
+MIN_DIALOG_WIDTH = 600
 MIN_DIALOG_HEIGHT = 500
 # default sizes
 DEFAULT_BLOCKS_WINDOW_WIDTH = 100
diff --git a/grc/gui/Param.py b/grc/gui/Param.py
index 1c5b0c9..a087d4b 100644
--- a/grc/gui/Param.py
+++ b/grc/gui/Param.py
@@ -19,12 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
MA  02110-1301, USA
 
 import os
 
-import gi
-gi.require_version('Gtk', '3.0')
-from gi.repository import Gtk
-from gi.repository import Gdk
-from gi.repository import GObject
-
+from gi.repository import Gtk, Gdk
 
 from . import Colors, Utils, Constants
 from .Element import Element
@@ -37,17 +32,20 @@ class InputParam(Gtk.HBox):
     expand = False
 
     def __init__(self, param, changed_callback=None, editing_callback=None):
-        GObject.GObject.__init__(self)
+        Gtk.HBox.__init__(self)
+
         self.param = param
         self._changed_callback = changed_callback
         self._editing_callback = editing_callback
-        self.label = Gtk.Label() #no label, markup is added by set_markup
+
+        self.label = Gtk.Label()
         self.label.set_size_request(150, -1)
-        self.pack_start(self.label, False)
-        self.set_markup = lambda m: self.label.set_markup(m)
+        self.label.show()
+        self.pack_start(self.label, False, False, 0)
+
         self.tp = None
         self._have_pending_changes = False
-        #connect events
+
         self.connect('show', self._update_gui)
 
     def set_color(self, color):
@@ -63,40 +61,17 @@ class InputParam(Gtk.HBox):
         """
         Set the markup, color, tooltip, show/hide.
         """
-        param = self.param
+        
self.label.set_markup(self.param.format_label_markup(self._have_pending_changes))
 
-        has_callback = \
-            hasattr(param.get_parent(), 'get_callbacks') and \
-            any(param.get_key() in callback for callback in 
param.get_parent()._callbacks)
+        # fixme: find a non-deprecated way to change colors
+        # self.set_color(Colors.PARAM_ENTRY_COLORS.get(
+        #     self.param.get_type(), Colors.PARAM_ENTRY_DEFAULT_COLOR)
+        # )
 
-        self.set_markup('<span underline="{line}" foreground="{color}" 
font_desc="Sans 9">{label}</span>'.format(
-            line='low' if has_callback else 'none',
-            color='blue' if self._have_pending_changes else
-                  'black' if param.is_valid() else
-                  'red',
-            label=Utils.encode(self.param.get_name())
-        ))
-
-        self.set_color(Colors.PARAM_ENTRY_COLORS.get(
-            self.param.get_type(), Colors.PARAM_ENTRY_DEFAULT_COLOR)
-        )
-
-        errors = param.get_error_messages()
-        tooltip_lines = ['Key: ' + param.get_key(), 'Type: ' + 
param.get_type()]
-        if param.is_valid():
-            value = str(param.get_evaluated())
-            if len(value) > 100:
-                value = '{}...{}'.format(value[:50], value[-50:])
-            tooltip_lines.append('Value: ' + value)
-        elif len(errors) == 1:
-            tooltip_lines.append('Error: ' + errors[0])
-        elif len(errors) > 1:
-            tooltip_lines.append('Error:')
-            tooltip_lines.extend(' * ' + msg for msg in errors)
-        self.set_tooltip_text('\n'.join(tooltip_lines))
+        self.set_tooltip_text(self.param.format_tooltip_text())
 
         if self.param.get_hide() == 'all':
-            self.hide_all()
+            self.hide()
         else:
             self.show_all()
 
@@ -146,7 +121,7 @@ class EntryParam(InputParam):
         self._input.connect('changed', self._mark_changed)
         self._input.connect('focus-out-event', self._apply_change)
         self._input.connect('key-press-event', self._handle_key_press)
-        self.pack_start(self._input, True)
+        self.pack_start(self._input, True, True, 0)
 
     def get_text(self):
         return self._input.get_text()
@@ -155,10 +130,7 @@ class EntryParam(InputParam):
         self._input.override_background_color(Gtk.StateType.NORMAL, color)
 
     def set_tooltip_text(self, text):
-        try:
-            self._input.set_tooltip_text(text)
-        except AttributeError:
-            pass  # no tooltips for old GTK
+        self._input.set_tooltip_text(text)
 
 
 class MultiLineEntryParam(InputParam):
@@ -171,29 +143,29 @@ class MultiLineEntryParam(InputParam):
         self._buffer.set_text(self.param.get_value())
         self._buffer.connect('changed', self._mark_changed)
 
-        self._view = Gtk.TextView(self._buffer)
+        self._view = Gtk.TextView()
+        self._view.set_buffer(self._buffer)
         self._view.connect('focus-out-event', self._apply_change)
         self._view.connect('key-press-event', self._handle_key_press)
+        # fixme: add border to TextView
 
         self._sw = Gtk.ScrolledWindow()
         self._sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
         self._sw.add_with_viewport(self._view)
 
-        self.pack_start(self._sw, True)
+        self.pack_start(self._sw, True, True, True)
 
     def get_text(self):
         buf = self._buffer
-        return buf.get_text(buf.get_start_iter(),
-                            buf.get_end_iter()).strip()
+        text = buf.get_text(buf.get_start_iter(), buf.get_end_iter(),
+                            include_hidden_chars=False)
+        return text.strip()
 
     def set_color(self, color):
         self._view.override_background_color(Gtk.StateType.NORMAL, color)
 
     def set_tooltip_text(self, text):
-        try:
-            self._view.set_tooltip_text(text)
-        except AttributeError:
-            pass  # no tooltips for old GTK
+        self._view.set_tooltip_text(text)
 
 
 # try:
@@ -264,16 +236,13 @@ class EnumParam(InputParam):
         
self._input.set_active(self.param.get_option_keys().index(self.param.get_value()))
         self._input.connect('changed', self._editing_callback)
         self._input.connect('changed', self._apply_change)
-        self.pack_start(self._input, False)
+        self.pack_start(self._input, False, False, 0)
 
     def get_text(self):
         return self.param.get_option_keys()[self._input.get_active()]
 
     def set_tooltip_text(self, text):
-        try:
-            self._input.set_tooltip_text(text)
-        except AttributeError:
-            pass  # no tooltips for old GTK
+        self._input.set_tooltip_text(text)
 
 
 class EnumEntryParam(InputParam):
@@ -281,17 +250,23 @@ class EnumEntryParam(InputParam):
 
     def __init__(self, *args, **kwargs):
         InputParam.__init__(self, *args, **kwargs)
-        self._input = Gtk.combo_box_entry_new_text()
-        for option in self.param.get_options(): 
self._input.append_text(option.get_name())
-        try: 
self._input.set_active(self.param.get_option_keys().index(self.param.get_value()))
-        except:
+        self._input = Gtk.ComboBoxText.new_with_entry()
+        for option in self.param.get_options():
+            self._input.append_text(option.get_name())
+
+        value = self.param.get_value()
+        try:
+            active_index = self.param.get_option_keys().index(value)
+            self._input.set_active(active_index)
+        except ValueError:
             self._input.set_active(-1)
-            self._input.get_child().set_text(self.param.get_value())
+            self._input.get_child().set_text(value)
+
         self._input.connect('changed', self._apply_change)
         self._input.get_child().connect('changed', self._mark_changed)
         self._input.get_child().connect('focus-out-event', self._apply_change)
         self._input.get_child().connect('key-press-event', 
self._handle_key_press)
-        self.pack_start(self._input, False)
+        self.pack_start(self._input, False, False, 0)
 
     @property
     def has_custom_value(self):
@@ -302,13 +277,10 @@ class EnumEntryParam(InputParam):
         return self.param.get_option_keys()[self._input.get_active()]
 
     def set_tooltip_text(self, text):
-        try:
-            if self._input.get_active() == -1: #custom entry
-                self._input.get_child().set_tooltip_text(text)
-            else:
-                self._input.set_tooltip_text(text)
-        except AttributeError:
-            pass  # no tooltips for old GTK
+        if self.has_custom_value:  # custom entry
+            self._input.get_child().set_tooltip_text(text)
+        else:
+            self._input.set_tooltip_text(text)
 
     def set_color(self, color):
         self._input.get_child().modify_base(
@@ -324,7 +296,7 @@ class FileParam(EntryParam):
         EntryParam.__init__(self, *args, **kwargs)
         input = Gtk.Button('...')
         input.connect('clicked', self._handle_clicked)
-        self.pack_start(input, False)
+        self.pack_start(input, False, False, 0)
 
     def _handle_clicked(self, widget=None):
         """
@@ -403,7 +375,36 @@ class Param(Element, _Param):
 
         return input_widget
 
-    def get_markup(self):
+    def format_label_markup(self, have_pending_changes=False):
+        block = self.get_parent()
+        has_callback = \
+            hasattr(block, 'get_callbacks') and \
+            any(self.get_key() in callback for callback in block._callbacks)
+
+        return '<span underline="{line}" foreground="{color}" font_desc="Sans 
9">{label}</span>'.format(
+            line='low' if has_callback else 'none',
+            color='blue' if have_pending_changes else
+            'black' if self.is_valid() else
+            'red',
+            label=Utils.encode(self.get_name())
+        )
+
+    def format_tooltip_text(self):
+        errors = self.get_error_messages()
+        tooltip_lines = ['Key: ' + self.get_key(), 'Type: ' + self.get_type()]
+        if self.is_valid():
+            value = str(self.get_evaluated())
+            if len(value) > 100:
+                value = '{}...{}'.format(value[:50], value[-50:])
+            tooltip_lines.append('Value: ' + value)
+        elif len(errors) == 1:
+            tooltip_lines.append('Error: ' + errors[0])
+        elif len(errors) > 1:
+            tooltip_lines.append('Error:')
+            tooltip_lines.extend(' * ' + msg for msg in errors)
+        return '\n'.join(tooltip_lines)
+
+    def format_block_surface_markup(self):
         """
         Get the markup for this param.
 
diff --git a/grc/gui/Param.py b/grc/gui/ParamWidgets.py
similarity index 51%
copy from grc/gui/Param.py
copy to grc/gui/ParamWidgets.py
index 1c5b0c9..eab6a31 100644
--- a/grc/gui/Param.py
+++ b/grc/gui/ParamWidgets.py
@@ -1,35 +1,12 @@
-"""
-Copyright 2007-2011 Free Software Foundation, Inc.
-This file is part of GNU Radio
-
-GNU Radio Companion is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-GNU Radio Companion is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
-"""
-
+# -*- coding: utf-8 -*-
+"""${FILE_NAME}"""
 import os
 
-import gi
-gi.require_version('Gtk', '3.0')
-from gi.repository import Gtk
-from gi.repository import Gdk
-from gi.repository import GObject
-
-
-from . import Colors, Utils, Constants
-from .Element import Element
+from grc.gui import Colors
 
-from ..core.Param import Param as _Param
+__author__ = "Sebastian Koslowski"
+__email__ = "address@hidden"
+__copyright__ = "Copyright 2016, Sebastian Koslowski"
 
 
 class InputParam(Gtk.HBox):
@@ -37,17 +14,20 @@ class InputParam(Gtk.HBox):
     expand = False
 
     def __init__(self, param, changed_callback=None, editing_callback=None):
-        GObject.GObject.__init__(self)
+        Gtk.HBox.__init__(self)
+
         self.param = param
         self._changed_callback = changed_callback
         self._editing_callback = editing_callback
-        self.label = Gtk.Label() #no label, markup is added by set_markup
+
+        self.label = Gtk.Label()
         self.label.set_size_request(150, -1)
-        self.pack_start(self.label, False)
-        self.set_markup = lambda m: self.label.set_markup(m)
+        self.label.show()
+        self.pack_start(self.label, False, False, 0)
+
         self.tp = None
         self._have_pending_changes = False
-        #connect events
+
         self.connect('show', self._update_gui)
 
     def set_color(self, color):
@@ -63,40 +43,17 @@ class InputParam(Gtk.HBox):
         """
         Set the markup, color, tooltip, show/hide.
         """
-        param = self.param
-
-        has_callback = \
-            hasattr(param.get_parent(), 'get_callbacks') and \
-            any(param.get_key() in callback for callback in 
param.get_parent()._callbacks)
-
-        self.set_markup('<span underline="{line}" foreground="{color}" 
font_desc="Sans 9">{label}</span>'.format(
-            line='low' if has_callback else 'none',
-            color='blue' if self._have_pending_changes else
-                  'black' if param.is_valid() else
-                  'red',
-            label=Utils.encode(self.param.get_name())
-        ))
-
-        self.set_color(Colors.PARAM_ENTRY_COLORS.get(
-            self.param.get_type(), Colors.PARAM_ENTRY_DEFAULT_COLOR)
-        )
+        
self.label.set_markup(self.param.format_label_markup(self._have_pending_changes))
+
+        # fixme: find a non-deprecated way to change colors
+        # self.set_color(Colors.PARAM_ENTRY_COLORS.get(
+        #     self.param.get_type(), Colors.PARAM_ENTRY_DEFAULT_COLOR)
+        # )
 
-        errors = param.get_error_messages()
-        tooltip_lines = ['Key: ' + param.get_key(), 'Type: ' + 
param.get_type()]
-        if param.is_valid():
-            value = str(param.get_evaluated())
-            if len(value) > 100:
-                value = '{}...{}'.format(value[:50], value[-50:])
-            tooltip_lines.append('Value: ' + value)
-        elif len(errors) == 1:
-            tooltip_lines.append('Error: ' + errors[0])
-        elif len(errors) > 1:
-            tooltip_lines.append('Error:')
-            tooltip_lines.extend(' * ' + msg for msg in errors)
-        self.set_tooltip_text('\n'.join(tooltip_lines))
+        self.set_tooltip_text(self.param.format_tooltip_text())
 
         if self.param.get_hide() == 'all':
-            self.hide_all()
+            self.hide()
         else:
             self.show_all()
 
@@ -146,7 +103,7 @@ class EntryParam(InputParam):
         self._input.connect('changed', self._mark_changed)
         self._input.connect('focus-out-event', self._apply_change)
         self._input.connect('key-press-event', self._handle_key_press)
-        self.pack_start(self._input, True)
+        self.pack_start(self._input, True, True, 0)
 
     def get_text(self):
         return self._input.get_text()
@@ -155,10 +112,7 @@ class EntryParam(InputParam):
         self._input.override_background_color(Gtk.StateType.NORMAL, color)
 
     def set_tooltip_text(self, text):
-        try:
-            self._input.set_tooltip_text(text)
-        except AttributeError:
-            pass  # no tooltips for old GTK
+        self._input.set_tooltip_text(text)
 
 
 class MultiLineEntryParam(InputParam):
@@ -171,69 +125,30 @@ class MultiLineEntryParam(InputParam):
         self._buffer.set_text(self.param.get_value())
         self._buffer.connect('changed', self._mark_changed)
 
-        self._view = Gtk.TextView(self._buffer)
+        self._view = Gtk.TextView()
+        self._view.set_buffer(self._buffer)
         self._view.connect('focus-out-event', self._apply_change)
         self._view.connect('key-press-event', self._handle_key_press)
+        # fixme: add border to TextView
 
         self._sw = Gtk.ScrolledWindow()
         self._sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
         self._sw.add_with_viewport(self._view)
 
-        self.pack_start(self._sw, True)
+        self.pack_start(self._sw, True, True, True)
 
     def get_text(self):
         buf = self._buffer
-        return buf.get_text(buf.get_start_iter(),
-                            buf.get_end_iter()).strip()
+        text = buf.get_text(buf.get_start_iter(), buf.get_end_iter(),
+                            include_hidden_chars=False)
+        return text.strip()
 
     def set_color(self, color):
         self._view.override_background_color(Gtk.StateType.NORMAL, color)
 
     def set_tooltip_text(self, text):
-        try:
-            self._view.set_tooltip_text(text)
-        except AttributeError:
-            pass  # no tooltips for old GTK
-
-
-# try:
-#     import gtksourceview
-#     lang_manager = gtksourceview.SourceLanguagesManager()
-#     py_lang = lang_manager.get_language_from_mime_type('text/x-python')
-#
-#     class PythonEditorParam(InputParam):
-#         expand = True
-#
-#         def __init__(self, *args, **kwargs):
-#             InputParam.__init__(self, *args, **kwargs)
-#
-#             buf = self._buffer = gtksourceview.SourceBuffer()
-#             buf.set_language(py_lang)
-#             buf.set_highlight(True)
-#             buf.set_text(self.param.get_value())
-#             buf.connect('changed', self._mark_changed)
-#
-#             view = self._view = gtksourceview.SourceView(self._buffer)
-#             view.connect('focus-out-event', self._apply_change)
-#             view.connect('key-press-event', self._handle_key_press)
-#             view.set_tabs_width(4)
-#             view.set_insert_spaces_instead_of_tabs(True)
-#             view.set_auto_indent(True)
-#             view.set_border_width(2)
-#
-#             scroll = Gtk.ScrolledWindow()
-#             scroll.set_policy(Gtk.PolicyType.AUTOMATIC, 
Gtk.PolicyType.AUTOMATIC)
-#             scroll.add_with_viewport(view)
-#             self.pack_start(scroll, True)
-#
-#         def get_text(self):
-#             buf = self._buffer
-#             return buf.get_text(buf.get_start_iter(),
-#                                 buf.get_end_iter()).strip()
-#
-# except ImportError:
-#     print "Package 'gtksourceview' not found. No Syntax highlighting."
-#     PythonEditorParam = MultiLineEntryParam
+        self._view.set_tooltip_text(text)
+
 
 class PythonEditorParam(InputParam):
 
@@ -260,20 +175,22 @@ class EnumParam(InputParam):
     def __init__(self, *args, **kwargs):
         InputParam.__init__(self, *args, **kwargs)
         self._input = Gtk.ComboBoxText()
-        for option in self.param.get_options(): 
self._input.append_text(option.get_name())
-        
self._input.set_active(self.param.get_option_keys().index(self.param.get_value()))
+        for option in self.param.get_options():
+            self._input.append_text(option.get_name())
+
+        value = self.param.get_value()
+        active_index = self.param.get_option_keys().index(value)
+        self._input.set_active(active_index)
+
         self._input.connect('changed', self._editing_callback)
         self._input.connect('changed', self._apply_change)
-        self.pack_start(self._input, False)
+        self.pack_start(self._input, False, False, 0)
 
     def get_text(self):
         return self.param.get_option_keys()[self._input.get_active()]
 
     def set_tooltip_text(self, text):
-        try:
-            self._input.set_tooltip_text(text)
-        except AttributeError:
-            pass  # no tooltips for old GTK
+        self._input.set_tooltip_text(text)
 
 
 class EnumEntryParam(InputParam):
@@ -281,34 +198,39 @@ class EnumEntryParam(InputParam):
 
     def __init__(self, *args, **kwargs):
         InputParam.__init__(self, *args, **kwargs)
-        self._input = Gtk.combo_box_entry_new_text()
-        for option in self.param.get_options(): 
self._input.append_text(option.get_name())
-        try: 
self._input.set_active(self.param.get_option_keys().index(self.param.get_value()))
-        except:
+        self._input = Gtk.ComboBoxText.new_with_entry()
+        for option in self.param.get_options():
+            self._input.append_text(option.get_name())
+
+        value = self.param.get_value()
+        try:
+            active_index = self.param.get_option_keys().index(value)
+            self._input.set_active(active_index)
+        except ValueError:
             self._input.set_active(-1)
-            self._input.get_child().set_text(self.param.get_value())
+            self._input.get_child().set_text(value)
+
         self._input.connect('changed', self._apply_change)
         self._input.get_child().connect('changed', self._mark_changed)
         self._input.get_child().connect('focus-out-event', self._apply_change)
         self._input.get_child().connect('key-press-event', 
self._handle_key_press)
-        self.pack_start(self._input, False)
+        self.pack_start(self._input, False, False, 0)
 
     @property
     def has_custom_value(self):
         return self._input.get_active() == -1
 
     def get_text(self):
-        if self._input.get_active() == -1: return 
self._input.get_child().get_text()
-        return self.param.get_option_keys()[self._input.get_active()]
+        if self.has_custom_value:
+            return self._input.get_child().get_text()
+        else:
+            return self.param.get_option_keys()[self._input.get_active()]
 
     def set_tooltip_text(self, text):
-        try:
-            if self._input.get_active() == -1: #custom entry
-                self._input.get_child().set_tooltip_text(text)
-            else:
-                self._input.set_tooltip_text(text)
-        except AttributeError:
-            pass  # no tooltips for old GTK
+        if self.has_custom_value:  # custom entry
+            self._input.get_child().set_tooltip_text(text)
+        else:
+            self._input.set_tooltip_text(text)
 
     def set_color(self, color):
         self._input.get_child().modify_base(
@@ -322,9 +244,9 @@ class FileParam(EntryParam):
 
     def __init__(self, *args, **kwargs):
         EntryParam.__init__(self, *args, **kwargs)
-        input = Gtk.Button('...')
-        input.connect('clicked', self._handle_clicked)
-        self.pack_start(input, False)
+        self._open_button = Gtk.Button(label='...')
+        self._open_button.connect('clicked', self._handle_clicked)
+        self.pack_start(self._open_button, False, False, 0)
 
     def _handle_clicked(self, widget=None):
         """
@@ -364,53 +286,3 @@ class FileParam(EntryParam):
             self._editing_callback()
             self._apply_change()
         file_dialog.destroy()  # destroy the dialog
-
-
-class Param(Element, _Param):
-    """The graphical parameter."""
-
-    def __init__(self, **kwargs):
-        Element.__init__(self)
-        _Param.__init__(self, **kwargs)
-
-    def get_input(self, *args, **kwargs):
-        """
-        Get the graphical gtk class to represent this parameter.
-        An enum requires and combo parameter.
-        A non-enum with options gets a combined entry/combo parameter.
-        All others get a standard entry parameter.
-
-        Returns:
-            gtk input class
-        """
-        if self.get_type() in ('file_open', 'file_save'):
-            input_widget = FileParam(self, *args, **kwargs)
-
-        elif self.is_enum():
-            input_widget = EnumParam(self, *args, **kwargs)
-
-        elif self.get_options():
-            input_widget = EnumEntryParam(self, *args, **kwargs)
-
-        elif self.get_type() == '_multiline':
-            input_widget = MultiLineEntryParam(self, *args, **kwargs)
-
-        elif self.get_type() == '_multiline_python_external':
-            input_widget = PythonEditorParam(self, *args, **kwargs)
-
-        else:
-            input_widget = EntryParam(self, *args, **kwargs)
-
-        return input_widget
-
-    def get_markup(self):
-        """
-        Get the markup for this param.
-
-        Returns:
-            a pango markup string
-        """
-        return '<span foreground="{color}" font_desc="{font}"><b>{label}:</b> 
{value}</span>'.format(
-            color='black' if self.is_valid() else 'red', 
font=Constants.PARAM_FONT,
-            label=Utils.encode(self.get_name()), 
value=Utils.encode(repr(self).replace('\n', ' '))
-        )
diff --git a/grc/gui/PropsDialog.py b/grc/gui/PropsDialog.py
index d6f3cb4..e7576dd 100644
--- a/grc/gui/PropsDialog.py
+++ b/grc/gui/PropsDialog.py
@@ -19,33 +19,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
MA  02110-1301, USA
 
 import gi
 gi.require_version('Gtk', '3.0')
-from gi.repository import Gtk
-from gi.repository import Gdk
-from gi.repository import GObject
-
-import Actions
-from Dialogs import SimpleTextDisplay
-from Constants import MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT, FONT_SIZE
-import Utils
+from gi.repository import Gtk, Gdk, GObject
 from gi.repository import Pango
 
-
-def get_title_label(title):
-    """
-    Get a title label for the params window.
-    The title will be bold, underlined, and left justified.
-
-    Args:
-        title: the text of the title
-
-    Returns:
-        a gtk object
-    """
-    label = Gtk.Label()
-    label.set_markup('\n<b><span 
underline="low">{title}</span>:</b>\n'.format(title))
-    hbox = Gtk.HBox()
-    hbox.pack_start(label, False, False, padding=11)
-    return hbox
+from . import Actions, Utils, Constants
+from .Dialogs import SimpleTextDisplay
 
 
 class PropsDialog(Gtk.Dialog):
@@ -53,25 +31,30 @@ class PropsDialog(Gtk.Dialog):
     A dialog to set block parameters, view errors, and view documentation.
     """
 
-    def __init__(self, block):
+    def __init__(self, parent, block):
         """
         Properties dialog constructor.
 
-        Args:
+        Args:%
             block: a block instance
         """
-        self._hash = 0
 
-        GObject.GObject.__init__(
+        Gtk.Dialog.__init__(
             self,
-            title='Properties: %s' % block.get_name(),
-            buttons=(Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT,
-                     Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,
-                     Gtk.STOCK_APPLY, Gtk.ResponseType.APPLY)
+            title='Properties: ' + block.get_name(),
+            transient_for=parent,
+            modal=True,
+        )
+        self.add_buttons(
+            Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT,
+            Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,
+            Gtk.STOCK_APPLY, Gtk.ResponseType.APPLY,
         )
         self.set_response_sensitive(Gtk.ResponseType.APPLY, False)
-        self.set_size_request(MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT)
+        self.set_size_request(Constants.MIN_DIALOG_WIDTH, 
Constants.MIN_DIALOG_HEIGHT)
+
         self._block = block
+        self._hash = 0
 
         vpaned = Gtk.VPaned()
         self.vbox.pack_start(vpaned, True, True, 0)
@@ -107,8 +90,7 @@ class PropsDialog(Gtk.Dialog):
             self._code_text_display = code_view = SimpleTextDisplay()
             code_view.set_wrap_mode(Gtk.WrapMode.NONE)
             code_view.get_buffer().create_tag('b', weight=Pango.Weight.BOLD)
-            code_view.modify_font(Pango.FontDescription(
-                'monospace %d' % FONT_SIZE))
+            code_view.override_font(Pango.FontDescription('monospace %d' % 
Constants.FONT_SIZE))
             code_box = Gtk.ScrolledWindow()
             code_box.set_policy(Gtk.PolicyType.AUTOMATIC, 
Gtk.PolicyType.AUTOMATIC)
             code_box.add_with_viewport(self._code_text_display)
@@ -122,7 +104,7 @@ class PropsDialog(Gtk.Dialog):
         self._error_box.set_policy(Gtk.PolicyType.AUTOMATIC, 
Gtk.PolicyType.AUTOMATIC)
         self._error_box.add_with_viewport(self._error_messages_text_display)
         vpaned.pack2(self._error_box)
-        vpaned.set_position(int(0.65 * MIN_DIALOG_HEIGHT))
+        vpaned.set_position(int(0.65 * Constants.MIN_DIALOG_HEIGHT))
 
         # Connect events
         self.connect('key-press-event', self._handle_key_press)
@@ -142,19 +124,17 @@ class PropsDialog(Gtk.Dialog):
             true if changed
         """
         old_hash = self._hash
-        # create a tuple of things from each param that affects the params box
-        self._hash = hash(tuple([(
-            hash(param), param.get_name(), param.get_type(),
-            param.get_hide() == 'all',
-        ) for param in self._block.get_params()]))
-        return self._hash != old_hash
+        new_hash = self._hash = hash(tuple(
+            (hash(param), param.get_name(), param.get_type(), param.get_hide() 
== 'all',)
+            for param in self._block.get_params()
+        ))
+        return new_hash != old_hash
 
     def _handle_changed(self, *args):
         """
         A change occurred within a param:
         Rewrite/validate the block and update the gui.
         """
-        # update for the block
         self._block.rewrite()
         self._block.validate()
         self.update_gui()
@@ -171,47 +151,46 @@ class PropsDialog(Gtk.Dialog):
         Update the documentation block.
         Hide the box if there are no docs.
         """
-        # update the params box
         if force or self._params_changed():
             # hide params box before changing
             for tab, label, vbox in self._params_boxes:
-                vbox.hide_all()
+                vbox.hide()
                 # empty the params box
                 for child in vbox.get_children():
                     vbox.remove(child)
-                    child.destroy()
+                    # child.destroy()   # disabled because it throw errors...
                 # repopulate the params box
                 box_all_valid = True
                 for param in filter(lambda p: p.get_tab_label() == tab, 
self._block.get_params()):
+                    # fixme: why do we even rebuild instead of really hiding 
params?
                     if param.get_hide() == 'all':
                         continue
                     box_all_valid = box_all_valid and param.is_valid()
+
                     input_widget = param.get_input(self._handle_changed, 
self._activate_apply)
-                    vbox.pack_start(input_widget, input_widget.expand)
-                label.set_markup(
-                    '<span foreground="{color}">{name}</span>'.format(
-                        color='black' if box_all_valid else 'red', 
name=Utils.encode(tab)
-                    )
-                )
-                # show params box with new params
-                vbox.show_all()
-        # update the errors box
+                    input_widget.show_all()
+                    vbox.pack_start(input_widget, input_widget.expand, True, 1)
+
+                label.set_markup('<span 
foreground="{color}">{name}</span>'.format(
+                    color='black' if box_all_valid else 'red', 
name=Utils.encode(tab)
+                ))
+                vbox.show()  # show params box with new params
+
         if self._block.is_valid():
             self._error_box.hide()
         else:
             self._error_box.show()
         messages = '\n\n'.join(self._block.get_error_messages())
         self._error_messages_text_display.set_text(messages)
-        # update the docs box
+
         self._update_docs_page()
-        # update the generated code
         self._update_generated_code_page()
 
     def _update_docs_page(self):
         """Show documentation from XML and try to display best matching 
docstring"""
-        buffer = self._docs_text_display.get_buffer()
-        buffer.delete(buffer.get_start_iter(), buffer.get_end_iter())
-        pos = buffer.get_end_iter()
+        buf = self._docs_text_display.get_buffer()
+        buf.delete(buf.get_start_iter(), buf.get_end_iter())
+        pos = buf.get_end_iter()
 
         docstrings = self._block.get_doc()
         if not docstrings:
@@ -221,11 +200,11 @@ class PropsDialog(Gtk.Dialog):
         from_xml = docstrings.pop('', '')
         for line in from_xml.splitlines():
             if line.lstrip() == line and line.endswith(':'):
-                buffer.insert_with_tags_by_name(pos, line + '\n', 'b')
+                buf.insert_with_tags_by_name(pos, line + '\n', 'b')
             else:
-                buffer.insert(pos, line + '\n')
+                buf.insert(pos, line + '\n')
         if from_xml:
-            buffer.insert(pos, '\n')
+            buf.insert(pos, '\n')
 
         # if given the current parameters an exact match can be made
         block_constructor = self._block.get_make().rsplit('.', 2)[-1]
@@ -235,16 +214,16 @@ class PropsDialog(Gtk.Dialog):
 
         # show docstring(s) extracted from python sources
         for cls_name, docstring in docstrings.iteritems():
-            buffer.insert_with_tags_by_name(pos, cls_name + '\n', 'b')
-            buffer.insert(pos, docstring + '\n\n')
+            buf.insert_with_tags_by_name(pos, cls_name + '\n', 'b')
+            buf.insert(pos, docstring + '\n\n')
         pos.backward_chars(2)
-        buffer.delete(pos, buffer.get_end_iter())
+        buf.delete(pos, buf.get_end_iter())
 
     def _update_generated_code_page(self):
         if not self._code_text_display:
             return  # user disabled code preview
 
-        buffer = self._code_text_display.get_buffer()
+        buf = self._code_text_display.get_buffer()
         block = self._block
         key = block.get_key()
 
@@ -258,31 +237,27 @@ class PropsDialog(Gtk.Dialog):
         def insert(header, text):
             if not text:
                 return
-            buffer.insert_with_tags_by_name(buffer.get_end_iter(), header, 'b')
-            buffer.insert(buffer.get_end_iter(), text)
+            buf.insert_with_tags_by_name(buf.get_end_iter(), header, 'b')
+            buf.insert(buf.get_end_iter(), text)
 
-        buffer.delete(buffer.get_start_iter(), buffer.get_end_iter())
+        buf.delete(buf.get_start_iter(), buf.get_end_iter())
         insert('# Imports\n', '\n'.join(block.get_imports()))
-        if key.startswith('variable'):
+        if block.is_variable:
             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)
 
     def _handle_key_press(self, widget, event):
-        """
-        Handle key presses from the keyboard.
-        Call the ok response when enter is pressed.
-
-        Returns:
-            false to forward the keypress
-        """
-        if (event.keyval == Gdk.KEY_Return and
+        close_dialog = (
+            event.keyval == Gdk.KEY_Return and
             event.get_state() & Gdk.ModifierType.CONTROL_MASK == 0 and
             not isinstance(widget.get_focus(), Gtk.TextView)
-        ):
+        )
+        if close_dialog:
             self.response(Gtk.ResponseType.ACCEPT)
             return True  # handled here
+
         return False  # forward the keypress
 
     def _handle_response(self, widget, response):



reply via email to

[Prev in Thread] Current Thread [Next in Thread]