Coscine TypeError while trying to update the metadata form [20230808-0210]
We received this question in the ticketTool. I'm not sure exactly why the user is getting this TypeError. But it may have to do with the def update()
There is some TypeError here in my code. I have tried to print out the variable self.metadata as well and it looks like this. But when I try to update the metadata, TypeError shows up. Could you possibly look into this and explain to me what went wrong here?
class ScrollableEntryFrame(customtkinter.CTkScrollableFrame):
def __init__(self, master, width=None, height=None, resource_name = None, **kwargs):
super().__init__(master, **kwargs)
if resource_name == None:
messagebox.showerror("Error", "No input provided!")
with open(r'C:\Users\user\sciebo\Austausch_Hm_Warisa\Probetracker\QR_Code_generator\api_token.txt', 'r') as f:
token = f.read().strip()
client = coscine.Client(token)
project = client.project("My Project").subproject("My Subproject")
self.resource = project.resource(resource_name)
self.metadata = self.resource.metadata_form()
def add_item(self, key):
entry_frame = customtkinter.CTkFrame(self)
entry_frame.pack(fill="x", pady=(0, 10))
entry_frame.item_name = key
label_text = key
if self.metadata.is_required(key):
label_text = key + "*"
label_name = customtkinter.CTkLabel(entry_frame, text=label_text, wraplength=67)
label_name.pack(side="left")
label_name.update()
label_width = label_name.winfo_width()
if self.metadata.is_controlled(key):
vocabulary = self.metadata.vocabulary(key)
combobox = customtkinter.CTkComboBox(entry_frame, values=vocabulary.keys())
combobox.set("------")
combobox.pack(side="left", padx=(75 - label_width, 0))
elif (self.metadata.type_format(key) == "%d"):
combobox = customtkinter.CTkComboBox(entry_frame, values=["Yes" , "No"])
combobox.set("------")
combobox.pack(side="left", padx=(75 - label_width, 0))
else:
entry = customtkinter.CTkEntry(entry_frame)
entry.pack(side="left", padx=(75-label_width, 0))
self.entry_list.append(entry_frame)
if self.width is not None:
self.configure(width=self.width)
if self.height is not None:
self.configure(height=self.height)
self.entry_list = []
self.width = width
self.height = height
self.configure(width=width, height=height)
for key in self.metadata:
add_item(self, key)
def record_values(self):
for entry_frame in self.entry_list:
entry = entry_frame.winfo_children()[1] # Assuming the entry is always the second child
key = entry_frame.item_name
if isinstance(entry, customtkinter.CTkComboBox):
if entry.get() == "------" and self.metadata.is_required(key):
messagebox.showerror("Error", f"Input needed for {key}!")
else:
value = entry.get()
if self.metadata.type_format(key) == "%d":
if value == "Yes":
value = True
else:
value = False #default value is False
else:
if entry.get() == "" and self.metadata.is_required(key):
messagebox.showerror("Error", f"Input needed for {key}!")
else:
value = entry.get()
if value != "" and value != "------":
self.metadata[key] = value
print (self.metadata)
self.resource.update(self.metadata)
The result of self.metadata:
+---+------+------------------------------+----------------+
| C | Type | Property | Value |
+---+------+------------------------------+----------------+
| | str | Current* | adf |
| | str | Voltage* | asdfdsa |
| V | str | Polarity* | Normal |
| | str | Wire diameter* | adsf |
| | str | Wire Material* | asdf |
| V | str | Wire type* | Solid wire |
| | str | Inert gas composition* | sadf |
| | str | Inert gas flow* | sdaf |
| | str | Contact tube life* | sdfdf |
| | str | Wire feed speed* | asfdsa |
| | str | Torch angle* | afdsaf |
| | str | Contact tube distance* | afdsadf |
| | str | Torch Offset* | addfsaf |
| V | str | Welding position* | PD |
| | str | Gas nozzle life* | adsf |
| | str | Torch movement* | asfd |
| | str | Power source* | safd |
| | str | Synergy characteristic line* | adsf |
| V | str | Arc type* | Transition arc |
| | str | Workpiece material* | asfd |
| V | str | Joint type* | Lap joint |
| | str | Joint Preparation* | asdf |
| | bool | Backing* | false |
| V | str | Surface treatment* | Galvanization |
| | str | Welding speed* | asfd |
| | bool | Robot* | true |
| | str | Preheating | |
| | bool | Expected arc blow?* | true |
| | bool | External magnetic field* | false |
| V | str | Video recordings | |
| | str | Frames per secound | |
| | str | Aperture | |
| | str | Exposure time | |
| | str | Camera name | |
| | str | Pyrometer Recordings | |
| | str | Cross section | |
| | str | Micro structure examination | |
+---+------+------------------------------+----------------+
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\tkinter\__init__.py", line 1948, in __call__
return self.func(*args)
^^^^^^^^^^^^^^^^
File "c:\Users\user\sciebo\Austausch_Hm_Warisa\Probetracker\QR_Code_generator\ScrollableEntryFrame.py", line 90, in on_button_click
scrollable_frame.record_values()
File "c:\Users\user\sciebo\Austausch_Hm_Warisa\Probetracker\QR_Code_generator\ScrollableEntryFrame.py", line 86, in record_values
self.resource.update(self.metadata)
File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\coscine\resource.py", line 635, in update
raise TypeError("Resource metadata form has unexpected type.")
TypeError: Resource metadata form has unexpected type.