Created
June 30, 2014 20:41
-
-
Save dijit/6011edf5f6d76e9640b9 to your computer and use it in GitHub Desktop.
Testing some things I've never used before, mostly Qt, some argument parsing, copying to clipboard etc;
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 | |
# -*- coding: utf-8 -*- | |
"""" | |
Author: Jan Harasym <jharasym@linux.com> | |
Website: dijit.sh | |
Creation Date: 30-06-2014 | |
Last Modified: Mon 30 Jun 2014 21:40:53 BST | |
Description: | |
Expected Use: | |
""" | |
from optparse import OptionParser | |
from PySide import QtGui, QtCore | |
import urllib | |
import sys | |
def Get_IP(): | |
try: | |
sock = urllib.urlopen("http://eitin.drk.sc/~dijit/ip.php") | |
except: | |
sock = urllib.urlopen("http://ifconfig.me") | |
IP = sock.readline().rstrip() | |
del sock | |
return(IP) | |
class Small_Window(QtGui.QWidget): | |
def __init__(self): | |
super(Small_Window, self).__init__() | |
self.IP = Get_IP() | |
self.create_window() | |
self.create_buttons() | |
def create_window(self): | |
self.resize(96, 25) | |
self.center() | |
self.setWindowTitle('IP Tracker in Qt/Python') | |
def create_buttons(self): | |
button = QtGui.QPushButton(self.IP, self) | |
button.move(1, 1) | |
button.clicked.connect(self.copy_clip) | |
def copy_clip(self): | |
clipboard = QtGui.QApplication.clipboard() | |
clipboard.setText(self.IP) | |
def center(self): | |
qr = self.frameGeometry() | |
cp = QtGui.QDesktopWidget().availableGeometry().center() | |
qr.moveCenter(cp) | |
self.move(qr.topLeft()) | |
def main(): | |
parser = OptionParser() | |
parser.add_option("-w", "--window", action="store_true", dest="windowed", default=False, help="Run in windowed mode") | |
(options, args) = parser.parse_args() | |
if options.windowed == True: | |
app = QtGui.QApplication(sys.argv) | |
window = Small_Window() | |
window.show() | |
sys.exit(app.exec_()) | |
else: | |
print(Get_IP()) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't need QtCore, ignore that.