Skip to content

Commit

Permalink
Move traitsui.qt4 to traitsui.qt (#2004)
Browse files Browse the repository at this point in the history
Also updates imports etc. This means that we need Pyface 8.0 or greater.
  • Loading branch information
corranwebster authored Apr 6, 2023
1 parent 2e224d6 commit 3a6fb75
Show file tree
Hide file tree
Showing 137 changed files with 268 additions and 182 deletions.
1 change: 1 addition & 0 deletions .github/actions/install-qt-support/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ runs:
sudo apt-get install libxcb-render-util0
sudo apt-get install libxcb-xinerama0
sudo apt-get install libxcb-shape0
sudo apt-get install libxcb-cursor0
sudo apt-get install pulseaudio
sudo apt-get install libpulse-mainloop-glib0
# Needed to work around https://bugreports.qt.io/browse/PYSIDE-1547
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-with-edm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

name: Test with EDM

on: [pull_request, workflow_dispatch]
on: [workflow_dispatch]

env:
INSTALL_EDM_VERSION: 3.5.0
Expand Down
2 changes: 1 addition & 1 deletion docs/source/traitsui_user_manual/adapters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ The Qt backend allows users to completely override the rendering of cells in
a TreeEditor. To do this, the TreeNode should override the
:py:meth:`TreeNode.get_renderer` method to return an instance of a
subclass of :py:class:`~traitsui.tree_node_renderer.AbstractTreeNodeRenderer`.
A :py:class:`~traitsui.qt4.tree_node_renderers.WordWrapRenderer` is available
A :py:class:`~traitsui.qt.tree_node_renderers.WordWrapRenderer` is available
to provide basic word-wrapped layout in a cell, but user-defined subclasses
can do any rendering that they want by implementing their own
:py:class:`~traitsui.tree_node_renderer.AbstractTreeNodeRenderer` subclass.
Expand Down
6 changes: 3 additions & 3 deletions ets-demo/etstool.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@
BUNDLE_NAME = f"etsdemo-{APP_BUNDLE_VERSION}.bundle"

environment_vars = {
'pyside2': {'ETS_TOOLKIT': 'qt4', 'QT_API': 'pyside2'},
'pyside6': {'ETS_TOOLKIT': 'qt4', 'QT_API': 'pyside6'},
'pyqt5': {"ETS_TOOLKIT": "qt4", "QT_API": "pyqt5"},
'pyside2': {'ETS_TOOLKIT': 'qt', 'QT_API': 'pyside2'},
'pyside6': {'ETS_TOOLKIT': 'qt', 'QT_API': 'pyside6'},
'pyqt5': {"ETS_TOOLKIT": "qt", "QT_API": "pyqt5"},
'wx': {'ETS_TOOLKIT': 'wx'},
'null': {'ETS_TOOLKIT': 'null'},
}
Expand Down
13 changes: 6 additions & 7 deletions etstool.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@

# Required runtime dependencies. Should match pyproject.toml.
dependencies = {
# temporarily get pyface from pip until EDM release
# "pyface>=7.4.1",
"pyface>=8.0",
"traits",
"setuptools",
}
Expand Down Expand Up @@ -192,16 +191,16 @@

#: Paths to ignore in Sphinx-apidoc
doc_ignore = {
"traitsui/qt4/*",
"traitsui/qt/*",
"traitsui/wx/*",
"*/tests",
}

environment_vars = {
'pyside2': {'ETS_TOOLKIT': 'qt', 'QT_API': 'pyside2'},
'pyside6': {'ETS_TOOLKIT': 'qt', 'QT_API': 'pyside6'},
'pyqt5': {"ETS_TOOLKIT": "qt", "QT_API": "pyqt5"},
'pyqt6': {"ETS_TOOLKIT": "qt", "QT_API": "pyqt6"},
'pyside2': {'ETS_TOOLKIT': 'qt4', 'QT_API': 'pyside2'},
'pyside6': {'ETS_TOOLKIT': 'qt4', 'QT_API': 'pyside6'},
'pyqt5': {"ETS_TOOLKIT": "qt4", "QT_API": "pyqt5"},
'pyqt6': {"ETS_TOOLKIT": "qt4", "QT_API": "pyqt6"},
'wx': {'ETS_TOOLKIT': 'wx'},
'null': {'ETS_TOOLKIT': 'null'},
}
Expand Down
2 changes: 1 addition & 1 deletion image_LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ traitsui/extras/images:
reload.png | Nuvola
run.png | Nuvola

traitsui/qt4/images:
traitsui/qt/images:
closetab.png | Qt
next.png | Qt
previous.png | Qt
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ classifiers = [
]
dependencies = [
'traits>=6.2',
'pyface>=7.4.1',
'pyface>=8.0',
'importlib-metadata>=3.6; python_version<"3.8"',
]
license = {file = "LICENSE.txt"}
version = "8.0.0.dev0"

[project.entry-points.'traitsui.toolkits']
qt = 'traitsui.qt4:toolkit'
qt4 = 'traitsui.qt4:toolkit'
qt = 'traitsui.qt:toolkit'
qt4 = 'traitsui.qt:toolkit'
wx = 'traitsui.wx:toolkit'
null = 'traitsui.null:toolkit'

Expand Down Expand Up @@ -70,6 +70,6 @@ traitsui = [
'image/library/*.zip',
'images/*',
'wx/images/*',
'qt4/images/*',
'qt/images/*',
'testing/data/*',
]
2 changes: 1 addition & 1 deletion traitsui/examples/demo/Advanced/Date_range_editor_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _date_range_changed(self):


if __name__ == "__main__":
if ETSConfig.toolkit == "qt4":
if ETSConfig.toolkit in {"qt", "qt4"}:
# DateRangeEditor is currently only available for qt backend.
demo = DateRangeEditorDemo()
demo.configure_traits()
2 changes: 1 addition & 1 deletion traitsui/examples/demo/Advanced/String_list_ui_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
if ETSConfig.toolkit == 'wx':
from traitsui.wx.ui_editor import UIEditor
else:
from traitsui.qt4.ui_editor import UIEditor
from traitsui.qt.ui_editor import UIEditor


# -- Define the reusable StringListEditor class and its helper classes --------
Expand Down
2 changes: 1 addition & 1 deletion traitsui/examples/demo/Advanced/Tabular_editor_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def _get_MarriedPerson_spouse_text(self):
adapter=ReportAdapter(),
operations=['move', 'edit'],
# Row titles are not supported in WX:
show_row_titles=ETSConfig.toolkit == 'qt4',
show_row_titles=(ETSConfig.toolkit in {"qt", "qt4"}),
)


