[gedit-latex] PanelView: correctly implement it using a GtkBin.



commit eacbbd8c49faf796ab0cc3281c56711d41263c7e
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Sun Oct 9 13:36:50 2011 +0200

    PanelView: correctly implement it using a GtkBin.
    
    Use a GtkBin and implement Gtk.Orientatable. Also this patch converts
    the widgets inheriting from it to use GtkGrid.

 latex/issues.py      |    3 ---
 latex/latex/views.py |   19 +++++++++++++------
 latex/outline.py     |   10 ++++++++--
 latex/panelview.py   |   38 ++++++++++++++++++++++++++++++--------
 latex/tools/views.py |    9 +++++++--
 latex/views.py       |   10 ++++++++--
 6 files changed, 66 insertions(+), 23 deletions(-)
---
diff --git a/latex/issues.py b/latex/issues.py
index d52cfea..62a8561 100644
--- a/latex/issues.py
+++ b/latex/issues.py
@@ -148,7 +148,4 @@ class Issue(object):
     def __str__(self):
         return "Issue{'%s', %s, %s, %s, %s}" % (self.message, self.start, self.end, self.file, self.severity)
 
-
-
-
 # ex:ts=4:et:
diff --git a/latex/latex/views.py b/latex/latex/views.py
index 08451a5..3fd0e33 100644
--- a/latex/latex/views.py
+++ b/latex/latex/views.py
@@ -92,15 +92,20 @@ class LaTeXSymbolMapView(PanelView):
 
         self._preferences = Preferences()
 
+        grid = Gtk.Grid()
+        grid.set_orientation(Gtk.Orientation.VERTICAL)
+        self.add(grid)
+
         scrolled = Gtk.ScrolledWindow()
-        scrolled.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
+        scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
         scrolled.set_shadow_type(Gtk.ShadowType.NONE)
 
-        self._box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
-        self._box.set_vexpand(True)
-        scrolled.add_with_viewport(self._box)
+        self._grid = Gtk.Grid()
+        self._grid.set_orientation(Gtk.Orientation.VERTICAL)
+        scrolled.add_with_viewport(self._grid)
+        scrolled.set_vexpand(True)
 
-        self.add(scrolled)
+        grid.add(scrolled)
         self.show_all()
 
         self._load_collection(SymbolCollection())
@@ -143,6 +148,8 @@ class LaTeXSymbolMapView(PanelView):
         view.show()
 
         expander = Gtk.Expander(label=group.label)
+        expander.set_hexpand(True)
+        expander.set_vexpand(True)
         expander.add(view)
         expander.show_all()
 
@@ -151,7 +158,7 @@ class LaTeXSymbolMapView(PanelView):
 
         expander.connect("notify::expanded", self._on_group_expanded, group.label)
 
