3 Replies - 542 Views - Last Post: 06 September 2013 - 10:59 PM Rate Topic: -----

#1 XaPiQ  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 05-September 13

Send input from one script to another

Posted 05 September 2013 - 03:47 AM

Hello everyone,

I'm trying to get the input from PyQt4 gui script to be processed by my main script, but this thing does not works and I just call my other program when I click the OK button. The purpose of having GUI is to ease the process from launching a new terminal and navigating thru the directories and typing python dd.py 123456 (where the numbers will be processed by the script). What I want is the input from pyqt4 to be sent over dd.py as is, without the need to open up or call dd.py manually. These are the both scripts:

pyqt4.py:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'untitled.ui'
#
# Created: Tue Sep  3 16:46:29 2013
#      by: PyQt4 UI code generator 4.10.3
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui
import sys
import os
import subprocess

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s


def butsend():
    subprocess.call(["xfce4-terminal", "-H", "-x", "python2", "dd.py"])

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName(_fromUtf8("Dialog"))
        Dialog.resize(400, 79)
        self.buttonBox = QtGui.QDialogButtonBox(Dialog)
        self.buttonBox.setGeometry(QtCore.QRect(50, 30, 341, 32))
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
        self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
        self.lineEdit = QtGui.QLineEdit(Dialog)
        self.lineEdit.setGeometry(QtCore.QRect(10, 30, 161, 31))
        self.lineEdit.setObjectName(_fromUtf8("lineEdit"))

        self.retranslateUi(Dialog)
        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), butsend)
        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), Dialog.reject)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    Dialog = QtGui.QDialog()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    Dialog.show()
    sys.exit(app.exec_())




dd.py (the script that must process the numbers):
#!/usr/bin/env python
# touchspeedcalc_test.py (2009/10/09)
# Example for demonstrating use of SpeedTouch wireless router default password lookup tables
#
# 	http://www.mentalpitstop.com/touchspeedcalc
#
# Distributed under the Creative Commons Attribution Non-commercial Share-Alike license,
# http://creativecommons.org/licenses/by-nc-sa/3.0/us/
# Contact me at mentalpitstop.com for more information and licensing info.
#
# Make sure the correct modules (like hashlib) are installed in your python version, as I've noticed some python versions (2.4 vs 2.6) handle this differently
# Created and tested with Python 2.6
# Note that the data files must be located in the /data/ subdirectory for this script to find them.
#
# Usage:
# 	python2.6 touchspeedcalc_test.py [SSID]
# Where [SSID] are the last 6 characters of the SSID.
#
# Edit the 'YEARS' variable if you want to include 2010 (not tested)

import hashlib
import sys
import binascii
import re


#SSIDEND = "1234AB"	#example
if len(sys.argv) < 2:
  print str(len(sys.argv))
  print "Usage: "
  print "  python2.6 touchspeedcalc_test.py [SSID]"
  print "Where [SSID] are the last 6 characters of the SSID."
  sys.exit()

SSIDEND = sys.argv[1].upper()
#sys.argv[1].decode("hex")


if len(SSIDEND) == 6:
  #SpeedTouch:
  FINDPOS = 0
elif len(SSIDEND) == 4:
  #BT HomeHub:
  FINDPOS = 1
else:
  print "SSID-end must be either 6 or 4 characters."
  sys.exit()

YEARS = [2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029, 2030, 2031, 2032, 2033, 2034, 2035, 2036, 2037, 2038, 2039, 2040, 2041, 2042, 2043, 2044, 2045, 2046, 2047, 2048, 2049, 2050, 2051, 2052, 2053, 2054, 2055, 2056, 2057, 2058, 2059, 2060, 2061, 2062, 2063, 2064, 2065, 2066, 2067, 2068, 2069, 2070, 2071, 2072, 2073, 2074, 2075, 2076, 2077, 2078, 2079, 2080, 2081, 2082, 2083, 2084, 2085, 2086, 2087, 2088, 2089, 2090, 2091, 2092, 2093, 2094, 2095, 2096, 2097, 2098, 2099, 2100]
#YEARS = [ 2009, 2008, 2007, 2006, 2005, 2004, 2010 ]
#YEAR = sys.argv[2].lower()

def ascii2hex(char):
  return hex(ord(char))[2:].upper()

CHARSET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
BINCODE = binascii.unhexlify("".join(SSIDEND.split()))
#print "Compressed SSID: ", BINCODE


for YEAR in YEARS:
  FILE = "db/db_with_keys___" + str(YEAR) + ".dat"
  INFILE = open(FILE,"rb")
  FILEDATA = INFILE.read()
  INFILE.close()
  WHEREFOUND = FILEDATA.find(BINCODE, 0)
  while (WHEREFOUND > -1):
    if WHEREFOUND % 3 == FINDPOS:
      PRODIDNUM = (WHEREFOUND / 3) % (36*36*36)
      PRODWEEK = (WHEREFOUND / 3) / (36*36*36) +1
      PRODID1 = PRODIDNUM / (36*36)
      PRODID2 = (PRODIDNUM / 36) % 36
      PRODID3 = PRODIDNUM % 36
      SERIAL = 'CP%02d%02d%s%s%s' % (YEAR-2000,PRODWEEK,ascii2hex(CHARSET[PRODID1:PRODID1+1]),ascii2hex(CHARSET[PRODID2:PRODID2+1]),ascii2hex(CHARSET[PRODID3:PRODID3+1]))
      SHA1SUM = hashlib.sha1(SERIAL).digest().encode("hex").upper()
      SSID = SHA1SUM[-6:]
      ACCESSKEY = SHA1SUM[0:10]
      if len(SSIDEND) == 4:
        # BT HomeHub password is lowercase:
        ACCESSKEY = ACCESSKEY.lower()
      #print "Serial number:", str(SERIAL)  # does not give proper serial number for the thompsons BT series
      #print "SHA1SUM:", str(SHA1SUM)
      print "", str(ACCESSKEY)

    WHEREFOUND = FILEDATA.find(BINCODE, WHEREFOUND+1)


I've tried earlier with but it does not opens a new window and does not process the input numbers
def butsend(self):
    my_button = subprocess.Popen("/home/frost/Desktop/dd.py " + self.argument ,shell=True)
    return my_button.read() 


Is This A Good Question/Topic? 0
  • +

Replies To: Send input from one script to another

#2 XaPiQ  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 05-September 13

Re: Send input from one script to another

Posted 05 September 2013 - 03:55 AM

Take a look at the video: https://docs.google....dit?usp=sharing , this is what it should do, but in this demo I added earlier these numbers in the dd.py script. I want the input to be sent over dd.py and be processed from it, without the need to add manually these numbers anymore.
Was This Post Helpful? 0
  • +
  • -

#3 woooee  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 89
  • Joined: 21-November 12

Re: Send input from one script to another

Posted 05 September 2013 - 08:31 AM

The easiest way is to pass the input to a function or class in the second program. You have to import the second program file so the first program knows about it.
## test_1.py
import second_program
user_input = raw_input("Enter something ")
second_program.print_input(user_input)

## second_program.py
def print_input(str_in):
    print "second_program", str_in 

This post has been edited by woooee: 05 September 2013 - 08:32 AM

Was This Post Helpful? 1
  • +
  • -

#4 XaPiQ  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 05-September 13

Re: Send input from one script to another

Posted 06 September 2013 - 10:59 PM

View Postwoooee, on 05 September 2013 - 08:31 AM, said:

The easiest way is to pass the input to a function or class in the second program. You have to import the second program file so the first program knows about it.
## test_1.py
import second_program
user_input = raw_input("Enter something ")
second_program.print_input(user_input)

## second_program.py
def print_input(str_in):
    print "second_program", str_in 


Thank you so much wooee :-)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1