Skip to content

Commit

Permalink
[pydrake] Deprecate tkinter-using classes (RobotLocomotion#16656)
Browse files Browse the repository at this point in the history
Also remove then from pydrake.all.
Therefore, pydrake no longer depends on python3-tk.
  • Loading branch information
bardkw authored Feb 28, 2022
1 parent 77282be commit 0755b9a
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 21 deletions.
1 change: 1 addition & 0 deletions bindings/pydrake/manipulation/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ drake_py_unittest(
],
deps = [
":simple_ui_py",
"//bindings/pydrake/common/test_utilities:deprecation_py",
"//bindings/pydrake/multibody",
],
)
Expand Down
1 change: 0 additions & 1 deletion bindings/pydrake/manipulation/all.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from .kuka_iiwa import *
from .planner import *
from .schunk_wsg import *
from .simple_ui import *
7 changes: 7 additions & 0 deletions bindings/pydrake/manipulation/simple_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@
PublishEvent,
VectorSystem,
)
from pydrake.common.deprecation import deprecated_callable


@deprecated_callable("pydrake.manipulation.simple_ui.JointSliders has been"
"deprecated in favor of "
"pydrake.multibody.meshcat.JointSliders",
date="2022-06-01")
class JointSliders(VectorSystem):
"""
Provides a simple tcl/tk gui with one slider per joint of the
Expand Down Expand Up @@ -155,6 +160,8 @@ def DoCalcVectorOutput(self, context, unused, unused2, output):
output[self._slider_position_start[i]] = self._slider[i].get()


@deprecated_callable("pydrake.manipulation.simple_ui.SchunkWsgButtons has been"
" deprecated", date="2022-06-01")
class SchunkWsgButtons(LeafSystem):
"""
Adds buttons to open/close the Schunk WSG gripper to an existing Tkinter
Expand Down
16 changes: 9 additions & 7 deletions bindings/pydrake/manipulation/test/simple_ui_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import Tkinter as tk

from pydrake.common import FindResourceOrThrow
from pydrake.common.test_utilities.deprecation import catch_drake_warnings
from pydrake.multibody.plant import MultibodyPlant
from pydrake.multibody.parsing import Parser
from pydrake.systems.framework import BasicVector
Expand All @@ -24,10 +25,10 @@ def test_joint_slider(self):
plant = MultibodyPlant(0.0)
Parser(plant).AddModelFromFile(file_name)
plant.Finalize()

slider = JointSliders(robot=plant, lower_limit=-5., upper_limit=5.,
resolution=0.001, update_period_sec=0.01,
title='test', length=300)
with catch_drake_warnings(expected_count=1):
slider = JointSliders(robot=plant, lower_limit=-5., upper_limit=5.,
resolution=0.001, update_period_sec=0.01,
title='test', length=300)
slider.window.withdraw() # Don't open a window during testing.
context = slider.CreateDefaultContext()
output = slider.AllocateOutput()
Expand All @@ -42,9 +43,10 @@ def test_joint_slider(self):
def test_schunk_wsg_buttons(self):
window = tk.Tk()
window.withdraw() # Don't open a window during testing.
wsg_buttons = SchunkWsgButtons(window, closed_position=0.008,
open_position=0.05, force_limit=50,
update_period_sec=1.0)
with catch_drake_warnings(expected_count=1):
wsg_buttons = SchunkWsgButtons(window, closed_position=0.008,
open_position=0.05, force_limit=50,
update_period_sec=1.0)
context = wsg_buttons.CreateDefaultContext()
output = wsg_buttons.AllocateOutput()

Expand Down
1 change: 1 addition & 0 deletions bindings/pydrake/systems/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ drake_py_unittest(
deps = [
":primitives_py",
":system_sliders_py",
"//bindings/pydrake/common/test_utilities:deprecation_py",
],
)

Expand Down
1 change: 0 additions & 1 deletion bindings/pydrake/systems/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from .rendering import *
from .scalar_conversion import *
from .sensors import *
from .system_sliders import *
from .trajectory_optimization import *

