hoffstadt / DearPyGui

Dear PyGui: A fast and powerful Graphical User Interface Toolkit for Python with minimal dependencies
https://dearpygui.readthedocs.io/en/latest/
MIT License
12.62k stars 669 forks source link

set_value does not work on selectable tabel cell #2344

Closed KrankerSchrank closed 3 weeks ago

KrankerSchrank commented 3 weeks ago

ups enter...

Exception:
Error:     [1005]
Commups enter...
Exception:
Error:     [1005]
Command:   set_value
Item:      0
Label:     Not found
Item Type: Unknown
Message:   Item not found: 0

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\Git\dino\dinoai\doubletiktaktoe.py", line 210, in clb_selectable
    dpg.set_value(str(self.tableObjects[a][b][c][d]), f"{text}")
  File "C:\Users\lenna\AppData\Local\Programs\Python\Python312\Lib\site-packages\dearpygui\dearpygui.py", line 9157, in set_value
    return internal_dpg.set_value(item, value, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SystemError: <built-in function set_value> returned a result with an exception setand:   set_value
Item:      0
Label:     Not found
Item Type: Unknown
Message:   Item not found: 0

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\Git\dino\dinoai\doubletiktaktoe.py", line 210, in clb_selectable
    dpg.set_value(str(self.tableObjects[a][b][c][d]), f"{text}")
  File "C:\Users\lenna\AppData\Local\Programs\Python\Python312\Lib\site-packages\dearpygui\dearpygui.py", line 9157, in set_value
    return internal_dpg.set_value(item, value, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SystemError: <built-in function set_value> returned a result with an exception set
dpg.set_value(str(self.tableObjects[a][b][c][d]), f"{text}")

-> self.tableObjects is the uuid in this case 134

self.tableObjects[a][b][c][d] = uuid = dpg.generate_uuid()

dpg.add_selectable(label=f"{text}", callback=self.clb_selectable, user_data=(a, b, c, d), tag=self.tableObjects[a][b][c][d])

So like I generate and save a uuid for every cell so I can edit its contents, but when I try to edit the Labels i get that error

v-ein commented 3 weeks ago

The value returned by generate_uuid is a numeric UUID. DPG accepts both numeric UUIDs and string tags to identify items; however, the string tags must be assigned explicitly as such when you create items (and in this case, the item will still have a uniquie numeric ID; the string tag is just an alias).

When you do add_selectable(tag=self.tableObjects[a][b][c][d]), you're asking DPG to create an item with a specific numeric ID, and it does so by simply assigning the UUID you passed (134) and not generating a new one.

Then, when you do dpg.set_value(str(self.tableObjects[a][b][c][d])), you're asking DPG to find an item with a string tag "134" rather than a numeric ID 134. There's no such item because none of the were added with tag="134".

All you need to do is to remove that str() around self.tableObjects[a][b][c][d].

P.S. Next time you open an issue in this project, please make an effort to read the issue template and follow it. Proper description helps a lot in diagnosing the issue, as well as shows your respect to the time of whoever does that diagnostics.

KrankerSchrank commented 3 weeks ago

Thanks for your quick response, next time I will use the Issue format I just was unsure wich one is the right, and I wasn't able to find a template, wich was probably my fault, so after I made these changes:

dpg.set_value(self.tableObjects[a][b][c][d], True)

The code doesn't gives out a error anymore, but what I tried to do is to change the label of the item, is that in any way possible? (It is a selectable Table)

with dpg.window(tag="Selectable Tables"):
            with dpg.table(tag="SelectCells", header_row=False) as selectablecells:
                dpg.add_table_column()
                dpg.add_table_column()
                dpg.add_table_column()
                dpg.add_table_column()
                dpg.add_table_column()
                dpg.add_table_column()
                dpg.add_table_column()
                dpg.add_table_column()
                dpg.add_table_column()

                for i in range(9):
                    with dpg.table_row():
                        for j in range(9):
                            if i < 3: a = 0
                            elif i <6: a = 1
                            else: a = 0
                            if j < 3: b = 0
                            elif j <6: b = 1
                            else: b = 0

                            if i == 0 or i == 3 or i == 7: c = 0
                            elif i == 1 or i == 4 or i == 8: c = 1
                            else: c = 2
                            if j == 0 or j == 3 or j == 7: d = 0
                            elif j == 1 or j == 4 or j == 8: d = 1
                            else: d = 2
                            text = "#" if self.board[a][b][c][d] == " " else self.board[a][b][c][d]

                            self.tableObjects[a][b][c][d] = uuid = dpg.generate_uuid()

                            dpg.add_selectable(label=f"{text}", callback=self.clb_selectable, user_data=(a, b, c, d), tag=self.tableObjects[a][b][c][d])
                    if i == 2 or i == 5:
                        with dpg.table_row():
                            for j in range(9):
                                dpg.add_selectable(label=f"---", callback=self.clb_selectable, user_data=(99,99))
v-ein commented 3 weeks ago

Try dpg.set_item_label.

Regarding the template, it's what appears in the description field when you open a new ticket. Maybe you were opening this ticket in a non-standard way, not sure.

image