Last active
February 28, 2016 17:04
-
-
Save donjajo/29576f38c84196aa7aa4 to your computer and use it in GitHub Desktop.
My First Python GUI Program :D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
from PyQt4.QtCore import * | |
from PyQt4.QtGui import * | |
import urllib2 | |
class Form( QDialog ): | |
def __init__( self, parent = None ): | |
super( Form, self ).__init__( parent ) | |
self.urlbox = QLineEdit( 'http://' ) | |
self.urlbox.selectAll | |
self.textBox = QTextBrowser() | |
self.label = QLabel( '<strong>Enter URL:</strong>' ) | |
self.textLabel = QLabel( '<strong>Response:</strong>' ) | |
self.uaText = QLineEdit() | |
self.refererText = QLineEdit() | |
self.options = QComboBox() | |
self.options.insertItem( 0, 'Show Webpage' ) | |
self.options.insertItem( 1, 'Show Response Headers' ) | |
self.button = QPushButton( 'Shit' ) | |
self.copy_button = QPushButton( 'Copy' ) | |
self.host_replace = QLineEdit() | |
grid = QGridLayout() | |
grid.addWidget( self.label, 0, 0 ) | |
grid.addWidget( self.urlbox, 1, 0 ) | |
grid.addWidget( QLabel( 'Options' ), 0, 1 ) | |
grid.addWidget( self.options, 1, 1 ) | |
grid.addWidget( QLabel( 'Custom User Agent:' ), 2, 0 ) | |
grid.addWidget( self.uaText, 3, 0 ) | |
grid.addWidget( QLabel( 'Custom Referer:' ), 2, 1 ) | |
grid.addWidget( self.refererText, 3, 1 ) | |
grid.addWidget( QLabel( 'Replace Host:' ), 4, 0 ) | |
grid.addWidget( self.host_replace, 5, 0, 1,2 ) | |
grid.addWidget( self.textLabel, 6, 0 ) | |
grid.addWidget( self.textBox, 7, 0, 1, 2 ) | |
grid.addWidget( self.button, 8, 0) | |
grid.addWidget( self.copy_button, 8, 1 ) | |
self.setLayout( grid ) | |
self.urlbox.setFocus() | |
self.setWindowTitle( 'Simple Header Response' ) | |
self.connect( self.button, SIGNAL( 'clicked()' ), self.load_page ) | |
self.connect( self.copy_button, SIGNAL( 'clicked()' ), self.copy_text ) | |
def copy_text( self ): | |
clipboard = QApplication.clipboard() | |
clipboard.setText( self.textBox.toPlainText() ) | |
def load_page( self ): | |
url = str( self.urlbox.text() ) | |
self.textBox.insertPlainText( 'Loading...' ) | |
try: | |
ua = self.uaText.text() if self.uaText.text() else '' | |
referer = str( self.refererText.text() ) | |
host = str( self.host_replace.text() ) | |
headers = { } | |
if ua: | |
headers[ 'User-Agent' ] = ua | |
if referer: | |
headers[ 'Referer' ] = referer | |
if host: | |
headers[ 'Host' ] = host | |
request = urllib2.Request( url, headers = headers ) | |
data = urllib2.urlopen( request ) | |
print self.options.currentIndex() | |
if self.options.currentIndex() == 0: | |
self.textBox.clear() | |
self.textBox.insertPlainText( data.read() ) | |
else: | |
self.textBox.clear() | |
self.textBox.insertPlainText( str( data.info() ) ) | |
except urllib2.URLError, e: | |
self.textBox.clear() | |
self.textBox.insertPlainText( 'Error %s' % e ) | |
except urllib2.HTTPError, e: | |
self.textBox.clear() | |
self.textBox.insertPlainText( 'Error %s' % e ) | |
except ValueError, e: | |
self.textBox.clear() | |
self.textBox.insertPlainText( 'Error %s' % e ) | |
app = QApplication( sys.argv ) | |
form = Form() | |
form.show() | |
form.exec_() |
Hehehe, forgot to clean up that...Was using it as test data :D
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did your code actually say shit.???