I am new to Python and Qt4 and am running into some problems with taking user entered/selected information and then using them as arguments for other python files. Here's the two situations & code:
- Users enter an ID # into a lineEdit box, and on button click, program will run a script with the ID # entered as an argument. e.g., ID # = 11503, on button click: programname.py 11503 will run. This sort of works, but puts spaces between each number in the ID and I don't know if it's the cleanest way to do what I want.
ID # process button SIGNAL:
QtCore.QObject.connect(self.ui.pushButton_2, QtCore.SIGNAL('clicked()'), self.processID)
SIGNAL calls this:
def processID(self):
import subprocess
from PyQt4 import QtCore, QtGui
rawID = (self.ui.lineEdit.text())
idList = []
for x in rawID:
idList.append(str(x))
subprocess.call(["Python" "programname.py"] + idList, shell=True)
- Pretty much the same situation as above, but one of the arguments needed for the "programname.py" script is a file directory. I have a comboBox populating with the names of the directories, but can't get it to take the selection and print it as an argument. Here's the code for that:
Combobox Directory population
import glob, os
myList = sorted(glob.glob('C:\\Python27\\test_directories\\*'))
new_myList = []
for x in myList:
new_myList.append(os.path.basename(x))
self.ui.comboBox_4.addItems(new_myList)
Directory combobox SIGNAL
self.ui.comboBox_4.activated[str].connect(self.Directory)
I connected a different button to the comboBox and tried to replicate what I did with the lineEdit, but it just won't work at all. However, I CAN print the user selection with the code below, so it's functional, just not in the way I want.
Directory comboBox selection print test
def Directory(self, item):
print(item)
Any help would be greatly appreciated. (And if you make it all the way through this long post, thank you!)