summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--IrcChannel.qml5
-rw-r--r--IrcConnection.py65
-rw-r--r--IrcHandler.py52
-rw-r--r--IrcWindow.py46
-rw-r--r--main.qml44
-rwxr-xr-xrelay.py29
6 files changed, 241 insertions, 0 deletions
diff --git a/IrcChannel.qml b/IrcChannel.qml
new file mode 100644
index 0000000..5654c57
--- /dev/null
+++ b/IrcChannel.qml
@@ -0,0 +1,5 @@
+import QtQuick 2.7
+
+IrcChannelForm {
+
+}
diff --git a/IrcConnection.py b/IrcConnection.py
new file mode 100644
index 0000000..e51e4e3
--- /dev/null
+++ b/IrcConnection.py
@@ -0,0 +1,65 @@
+from PyQt5.QtCore import QUrl, QThread, pyqtSignal, QObject, pyqtSlot, Qt
+import irc.client
+
+class ircConnectThread(QThread):
+ sig = pyqtSignal(str)
+ nick_sig = pyqtSignal(str, str)
+ join_sig = pyqtSignal(str)
+ def __init__(self):
+ QThread.__init__(self)
+ self.reactor = irc.client.Reactor()
+ self.server = self.reactor.server()
+
+ def __del__(self):
+ self.wait()
+
+ def run(self):
+ try:
+ self.c = self.server.connect("irc.blatech.net", 6667, "wtest")
+ except irc.client.ServerConnectionError:
+ print(sys.exc_info()[1])
+ raise SystemExit(1)
+
+ # self.sig.connect(IrcWindow.updateTextArea)
+ print("start")
+ self.c.add_global_handler("welcome", self.on_connect)
+ self.c.add_global_handler("pubmsg", self.on_pubmsg)
+ self.c.add_global_handler("privmsg", self.on_privmsg)
+ self.c.add_global_handler("join", self.on_join)
+ self.c.add_global_handler("namreply", self.on_names)
+ self.reactor.process_forever()
+
+ def on_connect(self, connection, event):
+ if irc.client.is_channel("#wtest"):
+ connection.join("#wtest")
+ return
+ def on_pubmsg(self, connection, event):
+ self.sig.emit(event.source + ": " + event.arguments[0])
+
+ def on_privmsg(self, connection, event):
+ self.sig.emit(event.source + ": " + event.arguments[0])
+
+ def on_join(self, connection, event):
+ print(event)
+ nick = event.source.split("!")[0]
+ self.nick_sig.emit(event.target, event.source.split("!")[0])
+ self.sig.emit(event.source + " joined " + event.target)
+
+ def on_names(self, connection, event):
+ print(event)
+ for nick in event.arguments[2].split(" "):
+ if (nick.strip() != ""):
+ self.nick_sig.emit(event.arguments[1], nick)
+
+ @pyqtSlot(str, str)
+ def send_msg(self, channel, message):
+ if (message.startswith("/join")):
+ self.handle_join(message)
+ else:
+ self.server.privmsg(channel, message)
+ print(message)
+
+ def handle_join(self, message):
+ print(message)
+ self.c.join(message.split(" ")[1])
+ self.join_sig.emit(message.split(" ")[1])
diff --git a/IrcHandler.py b/IrcHandler.py
new file mode 100644
index 0000000..1427f3e
--- /dev/null
+++ b/IrcHandler.py
@@ -0,0 +1,52 @@
+from PyQt5.QtCore import QUrl, QThread, pyqtSignal, QObject, pyqtSlot, Qt
+from PyQt5.QtWidgets import QApplication
+from PyQt5.QtQuick import QQuickView, QQuickItem, QQuickWindow
+from PyQt5.QtQml import QQmlApplicationEngine
+from PyQt5.QtGui import QGuiApplication, QKeyEvent
+
+import IrcConnection
+
+class IrcHandler(QObject):
+ sig = pyqtSignal(str,str)
+
+ def __init__(self):
+ super(self.__class__, self).__init__()
+ self.channels = list()
+ self.nick = ""
+ self.server = "irc.blatech.net"
+ self.irc = IrcConnection.ircConnectThread()
+
+ def get_channels():
+ return self.channels
+
+ def set_channels(channels):
+ self.channels = channels
+
+ def add_channel(channel):
+ self.channels.append(channel)
+
+ def get_server():
+ return self.server
+
+ def set_server(server):
+ self.server = server
+
+ def get_nick():
+ return self.nick
+
+ def set_nick(nick):
+ self.nick = nick
+
+ def handle_input(self, view):
+ text = view.get_input()
+ print(text)
+ self.sig.emit("#wtest", text)
+ view.reset_input()
+ view.update_chat(text)
+
+ def connect_to_irc(self, view):
+ self.irc.sig.connect(view.update_chat)
+ # self.irc.nick_sig.connect(self.add_nick)
+ # self.irc.join_sig.connect(self.join_channel)
+ self.irc.start()
+ self.sig.connect(self.irc.send_msg)
diff --git a/IrcWindow.py b/IrcWindow.py
new file mode 100644
index 0000000..77a61cd
--- /dev/null
+++ b/IrcWindow.py
@@ -0,0 +1,46 @@
+from PyQt5.QtCore import QUrl, QThread, pyqtSignal, QObject, pyqtSlot, Qt
+from PyQt5.QtWidgets import QApplication
+from PyQt5.QtQuick import QQuickView, QQuickItem, QQuickWindow
+from PyQt5.QtQml import QQmlApplicationEngine
+from PyQt5.QtGui import QGuiApplication, QKeyEvent
+
+import IrcHandler
+
+class IrcWindow(QQuickWindow):
+
+ def __init__(self, view):
+ super(self.__class__, self).__init__()
+ self.view = view
+ self.handler = IrcHandler.IrcHandler()
+
+ self.dumpQMLComponents(self.view)
+ self.connect_button = self.view.findChild(QQuickItem, "connect_button")
+ self.send_button = self.view.findChild(QQuickItem, "send_button")
+ self.input_field = self.view.findChild(QQuickItem, "input")
+ self.chat_area = self.view.findChild(QQuickItem, "chat_area")
+
+ self.send_button.clicked.connect(self.handle_input)
+ self.connect_button.clicked.connect(self.connect_to_irc)
+ self.input_field.send_to_irc.connect(self.handle_input)
+ print(self.input_field)
+
+ def connect_to_irc(self):
+ self.handler.connect_to_irc(self)
+
+ def handle_input(self):
+ self.handler.handle_input(self)
+
+ def get_input(self):
+ return self.input_field.property("text")
+
+ def reset_input(self):
+ self.input_field.setProperty("text", "")
+
+ @pyqtSlot(str)
+ def update_chat(self, text):
+ self.chat_area.append(text)
+
+ def dumpQMLComponents(self, root):
+ children = root.findChildren(QObject)
+ for item in children:
+ print(item, item.objectName())
diff --git a/main.qml b/main.qml
new file mode 100644
index 0000000..e1052fd
--- /dev/null
+++ b/main.qml
@@ -0,0 +1,44 @@
+import QtQuick 2.7
+import QtQuick.Controls 2.1
+import QtQuick.Layouts 1.3
+
+ApplicationWindow {
+ visible: true
+ width: 640
+ height: 530
+ title: qsTr("blachat")
+
+
+ StackLayout {
+ id: swipeView
+ anchors.fill: parent
+ currentIndex: channel_tabs.currentIndex
+
+ IrcChannel {
+ }
+
+ }
+ Component {
+ id: tabButton
+ TabButton { text: "TabButton" }
+ }
+
+ footer: TabBar {
+ id: channel_tabs
+ objectName: "channel_tabs"
+ TabButton {
+ text: "a"
+ }
+
+ function add_channel(channel){
+ var newTab = tabButton.createObject(channel_tabs, {"text": channel})
+ channel_tabs.addItem(newTab)
+ var newChannel = Qt.createComponent("Page1.qml").createObject(swipeView, {"objectName": "channel"+channel})
+
+ }
+
+
+
+ }
+
+}
diff --git a/relay.py b/relay.py
new file mode 100755
index 0000000..6bafc5e
--- /dev/null
+++ b/relay.py
@@ -0,0 +1,29 @@
+#!/usr/bin/python
+
+import irc.client
+import sys
+import random
+import IrcWindow
+
+from PyQt5.QtCore import QUrl, QThread, pyqtSignal, QObject, pyqtSlot, Qt
+from PyQt5.QtWidgets import QApplication
+from PyQt5.QtQuick import QQuickView, QQuickItem, QQuickWindow
+from PyQt5.QtQml import QQmlApplicationEngine
+from PyQt5.QtGui import QGuiApplication, QKeyEvent
+
+
+if __name__ == '__main__':
+ qmlUrl=QUrl("main.qml")
+ assert qmlUrl.isValid()
+ app = QApplication(sys.argv)
+ engine = QQmlApplicationEngine()
+ ctx = engine.rootContext()
+ ctx.setContextProperty("main", engine)
+ engine.load(qmlUrl)
+ win = engine.rootObjects()[0]
+
+ view = QQuickWindow(win)
+ win.show()
+ ircWindow = IrcWindow.IrcWindow(win)
+
+ sys.exit(app.exec_())