def _set_export_file(self): """Set the public export file to something new and return it. The returned Path does not exist as file.""" # prepare mock type(self)._export_to_file = tempfile.mkstemp('.ma')[1] exp_file = Path(self._export_to_file) return exp_file.remove() # just keep the path
def _parse_bookmark(self, bookmark): """:return: root,path tuple or raise""" root, path = None, None if isinstance(bookmark, tuple) and len(bookmark) == 2: root, path = bookmark else: bookmark = Path(bookmark) root = bookmark.root() root_with_sep = (root.endswith(root.sep) and root) or (root + root.sep) path = Path(bookmark.replace(root_with_sep, '', 1)) # END handle bookmark return root, path
def test_base( self ): exp_file = Path(tempfile.mkstemp('.ma')[1]) exp_file.remove() # just keep the path alib = AnimInOutLibrary # export with without any animation fails self.failUnlessRaises(ValueError, alib.export, exp_file, iter(list())) assert not exp_file.isfile() self._assert_no_handles() # something is selected, but there is no animation nstill = nt.Node("cylinderStill") self.failUnlessRaises(ValueError, alib.export, exp_file, (nstill,) ) assert not exp_file.isfile() self._assert_no_handles() # something with keys works fine nani = nt.Node('coneAnimated') alib.export(exp_file, (nani,)) assert exp_file.isfile() self._assert_no_handles() # import from the previous file, use remapping to get the animation onto still object exp_file.remove()
def _on_export(self, sender, *args): """Perform the actual export after gathering UI data""" # NOTE: Ignores timerange for now if not self.nodeselector.uses_selection() and not self.nodeselector.selected_namespaces(): raise ValueError("Please select what to export from the scroll list") # END handle invalid input # GET FILEPATH # on linux, only one filter is possible - it would be good to have a # capable file dialog coming from MRV ( in 2011 maybe just an adapter to # fileDialog2 ) file_path = cmds.fileDialog(mode=1,directoryMask="*.mb") if not file_path: return # END bail out extlist = ( ".ma", ".mb" ) collection = [ p.basename() for p in ui.UI(self.filetype.p_collectionItemArray) ] target_ext = extlist[collection.index(self.filetype.p_select)] file_path = Path(file_path) file_path = file_path.stripext() + target_ext lib.AnimInOutLibrary.export(file_path, self.nodeselector.iter_nodes(asNode=False))
def __init__(self, *args, **kwargs): """Initialize all ui elements :param kwargs: The following keywords are defined * **defaultRoots**: default False, if True, show all roots available on the system.""" num_splits = 1 + (self.t_options is not None) config = (num_splits == 1 and "single") or "vertical%i" % num_splits pane = ui.PaneLayout(configuration=config) pane.p_paneSize = (1, 75, 100) # attach the elements t, b, l, r = self.kSides m = 2 try: pane.p_staticWidthPane = 1 except (RuntimeError, TypeError): # maya >= 2011 pass # END exception handling # populate main pane if pane: if self.t_stack is not None: finder_form = ui.FormLayout() if finder_form: sdc = FrameDecorator("Stack", self.t_stack) self.stack = sdc.layout popup = ui.PopupMenu(markingMenu=True) self._create_stack_menu(popup) fdc = FrameDecorator("Finder", self.t_finder) self.finder = fdc.layout fi, st = fdc, sdc finder_form.setup( attachForm=((fi, t, m), (fi, b, m), (fi, l, m), (st, t, m), (st, b, m), (st, r, m)), attachNone=((st, l)), attachControl=((fi, r, m, st)), ) # END finder form self.setActive() else: self.finder = self.t_finder() # END handle stack # setup RMB menu finder_popup = ui.PopupMenu(markingMenu=True) self._create_finder_menu(finder_popup) # END popupMenu if self.t_options is not None: self.options = self.t_options() # END pane layout self.setActive() # if we have a filter, set it to the finder # FILEPATH ########## fp = self.t_filepath() fp.setEditable(False) self.fpctrl = fp self.finder.url_changed = fp.setPath # BOOKMARKS AND SELECTOR ######################## num_panes = (self.t_bookmarks is not None) + (self.t_root_selector is not None) assert num_panes, "Require at least one bookmark type or a selector type" config = "horizontal%i" % num_panes lpane = ui.PaneLayout(configuration=config) if lpane: self.rootselector, self.bookmarks = None, None if self.t_root_selector: rdc = FrameDecorator("Roots", self.t_root_selector) self.rootselector = rdc.layout self.rootselector.root_changed = self.finder.setProvider if kwargs.get("defaultRoots", False): roots = list() if not sys.platform.startswith("win"): roots.append(Path("/")) else: # just try all accessible drives for letter in string.ascii_uppercase: try: p = Path(letter + ":\\") p.stat() roots.append(p) except OSError: continue # END ignore exceptions # END for each letter # END handle roots if self.t_finder_provider is not None: for rootpath in roots: self.rootselector.addItem(self.t_finder_provider(rootpath)) # END for each rootpath if roots: self.rootselector.setSelectedItem(roots[0]) # END if we have a provider type # END handle default roots # END root selector setup lpane.setActive() if self.t_bookmarks: bdc = FrameDecorator("Bookmarks", self.t_bookmarks) self.bookmarks = bdc.layout self.bookmarks.bookmark_changed = self._on_bookmark_change # BOOKMARK POPUP pmenu = ui.PopupMenu(markingMenu=True) pmenu.e_postMenuCommand = self._build_bookmark_popup # END bookmarks setup # END left pane layout self.setActive() # FILTER ELEMENT ################ assert self.t_filter is not None, "Require filter element, replace it by a dummy filter if it is not required" self.filter = self.t_filter() fil = self.filter self.setActive() # BUTTONS ######### bl = self._create_button_layout() # CONTROL ASSEMBLY ################## self.setup( attachForm=( (fil, t, m), (fil, l, m), (fil, r, m), (lpane, l, m), (lpane, b, m), (pane, r, m), (fp, b, m), (bl, r, m), (bl, b, m), ), attachNone=((fp, t), (lpane, r), (fil, b), (bl, l), (bl, t)), attachControl=( (lpane, t, m, fil), (pane, t, m, fil), (pane, b, m, bl), (pane, l, m, lpane), (fp, l, m, lpane), (fp, r, m, bl), ), )
def fixture_path(name): """:return: full path to fixture with given name""" return Path(__file__).dirname() / "fixtures" / name