Jump to content
Ultimaker Community of 3D Printing Experts

Looking for sample code concerning ComboBox in plugin creation


Cuq
 Share

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
     Share

    • Our picks

      • New here? Get ahead with a free onboarding course
        Hi,
         
        Often getting started is the most difficult part of any process. A good start sets you up for success and saves you time and energy that could be spent elsewhere. That is why we have a onboarding course ready for
        Ultimaker S5 Pro Bundle, Ultimaker S5, Ultimaker S3 Ultimaker 2+ Connect.   
        They're ready for you on the Ultimaker Academy platform. All you need to do to gain access is to register your product to gain free access. 
        Ready? Register your product here in just 60 seconds.
          • Like
        • 11 replies
    ×
    ×
    • Create New...