2

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:

  1. 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)
  1. 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!)

  • UPDATE: I have the comboBox directory selection printing as an argument for the file run with subprocess now. I copied the lineEdit subprocess code only I replaced (self.ui.lineEdit.text()) with (self.ui.comboBox_4.currentText()) However, it's still printing the arguments with spaces between each value. Is there something really basic I'm missing here? Perhaps it has something to do with subprocess wanting arguments to come from a list and the way I am appending the user entered info to idList? – rocketstothemoon Feb 14 '14 at 23:02
  • UPDATE #2: Still struggling with the lists being appended with each character (string or int) being added as an individual item in the list. I've fumbled through a ton of ideas, but can't get them to be added as whole words/number groups. The rest seems to work, even tho my instinct says it's not the most efficient way. Would love some feedback...ANY thoughts on this are greatly appreciated. – rocketstothemoon Feb 16 '14 at 01:20
  • UPDATE #3: Figured it out on my own. It was a beginner mistake. Not sure why someone didn't comment and point it out. – rocketstothemoon Feb 16 '14 at 08:36

0 Answers0