I am writing a pyqt application that will go and grab a wifi password behind a password protected site, I want to write a qt application that will use the form to provide my python script with the username and password, then return all that information back and put it in a label i've previously left blank. Here is the Qt code:
from PyQt4.QtGui import QApplication, QWidget, QLabel, QComboBox, QLineEdit, QPushButton
import sys
import wifiRetriever
qt_app = QApplication(sys.argv)
class pyGui(QWidget):
def __init__(self):
# Initialize the object as a QWidget
QWidget.__init__(self)
# We have to set the size of the main window
# ourselves, since we control the entire layout
self.setMinimumSize(400, 185)
self.setWindowTitle('some Public Wifi')
# Create the controls with this object as their parent and set
# their position individually; each row is a label followed by
# another control
# Label for the username field
self.username_lbl = QLabel('Username', self)
self.username_lbl.move(5, 5)
self.username = QLineEdit(self)
self.username.setPlaceholderText("some Username")
# Allow 100px for the label and 5px each for borders at the
# far left, between the label and the combobox, and at the far
# right
self.username.setMinimumWidth(285)
# Place it five pixels to the right of the end of the label
self.username.move(110, 5)
# The label for the password
self.password_lbl = QLabel('Password:', self)
# 5 pixel indent, 25 pixels lower than last pair of widgets
self.password_lbl.move(5, 50)
# The recipient control is an entry textbox
self.password = QLineEdit(self)
# Add some ghost text to indicate what sort of thing to enter
self.password.setPlaceholderText("some Password")
# Same width as the salutation
self.password.setMinimumWidth(285)
# Same indent as salutation but 25 pixels lower
self.password.move(110, 50)
# Hide the Characters
self.password.setEchoMode(QLineEdit.Password)
# The label for the greeting widget
self.guestWifi_lbl = QLabel('Guest Wifi Password is:', self)
# Same indent as the others, but 45 pixels lower so it has
# physical separation, indicating difference of function
self.guestWifi_lbl.move(5, 100)
# The greeting widget is also a label
self.greeting = QLabel('', self)
# Same indent as the other controls
self.greeting.move(175, 100)
# The build button is a push button
self.build_button = QPushButton('Submit', self)
# Place it at the bottom right, narrower than
# the other interactive widgets
self.build_button.setMinimumWidth(145)
self.build_button.move(250, 150)
def run(self):
# Show the form
self.show()
# Run the Qt application
qt_app.exec_()
app = pyGui()
app.run()`
And Here is the python Script, (I know this works as I'm running it as a script already printing the value instead of returning it.)
#! /usr/bin/python2.7
import urllib2
import getpass
from BeautifulSoup import BeautifulSoup
import re
def getWifiPassword(username, password):
url = 'someurl'
# username = getpass._raw_input('What is your username?: ')
# password = getpass.unix_getpass('Password: ')
p = urllib2.HTTPPasswordMgrWithDefaultRealm()
p.add_password(None, url, username, password)
handler = urllib2.HTTPBasicAuthHandler(p)
opener = urllib2.build_opener(handler)
urllib2.install_opener(opener)
page = urllib2.urlopen(url).read()
soup = BeautifulSoup(page)
data = soup.findAll('strong')
for d in data:
value= re.sub("<.*?>", "", str(d))
return value
Any Help would be greatly appreciated as qt and gtk seem to be really kicking my butt. Thanks!