formatting changes

This commit is contained in:
iLLiCiTiT 2021-01-06 13:06:55 +01:00
parent 489cad80fd
commit ad92cb8fcd
2 changed files with 42 additions and 52 deletions

View file

@ -429,9 +429,11 @@ class FilesWidget(QtWidgets.QWidget):
"""Return a modified session for the current asset and task""" """Return a modified session for the current asset and task"""
session = api.Session.copy() session = api.Session.copy()
changes = pipeline.compute_session_changes(session, changes = pipeline.compute_session_changes(
asset=self._asset, session,
task=self._task) asset=self._asset,
task=self._task
)
session.update(changes) session.update(changes)
return session return session
@ -440,9 +442,11 @@ class FilesWidget(QtWidgets.QWidget):
"""Enter the asset and task session currently selected""" """Enter the asset and task session currently selected"""
session = api.Session.copy() session = api.Session.copy()
changes = pipeline.compute_session_changes(session, changes = pipeline.compute_session_changes(
asset=self._asset, session,
task=self._task) asset=self._asset,
task=self._task
)
if not changes: if not changes:
# Return early if we're already in the right Session context # Return early if we're already in the right Session context
# to avoid any unwanted Task Changed callbacks to be triggered. # to avoid any unwanted Task Changed callbacks to be triggered.
@ -454,13 +458,12 @@ class FilesWidget(QtWidgets.QWidget):
host = self.host host = self.host
if host.has_unsaved_changes(): if host.has_unsaved_changes():
result = self.save_changes_prompt() result = self.save_changes_prompt()
if result is None: if result is None:
# Cancel operation # Cancel operation
return False return False
# Save first if has changes
if result: if result:
current_file = host.current_file() current_file = host.current_file()
if not current_file: if not current_file:
# If the user requested to save the current scene # If the user requested to save the current scene
@ -474,17 +477,12 @@ class FilesWidget(QtWidgets.QWidget):
# Save current scene, continue to open file # Save current scene, continue to open file
host.save_file(current_file) host.save_file(current_file)
else:
# Don't save, continue to open file
pass
self._enter_session() self._enter_session()
host.open_file(filepath) host.open_file(filepath)
self.window().close() self.window().close()
def save_changes_prompt(self): def save_changes_prompt(self):
self._messagebox = QtWidgets.QMessageBox() self._messagebox = messagebox = QtWidgets.QMessageBox()
messagebox = self._messagebox
messagebox.setWindowFlags(QtCore.Qt.FramelessWindowHint) messagebox.setWindowFlags(QtCore.Qt.FramelessWindowHint)
messagebox.setIcon(messagebox.Warning) messagebox.setIcon(messagebox.Warning)
@ -502,13 +500,11 @@ class FilesWidget(QtWidgets.QWidget):
messagebox.setStyleSheet(style.load_stylesheet()) messagebox.setStyleSheet(style.load_stylesheet())
result = messagebox.exec_() result = messagebox.exec_()
if result == messagebox.Yes: if result == messagebox.Yes:
return True return True
elif result == messagebox.No: elif result == messagebox.No:
return False return False
else: return None
return None
def get_filename(self): def get_filename(self):
"""Show save dialog to define filename for save or duplicate """Show save dialog to define filename for save or duplicate
@ -519,24 +515,22 @@ class FilesWidget(QtWidgets.QWidget):
""" """
session = self._get_session() session = self._get_session()
window = NameWindow(parent=self, window = NameWindow(
root=self.root, parent=self,
session=session) root=self.root,
session=session
)
window.exec_() window.exec_()
return window.get_result() return window.get_result()
def on_duplicate_pressed(self): def on_duplicate_pressed(self):
work_file = self.get_filename() work_file = self.get_filename()
if not work_file: if not work_file:
return return
src = self._get_selected_filepath() src = self._get_selected_filepath()
dst = os.path.join( dst = os.path.join(self.root, work_file)
self.root, work_file
)
shutil.copy(src, dst) shutil.copy(src, dst)
self.refresh() self.refresh()
@ -553,7 +547,6 @@ class FilesWidget(QtWidgets.QWidget):
return index.data(model.FilePathRole) return index.data(model.FilePathRole)
def on_open_pressed(self): def on_open_pressed(self):
path = self._get_selected_filepath() path = self._get_selected_filepath()
if not path: if not path:
print("No file selected to open..") print("No file selected to open..")
@ -562,26 +555,23 @@ class FilesWidget(QtWidgets.QWidget):
self.open_file(path) self.open_file(path)
def on_browse_pressed(self): def on_browse_pressed(self):
ext_filter = "Work File (*{0})".format(
filter = " *".join(self.host.file_extensions()) " *".join(self.host.file_extensions())
filter = "Work File (*{0})".format(filter) )
kwargs = { kwargs = {
"caption": "Work Files", "caption": "Work Files",
"filter": filter "filter": ext_filter
} }
if Qt.__binding__ in ("PySide", "PySide2"): if Qt.__binding__ in ("PySide", "PySide2"):
kwargs["dir"] = self.root kwargs["dir"] = self.root
else: else:
kwargs["directory"] = self.root kwargs["directory"] = self.root
work_file = QtWidgets.QFileDialog.getOpenFileName(**kwargs)[0] work_file = QtWidgets.QFileDialog.getOpenFileName(**kwargs)[0]
if work_file:
if not work_file: self.open_file(work_file)
return
self.open_file(work_file)
def on_save_as_pressed(self): def on_save_as_pressed(self):
work_file = self.get_filename() work_file = self.get_filename()
if not work_file: if not work_file:
return return
@ -592,8 +582,9 @@ class FilesWidget(QtWidgets.QWidget):
self.initialize_work_directory() self.initialize_work_directory()
if not os.path.exists(self.root): if not os.path.exists(self.root):
# Failed to initialize Work Directory # Failed to initialize Work Directory
log.error("Failed to initialize Work Directory: " log.error(
"%s", self.root) "Failed to initialize Work Directory: {}".format(self.root)
)
return return
file_path = os.path.join(self.root, work_file) file_path = os.path.join(self.root, work_file)
@ -616,9 +607,11 @@ class FilesWidget(QtWidgets.QWidget):
# Inputs (from the switched session and running app) # Inputs (from the switched session and running app)
session = api.Session.copy() session = api.Session.copy()
changes = pipeline.compute_session_changes(session, changes = pipeline.compute_session_changes(
asset=self._asset, session,
task=self._task) asset=self._asset,
task=self._task
)
session.update(changes) session.update(changes)
# Prepare documents to get workdir data # Prepare documents to get workdir data
@ -647,11 +640,9 @@ class FilesWidget(QtWidgets.QWidget):
self.model.refresh() self.model.refresh()
if self.auto_select_latest_modified: if self.auto_select_latest_modified:
tools_lib.schedule(self._select_last_modified_file, tools_lib.schedule(self._select_last_modified_file, 100)
100)
def on_context_menu(self, point): def on_context_menu(self, point):
view = self.widgets["list"] view = self.widgets["list"]
index = view.indexAt(point) index = view.indexAt(point)
if not index.isValid(): if not index.isValid():
@ -679,7 +670,6 @@ class FilesWidget(QtWidgets.QWidget):
def _select_last_modified_file(self): def _select_last_modified_file(self):
"""Utility function to select the file with latest date modified""" """Utility function to select the file with latest date modified"""
role = self.model.DateModifiedRole role = self.model.DateModifiedRole
view = self.widgets["list"] view = self.widgets["list"]
model = view.model() model = view.model()
@ -773,7 +763,6 @@ class Window(QtWidgets.QMainWindow):
tools_lib.schedule(self._on_asset_changed, 50, channel="mongo") tools_lib.schedule(self._on_asset_changed, 50, channel="mongo")
def set_context(self, context): def set_context(self, context):
if "asset" in context: if "asset" in context:
asset = context["asset"] asset = context["asset"]
asset_document = io.find_one( asset_document = io.find_one(

View file

@ -1,10 +1,10 @@
import os import os
import logging import logging
from avalon import style
from Qt import QtCore from Qt import QtCore
from avalon.vendor import qtawesome
from avalon import style
from avalon.vendor import qtawesome
from avalon.tools.models import TreeModel, Item from avalon.tools.models import TreeModel, Item
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -71,18 +71,19 @@ class FilesModel(TreeModel):
extensions = self._file_extensions extensions = self._file_extensions
for f in os.listdir(root): for filename in os.listdir(root):
path = os.path.join(root, f) path = os.path.join(root, filename)
if os.path.isdir(path): if os.path.isdir(path):
continue continue
if extensions and os.path.splitext(f)[1] not in extensions: ext = os.path.splitext(filename)[1]
if extensions and ext not in extensions:
continue continue
modified = os.path.getmtime(path) modified = os.path.getmtime(path)
item = Item({ item = Item({
"filename": f, "filename": filename,
"date": modified, "date": modified,
"filepath": path "filepath": path
}) })