-        self._box.pack_start(expander, False, False, 0)
+        self._grid.add(expander)
 
     def _on_group_expanded(self, expander, paramSpec, group_label):
         """
diff --git a/latex/outline.py b/latex/outline.py
index a3286ce..9db46a9 100644
--- a/latex/outline.py
+++ b/latex/outline.py
@@ -48,6 +48,10 @@ class BaseOutlineView(PanelView):
 
         self._preferences = Preferences()
 
+        grid = Gtk.Grid()
+        grid.set_orientation(Gtk.Orientation.VERTICAL)
+        self.add(grid)
+
         # toolbar
 
         btn_follow = Gtk.ToggleToolButton.new_from_stock(Gtk.STOCK_CONNECT)
@@ -71,8 +75,9 @@ class BaseOutlineView(PanelView):
         self._toolbar.insert(btn_expand, -1)
         self._toolbar.insert(btn_collapse, -1)
         self._toolbar.insert(Gtk.SeparatorToolItem(), -1)
+        self._toolbar.set_hexpand(True)
 
-        self.pack_start(self._toolbar, False, True, 0)
+        grid.add(self._toolbar)
 
         # tree view
 
@@ -99,8 +104,9 @@ class BaseOutlineView(PanelView):
         scrolled = Gtk.ScrolledWindow()
         scrolled.add(self._view)
         scrolled.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
+        scrolled.set_vexpand(True)
 
-        self.pack_start(scrolled, True, True, 0)
+        grid.add(scrolled)
 
         # this holds a list of the currently expanded paths
         self._expandedPaths = None
diff --git a/latex/panelview.py b/latex/panelview.py
index e7ab8eb..8fd4090 100644
--- a/latex/panelview.py
+++ b/latex/panelview.py
@@ -20,22 +20,44 @@
 
 import logging
 
-from gi.repository import Gtk
+from gi.repository import GObject, Gtk
 
-LOG = logging.getLogger(__name__)
-
-#FIXME: this should probably be just a Gtk.Orientable iface
-# HORIZONTAL: means Bottom Panel
-# VERTICAL: means Side Panel
-class PanelView(Gtk.Box):
+class PanelView(Gtk.Bin, Gtk.Orientable):
     """
     Base class for a View
     """
 
+    orientation = GObject.property(type=Gtk.Orientation, default=Gtk.Orientation.HORIZONTAL)
+
     def __init__(self, context):
-        Gtk.Box.__init__(self)
+        Gtk.Bin.__init__(self)
         self._context = context
 
+    def _get_size(self, orientation):
+        minimum, maximum = 0, 0
+        child = self.get_child()
+
+        if child is not None and child.get_visible():
+            if orientation == Gtk.Orientation.HORIZONTAL:
+                minimum, maximum = child.get_preferred_width()
+            else:
+                minimum, maximum = child.get_preferred_height()
+
+        return minimum, maximum
+
+    def do_get_preferred_width(self):
+        return self._get_size(Gtk.Orientation.HORIZONTAL)
+
+    def do_get_preferred_height(self):
+        return self._get_size(Gtk.Orientation.VERTICAL)
+
+    def do_size_allocate(self, allocation):
+        Gtk.Bin.do_size_allocate(self, allocation)
+
+        child = self.get_child()
+        if child is not None and child.get_visible():
+            child.size_allocate(allocation)
+
     # these should be overriden by subclasses
 
     # a label string used for this view
diff --git a/latex/tools/views.py b/latex/tools/views.py
index d4c4d9e..d1ebccf 100644
--- a/latex/tools/views.py
+++ b/latex/tools/views.py
@@ -48,6 +48,9 @@ class ToolView(PanelView, IStructuredIssueHandler):
         self._ICON_WARNING = GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("warning.png"))
         self._ICON_ABORT = GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("abort.png"))
 
+        grid = Gtk.Grid()
+        self.add(grid)
+
         self._scroll = Gtk.ScrolledWindow()
         self._scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
         self._scroll.set_shadow_type(Gtk.ShadowType.IN)
@@ -73,8 +76,9 @@ class ToolView(PanelView, IStructuredIssueHandler):
         self._handlers[self._view] = self._view.connect("row-activated", self._on_row_activated)
 
         self._scroll.add(self._view)
+        self._scroll.set_hexpand(True)
 
-        self.pack_start(self._scroll, True, True, 0)
+        grid.add(self._scroll)
 
         # toolbar
 
@@ -94,8 +98,9 @@ class ToolView(PanelView, IStructuredIssueHandler):
         self._toolbar.set_orientation(Gtk.Orientation.VERTICAL)
         self._toolbar.insert(self._button_cancel, -1)
         self._toolbar.insert(self._button_details, -1)
+        self._toolbar.set_vexpand(True)
 
-        self.pack_start(self._toolbar, False, False, 0)
+        grid.add(self._toolbar)
 
         # theme like gtk3
         ctx = self._scroll.get_style_context()
diff --git a/latex/views.py b/latex/views.py
index 25dd246..de8c5af 100644
--- a/latex/views.py
+++ b/latex/views.py
@@ -56,6 +56,9 @@ class IssueView(PanelView):
                         Issue.SEVERITY_INFO : None,
                         Issue.SEVERITY_TASK : GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("task.png")) }
 
+        grid = Gtk.Grid()
+        self.add(grid)
+
         self._store = Gtk.ListStore(GdkPixbuf.Pixbuf, str, str, object)
 
         self._view = Gtk.TreeView(model=self._store)
@@ -86,8 +89,10 @@ class IssueView(PanelView):
         self._scr.add(self._view)
         self._scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
         self._scr.set_shadow_type(Gtk.ShadowType.IN)
+        self._scr.set_hexpand(True)
+        self._scr.set_vexpand(True)
 
-        self.pack_start(self._scr, True, True, 0)
+        grid.add(self._scr)
 
         # toolbar
         self._button_warnings = Gtk.ToggleToolButton()
@@ -112,8 +117,9 @@ class IssueView(PanelView):
         toolbar.set_icon_size(Gtk.IconSize.MENU)
         toolbar.insert(self._button_warnings, -1)
         toolbar.insert(self._button_tasks, -1)
+        toolbar.set_vexpand(True)
 
-        self.pack_start(toolbar, False, False, 0)
+        grid.add(toolbar)
 
         # theme like gtk3
         ctx = self._scr.get_style_context()



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