Skip to content

Commit

Permalink
canvasmain: Remove optional scheme margins
Browse files Browse the repository at this point in the history
Does not conform to standard guidelines, wastes space and the implementation is ugly.
  • Loading branch information
ales-erjavec committed Jul 16, 2024
1 parent fb8501a commit 16d5be1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 108 deletions.
109 changes: 2 additions & 107 deletions orangecanvas/application/canvasmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
QWhatsThisClickedEvent, QShowEvent, QCloseEvent
)
from AnyQt.QtCore import (
Qt, QObject, QEvent, QSize, QUrl, QByteArray, QFileInfo,
Signal, Qt, QObject, QEvent, QSize, QUrl, QByteArray, QFileInfo,
QSettings, QStandardPaths, QAbstractItemModel, QMimeData, QT_VERSION)

try:
Expand All @@ -41,11 +41,6 @@
except ImportError:
QWebView = None # type: ignore


from AnyQt.QtCore import (
pyqtProperty as Property, pyqtSignal as Signal
)

from ..scheme import Scheme, IncompatibleChannelTypeError, SchemeNode
from ..scheme import readwrite
from ..scheme.readwrite import UnknownWidgetDefinition
Expand Down Expand Up @@ -98,25 +93,6 @@ def user_documents_path():
return QStandardPaths.writableLocation(QStandardPaths.DocumentsLocation)