Expand Down
2 changes: 1 addition & 1 deletion traitsui/examples/demo/Extras/LED_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
if ETSConfig.toolkit == 'wx':
from traitsui.wx.extra.led_editor import LEDEditor
else:
from traitsui.qt4.extra.led_editor import LEDEditor
from traitsui.qt.extra.led_editor import LEDEditor

# Handler class for the LEDDemo class view:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from traitsui.api import TreeEditor, TreeNode, UItem, View, RGBColor
from traitsui.tree_node_renderer import AbstractTreeNodeRenderer
from traitsui.qt4.tree_editor import WordWrapRenderer
from traitsui.qt.tree_editor import WordWrapRenderer


class MyDataElement(HasTraits):
Expand Down
2 changes: 1 addition & 1 deletion traitsui/extras/checkbox_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
if ETSConfig.toolkit == "wx":
from pyface.ui.wx.grid.checkbox_renderer import CheckboxRenderer
elif ETSConfig.toolkit in {"qt", "qt4"}:
from ..qt4.extra.checkbox_renderer import CheckboxRenderer
from ..qt.extra.checkbox_renderer import CheckboxRenderer
else:
raise NotImplementedError("No checkbox renderer for backend")

Expand Down
2 changes: 1 addition & 1 deletion traitsui/mimedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
# Import the toolkit specific version.
from traitsui.toolkit import toolkit_object

