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/env python | |
# -*- coding: utf-8 -*- | |
# -*- coded by db~@NC -*- | |
import os | |
import sys | |
import traceback | |
import types | |
import getpass | |
import locale | |
import warnings | |
import time | |
import logging | |
import random | |
import urllib | |
import threading,thread | |
from decimal import Decimal | |
import wx | |
if "2.8" in wx.version(): | |
import wx.lib.pubsub.setupkwargs | |
else: | |
from wx.lib.pubsub import setuparg1 | |
import wx.lib.agw.hyperlink as hl | |
import wx, wx.html | |
#MIN_SIZE = (400,500) | |
class MainWindow(wx.Frame): | |
def __init__(self,parent,id,title): | |
wx.Frame.__init__(self, parent,id,title="Nimbuzz Simple Login App Coded by db~@NC",size=(520,600),style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER ^ wx.MAXIMIZE_BOX) | |
self.parent = None | |
self.initialize() | |
def initialize(SELF): | |
db1_lbl_sizer = wx.BoxSizer(wx.HORIZONTAL) | |
db1_lbl = wx.StaticText(SELF,wx.ALIGN_RIGHT ,label="Nimbuzz Login WXPYTHON GUI Coded by db~@NC") | |
db1_lbl_sizer.Add(db1_lbl,0,wx.ALL,5) | |
db1_lbl.SetForegroundColour(wx.BLUE) | |
font_db1_lbl = wx.Font(15, wx.DECORATIVE, wx.ITALIC, wx.BOLD) | |
db1_lbl.SetFont(font_db1_lbl) | |
def resource_path(relative): #define RESOURCE PATH from where all the required resources are loaded when script is being executed | |
if hasattr(sys,"_MEIPASS"): | |
return os.path.join(sys._MEIPASS, relative) | |
return os.path.join(relative) | |
image_sizer = wx.BoxSizer(wx.HORIZONTAL) | |
image = wx.StaticBitmap(SELF,-1,size=(545,80)) | |
image.SetBitmap(wx.Bitmap(resource_path('images\db.jpg'))) #Replace this folder and filename with your required needs | |
image_sizer.Add(image,0,wx.RIGHT,5) | |
user_sizer = wx.BoxSizer(wx.HORIZONTAL) | |
user_lbl = wx.StaticText(SELF, label= "Username:") | |
user_sizer.Add(user_lbl,0,wx.ALL|wx.CENTER,5) | |
SELF.user = wx.TextCtrl(SELF) | |
user_sizer.Add(SELF.user,0,wx.ALL,2) | |
p_sizer = wx.BoxSizer(wx.HORIZONTAL) | |
p_lbl = wx.StaticText(SELF, label="Password:") | |
p_sizer.Add(p_lbl,0,wx.ALL|wx.CENTER,5) | |
SELF.password = wx.TextCtrl(SELF, style=wx.TE_PASSWORD|wx.TE_PROCESS_ENTER) | |
p_sizer.Add(SELF.password,0,wx.ALL,4) | |
res_sizer = wx.BoxSizer(wx.HORIZONTAL) | |
res_lbl = wx.StaticText(SELF, label= "Resource:") | |
res_sizer.Add(res_lbl,0,wx.ALL|wx.CENTER,6) | |
SELF.res = wx.TextCtrl(SELF) | |
res_sizer.Add(SELF.res,0,wx.ALL,5) | |
room_sizer = wx.BoxSizer(wx.HORIZONTAL) | |
room_lbl = wx.StaticText(SELF, label= "Room:") | |
room_sizer.Add(room_lbl,0,wx.ALL|wx.CENTER,14) | |
SELF.room = wx.TextCtrl(SELF) | |
room_sizer.Add(SELF.room,0,wx.ALL,5) | |
button_sizer = wx.BoxSizer(wx.HORIZONTAL) | |
SELF.button = wx.Button(SELF,-1,label="Login") | |
SELF.Bind(wx.EVT_BUTTON,SELF.OnButtonClick,SELF.button) | |
button_sizer.Add(SELF.button,0,wx.LEFT,70) | |
font_button= wx.Font(12, wx.DECORATIVE, wx.ITALIC, wx.BOLD) | |
SELF.button.SetFont(font_button) | |
SELF.button.SetForegroundColour(wx.RED) | |
listbox_sizer = wx.BoxSizer(wx.HORIZONTAL) | |
SELF.dbListBox = wx.ListBox(SELF,-1,size=(400,230),style=wx.LB_SINGLE|wx.LB_SORT) | |
listbox_sizer.Add(SELF.dbListBox,0,wx.CENTER,5) | |
SELF.dbListBox.SetForegroundColour(wx.BLUE) | |
SELF.dbListBox.Show(True) | |
main_sizer= wx.BoxSizer(wx.VERTICAL) | |
main_sizer.Add(db1_lbl_sizer,0,wx.ALL,3) | |
main_sizer.Add(image_sizer,0,wx.ALIGN_RIGHT,5) | |
main_sizer.Add(user_sizer,0,wx.ALL,3) | |
#main_sizer.Add(avi_sizer,0,wx.ALIGN_RIGHT,0) | |
main_sizer.Add(p_sizer,0,wx.ALL,3) | |
main_sizer.Add(res_sizer,0,wx.ALL,3) | |
main_sizer.Add(room_sizer,0,wx.ALL,3) | |
main_sizer.Add(button_sizer,0,wx.ALIGN_LEFT,5) | |
main_sizer.Add(SELF.dbListBox,0,wx.CENTER,15) | |
#main_sizer.Add(button2_sizer,0,wx.ALIGN_RIGHT,0) | |
hyper_sizer = wx.BoxSizer(wx.HORIZONTAL) | |
hyper = hl.HyperLinkCtrl(SELF,-1,"For More Nimbuzz Tools, Visit my Blog now!",URL="http://dbh4ck.blogspot.in") | |
hyper_sizer.Add(hyper,0,wx.ALL|wx.CENTER,10) | |
#wx.LaunchDefaultBrowser("http://dbh4ck.blogspot.in") | |
hyper.AutoBrowse(False) | |
hyper.SetColours("BLUE","BLUE","BLUE") | |
hyper.EnableRollover(True) | |
hyper.SetUnderlines(False,False,True) | |
hyper.SetBold(True) | |
hyper.OpenInSameWindow(True) | |
main_sizer.Add(hyper,0,wx.CENTER,8) | |
SELF.SetSizer(main_sizer) | |
SELF.Show(True) | |
SELF.Center() | |
def OnButtonClick(SELF,event): | |
STATUS = 'db here' | |
SHOW = 'chat' | |
NICK = 'G-Fiber' | |
SERVER = 'nimbuzz.com' | |
HOST = 'o.nimbuzz.com' | |
PORT = 5222 | |
ROOM_SERVER = 'conference.nimbuzz.com' | |
USR = SELF.user.GetValue() | |
PW = SELF.password.GetValue() | |
RS = SELF.res.GetValue() | |
usrjid='%s@%s/%s'%(USR,SERVER,RS) | |
import xmpp | |
class db: | |
def __init__(self): #initialize class and setup connection details to get connected to Nimbuzz server | |
self.client = xmpp.Client('nimbuzz.com', debug=False) | |
if self.client.connect( server=('o.nimbuzz.com',5222), secure=False ): | |
print ("Connected") | |
print ("\nTrying to login..\n") | |
if self.client.auth(USR,PW,'res'): | |
print ("Logged in\n\n") | |
SELF.user.SetBackgroundColour(wx.GREEN) | |
SELF.password.SetBackgroundColour(wx.GREEN) | |
SELF.res.SetBackgroundColour(wx.GREEN) | |
else: | |
print ("Unable to Login. Check your username and password") | |
SELF.user.SetBackgroundColour(wx.RED) | |
SELF.password.SetBackgroundColour(wx.RED) | |
SELF.res.SetBackgroundColour(wx.RED) | |
raw_input('Press Enter to exit...') | |
sys.exit(1) | |
else: | |
print ("Couldn't Connect. Restarting..") | |
os.execl(sys.executable, sys.executable, sys.argv[0]) | |
prs = xmpp.simplexml.XML2Node(unicode("<presence><status>%s</status><priority>1</priority><show>%s</show><nick xmlns='http://jabber.org/protocol/nick'>%s</nick></presence>" % (STATUS,SHOW,NICK)).encode('utf8')) | |
self.client.send(prs) | |
roster = self.client.getRoster() | |
#self.client.sendInitPresence() | |
items = roster.getItems() | |
for jid in items: | |
name = roster.getName(jid) | |
jidres = roster.getResources(jid) | |
for res in jidres: | |
resource = roster.getResources(jid.split('/', 1)[0] + '/' + res) | |
dbcontactlist = u'%s %s/%s' % (name or '', jid, res) | |
SELF.dbListBox.Append(str(dbcontactlist)) | |
chatroom = SELF.room.GetValue() | |
muc = xmpp.simplexml.XML2Node("<presence to ='%s@conference.nimbuzz.com/%s'><priority>1</priority></presence>"%(chatroom,NICK)) | |
self.client.send(muc) | |
def wake(self): | |
self.awake = True | |
def messages(self, msg): | |
frm = unicode(msg.getFrom()).encode('utf8') | |
typ = msg.getType() | |
body = msg.getBody() | |
print frm, typ, body | |
print msg | |
self.client.RegisterHandler('message',messages) | |
while 1: | |
self.client.Process() | |
if __name__ == '__main__': | |
logging.basicConfig(level=logging.ERROR, format='%(levelname)-8s %(message)s') | |
xmpp = db() | |
xmpp.wake() | |
if __name__ == "__main__": | |
app = wx.App(False) | |
frame = MainWindow(None,wx.ID_ANY,'Nimbuzz Login wxPython GUI App') | |
app.MainLoop() |