class FakeToolBar(QToolBar):
"""A Toolbar with no contents (used to reserve top and bottom margins
on the main window).
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setFloatable(False)
self.setMovable(False)

# Don't show the tool bar action in the main window's
# context menu.
self.toggleViewAction().setVisible(False)

def paintEvent(self, event):
# Do nothing.
pass


class DockWidget(QDockWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -134,8 +110,6 @@ class CanvasMainWindow(QMainWindow):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.__scheme_margins_enabled = True
self.__document_title = "untitled"
self.__first_show = True
self.__is_transient = True
Expand Down Expand Up @@ -180,28 +154,10 @@ def __init__(self, *args, **kwargs):
def setup_ui(self):
"""Setup main canvas ui
"""
# Two dummy tool bars to reserve space
self.__dummy_top_toolbar = FakeToolBar(
objectName="__dummy_top_toolbar")
self.__dummy_bottom_toolbar = FakeToolBar(
objectName="__dummy_bottom_toolbar")

self.__dummy_top_toolbar.setFixedHeight(20)
self.__dummy_bottom_toolbar.setFixedHeight(20)

self.addToolBar(Qt.TopToolBarArea, self.__dummy_top_toolbar)
self.addToolBar(Qt.BottomToolBarArea, self.__dummy_bottom_toolbar)

self.setCorner(Qt.BottomLeftCorner, Qt.LeftDockWidgetArea)
self.setCorner(Qt.BottomRightCorner, Qt.RightDockWidgetArea)

self.setDockOptions(QMainWindow.AnimatedDocks)
# Create an empty initial scheme inside a container with fixed
# margins.
w = QWidget()
w.setLayout(QVBoxLayout())
w.layout().setContentsMargins(20, 0, 10, 0)

self.scheme_widget = SchemeEditWidget()
self.scheme_widget.setDropHandlers([interactions.PluginDropHandler(),])
self.set_scheme(config.workflow_constructor(parent=self))
Expand All @@ -214,9 +170,7 @@ def setup_ui(self):
self.scheme_widget.setAcceptDrops(True)
self.scheme_widget.view().viewport().installEventFilter(dropfilter)

w.layout().addWidget(self.scheme_widget)

self.setCentralWidget(w)
self.setCentralWidget(self.scheme_widget)

# Drop shadow around the scheme document
frame = DropShadowFrame(radius=15)
Expand Down Expand Up @@ -341,9 +295,6 @@ def setup_ui(self):
self.dock_widget.expandedChanged.connect(self._on_tool_dock_expanded)

self.addDockWidget(Qt.LeftDockWidgetArea, self.dock_widget)
self.dock_widget.dockLocationChanged.connect(
self._on_dock_location_changed
)

self.output_dock = DockWidget(
self.tr("Log"), self, objectName="output-dock",
Expand Down Expand Up @@ -599,15 +550,6 @@ def config_url_action(action, role):
# TODO: This is bad (should be moved here).
self.dock_help_action = None

self.toogle_margins_action = QAction(
self.tr("Show Workflow Margins"), self,
checkable=True,
toolTip=self.tr("Show margins around the workflow view."),
)
self.toogle_margins_action.setChecked(True)
self.toogle_margins_action.toggled.connect(
self.set_scheme_margins_enabled)

self.float_widgets_on_top_action = QAction(
self.tr("Display Widgets on Top"), self,
checkable=True,
Expand Down Expand Up @@ -720,7 +662,6 @@ def setup_menu(self):
sep = self.view_menu.addSeparator()
sep.setObjectName("view-zoom-actions-separator")

self.view_menu.addAction(self.toogle_margins_action)
menu_bar.addMenu(self.view_menu)

# Options menu
Expand Down Expand Up @@ -787,9 +728,6 @@ def restore(self):
settings.value("toolbox-dock-exclusive", False, type=bool)
)

self.toogle_margins_action.setChecked(
settings.value("scheme-margins-enabled", False, type=bool)
)
self.show_output_action.setChecked(
settings.value("output-dock/is-visible", False, type=bool))

Expand Down Expand Up @@ -961,39 +899,6 @@ def on_quick_category_action(self, action):

self.dock_widget.expand()

def set_scheme_margins_enabled(self, enabled):
# type: (bool) -> None
"""Enable/disable the margins around the scheme document.
"""
if self.__scheme_margins_enabled != enabled:
self.__scheme_margins_enabled = enabled
self.__update_scheme_margins()

def _scheme_margins_enabled(self):
# type: () -> bool
return self.__scheme_margins_enabled

scheme_margins_enabled: bool
scheme_margins_enabled = Property( # type: ignore
bool, _scheme_margins_enabled, set_scheme_margins_enabled)

def __update_scheme_margins(self):
"""Update the margins around the scheme document.
"""
enabled = self.__scheme_margins_enabled
self.__dummy_top_toolbar.setVisible(enabled)
self.__dummy_bottom_toolbar.setVisible(enabled)
central = self.centralWidget()

margin = 20 if enabled else 0

if self.dockWidgetArea(self.dock_widget) == Qt.LeftDockWidgetArea:
margins = (margin // 2, 0, margin, 0)
else:
margins = (margin, 0, margin // 2, 0)

central.layout().setContentsMargins(*margins)

def is_transient(self):
# type: () -> bool
"""
Expand Down Expand Up @@ -2292,13 +2197,6 @@ def _on_recent_scheme_action(self, action):
filename = str(action.data())
self.open_scheme_file(filename)

def _on_dock_location_changed(self, location):
# type: (Qt.DockWidgetArea) -> None
"""Location of the dock_widget has changed, fix the margins
if necessary.
"""
self.__update_scheme_margins()

def set_tool_dock_expanded(self, expanded):
# type: (bool) -> None
"""
Expand Down Expand Up @@ -2358,9 +2256,6 @@ def closeEvent(self, event):
settings.setValue("state", state)
settings.setValue("canvasdock/expanded",
self.dock_widget.expanded())
settings.setValue("scheme-margins-enabled",
self.scheme_margins_enabled)

settings.setValue("widgettoolbox/state",
self.widgets_tool_box.saveState())

Expand Down
1 change: 0 additions & 1 deletion orangecanvas/application/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def test_create_new_window(self):
w.show()
new.show()

w.set_scheme_margins_enabled(True)
new.deleteLater()
stream = TextStream()
w.connect_output_stream(stream)
Expand Down

0 comments on commit 16d5be1

Please sign in to comment.