Skip to content

Merge Context Manager + Work Files (Fix #412) #442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Feb 17, 2020

Conversation

BigRoy
Copy link
Collaborator

@BigRoy BigRoy commented Sep 10, 2019

This is a work in progress implementation for issue #412 that describes to merge the Context Manager and Work Files tool into one single tool that handles both, as usually the actions performed with these happen in relation to each other.

What's changed?

  • The refactoring code is now written into the work files tool. I haven't removed the Context Manager yet (WIP)
  • I've also started to refactor the code for the work files app.py according to the contribution guidelines, however I think this will introduce quite some discussion and pointers on how to improve - as such I'm opening this PR In an early stage to ensure as much as possible this can be discussed and I can improve it as needed.
  • The current implementation works roughly similar to what was described here.

Note: This is a work-in-progress and I'm opening a PR to kickstart a discussion on code style, but I'm fully aware this is not as clean as it can be. However, even at this stage, code style ideas or notes according to the contribution guidelines are very welcome.

Note 2: I've added some todos that are more notes to self as I'm developing and changing some minor things purely for testing/development sake. Feel free to be captain obvious and point out if you have questions - just wanted to highlight that many are reminders to myself.

@BigRoy BigRoy self-assigned this Sep 10, 2019
Copy link
Collaborator

@davidlatwe davidlatwe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a quick glance, the code style seems quite good :)

@mkolar
Copy link
Member

mkolar commented Sep 17, 2019

Just realised that I commented on the issue rather than here. So for completeness here's clarification on my early comments #412 (comment)

@tokejepsen
Copy link
Collaborator

Have recently been using the Context Switcher more, and I immediately go to the Workfiles app afterwards, so merging the two would make it very streamlined.

@BigRoy
Copy link
Collaborator Author

BigRoy commented Dec 15, 2019

I've been recently fiddling with the Work Files API to allow the tool to list the files even without requiring to switch the context prior to it. Admittedly it's a bit hacky, especially with the root dir in Maya being dependent of the workspace.mel.

Anyway, in the end it seemed to be fast and work quite well. I think from there it's a matter of cleaning up and simplifying again.

I hope to share some bits of it in about two or three days as my schedule this week is quite busy. Just wanted to let you know I am back on this PR.

@jasperges
Copy link
Contributor

@BigRoy That's awesome! This would also help in adopting 'Allzparkalon'. And like @tokejepsen is saying: most of the time when you switch context you open the Workfiles app anyways.

@BigRoy
Copy link
Collaborator Author

BigRoy commented Dec 16, 2019

Here's a preview of the latest functionality:
avalon_workfiles_merged_simple_gif

Download zipped .mp4: avalon_workfiles_merged_simple.zip

The little log window at the bottom is Maya's script editor and is not part of the Work Files UI.

