Added user list + some cosmetics to GGSChat
This commit is contained in:
parent
c4f244e778
commit
7de4fc58cd
3 changed files with 134 additions and 11 deletions
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys, socket, thread, gobject, getpass
|
||||
import sys, socket, thread, gobject, getpass, time
|
||||
try:
|
||||
import pygtk
|
||||
pygtk.require("2.16")
|
||||
|
@ -16,12 +16,14 @@ class GGSChat:
|
|||
|
||||
def __init__(self,host, port):
|
||||
#Set the Glade file
|
||||
self.nicksListStore = gtk.ListStore(str)
|
||||
self.gladefile = "ggschat.glade"
|
||||
self.wTree = gtk.glade.XML(self.gladefile, "window1")
|
||||
|
||||
self.setStatus("Not connected")
|
||||
self.connect(host, port)
|
||||
thread.start_new_thread(self.listenChat, ())
|
||||
thread.start_new_thread(self.luserCheck, ())
|
||||
#Create our dictionay and connect it
|
||||
dic = {"on_window1_destroy_event" : gtk.main_quit
|
||||
, "on_sendButton_clicked" : lambda x: self.chat()
|
||||
|
@ -35,7 +37,15 @@ class GGSChat:
|
|||
self.wTree.get_widget("nickBox").set_text(getpass.getuser())
|
||||
self.wTree.get_widget("window1").show()
|
||||
self.wTree.get_widget("entry").grab_focus()
|
||||
nicksList = self.wTree.get_widget("nicksList")
|
||||
self.changeNick()
|
||||
nicksList.set_model(self.nicksListStore)
|
||||
# self.nicksListStore.append(["Test!"])
|
||||
|
||||
rendererText = gtk.CellRendererText()
|
||||
column = gtk.TreeViewColumn("Participants", rendererText, text=0)
|
||||
column.set_sort_column_id(0)
|
||||
nicksList.append_column(column)
|
||||
|
||||
def setStatus(self, msg):
|
||||
self.wTree.get_widget("statusbar").push(0, msg)
|
||||
|
@ -90,10 +100,30 @@ class GGSChat:
|
|||
while True:
|
||||
line = fs.readline()
|
||||
print "Received: ", line
|
||||
if line.split(" ")[0] == "LUSERS":
|
||||
gobject.idle_add(self.updateUsers, line)
|
||||
else:
|
||||
gobject.idle_add(self.updateChatText, line)
|
||||
|
||||
def updateChatText(self, text):
|
||||
self.wTree.get_widget("chatBox").get_buffer().insert_at_cursor(text)
|
||||
|
||||
def luserCheck(self):
|
||||
while True:
|
||||
self.s.send("Game-Command: lusers\n" +
|
||||
"Token: %s\n" % self.token +
|
||||
"Content-Type: text\n" +
|
||||
"Content-Length: 0\n"+
|
||||
"\n")
|
||||
time.sleep(2)
|
||||
|
||||
def updateUsers(self, text):
|
||||
nicks = ' '.join(text.split(" ")[1:])
|
||||
evalNicks = eval(nicks)
|
||||
self.nicksListStore.clear()
|
||||
for nick in evalNicks:
|
||||
self.nicksListStore.append([nick])
|
||||
|
||||
if __name__ == "__main__":
|
||||
host = "localhost"
|
||||
port = 9000
|
||||
|
|
|
@ -10,22 +10,115 @@
|
|||
<widget class="GtkVBox" id="vbox1">
|
||||
<property name="visible">True</property>
|
||||
<child>
|
||||
<widget class="GtkHBox" id="hbox1">
|
||||
<widget class="GtkMenuBar" id="menubar1">
|
||||
<property name="visible">True</property>
|
||||
<property name="ubuntu_local">True</property>
|
||||
<child>
|
||||
<widget class="GtkMenuItem" id="menuitem1">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">_File</property>
|
||||
<property name="use_underline">True</property>
|
||||
<child>
|
||||
<widget class="GtkMenu" id="menu1">
|
||||
<property name="visible">True</property>
|
||||
<property name="ubuntu_local">True</property>
|
||||
<child>
|
||||
<widget class="GtkImageMenuItem" id="connectMenu">
|
||||
<property name="label" translatable="yes">Connect to ...</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_stock">False</property>
|
||||
<child internal-child="image">
|
||||
<widget class="GtkImage" id="image1">
|
||||
<property name="visible">True</property>
|
||||
<property name="stock">gtk-missing-image</property>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkSeparatorMenuItem" id="separatormenuitem1">
|
||||
<property name="visible">True</property>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkImageMenuItem" id="imagemenuitem5">
|
||||
<property name="label">gtk-quit</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkMenuItem" id="menuitem4">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">_Help</property>
|
||||
<property name="use_underline">True</property>
|
||||
<child>
|
||||
<widget class="GtkMenu" id="menu3">
|
||||
<property name="visible">True</property>
|
||||
<property name="ubuntu_local">True</property>
|
||||
<child>
|
||||
<widget class="GtkImageMenuItem" id="imagemenuitem10">
|
||||
<property name="label">gtk-about</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkHPaned" id="hpaned1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<child>
|
||||
<widget class="GtkScrolledWindow" id="scrolledwindow1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="hscrollbar_policy">automatic</property>
|
||||
<property name="vscrollbar_policy">automatic</property>
|
||||
<child>
|
||||
<widget class="GtkTextView" id="chatBox">
|
||||
<property name="width_request">412</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="editable">False</property>
|
||||
<signal name="focus" handler="on_chatBox_focus"/>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">0</property>
|
||||
<property name="resize">True</property>
|
||||
<property name="shrink">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkTreeView" id="nicksList">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="border_width">1</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="resize">False</property>
|
||||
<property name="shrink">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">0</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -74,7 +167,7 @@
|
|||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -84,7 +177,7 @@
|
|||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="position">2</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
|
|
|
@ -54,7 +54,7 @@ do_stuff(Command, Args, Player, Table) ->
|
|||
"lusers" ->
|
||||
{ok, Players} = ggs_table:get_player_list(Table),
|
||||
Nicks = lists:map(fun (P) -> ggs_db:getItem(Table, nicks, P) end, Players),
|
||||
ggs_player:notify(Player, server,io_lib:format("~p\n",[Nicks]));
|
||||
ggs_player:notify(Player, server,io_lib:format("LUSERS ~p\n",[Nicks]));
|
||||
"nick" ->
|
||||
ggs_db:setItem(Table,nicks,Player,Args),
|
||||
io:format("Changing nickname of ~p to ~p.", [Player, Args]);
|
||||
|
|
Reference in a new issue