Open
Description
First of all:
- System: Windows 10 x64 Version 2004
- Python: 3.10.4
- delphivcl: 0.1.40
I've tried to delete selected items in ListBox and to log witch items should be deleted.
Deleting works with DeleteSelected()
, but for logging I need to iterate over the list and if I use Selected[i]
-property I get an error.
Error in getting property "Selected".
Error: Unknown attribute
Here a minimal:
# from delphivcl import *
import delphivcl as vcl
import logging
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
class MyApp(vcl.Form):
def __init__(self, Owner):
self.Caption = "MyApp"
self.SetBounds(100,100,700,500)
# Button del
self.del_task_btn = vcl.Button(self)
self.del_task_btn.SetProps(
Parent=self,
Caption="Delete Task",
OnClick = self.__del_task_on_click
)
self.del_task_btn.SetBounds(150, 120, 100, 30)
# Listbox
self.list_of_tasks = vcl.ListBox(self)
self.list_of_tasks.SetProps(
Parent=self,
MultiSelect = True,
)
self.list_of_tasks.SetBounds(300, 50, 300, 350)
self.OnClose = self.__on_form_close
self.__fill_list()
def __on_form_close(self, Sender, Action):
Action.Value = vcl.caFree
def __del_task_on_click(self, Sender):
msg = f"{Sender.Caption}"
lot = self.list_of_tasks
# Delete only if at least one string in the list box is selected
if lot.SelCount > 0:
logging.debug(f"Selected items: {lot.SelCount}")
msg += ":\n\t" +'\n\t'.join([lot.Items[i] for i in range(lot.Items.Count) if lot.Selected[i]])
lot.DeleteSelected()
else:
if lot.ItemIndex > -1:
msg += f": {lot.Items[lot.ItemIndex]}"
lot.Items.Delete(lot.ItemIndex)
else:
msg += f": {lot.Items[0]}"
lot.Items.Delete(0)
logging.debug(msg)
def __fill_list(self):
lot = self.list_of_tasks
for i in range(10):
lot.Items.Add(str(i))
def main():
vcl.Application.Initialize()
vcl.Application.Title = "TODO App"
app = MyApp(vcl.Application)
app.Show()
# vcl.FreeConsole()
vcl.Application.Run()
app.Destroy()
main()
BR ramooon1