# WIP: Currently only supports qt4 backend. API might change without
# WIP: Currently only supports qt backend. API might change without
# prior notification
PyMimeData = toolkit_object("clipboard:PyMimeData")
38 changes: 38 additions & 0 deletions traitsui/qt/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# (C) Copyright 2008-2023 Enthought, Inc., Austin, TX
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!

# ------------------------------------------------------------------------------
# Copyright (c) 2007, Riverbank Computing Limited
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD license.
# However, when used with the GPL version of PyQt the additional terms
# described in the PyQt GPL exception also apply

#
# Author: Riverbank Computing Limited
# ------------------------------------------------------------------------------

""" Defines the concrete implementations of the traits Toolkit interface for
the PyQt user interface toolkit.
"""

# import pyface.qt before anything else is done so the sipapi
# can be set correctly if needed
import pyface.qt

# ----------------------------------------------------------------------------
# Define the reference to the exported GUIToolkit object:
# ----------------------------------------------------------------------------

from . import toolkit

# Reference to the GUIToolkit object for Qt.
toolkit = toolkit.GUIToolkit("traitsui", "qt", "traitsui.qt")
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 1 addition & 4 deletions traitsui/qt4/clipboard.py → traitsui/qt/clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
"""

from pyface.qt import QtGui
try:
from pyface.ui.qt.mimedata import PyMimeData, str2bytes
except ModuleNotFoundError:
from pyface.ui.qt4.mimedata import PyMimeData, str2bytes
from pyface.ui.qt.mimedata import PyMimeData, str2bytes
from traits.api import HasTraits, Instance, Property


Expand Down
5 changes: 1 addition & 4 deletions traitsui/qt4/code_editor.py → traitsui/qt/code_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@

from pyface.qt import QtGui
from pyface.key_pressed_event import KeyPressedEvent
try:
from pyface.ui.qt.code_editor.code_widget import AdvancedCodeWidget
except ModuleNotFoundError:
from pyface.ui.qt4.code_editor.code_widget import AdvancedCodeWidget
from pyface.ui.qt.code_editor.code_widget import AdvancedCodeWidget
from traits.api import (
Str,
List,
Expand Down
14 changes: 7 additions & 7 deletions traitsui/qt4/color_editor.py → traitsui/qt/color_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
# The PyQt ToolkitEditorFactory class.
# ---------------------------------------------------------------------------

## We need to add qt4-specific methods to the editor factory (since all editors
## We need to add qt-specific methods to the editor factory (since all editors
## will be accessing these functions. Making these functions global functions
## in this file does not work quite well, since we want custom editors to
## override these methods easily.
Expand All @@ -55,14 +55,14 @@
class ToolkitEditorFactory(BaseToolkitEditorFactory):
"""PyQt editor factory for color editors."""

def to_qt4_color(self, editor):
def to_qt_color(self, editor):
"""Gets the PyQt color equivalent of the object trait."""
if self.mapped:
return getattr(editor.object, editor.name + "_")

return getattr(editor.object, editor.name)

def from_qt4_color(self, color):
def from_qt_color(self, color):
"""Gets the application equivalent of a PyQt value."""
return color

Expand Down Expand Up @@ -95,7 +95,7 @@ class SimpleColorEditor(BaseSimpleEditor):

def popup_editor(self):
"""Invokes the pop-up editor for an object trait."""
color = self.factory.to_qt4_color(self)
color = self.factory.to_qt_color(self)
options = QtGui.QColorDialog.ColorDialogOption.ShowAlphaChannel
if not self.factory.use_native_dialog:
options |= QtGui.QColorDialog.ColorDialogOption.DontUseNativeDialog
Expand All @@ -104,7 +104,7 @@ def popup_editor(self):
)

if color.isValid():
self.value = self.factory.from_qt4_color(color)
self.value = self.factory.from_qt_color(color)
self.update_editor()

def update_editor(self):
Expand Down Expand Up @@ -144,7 +144,7 @@ def update_editor(self):
def update_object_from_swatch(self, color_text):
"""Updates the object trait when a color swatch is clicked."""
color = QtGui.QColor(*[int(part) for part in color_text.split(",")])
self.value = self.factory.from_qt4_color(color)
self.value = self.factory.from_qt_color(color)
self.update_editor()

def string_value(self, color):
Expand Down Expand Up @@ -205,7 +205,7 @@ def string_value(self, color):

def set_color(editor):
"""Sets the color of the specified color control."""
color = editor.factory.to_qt4_color(editor)
color = editor.factory.to_qt_color(editor)
pal = QtGui.QPalette(editor.control.palette())

pal.setColor(QtGui.QPalette.ColorRole.Base, color)
Expand Down
4 changes: 2 additions & 2 deletions traitsui/qt4/color_trait.py → traitsui/qt/color_trait.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ def convert_to_color(object, name, value):
# -------------------------------------------------------------------------

### FIXME: We have declared the 'editor' to be a function instead of the
# traitsui.qt4.color_editor.ToolkitEditorFactory class, since the
# traitsui.qt.color_editor.ToolkitEditorFactory class, since the
# latter is leading to too many circular imports. In the future, try to see if
# there is a better way to do this.


def get_color_editor(*args, **traits):
from traitsui.qt4.color_editor import ToolkitEditorFactory
from traitsui.qt.color_editor import ToolkitEditorFactory

return ToolkitEditorFactory(*args, **traits)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions traitsui/qt4/drop_editor.py → traitsui/qt/drop_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def init(self, parent):
drop_event_filter = _DropEventFilter(self.control)
self.control.installEventFilter(drop_event_filter)

self.control._qt4_editor = self
self.control._qt_editor = self

def dispose(self):
"""Disposes of the content of an editor."""
Expand Down Expand Up @@ -92,7 +92,7 @@ def eventFilter(self, source, event):

def dropEvent(self, e):
"""Handles a Python object being dropped on the tree."""
editor = self.parent()._qt4_editor
editor = self.parent()._qt_editor

klass = editor.factory.klass

Expand All @@ -119,7 +119,7 @@ def dropEvent(self, e):

def dragEnterEvent(self, e):
"""Handles a Python object being dragged over the tree."""
editor = self.parent()._qt4_editor
editor = self.parent()._qt_editor

if editor.factory.binding:
data = getattr(clipboard, "node", None)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from traits.api import Float, Any, Str, Union

from traitsui.editors.api import RangeEditor
from traitsui.qt4.editor import Editor
from traitsui.qt4.extra.range_slider import RangeSlider
from traitsui.qt.editor import Editor
from traitsui.qt.extra.range_slider import RangeSlider


class _BoundsEditor(Editor):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pyface.qt import QtCore, QtGui

# ETS imports
from traitsui.qt4.table_editor import TableDelegate
from traitsui.qt.table_editor import TableDelegate


class CheckboxRenderer(TableDelegate):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# Thanks for using Enthought open source!

from pyface.qt import QtGui
from traitsui.qt4.editor import Editor
from traitsui.qt.editor import Editor
from traitsui.basic_editor_factory import BasicEditorFactory
from traits.api import Any, Undefined

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from pyface.qt import QtCore, QtGui

# ETS imports
from traitsui.qt4.table_editor import TableDelegate
from traitsui.qt.table_editor import TableDelegate


class ProgressRenderer(TableDelegate):
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# ETS imports
from traits.api import Bool
from traitsui.qt4.table_editor import TableDelegate
from traitsui.qt.table_editor import TableDelegate


class TableImageRenderer(TableDelegate):
Expand Down
File renamed without changes.
Loading

0 comments on commit 3a6fb75

Please sign in to comment.