Repository: beeware/toga

Issue:
Slider and Switch Examples Gives Attribute Errors in Gtk+
## Expected Behavior
Slider example runs in Gtk+. I verified that this runs great in Cocoa.


## Current Behavior
    
    Traceback (most recent call last):
    File "/home/dan/.virtualenvs/toga/lib/python3.6/site-packages/toga_gtk/app.py", line 140, in startup self.interface.startup()
    File "/home/dan/Projects/toga/examples/slider/slider/app.py", line 25, in startup toga.Slider(),
    File "/home/dan/.virtualenvs/toga/lib/python3.6/site-packages/toga/widgets/slider.py", line 24, in __init__ self._impl = self.factory.Slider(interface=self)
    File "/home/dan/.virtualenvs/toga/lib/python3.6/site-packages/toga_gtk/widgets/base.py", line 12, in __init__ self.create()
    File "/home/dan/.virtualenvs/toga/lib/python3.6/site-packages/toga_gtk/widgets/slider.py", line 14, in create self.rehint()
    File "/home/dan/.virtualenvs/toga/lib/python3.6/site-packages/toga_gtk/widgets/slider.py", line 54, in rehint self.interface.style.hint(**hints)
    AttributeError: 'Pack' object has no attribute 'hint'


## Steps to reproduce

    $ cd examples/slider
    $ python -m slider

OR

    $ cd examples/switch
    $ python -m switch

## Your Environment
<!--- Provide details on your current environment you found the bug in -->

* Python Version (list the specific version number)
3.6.3
* Operating System and Version (select from the following and list the specific version number; if your OS is not listed, list that as well)

  - [ ] OSX
  - [ ] Linux
  - [ ] Windows
  - [X] Ubuntu

* Toga Target (the type of app you are trying to generate)
 
  - [ ] android
  - [ ] cocoa
  - [ ] django 
  - [X] gtk
  - [ ] iOS
  - [ ] tvOS
  - [ ] watchOS
  - [ ] winforms 
  - [ ] win32
  - [ ] Other (please specify)



Discussion:

Resolving patch:
diff --git a/examples/slider/slider/app.py b/examples/slider/slider/app.py
--- a/examples/slider/slider/app.py
+++ b/examples/slider/slider/app.py
@@ -11,6 +11,7 @@ def startup(self):
         # set up common styls
         label_style = Pack(flex=1, padding_right=24)
         box_style = Pack(direction=ROW, padding=10)
+        slider_style = Pack(flex=1)
 
         self.sliderValueLabel = toga.Label("slide me", style=label_style)
 
@@ -22,32 +23,32 @@ def startup(self):
                     toga.Label("default Slider -- range is 0 to 1",
                         style=label_style),
 
-                    toga.Slider(),
+                    toga.Slider(style=slider_style),
                 ]),
 
                 toga.Box(style=box_style, children=[
                     toga.Label("on a scale of 1 to 10, how easy is GUI with Toga?",
                         style=label_style),
 
-                    toga.Slider(range=(1, 10), default=10),
+                    toga.Slider(range=(1, 10), default=10, style=Pack(width=150)),
                 ]),
 
                 toga.Box(style=box_style, children=[
                     toga.Label("Sliders can be disabled", style=label_style),
 
-                    toga.Slider(enabled=False),
+                    toga.Slider(enabled=False, style=slider_style),
                 ]),
 
                 toga.Box(style=box_style, children=[
                     toga.Label("give a Slider some style!", style=label_style),
 
-                    toga.Slider(style=Pack(padding=16, width=300))
+                    toga.Slider(style=slider_style)
                 ]),
 
                 toga.Box(style=box_style, children=[
                     self.sliderValueLabel,
 
-                    toga.Slider(on_slide=self.my_on_slide, range=(-40, 58)),
+                    toga.Slider(on_slide=self.my_on_slide, range=(-40, 58), style=slider_style),
                 ]),
             ],
             style=Pack(direction=COLUMN, padding=24)
diff --git a/src/gtk/toga_gtk/widgets/slider.py b/src/gtk/toga_gtk/widgets/slider.py
--- a/src/gtk/toga_gtk/widgets/slider.py
+++ b/src/gtk/toga_gtk/widgets/slider.py
@@ -1,4 +1,5 @@
 from gi.repository import Gtk
+from travertino.size import at_least
 
 from .base import Widget
 
@@ -32,23 +33,12 @@ def set_range(self, range):
         self.adj.set_upper(range[1])
 
     def rehint(self):
-        hints = {}
+        # print("REHINT", self, self.native.get_preferred_width(), self.native.get_preferred_height())
         width = self.native.get_preferred_width()
-        minimum_width = 160
-        natural_width = width[1]
-
         height = self.native.get_preferred_height()
-        minimum_height = height[0]
-        natural_height = height[1]
-
-        if minimum_width > 0:
-            hints['min_width'] = minimum_width
-        if minimum_height > 0:
-            hints['min_height'] = minimum_height
-        if natural_width > 0:
-            hints['width'] = natural_width
-        if natural_height > 0:
-            hints['height'] = natural_height
-
-        if hints:
-            self.interface.style.hint(**hints)
+
+        # Set intrinsic width to at least the minimum width
+        self.interface.intrinsic.width = at_least(width[0])
+        # Set intrinsic height to the natural height
+        self.interface.intrinsic.height = height[1]
+
diff --git a/src/gtk/toga_gtk/widgets/switch.py b/src/gtk/toga_gtk/widgets/switch.py
--- a/src/gtk/toga_gtk/widgets/switch.py
+++ b/src/gtk/toga_gtk/widgets/switch.py
@@ -1,4 +1,5 @@
 from gi.repository import Gtk
+from travertino.size import at_least
 
 from .base import Widget
 
@@ -37,21 +38,11 @@ def set_is_on(self, value):
         self.switch.set_active(value)
 
     def rehint(self):
-        hints = {}
+        # print("REHINT", self, self.native.get_preferred_width(), self.native.get_preferred_height())
         width = self.native.get_preferred_width()
-        minimum_width = width[0]
-        natural_width = width[1]
-
         height = self.native.get_preferred_height()
-        minimum_height = height[0]
-        natural_height = height[1]
-
-        if minimum_width > 0:
-            hints['min_width'] = minimum_width
-        if minimum_height > 0:
-            hints['min_height'] = minimum_height
-        if natural_height > 0:
-            hints['height'] = natural_height
-
-        if hints:
-            self.interface.style.hint(**hints)
+
+        # Set intrinsic width to at least the minimum width
+        self.interface.intrinsic.width = at_least(width[0])
+        # Set intrinsic height to the natural height
+        self.interface.intrinsic.height = height[1]


Test patch: