Example Of Using Pyqt (qt4) And Python |
||
Welcome to the Zymic webmaster forums. Our forums are here to provide people the free ability to discuss a range of websites related topics such as design, development coding and marketing.
In order to post you will need to register for a zymic account or if you already have one simply login by using the form on the left.
Zymic Webmaster Forums Web Design & Development Server Side Scripting Python |
||
Example Of Using Pyqt (qt4) And Python |
||
Sep 19 2007, 03:53 AM
Post
#1
|
|
![]() La Naranja ![]() ![]() Group: Moderators Posts: 31 Joined: 18-June 07 From: US Member No.: 16 |
Here is a quick project I whipped up for retrieving the world status and highscore status from a MMORPG called "Runescape".
If you would like me to explain the script a bit more for your help, feel free to post any questions you have here. CODE #!/usr/bin/env python
""" +-----------------------------------------------------------------------------+ | Title: Runescape Utilities +-----------------------------------------------------------------------------+ | Author: Jeyrad Gerson (j3y.net) | Date: 2007-09-17 +-----------------------------------------------------------------------------+ """ import sys from qt import * import urllib #Start HighScores class class RSUtils(QWidget): def __init__(self, *args): QWidget.__init__(self, *args) #Set Window Title self.setCaption("Runescape Utilities") self.layout = QGridLayout(self, 3, 3, 5, 5) #Set up the widgets self.WidgetStart() def WidgetStart(self): """ +-------------------------------------+ | HighScore Widgets +-------------------------------------+ """ #ListView for the Highscores self.hsdisp = QListView(self) self.hsdisp.setMinimumSize(300, 100) self.hsdisp.addColumn("Skill") self.hsdisp.addColumn("Level") self.hsdisp.addColumn("XP") self.hsdisp.addColumn("Rank") #Nickname Textbox self.nickTxt = QLineEdit(self, "Nickname") self.nickTxt.setMinimumWidth(150) # Get Highscores Button self.gethsBtn = QPushButton("Get Highscores", self) self.connect(self.gethsBtn, SIGNAL("clicked()"), self.get_highscores) """ +-------------------------------------+ | World List Widgets +-------------------------------------+ """ #ListView for the World List self.wldisp = QListView(self) self.wldisp.setMinimumSize(490, 100) self.wldisp.addColumn("World") self.wldisp.addColumn("Type") self.wldisp.addColumn("Players") self.wldisp.addColumn("Activity") self.wldisp.addColumn("Location") #Refresh World list self.refreshBtn = QPushButton("Refresh", self) self.connect(self.refreshBtn, SIGNAL("clicked()"), self.get_worldlist) #Setup the widget layout self.layout.addMultiCellWidget(self.hsdisp, 1, 1, 0, 1) self.layout.addWidget(self.wldisp, 1, 2) self.layout.addWidget(self.gethsBtn, 0, 1) self.layout.addWidget(self.nickTxt, 0, 0) self.layout.addWidget(self.refreshBtn, 0, 2) def get_highscores(self): # Clear the HighScore List self.hsdisp.clear() # Grab the web page source url = urllib.urlopen("http://hiscore.runescape.com/hiscorepersonal.ws?user1="+str(self.nickTxt.text())) #Open, read, close through the socket source = url.read() url.close() #Start extracting stuffs self.skill("Overall", source) self.skill("Attack", source) self.skill("Defence", source) self.skill("Strength", source) self.skill("Hitpoints", source) self.skill("Ranged", source) self.skill("Prayer", source) self.skill("Magic", source) self.skill("Cooking", source) self.skill("Woodcutting", source) self.skill("Fletching", source) self.skill("Fishing", source) self.skill("Firemaking", source) self.skill("Crafting", source) self.skill("Smithing", source) self.skill("Mining", source) self.skill("Herblore", source) self.skill("Agility", source) self.skill("Thieving", source) self.skill("Slayer", source) self.skill("Farming", source) self.skill("Runecraft", source) self.skill("Hunter", source) self.skill("Construction", source) def get_worldlist(self): #Clear the listview self.wldisp.clear() # Grab the web page source url = urllib.urlopen("http://www.runescape.com/sln.ws") #Open, read, close through the socket source = url.read() url.close() #Start extracting stuffs # Checking for the empty worlds for i in range(144): if i == 138: lul = "lol" elif i == 139: lul = "lol" elif i == 121: lul = "lol" elif i == 122: lul = "lol" elif i == 48: lul = "lol" elif i == 59: lul = "lol" elif i == 72: lul = "lol" else: #world is not empty, grab and place into listview self.world(str(i+1), source) def extract(self, text, sub1, sub2): # Used for on-the-go slicing simplicity return text.split(sub1)[-1].split(sub2)[0] def world(self, world, text): # Slicing through the source for the specified world text = text.replace("\n", "<") texts = self.extract(text, "World "+world+"<", "</tr>") texts1 = self.extract(texts, "<td>", "<") texts = texts.replace("<td>"+texts1+"</td>", "") texts2 = self.extract(texts, "\">", "</") texts = texts.replace("\">"+texts2+"</td>", "") texts3 = self.extract(texts, "<td>", "</") texts = texts.replace("<td>"+texts3+"</td>", "") texts4 = self.extract(texts, "\">", "<") QListViewItem(self.wldisp, world, texts2, texts3, texts1, texts4) def skill(self, skillname, text): texts = self.extract(text, skillname, "</tr>") texts1 = self.extract(texts, "\">", "<") texts = texts.replace(">"+texts1+"<", "") texts2 = self.extract(texts, "\">", "<") texts = texts.replace(">"+texts2+"<", "") texts3 = self.extract(texts, "\">", "<") lvi = QListViewItem(self.hsdisp, skillname, texts2, texts1, texts3) if __name__ == "__main__": app = QApplication(sys.argv) app.connect(app, SIGNAL('lastWindowClosed()'), app,SLOT('quit()')) rsutils = RSUtils() rsutils.show() app.exec_loop() |
|
|
![]() |
Sep 19 2007, 04:33 AM
Post
#2
|
|
![]() La Naranja ![]() ![]() Group: Moderators Posts: 31 Joined: 18-June 07 From: US Member No.: 16 |
Hehe, very nice, very nice.
|
|
|
Sep 19 2007, 02:44 PM
Post
#3
|
|
|
Ninja ![]() ![]() ![]() Group: Members Posts: 202 Joined: 19-September 07 From: Earth Member No.: 42 |
Nice. I used to play. It's a pretty good game for java.. just got bored eventually.
|
|
|
Jeyrad Example Of Using Pyqt (qt4) And Python Sep 19 2007, 03:53 AM
Zytran Nice one Jeyrad
I writen one awhile back in php, ... Sep 19 2007, 04:31 AM
Alex Good example of how awesome and easy to learn Qt i... Sep 19 2007, 02:57 PM
Julieth Gecko Thanks for letting me buy levitra know about other... Aug 29 2011, 07:33 AM
topmakemoneyideas I thing your wrote well as well as very great and ... Sep 29 2011, 08:32 AM ![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users) |
||
| 0 Members: | ||
Forum Jump |
||
| Lo-Fi Version | Time is now: 20th May 2013 - 07:14 PM |