def record(upload_after_creation = None, play_after_creation = None, show_success_msg = True): # This a wrapper function and if called individually should mirror all the same effect as hitting 'record' in the UI recordData = {} capturedFile = _record() #Reencode to quicktime logger.info("capturedFile: {}".format(capturedFile)) recordData["playblast_file"] = video.encodeToH264Mov( capturedFile, output_file=capturedFile[:-4] + ".mov") logger.info("reencoded File: {}".format(recordData["playblast_file"])) # Post actions # To Do - post Recording script call if upload_after_creation is None: upload_after_creation = True if database.read_cache('ps_upload_after_creation_checkBox') == 'true' else False if play_after_creation is None: play_after_creation = True if database.read_cache('ps_play_after_creation_checkBox') == 'true' else False open_after_creation = True if database.read_cache('ps_open_afterUpload_checkBox') == 'true' else False if upload_after_creation: uploaded_item = upload(open_after_upload = open_after_creation) recordData["uploaded_item"] = uploaded_item else: if play_after_creation: play(recordData["playblast_file"]) return recordData
def record(upload_after_creation=None, play_after_creation=None, show_success_msg=True): # This a wrapper function and if called individually should mirror all the same effect as hitting 'record' in the UI recordData = {} recordData["playblast_file"] = _record() # Post actions # To Do - post Recording script call # Upload to the selected review or playground if the box is checked if upload_after_creation is None: upload_after_creation = True if database.read_cache( 'ps_upload_after_creation_checkBox') == 'true' else False if play_after_creation is None: play_after_creation = True if database.read_cache( 'ps_play_after_creation_checkBox') == 'true' else False open_after_creation = True if database.read_cache( 'ps_open_afterUpload_checkBox') == 'true' else False if upload_after_creation: uploaded_item = upload(open_after_upload=open_after_creation) recordData["uploaded_item"] = uploaded_item else: if play_after_creation: play(recordData["playblast_file"]) return recordData
def get_InOutFrames(type = 'Time Slider'): ''' Get Frame Range from maya ''' in_out = [] if type == r"Highlighted": slider = mel.eval('$tmpVal=$gPlayBackSlider') in_out = cmds.timeControl(slider, query=True, rangeArray = True) in_out[1] = in_out[1]-1 elif type == r"Start / End": in_out.append(cmds.playbackOptions(q=True, minTime = True)) in_out.append(cmds.playbackOptions(q=True, maxTime = True)) elif type == r"Time Slider": in_out.append(cmds.playbackOptions(q=True, animationStartTime = True)) in_out.append(cmds.playbackOptions(q=True, animationEndTime = True)) elif type == r"Current Frame": cf = cmds.currentTime(query=True) in_out = [cf,cf] else: start_frame = database.read_cache('frame_start') end_frame = database.read_cache('frame_end') in_out = [start_frame, end_frame] try: in_out = [str(int(val)) for val in in_out] except: pass return in_out
def __init__(self, parent=None): super(DownloadWindow, self).__init__(parent=parent) self.decorate_ui() self.align_to_center(self.parent) current_user = user.SyncSketchUser() self.ui.review_target_url.editingFinished.connect(self.editingFinished) self.media_id = None if not current_user.is_logged_in(): logger.info("Please Login to syncsketch to Download content") return try: target_media_id = int(database.read_cache('target_media_id')) logger.info("target_media_id: {}".format(target_media_id)) except Exception as e: logger.info(e) cmds.warning( "No target media selected, please select an item from the UI") return self.item_data = current_user.get_item_info( int(database.read_cache('target_media_id')))['objects'][0] review_id = database.read_cache('target_review_id') media_id = database.read_cache('target_media_id') target_url = database.read_cache('upload_to_value') thumb_url = current_user.get_item_info( media_id)['objects'][0]['thumbnail_url'] self.ui.review_target_url.setText(target_url) self.ui.thumbnail_pushButton.set_icon_from_url(thumb_url) self.ui.review_target_name.setText(self.item_data['name'])
def download(current_user=None): if not current_user: current_user = user.SyncSketchUser() review_id = database.read_cache('target_review_id') media_id = database.read_cache('target_media_id') logger.info("current_user: %s" % current_user) logger.info("target_review_id: %s" % review_id) logger.info("target_media_id: %s" % media_id) return current_user.download_greasepencil(review_id, media_id)
def rename_preset(self): title = 'Renaming Preset' message = 'Please choose a name for this preset.' old_preset_name = self.ui.ui_formatPreset_comboBox.currentText() new_preset_name, response = QtWidgets.QInputDialog.getText( self, "Rename this preset", "Please enter a new Name:", QtWidgets.QLineEdit.Normal, old_preset_name) if not new_preset_name: logger.info("No new preset name specified") return preset_file = path.get_config_yaml(PRESET_YAML) current_preset_names = database._parse_yaml(preset_file).keys() if new_preset_name in current_preset_names: title = 'Error Renaming' message = 'It appears this name already exists.' WarningDialog(self, title, message) return logger.info("Rename Preset from {} to {}".format( old_preset_name, new_preset_name)) database.rename_key_in_cache(old_preset_name, new_preset_name, preset_file) if database.read_cache("current_preset") == old_preset_name: self._update_current_preset(new_preset_name) self.populate_ui() self.ui.ui_formatPreset_comboBox.set_combobox_index( selection=new_preset_name)
def new_viewport_preset(cache_file, preset_name=None, source_preset=None, panel=None): preset_data = database._parse_yaml(cache_file) if not preset_data: preset_data = {} existing_keys = preset_data.keys() if source_preset and source_preset in existing_keys: options = database.read_cache(source_preset, cache_file) if not preset_name: preset_name = 'Copy of ' + source_preset else: if not panel: panel = get_active_editor() options = capture.parse_view(panel) if not preset_name or preset_name in existing_keys: logger.info('key exists') preset_name = create_unique_name(existing_keys, new_key = preset_name, suffix = 'Preset') logger.info(preset_name) if not options: options = capture.parse_view(panel) else: preset_data[preset_name] = options logger.info("preset_name %s" + preset_name) preset_data[preset_name] = options database.dump_cache(preset_data, cache_file) return preset_name
def upload(open_after_upload=None, show_success_msg=False): logger.info("open_after_upload Url: {}".format(open_after_upload)) uploaded_item = _upload() if not uploaded_item: return if open_after_upload is None: open_after_upload = True if database.read_cache( 'ps_open_afterUpload_checkBox') == 'true' else False if open_after_upload: url = path.make_url_offlineMode(uploaded_item['reviewURL']) logger.info("Url: {}".format(url)) logger.info("Uploaded Item: {}".format(uploaded_item)) logger.info("Opening Url: {}".format(uploaded_item['reviewURL'])) webbrowser.open(url, new=2, autoraise=True) if not open_after_upload: logger.info("uploaded_item: {}".format(uploaded_item)) show_success_message( path.make_url_offlineMode(uploaded_item['reviewURL'])) return uploaded_item
def downloadVideo(current_user=None, media_id=None): if not current_user: current_user = user.SyncSketchUser() media_id = media_id or database.read_cache('target_media_id') logger.info("current_user: %s" % current_user) logger.info("target_media_id: %s" % media_id) return current_user.download_converted_video(media_id)
def cycle_viewport_presets(): cache = path.get_config_yaml(VIEWPORT_PRESET_YAML) presets = database._parse_yaml(cache).keys() current_viewport_preset = database.read_cache('current_viewport_preset') logger.info(presets) l = len(presets) i = 0 if current_viewport_preset in presets: for k in range(l): i = k logger.info("presets[%s] %s" % (i, presets[i])) if current_viewport_preset == presets[i]: logger.info("%s is a match" % i) break else: i = 0 i += 1 if i >= l: i = 0 database.save_cache('current_viewport_preset', presets[i], yaml_file=CACHE_YAML) maya_scene.apply_viewport_preset(cache, presets[i])
def lookThruActiveCam(): currentCamName = database.read_cache('selected_camera') cam = cmds.ls(currentCamName) if cam: cmds.lookThru(cam[0]) cmds.refresh(currentView=False) else: # Todo: should fall back to default camera print "no syncSketchPlayer_camera found"
def apply_viewport_preset(cache_file, presetName, panels=[]): options = database.read_cache(presetName, cache_file) if not options: logger.info("No preset found") return if not len(panels): panels = [get_active_editor()] for panel in panels: capture.apply_view(panel, **options) logger.info("Applies preset %s to modelpanel %s"%(presetName,panel))
def load_preset(self, presetName=None): """ Load the user's current preset from yaml """ presetFile = path.get_config_yaml(PRESET_YAML) logger.info("reading YAML: {}".format(presetFile)) presetData = database._parse_yaml(presetFile) if not presetData: return if not presetName: self.ui.ui_formatPreset_comboBox.set_combobox_index( selection=database.read_cache('current_preset')) self.ui.format_comboBox.set_combobox_index(selection='avi') self.ui.encoding_comboBox.set_combobox_index(selection='none') self.ui.width_spinBox.setValue(1280) self.ui.height_spinBox.setValue(720) elif presetName == DEFAULT_PRESET: self.ui.ui_formatPreset_comboBox.set_combobox_index( selection=DEFAULT_PRESET) if sys.platform == 'darwin': format = 'avfoundation' encoding = 'H.264' elif sys.platform == 'linux2': format = 'movie' encoding = 'H.264' elif sys.platform == 'win32': format = 'avi' encoding = 'none' else: preset = presetData.get(presetName) logger.info("presetName: {}, preset: {} presetData: {}".format( presetName, preset, presetData)) if not preset: return logger.info(preset) format = preset.get('format') encoding = preset.get('encoding') width = preset.get('width') height = preset.get('height') self.ui.ui_formatPreset_comboBox.set_combobox_index( selection=presetName) self.ui.format_comboBox.set_combobox_index(selection=format) self.ui.encoding_comboBox.set_combobox_index(selection=encoding) self.ui.width_spinBox.setValue(width) self.ui.height_spinBox.setValue(height)
def get_current_file(): # validate file name filename = database.read_cache('last_recorded_selection') if not filename: raise RuntimeError('There is no previously recorded video file.') filename = path.sanitize(filename) if not os.path.isfile(filename): raise RuntimeError('Please provide a valid file.') return else: return filename
def playblast_with_settings(viewport_preset=None, viewport_preset_yaml=None, **recArgs): ''' Playblast with the user-defined settings recArgs are the arguments needed for the capture command ''' # get default viewport preset config if viewport_preset and viewport_preset_yaml: cache_file = path.get_config_yaml(viewport_preset_yaml) viewportArgs = database.read_cache(viewport_preset, cache_file) else: viewportArgs = {} # process filenames filepath = recArgs["filename"] if not filepath: filepath = path.get_default_playblast_folder() filepath = path.sanitize(filepath) filepath_with_ext = add_extension(filepath, recArgs) if is_file_on_disk( filepath_with_ext) and not recArgs.get("force_overwrite"): filename = os.path.split(filepath_with_ext)[-1] message = '[{}] already exists.\nDo you want to replace it?'.format( filename) if not confirm_overwrite_dialogue(message) == 'yes': return recArgs["show_ornaments"] = False recArgs["viewer"] = False # merge with viewport args viewport_options = viewportArgs.copy() viewport_options.update(recArgs) logger.info("viewport_options: {}".format(viewport_options)) playblast_file = capture.capture(**viewport_options) if playblast_file: playblast_file = add_extension(playblast_file, recArgs) recArgs["filename"] = playblast_file database.save_last_recorded(recArgs) database.dump_cache({"last_recorded_selection": playblast_file}) logger.info('Find your recorded file here: {}'.format(playblast_file)) return playblast_file else: logger.info("playblast_with_settings failed")
def delete_preset(self): preset_file = path.get_config_yaml(PRESET_YAML) preset_name = self.ui.ui_formatPreset_comboBox.currentText() database.delete_key_from_cache(preset_name, preset_file) current_preset = database.read_cache("current_preset") if current_preset == preset_name: current_preset_names = database._parse_yaml(preset_file).keys() new_preset_name = current_preset_names[0] self._update_current_preset(new_preset_name) else: self._update_current_preset(current_preset) self.populate_ui() self.ui.ui_formatPreset_comboBox.set_combobox_index(0)
def upload(open_after_upload=None, show_success_msg=False): uploaded_item = _upload() if not uploaded_item: return if open_after_upload is None: open_after_upload = True if database.read_cache( 'ps_open_afterUpload_checkBox') == 'true' else False if open_after_upload: webbrowser.open(uploaded_item['reviewURL'], new=2, autoraise=True) if not open_after_upload: show_success_message(uploaded_item) return uploaded_item
def get_current_file(): # validate file name filename = database.read_cache('last_recorded_selection') if not filename: title = 'No File for Upload' message = 'There is no previously recorded video file, please record one first through The Widget' qt_widgets.WarningDialog(None, title, message) return filename = path.sanitize(filename) if not os.path.isfile(filename): title = 'Not a valid file' message = 'Please provide a valid file' logger.debug("{} is not a valid file".format(filename)) qt_widgets.WarningDialog(None, title, message) return else: return filename
def screenshot_current_editor(cache_file, presetName, panel=None, camera=None): # Nice little screentshot function from BigRoy if not panel: panel = get_active_editor() options = database.read_cache(presetName, cache_file) if not options: logger.info("No preset found") return frame = cmds.currentTime(q=1) # When playblasting outside of an undo queue it seems that undoing # actually triggers a reset to frame 0. As such we sneak in the current # time into the undo queue to enforce correct undoing. cmds.currentTime(frame, update=True) with no_undo(): tempdir = tempfile.mkdtemp() # override some settings options = options.copy() options['complete_filename'] = os.path.join(tempdir, "temp.jpg") options['width'] = 960 options['height'] = 960 options['viewer'] = False options['frame'] = frame options['off_screen'] = True options['format'] = "image" options['compression'] = "jpg" options['sound'] = None if camera: options['camera'] = camera fname = capture.snap(**options) if not fname: logger.warning("Preview failed") return return fname
def _upload(current_user=None, ): errorLog = None if not current_user: current_user = user.SyncSketchUser() username = current_user.get_name() upload_file = get_current_file() if not upload_file or not os.path.isfile(upload_file): return # Try to upload to the last uploaded address first selected_item = database.read_cache('treewidget_selection') logger.info("selected_item: {0}".format(selected_item)) # ToDo rename media_id to item_id item_type = database.read_cache('target_url_type') review_id = database.read_cache('target_review_id') item_id = database.read_cache('target_media_id') item_name = database.read_cache('target_url_item_name') # Upload To current_item = selected_item upload_to_value = item_name logger.info('Selected Item: %s' % item_name) last_recorded_data = database.read_cache('last_recorded') postData = { "first_frame": last_recorded_data['start_frame'], "last_frame": last_recorded_data['end_frame'], } if item_type == 'review': logger.info('Uploading {} to {} with review_id {}'.format( upload_file, upload_to_value, review_id)) uploaded_item = current_user.upload_media_to_review(review_id, upload_file, noConvertFlag=True, itemParentId=False, data=postData) #logger.info("uploaded_item: {0}".format(pformat(uploaded_item))) elif item_type == 'media': logger.info('Updating item {} with file {}'.format( upload_to_value, upload_file)) logger.info("item id %s" % item_id) logger.info("filepath %s" % upload_file) logger.info("Trying to upload %s to item_id %s, review %s" % (upload_file, item_id, review_id)) uploaded_item = current_user.upload_media_to_review( review_id, upload_file, noConvertFlag=True, itemParentId=item_id, data=postData) logger.info(pformat(uploaded_item)) else: uploaded_item = None errorLog = 'You cannot upload to %s "%s" directly.\nPlease select a review in the tree widget to upload to!\n' % ( item_type, item_name) if not uploaded_item: if not errorLog: errorLog = 'No Uploaded Item returned from Syncsketch' logger.info('ERROR: This Upload failed: %s' % (errorLog)) return # * this is an old call, that we should replace with an async worker review_data = current_user.get_review_data_from_id(review_id) review_url = review_data.get('reviewURL') #uploaded_media_url = '{}'.format(review_url) uploaded_media_url = '{}#{}'.format(review_url, uploaded_item['id']) logger.info("review_data: {}".format(review_data)) logger.info('Upload successful. Uploaded item {} to {}'.format( upload_file, uploaded_media_url)) if 'none' in uploaded_media_url.lower(): uploaded_media_url = "" uploaded_item['reviewURL'] = uploaded_media_url return uploaded_item
def _record(): # filename & path filepath = database.read_cache('ps_directory_lineEdit') filename = database.read_cache('us_filename_lineEdit') clipname = database.read_cache('ps_clipname_lineEdit') if not filepath or not filename: title = 'Playblast Location' message = 'Please specify playblast file name and location.' return qt_widgets.WarningDialog(None, title, message) filepath = os.path.expanduser('~/Desktop/playblasts/') filename = 'playblast' if clipname: filename = filename + clipname filepath = path.sanitize(os.path.join(filepath, filename)) # preset preset_file = path.get_config_yaml(PRESET_YAML) preset_data = database._parse_yaml(preset_file) preset_name = database.read_cache('current_preset') preset = preset_data.get(preset_name) start_frame, end_frame = maya_scene.get_InOutFrames( database.read_cache('current_range_type')) start_frame = database.read_cache('frame_start') end_frame = database.read_cache('frame_end') #setting up args for recording recArgs = { "show_ornaments": False, "start_frame": start_frame, "end_frame": end_frame, "camera": database.read_cache('selected_camera'), "format": preset.get('format'), "viewer": True if database.read_cache('ps_play_after_creation_checkBox') == 'true' else False, "filename": filepath, "width": preset.get('width'), "height": preset.get('height'), "overwrite": True if database.read_cache('ps_force_overwrite_checkBox') == 'true' else False, "compression": preset.get('encoding'), "off_screen": True } logger.info("recArgs: {}".format(recArgs)) # read from database Settings playblast_file = maya_scene.playblast_with_settings( viewport_preset=database.read_cache('current_viewport_preset'), viewport_preset_yaml=VIEWPORT_PRESET_YAML, **recArgs) return playblast_file
def _upload(current_user=None, ): errorLog = None if not current_user: current_user = user.SyncSketchUser() username = current_user.get_name() upload_file = get_current_file() if not upload_file or not os.path.isfile(upload_file): self.update_tooltip( 'WebM file cannot be sourced. Uploading the original file.', color='LightYellow') # Try to upload to the last uploaded address first selected_item = database.read_cache('treewidget_selection') # if not selected_item: # database.read_cache('target_review_id') # ToDo rename media_id to item_id item_type = database.read_cache('target_url_type') review_id = database.read_cache('target_review_id') item_id = database.read_cache('target_media_id') item_name = database.read_cache('target_url_item_name') # Upload To current_item = selected_item upload_to_value = str() if item_type == 'playground': upload_to_value = 'Playground(public)' else: upload_to_value = item_name print 'Selected Item: %s' % item_name time.sleep(WAIT_TIME) # Don't need to login if we're uploading to playground. # Treewidget item selection must be review type to upload. # If selection is other item type, warn the user. last_recorded_data = database.read_cache('last_recorded') postData = { "first_frame": last_recorded_data['start_frame'], "last_frame": last_recorded_data['end_frame'], } if item_type == 'playground': playground_email = database.get_playground_email() if not path.validate_email_address(playground_email): user_input = qt_widgets.InputDialog() if not user_input.response: return playground_email = user_input.response_text database.save_playground_email(playground_email) uploaded_item = user.upload_to_playground(upload_file, playground_email) elif item_type == 'review': print 'Uploading {} to {}'.format(upload_file, upload_to_value) uploaded_item = current_user.upload_media_to_review(review_id, upload_file, noConvertFlag=True, itemParentId=False, data=postData) import pprint pprint.pprint(uploaded_item) elif item_type == 'media': print 'Updating item {} with file {}'.format(upload_to_value, upload_file) print "item id %s" % item_id print "filepath %s" % upload_file print "Trying to upload %s to item_id %s, review %s" % ( upload_file, item_id, review_id) uploaded_item = current_user.upload_media_to_review( review_id, upload_file, noConvertFlag=True, itemParentId=item_id, data=postData) import pprint pprint.pprint(uploaded_item) else: uploaded_item = None errorLog = 'You cannot upload to %s "%s" directly.\nPlease select a review in the tree widget to upload to!\n' % ( item_type, item_name) if not uploaded_item: if not errorLog: errorLog = 'No Uploaded Item returned from Syncsketch' print 'ERROR: This Upload failed: %s' % (errorLog) return # try: review_data = current_user.get_review_data_from_id(review_id) review_url = review_data.get('reviewURL') uploaded_media_url = 'https://syncsketchGUI.com/sketch/{}#{}'.format( str(review_data.get('id')).rstrip('/'), uploaded_item['id']) print 'Upload successful. Uploaded item {} to {}'.format( upload_file, uploaded_media_url) # except: # uploaded_media_url = uploaded_item.get('reviewURL') if 'none' in uploaded_media_url.lower(): uploaded_media_url = str() if uploaded_media_url: uploaded_media_url.replace(path.playground_url, path.playground_display_url) uploaded_item['reviewURL'] = uploaded_media_url return uploaded_item
def createOrUpdatePlayblastCam(): # apply_viewport_preset('') # apply_viewport_preset filePath = database.read_cache('last_recorded') maya_scene.createOrUpdatePlayblastCam(frameOffset=0, moviePath=filePath)
from syncsketchGUI.lib import database PRESET_YAML = 'syncsketch_preset.yaml' VIEWPORT_YAML = 'syncsketch_viewport.yaml' DEFAULT_PRESET = database.read_cache('current_preset') uploadPlaceHolderStr = "Pick a review/item or paste a SyncSketch URL here" message_is_not_loggedin = "Please sign into your account by clicking 'Log-In' or create a free Account by clicking 'Sign up'." message_is_not_connected = "WARNING: Could not connect to SyncSketch. It looks like you may not have an internet connection?" DEFAULT_VIEWPORT_PRESET = database.read_cache('current_viewport_preset')