def _handle_ref_node(self, node, widget, upstream=False, recursive=True): # get the reference snapshot (should maybe use the loader or # at least share the code instance = Xml.get_attribute(node,"instance") search_type = Xml.get_attribute(node,"search_type") search_id = Xml.get_attribute(node,"search_id") context = Xml.get_attribute(node,"context") version = Xml.get_attribute(node,"version") # this is often the Maya file node name or XSI long clip name node_name = Xml.get_attribute(node, "node") my_name = Xml.get_node_name(node) # get the snapshot ref_snapshot = Snapshot.get_by_version(search_type, search_id,\ context, version) #ref_snapshot = Snapshot.get_latest(search_type,search_id, context) if ref_snapshot == None: widget.add("|---> <font color='red'>Error: No reference found for [%s, %s, %s]</font>" % \ (search_type, search_id, context) ) return toggle_id = self.generate_unique_id('toggle') widget.add(FloatDivWdg(), toggle_id) version = ref_snapshot.get_value("version") try: sobject = ref_snapshot.get_sobject() except SObjectNotFoundException, e: widget.add('[%s|%s] may have been deleted or is not viewable.' % (ref_snapshot.get_value('search_type'),\ ref_snapshot.get_value('search_id'))) return
def add_ending(my, parts, auto_version=True): context = my.snapshot.get_value("context") filename = my.file_object.get_full_file_name() # make sure that the version in the file name does not yet exist version = my.get_version_from_file_name(filename) if not auto_version and version: # if the file version is not the same as the snapshot version # then check to see if the snapshot already exists if not context.startswith( "cache") and version != my.snapshot.get_value("version"): existing_snap = Snapshot.get_by_version(my.snapshot.get_value("search_type"),\ my.snapshot.get_value("search_id"), context, version) if existing_snap: raise TacticException( 'A snapshot with context "%s" and version "%s" already exists.' % (context, version)) my.snapshot.set_value("version", version) my.snapshot.commit() else: version = my.snapshot.get_value("version") if version == 0: version = "CURRENT" elif version == -1: version = "LATEST" else: version = "v%0.3d" % int(version) revision = my.snapshot.get_value("revision", no_exception=True) if revision: revision = "r%0.2d" % int(revision) ext = my.get_ext() parts.append(context.replace("/", "_")) if my.is_tactic_repo(): parts.append(version) if revision: parts.append(revision) # should all files be named with file_type ending? file_type = my.get_file_type() # backwards compatibility if file_type and file_type not in ['maya', 'main', 'geo', 'xml']: parts.append(file_type) #if file_type in ['web','icon']: # parts.append(file_type) value = ProdSetting.get_value_by_key("naming/add_initials") if value == "true": project = Project.get() initials = Project.get().get_initials() if initials: parts.append(initials) filename = "_".join(parts) if ext: filename = "%s%s" % (filename, ext) return filename
def add_ending(self, parts, auto_version=True): context = self.snapshot.get_value("context") filename = self.file_object.get_full_file_name() # make sure that the version in the file name does not yet exist version = self.get_version_from_file_name(filename) if not auto_version and version: # if the file version is not the same as the snapshot version # then check to see if the snapshot already exists if not context.startswith("cache") and version != self.snapshot.get_value("version"): existing_snap = Snapshot.get_by_version(self.snapshot.get_value("search_type"),\ self.snapshot.get_value("search_id"), context, version) if existing_snap: raise TacticException('A snapshot with context "%s" and version "%s" already exists.' % (context, version) ) self.snapshot.set_value("version", version) self.snapshot.commit() else: version = self.snapshot.get_value("version") if version == 0: version = "CURRENT" elif version == -1: version = "LATEST" else: version = "v%0.3d" % int(version) revision = self.snapshot.get_value("revision", no_exception=True) if revision: revision = "r%0.2d" % int(revision) ext = self.get_ext() parts.append(context.replace("/", "_")) if self.is_tactic_repo(): parts.append(version) if revision: parts.append(revision) # should all files be named with file_type ending? file_type = self.get_file_type() # backwards compatibility if file_type and file_type not in ['maya','main','geo','xml']: parts.append(file_type) #if file_type in ['web','icon']: # parts.append(file_type) value = ProdSetting.get_value_by_key("naming/add_initials") if value == "true": project = Project.get() initials = Project.get().get_initials() if initials: parts.append(initials) filename = "_".join(parts) if ext: filename = "%s%s" % (filename, ext) return filename
def init(self): WebContainer.register_cmd("pyasm.widget.AnnotateCbk") sobject = self.get_current_sobject() if not sobject: if not self.__dict__.has_key("search_type"): web = WebContainer.get_web() self.search_type = web.get_form_value("search_type") self.search_id = web.get_form_value("search_id") if not self.search_type: self.add("No search type") return search = Search(self.search_type) search.add_id_filter(self.search_id) sobject = search.get_sobject() snapshot = Snapshot.get_latest_by_sobject(sobject) # TODO: # this is a bit klunky snapshot_xml = snapshot.get_xml_value("snapshot") file_code = snapshot_xml.get_value( "snapshot/file[@type='web']/@file_code") file = File.get_by_code(file_code) web_dir = snapshot.get_web_dir() path = "%s/%s" % (web_dir, file.get_full_file_name()) # add the annotate js object script = HtmlElement.script("annotate = new Annotate()") self.add(script) # add the image self.add("<h3>Image Annotations</h3>") width = 600 img = HtmlElement.img(path) img.add_style("position: absolute") img.set_id("annotate_image") img.add_style("left: 0px") img.add_style("top: 0px") img.add_style("opacity: 1.0") img.add_style("z-index: 1") img.add_style("width", width) img.add_event("onmouseup", "annotate.add_new(event)") self.add(img) # test version = snapshot.get_value("version") if version != 1: last_version = version - 1 snapshot = Snapshot.get_by_version( \ self.search_type, self.search_id, version=last_version ) snapshot_xml = snapshot.get_xml_value("snapshot") file_code = snapshot_xml.get_value( "snapshot/file[@type='web']/@file_code") file = File.get_by_code(file_code) web_dir = snapshot.get_web_dir() path = "%s/%s" % (web_dir, file.get_full_file_name()) img = HtmlElement.img(path) img.set_id("annotate_image_alt") img.add_style("position: absolute") img.add_style("left: 0px") img.add_style("top: 0px") img.add_style("opacity: 1.0") img.add_style("z-index: 0") img.add_style("width", width) img.add_event("onmouseup", "annotate.add_new(event)") self.add(img) #script = HtmlElement.script("align_element('%s','%s')" % \ # ("annotate_image", "annotate_image_alt") ) #self.add(script) div = DivWdg() div.add_style("position: absolute") div.add_style("left: 620") div.add_style("top: 300") self.add(div) button = IconButtonWdg("Switch", IconWdg.REFRESH, True) button.add_event("onclick", "annotate.switch_alt()") div.add(button) button = IconButtonWdg("Opacity", IconWdg.LOAD, True) button.add_event("onclick", "annotate.set_opacity()") div.add(button) # add the new annotation div new_annotation_div = DivWdg() new_annotation_div.set_id("annotate_msg") new_annotation_div.set_class("annotate_new") new_annotation_div.add_style("top: 0") new_annotation_div.add_style("left: 0") title = DivWdg("Enter Annotation:") title.add_style("background-color: #000000") title.add_style("color: #ffffff") new_annotation_div.add(title) text = TextAreaWdg("annotate_msg") text.set_attr("cols", "30") text.set_attr("rows", "3") new_annotation_div.add(text) new_annotation_div.add("<br/>") cancel = ButtonWdg("Cancel") cancel.add_style("float: right") cancel.add_event("onclick", "toggle_display('annotate_msg')") new_annotation_div.add(cancel) submit = SubmitWdg("Add Annotation") submit.add_style("float: right") new_annotation_div.add(submit) new_annotation_div.add_style("display: none") new_annotation_div.add_style("position: absolute") self.add(new_annotation_div) # get all of the stored annotations for this image search = Search("sthpw/annotation") search.add_order_by("login") search.add_filter("file_code", file_code) annotations = search.get_sobjects() # sort by user sorted_annotations = {} for annotation in annotations: user = annotation.get_value("login") if not sorted_annotations.has_key(user): sorted_annotations[user] = [] sorted_annotations[user].append(annotation) buttons = [] for user, annotations in sorted_annotations.items(): button = IconButtonWdg(user, IconWdg.INSERT, True) button.add_event( "onclick", "annotate.show_marks('%s','%s')" % (user, len(annotations) - 1)) buttons.append(button) count = 0 for annotation in annotations: self.add(self.get_annotate_wdg(annotation, count)) count += 1 # add the user buttons table = Table() table.set_class("table") table.add_style("width: 0px") table.add_style("position: absolute") table.add_style("left: 620") table.add_style("top: 0") table.add_row() table.add_header("Annotations") for button in buttons: table.add_row() legend_wdg = DivWdg() legend_wdg.set_class("annotate_mark") legend_wdg.add_style("position: relative") legend_wdg.add(" ") table.add_cell(legend_wdg) table.add_cell(button) self.add(table) # add form elements hidden = HiddenWdg("mouse_xpos") self.add(hidden) hidden = HiddenWdg("mouse_ypos") self.add(hidden) hidden = HiddenWdg("file_code", file_code) self.add(hidden) # move the rest below self.add("<div style='height:300'> </div>")
def init(my): WebContainer.register_cmd("pyasm.widget.AnnotateCbk") sobject = my.get_current_sobject() if not sobject: if not my.__dict__.has_key("search_type"): web = WebContainer.get_web() my.search_type = web.get_form_value("search_type") my.search_id = web.get_form_value("search_id") if not my.search_type: my.add("No search type") return search = Search(my.search_type) search.add_id_filter(my.search_id) sobject = search.get_sobject() snapshot = Snapshot.get_latest_by_sobject(sobject) # TODO: # this is a bit klunky snapshot_xml = snapshot.get_xml_value("snapshot") file_code = snapshot_xml.get_value("snapshot/file[@type='web']/@file_code") file = File.get_by_code(file_code) web_dir = snapshot.get_web_dir() path = "%s/%s" % (web_dir, file.get_full_file_name() ) # add the annotate js object script = HtmlElement.script("annotate = new Annotate()") my.add(script) # add the image my.add("<h3>Image Annotations</h3>") width = 600 img = HtmlElement.img(path) img.add_style("position: absolute") img.set_id("annotate_image") img.add_style("left: 0px") img.add_style("top: 0px") img.add_style("opacity: 1.0") img.add_style("z-index: 1") img.add_style("width", width) img.add_event("onmouseup", "annotate.add_new(event)") my.add(img) # test version = snapshot.get_value("version") if version != 1: last_version = version - 1 snapshot = Snapshot.get_by_version( \ my.search_type, my.search_id, version=last_version ) snapshot_xml = snapshot.get_xml_value("snapshot") file_code = snapshot_xml.get_value("snapshot/file[@type='web']/@file_code") file = File.get_by_code(file_code) web_dir = snapshot.get_web_dir() path = "%s/%s" % (web_dir, file.get_full_file_name() ) img = HtmlElement.img(path) img.set_id("annotate_image_alt") img.add_style("position: absolute") img.add_style("left: 0px") img.add_style("top: 0px") img.add_style("opacity: 1.0") img.add_style("z-index: 0") img.add_style("width", width) img.add_event("onmouseup", "annotate.add_new(event)") my.add(img) #script = HtmlElement.script("align_element('%s','%s')" % \ # ("annotate_image", "annotate_image_alt") ) #my.add(script) div = DivWdg() div.add_style("position: absolute") div.add_style("left: 620") div.add_style("top: 300") my.add(div) button = IconButtonWdg("Switch", IconWdg.REFRESH, True) button.add_event("onclick", "annotate.switch_alt()") div.add(button) button = IconButtonWdg("Opacity", IconWdg.LOAD, True) button.add_event("onclick", "annotate.set_opacity()") div.add(button) # add the new annotation div new_annotation_div = DivWdg() new_annotation_div.set_id("annotate_msg") new_annotation_div.set_class("annotate_new") new_annotation_div.add_style("top: 0") new_annotation_div.add_style("left: 0") title = DivWdg("Enter Annotation:") title.add_style("background-color: #000000") title.add_style("color: #ffffff") new_annotation_div.add(title) text = TextAreaWdg("annotate_msg") text.set_attr("cols", "30") text.set_attr("rows", "3") new_annotation_div.add(text) new_annotation_div.add("<br/>") cancel = ButtonWdg("Cancel") cancel.add_style("float: right") cancel.add_event("onclick", "toggle_display('annotate_msg')") new_annotation_div.add( cancel ) submit = SubmitWdg("Add Annotation") submit.add_style("float: right") new_annotation_div.add( submit ) new_annotation_div.add_style("display: none") new_annotation_div.add_style("position: absolute") my.add(new_annotation_div) # get all of the stored annotations for this image search = Search("sthpw/annotation") search.add_order_by("login") search.add_filter("file_code", file_code) annotations = search.get_sobjects() # sort by user sorted_annotations = {} for annotation in annotations: user = annotation.get_value("login") if not sorted_annotations.has_key(user): sorted_annotations[user] = [] sorted_annotations[user].append(annotation) buttons = [] for user, annotations in sorted_annotations.items(): button = IconButtonWdg(user, IconWdg.INSERT, True) button.add_event("onclick", "annotate.show_marks('%s','%s')" % (user, len(annotations)-1) ) buttons.append(button) count = 0 for annotation in annotations: my.add( my.get_annotate_wdg(annotation,count) ) count += 1 # add the user buttons table = Table() table.set_class("table") table.add_style("width: 0px") table.add_style("position: absolute") table.add_style("left: 620") table.add_style("top: 0") table.add_row() table.add_header("Annotations") for button in buttons: table.add_row() legend_wdg = DivWdg() legend_wdg.set_class("annotate_mark") legend_wdg.add_style("position: relative") legend_wdg.add(" ") table.add_cell(legend_wdg) table.add_cell(button) my.add(table) # add form elements hidden = HiddenWdg("mouse_xpos") my.add(hidden) hidden = HiddenWdg("mouse_ypos") my.add(hidden) hidden = HiddenWdg("file_code", file_code) my.add(hidden) # move the rest below my.add("<div style='height:300'> </div>")