0

I would say I'm fairly decent with Python, but creating GUIs is a new concept for me. I've used Qt Creator to format the GUI and pyuic to convert the code from the file.ui.

I have most of the GUI coded, but I'm having this problem updating the text for labels for line edits, push buttons etc. So this GUI has an options window that opens from the main program where the user can specify certain parameters. Currently, I open the options, set the values, close, reopen the option window, and the text has not changed to the new values which are variables. Plain strings do work however. Variables will 'stick,' only if the program is restarted.

I'm importing a config.py file where there is a variable containing the string of parameters. These are formatted and set alongside all other labels etc. But there not being set for some reason.

config.py

configAttrs="clientid,oauth,123,source,123"

A nested function of mainProgram.py used to set the text of the labels etc.

def retranslateUi(self, OptionsWindow):
    OptionsWindow.setWindowTitle(_translate("OptionsWindow", "OptionsWindow", None))
    self.label_MainOptions.setText(_translate("OptionsWindow", "Options", None))


    confs = config.configAttrs.split(',')
    clientid = str(confs[0])
    oauth =  str(confs[1])
    cache = str(confs[2])
    heightAdjust = str(confs[4])

    #does NOT work when reopening options window
    #does work with restart
    self.lineEdit_ClientID.setText(_translate("OptionsWindow", clientid, None))

    #does NOT work when reopening options window
    #does work with restart
    self.lineEdit_ClientID.setText('{0}'.format(clientid))

    #does work when reopening options window
    #does work with restart
    self.lineEdit_ClientID.setText(_translate("OptionsWindow", 'string_clientid', None))

Shortened the code above.*

datguy.dev
  • 31
  • 1
  • 5
  • When you say it does not work you mean that when you run your application again it does not show what you saw before closing it? – eyllanesc May 30 '17 at 05:57
  • I'm new to stackoverflow, is there a reply button around here? :D I've added galleries to the OP to express the problem. – datguy.dev May 30 '17 at 06:25
  • I still do not understand you, you could explain it better. – eyllanesc May 30 '17 at 06:37
  • Do not put link of the images, if possible try to work everything here, then in some time these links will be broken and nobody can see them or replicate the solution or understand the problem. – eyllanesc May 30 '17 at 06:41
  • I understand your problem, to solve it I have to have a minimum code and reproduce the error, and the code you show is not ... you could share your code via github, drive or similar. – eyllanesc May 30 '17 at 06:47
  • Thanks for your attention, but I don't not know how to further explain it. I've posted the project folder if your interested. If I find a solution, I can edit the post more accurately. – datguy.dev May 30 '17 at 06:48

1 Answers1

0

The problem is caused because although the config.py file is modified this is not automatically reloaded by python, in order to force it you must use reload, in your case:

def retranslateUi(self, OptionsWindow):
    [...]
    reload(config)
    confs = config.configAttrs.split(',')
    [...]
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • That makes perfect sense. There are changes made to the config file, but it is only imported once at the very top of the main.py file. So the changes would only appear after a full restart. And now I feel dumb for overlooking such as simple task. :) I really needed a second pair of eyes as I'm not used to so much clutter given the GUI. Thank you Eyllanesc! – datguy.dev May 30 '17 at 22:43