Help needed to create a dialog

I am playing with a add on in order to automatically populate some fields. I have used the add on “Add note id” as the bones.

I have it working by using QInputDialog.getInt x 2 to get two user inputs.

BUT I am totally stuck trying to replace those two dialogs and create a single Dialog with multiple widgets. Can some one provide me with or point me to some code to replace my two dialogs with a single dialog.

what I have that works is

__input__.py

def get_index():

    global id_i
    global story_i
    
    #  want to replace the next two lines with a dialog with several widgets

    id_i,ok = QInputDialog.getInt(None, "Auto index +1 will be added ", "Start at")
    story_i,ok = QInputDialog.getText(None, "Auto index", "story number")         

def onLoadNote(self, *args, **kwargs):
    global id_i

    id_i = id_i + 1
    id_s =str(id_i)
    if len(id_s) == 1:
     id_s = '0' + id_s 

    for f in self.note.keys():
            
        if f == config["NoteIdFieldName"] and not self.note[f]:
           # self.note[f] = str(uuid.uuid1())
            self.note[f] = id_s
            
        if f == config["SoundFieldName"] and not self.note[f]:
             self.note[f] = '[sound:'+story_i+'_'+id_s+'.mp3]'          

if config["ShowMenu"]:
     add_nid = QAction(mw)
     mw.form.menuTools.addAction(add_nid)
     add_nid.setText(_("Auto index"))
     add_nid.triggered.connect(get_index)

A Qt tutorial may help: PyQt/Tutorials - Python Wiki

Thanks for the info on Python Wiki.

After a goodly amount of head banging I have finally managed to work out how qt5 dialogs work in Anki and just about have a solution.

Thank you very much to Anki Kings and their custom background addon which gave me most of my solution.

The amount of cut and pasting I did that did not work was amazing, if I new when I started what I know now it would have been so much easier.

I think Python Qt must have been written by a sadist.

whilst struggling with getting this little dialog to work I thought that it would be useful if the user could declare which fields they wanted filled in and with what but I think I will leave that for someone else I need to get back to learning Japanese

For the future, something like


needs more thought

So now have a hacked add on
the dialog constructed from bits in Custom background
the update from Note id
I have left in a whole lot of the original code so it’s not a tidy solution. But it works.

Thank you to the authors of both of those add ons, I could not have done it without you.

Bugs
I currently have one bug and that has to do with another add on ,Japanese Support, the Japanese Support is neat it provides a means to auto generate a field which contains furigana, problem is it reacts with my add on and cause my indexing to jump forward by 1 If I don’t click on the furigana field and then add a new card my indexing works great, if I click on furigana (which then updates the card) and then click on new card my index jumps forward by two instead 1. So I can live with this I just won’t click on that field.