Handle soft dependency for wxPython properly, addresses #6

This commit is contained in:
Ammar Askar 2012-09-08 03:07:17 +05:00
parent 057804b93e
commit 4ffcc4b04d
3 changed files with 43 additions and 35 deletions

14
GUI.py
View File

@ -1,15 +1,17 @@
import wx
import wx.lib.scrolledpanel as scrolled
import wx.richtext as rt
import start import start
import threading import threading
import time import time
from networking import NetworkManager, PacketSenderManager from networking import NetworkManager, PacketSenderManager
import thread import thread
from threading import Lock from threading import Lock
try:
#pydev error fix import wx
wx=wx import wx.lib.scrolledpanel as scrolled
import wx.richtext as rt
#Eclipse pyDev error fix
wx=wx
except ImportError:
pass
connection = None connection = None

View File

@ -1,5 +1,4 @@
import socket import socket
import wx
import PacketListenerManager import PacketListenerManager
import urllib2 import urllib2
import urllib import urllib
@ -14,9 +13,12 @@ from Crypto.Util import asn1
from Crypto.PublicKey import RSA from Crypto.PublicKey import RSA
from Crypto.Cipher import AES from Crypto.Cipher import AES
from Crypto.Cipher import PKCS1_v1_5 from Crypto.Cipher import PKCS1_v1_5
try:
#Eclipse pyDev error fix import wx
wx=wx #Eclipse pyDev error fix
wx=wx
except ImportError:
pass
EntityID = 0 EntityID = 0

View File

@ -4,16 +4,16 @@ import getpass
import sys import sys
from networking import PacketSenderManager, NetworkManager from networking import PacketSenderManager, NetworkManager
import NoGUIstuff import NoGUIstuff
import GUI
import time import time
import threading import threading
noGoooeees = False wxImportError = False
try: try:
import wx import wx
import GUI
wx = wx wx = wx
except ImportError: except ImportError:
print "wxPython not found, falling back to no gui version" print "wxPython not found, falling back to no gui version"
noGoooeees = True wxImportError = True
class MinecraftLoginThread(threading.Thread): class MinecraftLoginThread(threading.Thread):
@ -97,29 +97,33 @@ class KeepConnectionAlive(threading.Thread):
self.window.parent.loggedIn = True self.window.parent.loggedIn = True
if __name__ == "__main__": if __name__ == "__main__":
noGUI = False
if (len(sys.argv) > 1): if (len(sys.argv) > 1):
if(sys.argv[1] == "nogui" or noGoooeees == True): if (sys.argv.count("nogui") > 1) :
user = raw_input("Enter your username: ") noGUI = True
passwd = getpass.getpass("Enter your password: ")
derp = NoGUIstuff.loginToMinecraft(user, passwd) if(noGUI or wxImportError):
if(derp['Response'] == "Incorrect username/password" or derp['Response'] == "Can't connect to minecraft.net" or derp['Response'] == "Account migrated, use e-mail as username."): user = raw_input("Enter your username: ")
print derp['Response'] passwd = getpass.getpass("Enter your password: ")
sys.exit() derp = NoGUIstuff.loginToMinecraft(user, passwd)
sessionid = derp['SessionID'] if(derp['Response'] == "Incorrect username/password" or derp['Response'] == "Can't connect to minecraft.net" or derp['Response'] == "Account migrated, use e-mail as username."):
print "Logged in as " + derp['Username'] + "! Your session id is: " + sessionid print derp['Response']
stuff = raw_input("Enter host and port if any: ") sys.exit()
if ':' in stuff: sessionid = derp['SessionID']
StuffEnteredIntoBox = stuff.split(":") print "Logged in as " + derp['Username'] + "! Your session id is: " + sessionid
host = StuffEnteredIntoBox[0] stuff = raw_input("Enter host and port if any: ")
port = int(StuffEnteredIntoBox[1]) if ':' in stuff:
else: StuffEnteredIntoBox = stuff.split(":")
host = stuff host = StuffEnteredIntoBox[0]
port = 25565 port = int(StuffEnteredIntoBox[1])
connection = NetworkManager.ServerConnection(None, derp['Username'], passwd, sessionid, host, port) else:
connection.start() host = stuff
while True: port = 25565
chat = raw_input() connection = NetworkManager.ServerConnection(None, derp['Username'], passwd, sessionid, host, port)
PacketSenderManager.send03(connection.grabSocket(), chat) connection.start()
while True:
chat = raw_input()
PacketSenderManager.send03(connection.grabSocket(), chat)
else: else:
app = wx.PySimpleApp() app = wx.PySimpleApp()
Login = GUI.MainFrame(None, -1, "") Login = GUI.MainFrame(None, -1, "")