Jump to content

Recommended Posts

Posted · Looking for sample code concerning ComboBox in plugin creation

Hello,

 

I'm working on the evolution of one of my plugin and I wanted to integrate in one option the possibility to fill a Combobox, with a list of file present in a directory.  As I'm quite new on python I would like to know if someone could direct me to a simple example that would already do this kind of thing.

 

image.png.125a5ae49941defe260b53f818233fbc.png

 

Thanks a lot

 

  • Link to post
    Share on other sites

    Posted (edited) · Looking for sample code concerning ComboBox in plugin creation

    The Per Model Settings plugin already has a combobox, so you could have a look at that.

     

    As for getting a list of files in a directory: https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory

     

    You might need to create a ListModel to display the values that you want in the combobox.

    Edited by nallath
    • Like 1
    Link to post
    Share on other sites

    Posted · Looking for sample code concerning ComboBox in plugin creation

    Thank you @nallath for you answer.  My problem was not really to get the list of files but it's on the QML side.

     

    How to define the "Model" attribute of the Combobox .   right now  I have the possibility to hard coded the list :

     

    model: [ "Cross", "Section", "Pilar", "Bridge", "Custom" ]

     

    But how to transfer a list from the main Python program to the QML Module ?

  • Link to post
    Share on other sites

    Posted (edited) · Looking for sample code concerning ComboBox in plugin creation
    1 hour ago, Cuq said:

    But how to transfer a list from the main Python program to the QML Module ?

    Ah, right. I misunderstood the question.

    If you look at the perobject setting tool, you see that it does the following

    self.setExposedProperties("SelectedObjectId", "ContainerID", "SelectedActiveExtruder", "MeshType")


    It also defines the function

    def getMeshType(self):

     

    In the qml it then does the following:

    UM.ActiveTool.properties.getValue("MeshType")


    So in your case you could do something like
     

    self.setExposedProperties("ObjectTypes")
    
    def getObjectTypes(self):
        return self._object_types
    
    model: UM.ActiveTool.properties.getValue("ObjectTypes")
    Edited by nallath
    Removed trailing whitespaces
  • Link to post
    Share on other sites

    Posted · Looking for sample code concerning ComboBox in plugin creation

    Ok my explanations were certainly not very clear. Doesn't matter let's wait for the validation of this 2.5.1 version. It will be certainly much more easy to understand after that. And I will keep in mind for a 2.6, after some feedback of the user.

     

    Thanks a lot for your times ! 

     

     

  • Link to post
    Share on other sites

    Posted (edited) · Looking for sample code concerning ComboBox in plugin creation

    I hop I can be much more clear as the Code is now much mode clean

     

    Quote

            ComboBox {
                id: supportComboType
                objectName: "Support_Type"
                model: ListModel {
                   id: cbItems
                   ListElement { text: "cross"}
                   ListElement { text: "section"}
                   ListElement { text: "pillar"}
                   ListElement { text: "bridge"}
                   ListElement { text: "arch-buttress"}
                   ListElement { text: "t-support"}
                   ListElement { text: "custom"}
                }
                width: UM.Theme.getSize("setting_control").width
                height: UM.Theme.getSize("setting_control").height
                visible: freeformButton.checked
                Component.onCompleted: currentIndex = find(UM.ActiveTool.properties.getValue("SubType"))
                
                onCurrentIndexChanged: 
                { 
                    UM.ActiveTool.setProperty("SubType",cbItems.get(currentIndex).text);
                }
            }

     

    So the Request is to replace the ListModel by a list of STL file present in a directory. 

     

    Edited by Cuq
  • Link to post
    Share on other sites

    Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    • Our picks

      • UltiMaker Cura 5.9 stable released!
        Here comes Cura 5.9 and in this stable release we have lots of material and printer profiles for UltiMaker printers, including the newly released Sketch Sprint. Additionally, scarf seams have been introduced alongside even more print settings and improvements.  Check out the rest of this article to find out the details on all of that and more
          • Like
        • 5 replies
      • Introducing the UltiMaker Factor 4
        We are happy to announce the next evolution in the UltiMaker 3D printer lineup: the UltiMaker Factor 4 industrial-grade 3D printer, designed to take manufacturing to new levels of efficiency and reliability. Factor 4 is an end-to-end 3D printing solution for light industrial applications
          • Heart
          • Thanks
          • Like
        • 4 replies
    ×
    ×
    • Create New...