To-do:

  • Prior to save/open the Session should first be set to ensure it's switched prior to open/save automatically.
  • Set Context functionality: Double clicking the Task sets the context manually (forcing it) - I want to make that clear by having a "Breadcrumb" of sorts at the top of the UI showing the selected Asset/Task and color coding that e.g. orange when it is not the currently active Session context, if that's the case... behind that I'll add two buttons, one for "Setting the context" (like double clicking the task does now) and one for "Go to current context" that will browse back to your current active api.Session context. The buttons will be disabled when they are redundant (e.g. go to current context will be disabled when you're already there) and "set context" is disabled when you're already in the context. Then browsing should make this self-explanatory and the tooltips of the buttons can aid in that as well.
  • Initialize workdir: In the case when an Host has never been initialized to a specific asset+task the Workdir does not exist. What should happen then is to perform the App initialization to make sure it's setup like the studio config intended. When browsing to a non-initialized Work Directory I want the most right-widget to be swapped with a message saying "No work directory exist" with a "Initialize Work directory" button underneath. Currently performing this "App Initialize" is non-trivial yet a hacky method for it can be found here. What would be the best way to improve this?

Any first thoughts are more than welcome.

@tokejepsen
Copy link
Collaborator

Looks good!

Initialize Work directory might sound a bit too techy/cody. Maybe Create work area

@davidlatwe
Copy link
Collaborator

I like the ideas in #489, will they get implemented in this PR, or in another one ?

How about adding a "New" button, so there should be pretty much what artists will do when they open up context manager. Then I think we won't need double clicking to set context and the Breadcrumb.

@BigRoy
Copy link
Collaborator Author

BigRoy commented Dec 16, 2019

How about adding a "New" button, so there should be pretty much what artists will do when they open up context manager. Then I think we won't need double clicking to set context and the Breadcrumb.

@davidlatwe Sorry I'm not sure I get what you mean.

Whenever you launch the host it should have already initialized the current application. Or at least that is what Avalon currently does as it launches the host. So for the current context you would never have to "create work area" since it already exists. It would by default just show an empty folder on the right hand side. Where I'd want to add a single non-selectable greyed out entry in the list stating: "No files. Use Save As to save your first file."

The tricky thing is that as soon as you click on another Asset or Task you're operating in an area that is not related to you active Context/Session. Previously it came up that there could be reasons to force yourself into the workspace context, even without Saving/Opening a file there which @mkolar mentioned before. It would basically be, setting that context and doing some work prior to saving there if I understood correctly. Exactly that is what the "buttons" would allow, to if you want set the context. However, in most scenarios I assume an Artist doesn't care and will just open the scene (which will always first ensure the context is set appropriately).

@davidlatwe
Copy link
Collaborator

Ah, I meant "New" for set context + open new scene.

I assume that one would open up the tool only for following cases :

  1. Changing work space to start something new.
  2. Changing work space to open up old scene.
  3. Save the file, but change work space if other asset/task selected on save.

So if there's a "New" button for opening new scene, I think there wouldn't need double clicking to set context and the Breadcrumb.

And in the end, I think artist will no need to be aware of the concept of "context" when using this tool as long as there's only "New", "Open", "Save" these there buttons being presented.

# Conflicts:
#	avalon/tools/workfiles/app.py

Note this changes the fix from getavalon#465 to not store the widgets as explicit variables but by setting the parent widget
@@ -39,11 +39,10 @@ def current_file():
return current_filepath


def work_root():
from avalon import Session
def work_root(session):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each Work files API now requires session for the work_root to be able to compute the Work Root for a non-active Session object (e.g. not api.Session)

changes["AVALON_SILO"] = asset_document["silo"]

# Update hierarchy
parents = asset_document['data'].get('parents', [])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code has moved and fixes a BUG where previously if asset had not changed with the call then asset_document would not have been a set variable.

@@ -926,61 +926,103 @@ def get_representation_context(representation):
return context


def update_current_task(task=None, asset=None, app=None):
"""Update active Session to a new task work area.
def compute_session_changes(session, task=None, asset=None, app=None):
Copy link
Collaborator Author

@BigRoy BigRoy Dec 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made this a new function to compute the changes to the current session required to become a new valid session. Before we only had update_current_task which did the same but would always change the active session. That computing of the required changes is now moved to this separate function.

We might want to come up with a better name and maybe expose it in the API?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or not expose compute_session_changes in API, but add a new arg called dry_run=False to update_current_task ?

If dry_run set to True, then return early without update.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And maybe need to add one more internal arg called _changes=None to update_current_task, so we can pass the changes that returned from compute_session_changes into update_current_task to avoid double work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dry_run argument does sound like a decent alternative to having this in a separate function. @mkolar @mottosso any preference on this one? Separate functions like this or make one and add dry_run argument?

I'm not too big a fan of adding the _changes internal argument. It seems like a premature optimization that for now seemingly adds redundant complexity.


# Update silo and hierarchy when asset changed
if asset:
if isinstance(asset, dict):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has now additionally been allowed to be passed a database document for an asset as opposed to only working by its name. This allows to avoid the additional query to the database.

Comment on lines 759 to 760
# Refresh breadcrumbs
#self.widgets["header"].set_session(session)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabled widget, see comments above.

Comment on lines +807 to +809
def show(root=None, debug=False, parent=None, use_context=True):
"""Show Work Files GUI"""
# todo: remove `root` argument to show()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since now the Work Files tool can browse to different assets and tasks setting an explicit root makes no sense, since the root is computed based on asset/task work root.

As such, we can remove the root argument. Should we preserve this for API compatibility?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pop a warning if root in kwargs ?

@BigRoy
Copy link
Collaborator Author

BigRoy commented Dec 17, 2019

With 7ad657a I've pushed the new prototype functionality. It's not flawless yet but it works to some extent.

I've tried to comment on most of the important/big changes or odd choices above. Hope that helps reviewing what's there so far.

Regarding earlier TODO:

  • Prior to save/open the Session should first be set to ensure it's switched prior to open/save automatically. Should be done!
  • Set Context functionality: TODO
  • Initialize workdir: TODO

There's a lot to potentially check:

@BigRoy BigRoy requested a review from davidlatwe December 17, 2019 20:22
@jasperges
Copy link
Contributor

I'm also not a user, but I think it's a good thing it has been removed, because I don't think it's ever needed to switch the context without loading or saving a work file. (Although we probably have the need to publish several character rigs from one base rig. So inside the file we have to run the Creator for different assets... but that is an exception, not the rule.)
I think it's a good idea to show the current context somewhere, but inside a menu feels like the wrong place for that. Not sure where it should go, though...

@tokejepsen
Copy link
Collaborator

Just tested this out myself and it works nicely!

One question did pop up. If there arent any task assigned to the asset, you wont be able to save a workfile, so you would have to open the project manager to create one.
Maybe its taking too much responsibility on, but should the user be able to create tasks on assets through this UI?

@jasperges
Copy link
Contributor

Personally I don't think so. I think most of the time this is not something an artist should do (a production manager/coordinator should do this or automated from Shotgun/FTrack/Kitsu) and definitely not in the workfiles app.

Just my two cents.

@BigRoy
Copy link
Collaborator Author

BigRoy commented Feb 12, 2020

So, does this mean it's ready to merge? 🔥🚀

Or is the Hound still an issue? Since I see a red ❌ on the checks.

@tokejepsen
Copy link
Collaborator

So, does this mean it's ready to merge?

Except for the hound violations?

@BigRoy
Copy link
Collaborator Author

BigRoy commented Feb 12, 2020

Except for the hound violations?

Was just editing my comment to state that, yes. I can't seem to find the open Hound violations...

Had another look.. I think the Hound violations are still the "Black would make changes" errors that should be ignored as per #506 / #510

@tokejepsen
Copy link
Collaborator

Ahh, fair enough. Ready to merge!

@davidlatwe
Copy link
Collaborator

But what about the context label ? :O

I can agree that context label is not good to be in side the menu, but it's a place that work for most of the DCC hosts for now to indicate current context, right ?

@tokejepsen
Copy link
Collaborator

How about changing the window title?

@davidlatwe
Copy link
Collaborator

How about changing the window title?

That did cross my mind but should be in a separate issue/PR to discuss.

Anyway, if t's just me, then maybe it's okay to be merged. Either add back context label as a normal menu item, or merge it as is, both work for me now. ☺️

Still, IMHO, deprecating context manager with new workfile App is one thing, removing context indicator altogether is another, so I think this kind of UI change should be brought up earlier. 💡

@iLLiCiTiT
Copy link
Contributor

I've tried to add not enabled action item to menu PR: BigRoy#5

@BigRoy
Copy link
Collaborator Author

BigRoy commented Feb 13, 2020

Still, IMHO, deprecating context manager with new workfile App is one thing, removing context indicator altogether is another, so I think this kind of UI change should be brought up earlier.

Totally agree that these shouldn't be taken lightly. I just envisioned that to be part of it and assumed the discussion was already debating that too.

Anyway, shall we include BigRoy#5 and then open an additional issue to track any better ways to approach that @davidlatwe ?

@davidlatwe
Copy link
Collaborator

Anyway, shall we include BigRoy#5 and then open an additional issue to track any better ways to approach that @davidlatwe ?

That would be great :D

Just pulled and tested that branch, and only require one tiny fix and good to go for me !

@iLLiCiTiT
Copy link
Contributor

Just pulled and tested that branch, and only require one tiny fix and good to go for me !

Just pulled fix. Can you check please?

@davidlatwe
Copy link
Collaborator

Perfect !! 🚀

added context item to avalon menu
@BigRoy
Copy link
Collaborator Author

BigRoy commented Feb 13, 2020

Ready for take-off!

@jasperges
Copy link
Contributor

jasperges commented Feb 13, 2020

I've set AVALON_SCENEDIR to 'scenes' for Maya. But using this new workfiles app, I get an error when initializing the work directory (that doesn't exist yet). I've add default_dirs = ["scenes"] to the maya.toml, but still no luck. The 'base' directory is created, but the scenes directory is missing.

So I do get <project_root>/assets/character/batman/rigging/work/maya, but not <project_root>/assets/character/batman/rigging/work/maya/scenes.

Am I missing something?

@davidlatwe
Copy link
Collaborator

davidlatwe commented Feb 13, 2020

If you are using Avalon Launcher, maybe you need to head back to first page or restart the launcher so the environment vars get updated from those .toml change. 🤔

@iLLiCiTiT
Copy link
Contributor

Just realized small detail... Will that context label change on context change?

@davidlatwe
Copy link
Collaborator

Yeah, it did change in my test, and still does.

@davidlatwe
Copy link
Collaborator

@jasperges is everything working there now ?

@jasperges
Copy link
Contributor

@davidlatwe On Monday I can check again. I don't have access to Maya at home. Will let you know.

@jasperges
Copy link
Contributor

@davidlatwe All is good! I still have some small issues, but I'm pretty sure that's because of the Avalon configuration. So, go, go, go! 🚀

@davidlatwe
Copy link
Collaborator

Merging this !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants