Skip to content

Commit

Permalink
Merge pull request OpenShot#4656 from OpenShot/include-toolbar-in-freeze
Browse files Browse the repository at this point in the history
Freeze and unfreeze toolbar along with other windows.
  • Loading branch information
ferdnyc authored Feb 7, 2022
2 parents fb549e8 + f22fea3 commit 502a7d4
Showing 1 changed file with 45 additions and 35 deletions.
80 changes: 45 additions & 35 deletions src/windows/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@
import os
import shutil
import webbrowser
import functools
from copy import deepcopy
from time import sleep
from uuid import uuid4

import openshot # Python module for libopenshot (required video editing module installed separately)
from PyQt5.QtCore import (
Qt, pyqtSignal, QCoreApplication, PYQT_VERSION_STR,
Qt, pyqtSignal, pyqtSlot, QCoreApplication, PYQT_VERSION_STR,
QTimer, QDateTime, QFileInfo, QUrl,
)
from PyQt5.QtGui import QIcon, QCursor, QKeySequence, QTextCursor
Expand Down Expand Up @@ -2060,37 +2061,41 @@ def showDocks(self, docks):
# Only show correctly docked widgets
dock.show()

def freezeDocks(self):
""" Freeze all dockable widgets on the main screen
(prevent them being closed, floated, or moved) """
for dock in self.getDocks():
if self.dockWidgetArea(dock) != Qt.NoDockWidgetArea:
dock.setFeatures(QDockWidget.NoDockWidgetFeatures)

def unFreezeDocks(self):
""" Un-freeze all dockable widgets on the main screen
(allow them to be closed, floated, or moved, as appropriate) """
for dock in self.getDocks():
if self.dockWidgetArea(dock) != Qt.NoDockWidgetArea:
if dock is self.dockTimeline:
dock.setFeatures(
QDockWidget.DockWidgetFloatable
| QDockWidget.DockWidgetMovable)
else:
dock.setFeatures(
QDockWidget.DockWidgetClosable
| QDockWidget.DockWidgetFloatable
| QDockWidget.DockWidgetMovable)
def freezeDock(self, dock, frozen=True):
""" Freeze/unfreeze a dock widget on the main screen."""
if self.dockWidgetArea(dock) == Qt.NoDockWidgetArea:
# Don't freeze undockable widgets
return
if frozen:
dock.setFeatures(QDockWidget.NoDockWidgetFeatures)
else:
features = (
QDockWidget.DockWidgetFloatable
| QDockWidget.DockWidgetMovable)
if dock is not self.dockTimeline:
features |= QDockWidget.DockWidgetClosable
dock.setFeatures(features)

@pyqtSlot()
def freezeMainToolBar(self, frozen=None):
"""Freeze/unfreeze the toolbar if it's attached to the window."""
if frozen is None:
frozen = self.docks_frozen
floating = self.toolBar.isFloating()
log.debug(
"%s main toolbar%s",
"freezing" if frozen and not floating else "unfreezing",
" (floating)" if floating else "")
if floating:
self.toolBar.setMovable(True)
else:
self.toolBar.setMovable(not frozen)

def addViewDocksMenu(self):
""" Insert a Docks submenu into the View menu """
_ = get_app()._tr

# self.docks_menu = self.createPopupMenu()
# self.docks_menu.setTitle(_("Docks"))
# self.menuView.addMenu(self.docks_menu)
self.docks_menu = self.menuView.addMenu(_("Docks"))

for dock in sorted(self.getDocks(), key=lambda d: d.windowTitle()):
if (dock.features() & QDockWidget.DockWidgetClosable
!= QDockWidget.DockWidgetClosable):
Expand Down Expand Up @@ -2174,14 +2179,18 @@ def actionAdvanced_View_trigger(self):

def actionFreeze_View_trigger(self):
""" Freeze all dockable widgets on the main screen """
self.freezeDocks()
for dock in self.getDocks():
self.freezeDock(dock, frozen=True)
self.freezeMainToolBar(frozen=True)
self.actionFreeze_View.setVisible(False)
self.actionUn_Freeze_View.setVisible(True)
self.docks_frozen = True

def actionUn_Freeze_View_trigger(self):
""" Un-Freeze all dockable widgets on the main screen """
self.unFreezeDocks()
for dock in self.getDocks():
self.freezeDock(dock, frozen=False)
self.freezeMainToolBar(frozen=False)
self.actionFreeze_View.setVisible(True)
self.actionUn_Freeze_View.setVisible(False)
self.docks_frozen = False
Expand Down Expand Up @@ -2428,11 +2437,9 @@ def load_settings(self):
if s.get('window_state_v2'):
self.saved_state = qt_types.str_to_bytes(s.get('window_state_v2'))
if s.get('docks_frozen'):
# Freeze all dockable widgets on the main screen
self.freezeDocks()
self.actionFreeze_View.setVisible(False)
self.actionUn_Freeze_View.setVisible(True)
self.docks_frozen = True
self.actionFreeze_View_trigger()
else:
self.actionUn_Freeze_View_trigger()

# Load Recent Projects
self.load_recent_menu()
Expand All @@ -2450,7 +2457,6 @@ def load_recent_menu(self):
recent_projects = s.get("recent_projects")

# Add Recent Projects menu (after Open File)
import functools
if not self.recent_menu:
# Create a new recent menu
self.recent_menu = self.menuFile.addMenu(
Expand Down Expand Up @@ -2890,7 +2896,7 @@ def __init__(self, *args):
# Init UI
ui_util.init_ui(self)

# Setup toolbars that aren't on main window, set initial state of items, etc
# Create dock toolbars, set initial state of items, etc
self.setup_toolbars()

# Add window as watcher to receive undo/redo status updates
Expand Down Expand Up @@ -3059,6 +3065,10 @@ def __init__(self, *args):
self.SelectionAdded.connect(self.addSelection)
self.SelectionRemoved.connect(self.removeSelection)

# Ensure toolbar is movable when floated (even with docks frozen)
self.toolBar.topLevelChanged.connect(
functools.partial(self.freezeMainToolBar, None))

# Show window
self.show()

Expand Down

0 comments on commit 502a7d4

Please sign in to comment.