DelphiVCL4Python icon indicating copy to clipboard operation
DelphiVCL4Python copied to clipboard

ListBox does not have all Properties in Python

Open ramooon1 opened this issue 2 years ago • 2 comments

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

ramooon1 avatar Jul 22 '22 18:07 ramooon1

Thank you for your interest. Let me reproduce the issue and confirm whether the wrap of Selected property of ListBox component is working or not.

Priyatham10 avatar Jul 23 '22 10:07 Priyatham10

Hi @ramooon1 . I'm able to reproduce the issue. Yes, the Selected property of ListBox is not wrapped properly in the automatic wrapping process. We need to wrap it manually. We will add this wrap in our next release. Thank you for your notice and please keep posting any further issues you might face.

Priyatham10 avatar Jul 25 '22 03:07 Priyatham10