Jump to content

Looking for sample code concerning ComboBox in plugin creation


Cuq

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.7 stable released
        Cura 5.7 is here and it brings a handy new workflow improvement when using Thingiverse and Cura together, as well as additional capabilities for Method series printers, and a powerful way of sharing print settings using new printer-agnostic project files! Read on to find out about all of these improvements and more. 
         
          • Like
        • 18 replies
      • S-Line Firmware 8.3.0 was released Nov. 20th on the "Latest" firmware branch.
        (Sorry, was out of office when this released)

        This update is for...
        All UltiMaker S series  
        New features
         
        Temperature status. During print preparation, the temperatures of the print cores and build plate will be shown on the display. This gives a better indication of the progress and remaining wait time. Save log files in paused state. It is now possible to save the printer's log files to USB if the currently active print job is paused. Previously, the Dump logs to USB option was only enabled if the printer was in idle state. Confirm print removal via Digital Factory. If the printer is connected to the Digital Factory, it is now possible to confirm the removal of a previous print job via the Digital Factory interface. This is useful in situations where the build plate is clear, but the operator forgot to select Confirm removal on the printer’s display. Visit this page for more information about this feature.
          • Like
        • 0 replies
    ×
    ×
    • Create New...