irclib problems

T

Tina I

I'm playing around with the 'irclib' library working with the first
example at
http://www.devshed.com/c/a/Python/IRC-on-a-Higher-Level-Concluded/

When copying the example verbatim and running it from a console it works
flawlessly. It connects to the server, join the channel and sits there
'forever'...

However, I want to use it in a PyQt application and have done the following.
I have created a module named 'irclibtest.py' that looks like this:

### irclibtest start ###
import irclib
irclib.DEBUG = True

class Conn:
def __init__(self):
# Network information
self.network = '192.x.x.x'
self.port = 6667
self.channel = '#test'
self.nick = 'IRClibt'
self.name = 'Python Test'

# Subclass SimpleIRCClient
class ClientClass ( irclib.SimpleIRCClient ):
pass

# Create an instance of ClientClass and connect.
self.client = ClientClass()
self.client.connect ( self.network, self.port, self.nick,
ircname = self.name )
self.client.connection.join ( self.channel )
##irclibtest end ###

And my main Qt application:

### Main application start ###
#!/usr/bin/python
# -*- coding: utf-8 -*-


import sys, irclib
from PyQt4 import QtGui , QtCore
from tircUI import Ui_MainWindow
from irclibtest import Conn

class TircMain(QtGui.QMainWindow , Conn):
def __init__(self):
QtGui.QMainWindow.__init__(self )
Conn.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)

self.connect(self.ui.sendButton, QtCore.SIGNAL("clicked()"),
self.doSend)

def doSend(self):
''' Just a test to see if I can send to channel'''
self.client.connection.privmsg('#test' , 'Test text')

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
f = TircMain()
f.show()
sys.exit(app.exec_())
### Main application end ##

The problem is that this pings out (PING timeout). As far as I
understand it rclib.SimpleIRCClient is supposed to handle PING-PONG with
the server so I don't understand why it does not in my Qt test, but it
does 'raw'.
I can send to the channel right up to the point it times out by the way.

Anyone know what I'm missing here?

Thanks
Tina
 
D

David Boddie

I'm playing around with the 'irclib' library working with the first
example at
http://www.devshed.com/c/a/Python/IRC-on-a-Higher-Level-Concluded/

When copying the example verbatim and running it from a console it works
flawlessly. It connects to the server, join the channel and sits there
'forever'...

OK. So it works on its own.
However, I want to use it in a PyQt application and have done the
following. I have created a module named 'irclibtest.py' that looks like
this:

[...]

class Conn:
     def __init__(self):
         # Network information
         self.network = '192.x.x.x'
         self.port = 6667
         self.channel = '#test'
         self.nick = 'IRClibt'
         self.name = 'Python Test'

         # Subclass SimpleIRCClient
         class ClientClass ( irclib.SimpleIRCClient ):
             pass

         # Create an instance of ClientClass and connect.
         self.client = ClientClass()
         self.client.connect ( self.network, self.port, self.nick,
ircname = self.name )
         self.client.connection.join ( self.channel )

[...]
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
f = TircMain()
f.show()
sys.exit(app.exec_())
### Main application end ##

The problem is that this pings out (PING timeout). As far as I
understand it rclib.SimpleIRCClient is supposed to handle PING-PONG with
the server so I don't understand why it does not in my Qt test, but it
does 'raw'.

You don't call self.client.start() anywhere. Even if you did, you
would still have problems because you need to call app.exec_(), and
this would only happen after self.client.start() returns - if ever.
I can send to the channel right up to the point it times out by the way.

I think this is just a result of the way the IRC protocol works.
Anyone know what I'm missing here?

You have an application with two event loops, and you can't run them
both in the usual way. If SimpleIRCClient has a method that only
processes pending events and returns immediately afterwards, you could
create a QTimer, connect its timeout() signal to that method, and make
it fire every half a second or so, to ensure that the client doesn't
time out.

There may be other solutions with threads, but things could get
quite complicated. Making one event loop play well with the other
is probably the best approach to take.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top