mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-27 06:12:19 +01:00
adding a Qt lockfile dialog for lockfile tasks
This commit is contained in:
parent
365a90c3c1
commit
f6792d2e42
4 changed files with 74 additions and 36 deletions
|
|
@ -480,6 +480,7 @@ def on_before_save():
|
|||
|
||||
|
||||
def check_lock_on_current_file():
|
||||
|
||||
"""Check if there is a user opening the file"""
|
||||
if not handle_workfile_locks():
|
||||
return
|
||||
|
|
@ -492,23 +493,15 @@ def check_lock_on_current_file():
|
|||
create_workfile_lock(filepath)
|
||||
return
|
||||
|
||||
username = get_user_from_lock(filepath)
|
||||
reminder = cmds.window(title="Reminder", width=400, height=30)
|
||||
cmds.columnLayout(adjustableColumn=True)
|
||||
cmds.separator()
|
||||
cmds.columnLayout(adjustableColumn=True)
|
||||
comment = " %s is working the same workfile!" % username
|
||||
cmds.text(comment, align='center')
|
||||
cmds.text(vis=False)
|
||||
cmds.rowColumnLayout(numberOfColumns=3,
|
||||
columnWidth=[(1, 200), (2, 100), (3, 100)],
|
||||
columnSpacing=[(3, 10)])
|
||||
cmds.separator(vis=False)
|
||||
cancel_command = "cmds.file(new=True);cmds.deleteUI('%s')" % reminder
|
||||
ignore_command = "cmds.deleteUI('%s')" % reminder
|
||||
cmds.button(label='Cancel', command=cancel_command)
|
||||
cmds.button(label="Ignore", command=ignore_command)
|
||||
cmds.showWindow(reminder)
|
||||
# add lockfile dialog
|
||||
from Qt import QtWidgets
|
||||
from openpype.tools.workfiles.lock_dialog import WorkfileLockDialog
|
||||
|
||||
top_level_widgets = {w.objectName(): w for w in
|
||||
QtWidgets.QApplication.topLevelWidgets()}
|
||||
parent = top_level_widgets.get("MayaWindow", None)
|
||||
workfile_dialog = WorkfileLockDialog(filepath, parent=parent)
|
||||
workfile_dialog.show()
|
||||
|
||||
|
||||
def on_before_close():
|
||||
|
|
|
|||
|
|
@ -26,6 +26,11 @@ def is_workfile_locked(filepath):
|
|||
return True
|
||||
|
||||
|
||||
def get_workfile_lock_data(filepath):
|
||||
lock_filepath = _get_lock_file(filepath)
|
||||
return _read_lock_file(lock_filepath)
|
||||
|
||||
|
||||
def is_workfile_locked_for_current_process(filepath):
|
||||
if not is_workfile_locked(filepath):
|
||||
return False
|
||||
|
|
@ -49,15 +54,6 @@ def create_workfile_lock(filepath):
|
|||
json.dump(info, stream)
|
||||
|
||||
|
||||
def get_user_from_lock(filepath):
|
||||
lock_filepath = _get_lock_file(filepath)
|
||||
if not os.path.exists(lock_filepath):
|
||||
return
|
||||
data = _read_lock_file(lock_filepath)
|
||||
username = data["username"]
|
||||
return username
|
||||
|
||||
|
||||
def remove_workfile_lock(filepath):
|
||||
if is_workfile_locked_for_current_process(filepath):
|
||||
delete_workfile_lock(filepath)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ from openpype.host import IWorkfileHost
|
|||
from openpype.client import get_asset_by_id
|
||||
from openpype.pipeline.workfile.lock_workfile import (
|
||||
is_workfile_locked,
|
||||
get_user_from_lock,
|
||||
is_workfile_lock_enabled,
|
||||
is_workfile_locked_for_current_process
|
||||
)
|
||||
|
|
@ -20,6 +19,7 @@ from openpype.lib import (
|
|||
emit_event,
|
||||
create_workdir_extra_folders,
|
||||
)
|
||||
from openpype.tools.workfiles.lock_dialog import WorkfileLockDialog
|
||||
from openpype.pipeline import (
|
||||
registered_host,
|
||||
legacy_io,
|
||||
|
|
@ -30,6 +30,7 @@ from openpype.pipeline.context_tools import (
|
|||
change_current_context
|
||||
)
|
||||
from openpype.pipeline.workfile import get_workfile_template_key
|
||||
from openpype.tools.workfiles.lock_dialog import WorkfileLockDialog
|
||||
|
||||
from .model import (
|
||||
WorkAreaFilesModel,
|
||||
|
|
@ -468,15 +469,8 @@ class FilesWidget(QtWidgets.QWidget):
|
|||
def open_file(self, filepath):
|
||||
host = self.host
|
||||
if self._is_workfile_locked(filepath):
|
||||
username = get_user_from_lock(filepath)
|
||||
popup_dialog = QtWidgets.QMessageBox(parent=self)
|
||||
popup_dialog.setWindowTitle("Warning")
|
||||
popup_dialog.setText(username + " is using the file")
|
||||
popup_dialog.setStandardButtons(popup_dialog.Ok)
|
||||
|
||||
result = popup_dialog.exec_()
|
||||
if result == popup_dialog.Ok:
|
||||
return False
|
||||
# add lockfile dialog
|
||||
WorkfileLockDialog(filepath, parent=self)
|
||||
|
||||
if isinstance(host, IWorkfileHost):
|
||||
has_unsaved_changes = host.workfile_has_unsaved_changes()
|
||||
|
|
|
|||
55
openpype/tools/workfiles/lock_dialog.py
Normal file
55
openpype/tools/workfiles/lock_dialog.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
from Qt import QtWidgets, QtCore, QtGui
|
||||
from openpype.style import load_stylesheet, get_app_icon_path
|
||||
|
||||
from openpype.pipeline.workfile.lock_workfile import get_workfile_lock_data
|
||||
|
||||
|
||||
class WorkfileLockDialog(QtWidgets.QDialog):
|
||||
def __init__(self, workfile_path, parent=None):
|
||||
super(WorkfileLockDialog, self).__init__(parent)
|
||||
self.setWindowTitle("Warning")
|
||||
icon = QtGui.QIcon(get_app_icon_path())
|
||||
self.setWindowIcon(icon)
|
||||
|
||||
data = get_workfile_lock_data(workfile_path)
|
||||
|
||||
message = "{} on {} machine is working on the same workfile.".format(
|
||||
data["username"],
|
||||
data["hostname"]
|
||||
)
|
||||
|
||||
msg_label = QtWidgets.QLabel(message, self)
|
||||
|
||||
btns_widget = QtWidgets.QWidget(self)
|
||||
|
||||
cancel_btn = QtWidgets.QPushButton("Cancel", btns_widget)
|
||||
ignore_btn = QtWidgets.QPushButton("Ignore lock", btns_widget)
|
||||
|
||||
btns_layout = QtWidgets.QHBoxLayout(btns_widget)
|
||||
btns_layout.setContentsMargins(0, 0, 0, 0)
|
||||
btns_layout.setSpacing(10)
|
||||
btns_layout.addStretch(1)
|
||||
btns_layout.addWidget(cancel_btn, 0)
|
||||
btns_layout.addWidget(ignore_btn, 0)
|
||||
|
||||
main_layout = QtWidgets.QVBoxLayout(self)
|
||||
main_layout.setContentsMargins(15, 15, 15, 15)
|
||||
main_layout.addWidget(msg_label, 1, QtCore.Qt.AlignCenter),
|
||||
main_layout.addSpacing(10)
|
||||
main_layout.addWidget(btns_widget, 0)
|
||||
|
||||
cancel_btn.clicked.connect(self._on_cancel_click)
|
||||
ignore_btn.clicked.connect(self._on_ignore_click)
|
||||
|
||||
def showEvent(self, event):
|
||||
super(WorkfileLockDialog, self).showEvent(event)
|
||||
|
||||
self.setStyleSheet(load_stylesheet())
|
||||
|
||||
def _on_ignore_click(self):
|
||||
# Result is '1'
|
||||
self.accept()
|
||||
|
||||
def _on_cancel_click(self):
|
||||
# Result is '0'
|
||||
self.reject()
|
||||
Loading…
Add table
Add a link
Reference in a new issue