mrv.maya.ui.browse.util
Covered: 17 lines
Missed: 32 lines
Skipped 15 lines
Percent: 34 %
 2
"""Contains misc utiltiies"""
 3
__docformat__ = "restructuredtext"
 5
import mrv.maya
 6
import mrv.maya.ui as ui
 8
def concat_url(root, path):
 9
	if not root.endswith("/"):
10
		root += "/"
11
	return root + path
13
def handleUnsavedModifications():
14
	"""Ask the user whether he wants to handle his unsaved modifications.
15
	This may cause the current file to be saved, or the modifications to be 
16
	discarded.
17
	:return: True if the changes have been handled properly, or False if the 
18
		caller should not proceed"""
19
	if not mrv.maya.Scene.isModified():
20
		return True
22
	save = "Save and Proceed"
23
	abort = "Cancel"
24
	discard = "Discard Modifications"
25
	msg = "The currently loaded scene contains unsaved modifications.\n"
26
	msg += "Would you like to discard them, or save the scene before proceeding ?"
27
	answer = ui.ChoiceDialog(	t="Unsaved Modifications",
28
								m=msg, 
29
								c=[save, discard, abort],
30
								dc=save,
31
								cc=abort).choice()
33
	if answer == save:
34
		if mrv.maya.Scene.name().endswith("untitled"):
35
			import layout
36
			import maya.cmds
37
			maya.cmds.layoutDialog(ui=lambda *args: layout.FileSaveFinder(defaultRoots=True))
40
			if mrv.maya.Scene.name().endswith("untitled"):
41
				return False
43
		mrv.maya.Scene.save()
44
	elif answer == discard:
45
		mrv.maya.Scene.new(force=True)
46
	else:
47
		return False
50
	return True
53
class FrameDecorator(ui.FrameLayout):
54
	"""A simple helper to wrap a box around a layout or control."""
55
	def __new__(cls, name, layoutCreator):
56
		"""Provide the name of the decorator, which will be wrapped around the layoutCreator, 
57
		which will be called to create the layout. It will be kept and mayde availale 
58
		through the 'layout' member, the currently available layout will not be changed."""
59
		self = super(FrameDecorator, cls).__new__(cls, label=name, borderStyle="etchedOut")
60
		self.layout = layoutCreator()
61
		self.setParentActive();
62
		return self