try:
Expand Down
3 changes: 3 additions & 0 deletions bindings/pydrake/systems/system_sliders.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
import numpy as np

from pydrake.systems.framework import (PublishEvent, VectorSystem)
from pydrake.common.deprecation import deprecated_callable


@deprecated_callable("pydrake.systems.system_sliders.SystemSliders has been"
" deprecated", date="2022-06-01")
class SystemSliders(VectorSystem):
"""
Provides a set of tcl/tk-based sliders intended to control the values
Expand Down
25 changes: 16 additions & 9 deletions bindings/pydrake/systems/test/system_sliders_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Tkinter as tk

from pydrake.systems.system_sliders import SystemSliders
from pydrake.common.test_utilities.deprecation import catch_drake_warnings


class TestSystemSliders(unittest.TestCase):
Expand All @@ -17,11 +18,13 @@ def test_multibody_plant_slider(self):
# size of the output port is correct, and appropriate
# errors are thrown for incorrect usage.
port_size = 3
slider = SystemSliders(port_size,
slider_names=["x", "y", "z"], lower_limit=-5.,
upper_limit=[5., 1., 10.], resolution=0.001,
update_period_sec=0.01, title='test',
length=300)
with catch_drake_warnings(expected_count=1):
slider = SystemSliders(port_size,
slider_names=["x", "y", "z"],
lower_limit=-5.,
upper_limit=[5., 1., 10.], resolution=0.001,
update_period_sec=0.01, title='test',
length=300)
slider.window.withdraw() # Don't open a window during testing.
context = slider.CreateDefaultContext()
output = slider.AllocateOutput()
Expand Down Expand Up @@ -66,22 +69,26 @@ def test_multibody_plant_slider(self):
with self.assertRaisesRegex(
ValueError,
r"Slider names size \(2\) doesn't match port size \(3\)"):
SystemSliders(port_size, slider_names=["a", "b"])
with catch_drake_warnings(expected_count=1):
SystemSliders(port_size, slider_names=["a", "b"])

# Incorrect size of passed in lower limits.
with self.assertRaisesRegex(
ValueError,
r"Size of lower_limit \(4\) doesn't match port size \(3\)"):
SystemSliders(port_size, lower_limit=[2, 3, 4, 5])
with catch_drake_warnings(expected_count=1):
SystemSliders(port_size, lower_limit=[2, 3, 4, 5])

# Incorrect size of passed in upper limits.
with self.assertRaisesRegex(
ValueError,
r"Size of upper_limit \(0\) doesn't match port size \(3\)"):
SystemSliders(port_size, upper_limit=[])
with catch_drake_warnings(expected_count=1):
SystemSliders(port_size, upper_limit=[])

# Incorrect size of passed in resolutions.
with self.assertRaisesRegex(
ValueError,
r"Size of resolution \(5\) doesn't match port size \(3\)"):
SystemSliders(port_size, resolution=[1, 2, 3, 4, 5])
with catch_drake_warnings(expected_count=1):
SystemSliders(port_size, resolution=[1, 2, 3, 4, 5])
4 changes: 2 additions & 2 deletions doc/_pages/pip.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ For Ubuntu 18.04, install these additional libraries:

```bash
sudo apt-get install --no-install-recommends \
libpython3.6 python3-tk libx11-6 libsm6 libxt6 libglib2.0-0
libpython3.6 libx11-6 libsm6 libxt6 libglib2.0-0
```

For Ubuntu 20.04, install these additional libraries:

```bash
sudo apt-get install --no-install-recommends \
libpython3.8 python3-tk libx11-6 libsm6 libxt6 libglib2.0-0
libpython3.8 libx11-6 libsm6 libxt6 libglib2.0-0
```

Activate the virtual environment:
Expand Down
2 changes: 1 addition & 1 deletion tools/wheel/test/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apt-get -y update

apt-get -y install --no-install-recommends \
lib${PYTHON}-dev ${PYTHON}-venv \
python3-venv python3-tk \
python3-venv \
libx11-6 libsm6 libxt6 libglib2.0-0

${PYTHON} -m venv /opt/python

0 comments on commit 0755b9a

Please sign in to comment.