PySide6-PahoMqtt 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,80 @@
1
+ Metadata-Version: 2.1
2
+ Name: PySide6-PahoMqtt
3
+ Version: 0.1.0
4
+ Summary: This is a wrapping class for using paho-mqtt(V2.x) in pyside6.
5
+ Author: chanmin.park
6
+ Author-email: devcamp@gmail.com
7
+ Keywords: PySide6,paho-mqtt
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: paho-mqtt
14
+ Requires-Dist: PySide6
15
+
16
+ This is a wrapping class for using paho-mqtt(V2.x) in pyside6.
17
+
18
+ ### History
19
+ - V0.1.0
20
+ - Convert paho-mqtt callbacks to qt signal-slots
21
+ - Add wrapper method for paho-mqtt
22
+
23
+ ### Install
24
+ ```sh
25
+ pip install PySide6-PahoMqtt
26
+ ```
27
+
28
+ ### Example
29
+ ```python
30
+ from PySide6.QtWidgets import QApplication, QMainWindow
31
+ from PySide6.PahoMqtt import Client
32
+
33
+ class UI(QMainWindow):
34
+ def __init__(self):
35
+ super().__init__()
36
+
37
+ self.mqtt = Client()
38
+ self.mqtt.on_connect.connect(self.onConnect)
39
+ self.mqtt.on_connect_fail.connect(self.onConnectFail)
40
+ self.mqtt.on_disconnect.connect(self.onDisconnect)
41
+ self.mqtt.on_publish.connect(self.onPublish)
42
+ self.mqtt.on_subscribe.connect(self.onSubscribe)
43
+ self.mqtt.on_message.connect(self.onMessage)
44
+ self.mqtt.connection("mqtt.eclipseprojects.io")
45
+
46
+ def closeEvent(self, event):
47
+ print("Window is closing")
48
+ self.mqtt.disconnection()
49
+ event.accept()
50
+
51
+ def onConnect(self, connect_flags, reason_code, properties):
52
+ print(f"connect: {connect_flags}, {reason_code}, {properties}")
53
+
54
+ if reason_code == 0:
55
+ self.mqtt.subscribe("planxlabs/#")
56
+ self.mqtt.publish("planxlabs/test", {"data": "Hello World"})
57
+ else:
58
+ print("fail")
59
+
60
+ def onConnectFail(self):
61
+ print("connect fail")
62
+
63
+ def onDisconnect(self, disconnect_flags, reason_code):
64
+ print(f"disconnect: {disconnect_flags}, {reason_code}")
65
+
66
+ def onPublish(self, mid, reason_code):
67
+ print(f"publish: {mid}, {reason_code}")
68
+
69
+ def onSubscribe(self, mid, reason_code_list):
70
+ print(f"subscribe: {mid}, {reason_code_list}")
71
+
72
+ def onMessage(self, topic, payload, qos, retain, properties):
73
+ print(f"message: {topic}, {payload}, {qos}, {retain}, {properties}")
74
+
75
+ if __name__ == "__main__":
76
+ app = QApplication([])
77
+ win = UI()
78
+ win.show()
79
+ app.exec()
80
+ ```
@@ -0,0 +1,80 @@
1
+ Metadata-Version: 2.1
2
+ Name: PySide6-PahoMqtt
3
+ Version: 0.1.0
4
+ Summary: This is a wrapping class for using paho-mqtt(V2.x) in pyside6.
5
+ Author: chanmin.park
6
+ Author-email: devcamp@gmail.com
7
+ Keywords: PySide6,paho-mqtt
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: paho-mqtt
14
+ Requires-Dist: PySide6
15
+
16
+ This is a wrapping class for using paho-mqtt(V2.x) in pyside6.
17
+
18
+ ### History
19
+ - V0.1.0
20
+ - Convert paho-mqtt callbacks to qt signal-slots
21
+ - Add wrapper method for paho-mqtt
22
+
23
+ ### Install
24
+ ```sh
25
+ pip install PySide6-PahoMqtt
26
+ ```
27
+
28
+ ### Example
29
+ ```python
30
+ from PySide6.QtWidgets import QApplication, QMainWindow
31
+ from PySide6.PahoMqtt import Client
32
+
33
+ class UI(QMainWindow):
34
+ def __init__(self):
35
+ super().__init__()
36
+
37
+ self.mqtt = Client()
38
+ self.mqtt.on_connect.connect(self.onConnect)
39
+ self.mqtt.on_connect_fail.connect(self.onConnectFail)
40
+ self.mqtt.on_disconnect.connect(self.onDisconnect)
41
+ self.mqtt.on_publish.connect(self.onPublish)
42
+ self.mqtt.on_subscribe.connect(self.onSubscribe)
43
+ self.mqtt.on_message.connect(self.onMessage)
44
+ self.mqtt.connection("mqtt.eclipseprojects.io")
45
+
46
+ def closeEvent(self, event):
47
+ print("Window is closing")
48
+ self.mqtt.disconnection()
49
+ event.accept()
50
+
51
+ def onConnect(self, connect_flags, reason_code, properties):
52
+ print(f"connect: {connect_flags}, {reason_code}, {properties}")
53
+
54
+ if reason_code == 0:
55
+ self.mqtt.subscribe("planxlabs/#")
56
+ self.mqtt.publish("planxlabs/test", {"data": "Hello World"})
57
+ else:
58
+ print("fail")
59
+
60
+ def onConnectFail(self):
61
+ print("connect fail")
62
+
63
+ def onDisconnect(self, disconnect_flags, reason_code):
64
+ print(f"disconnect: {disconnect_flags}, {reason_code}")
65
+
66
+ def onPublish(self, mid, reason_code):
67
+ print(f"publish: {mid}, {reason_code}")
68
+
69
+ def onSubscribe(self, mid, reason_code_list):
70
+ print(f"subscribe: {mid}, {reason_code_list}")
71
+
72
+ def onMessage(self, topic, payload, qos, retain, properties):
73
+ print(f"message: {topic}, {payload}, {qos}, {retain}, {properties}")
74
+
75
+ if __name__ == "__main__":
76
+ app = QApplication([])
77
+ win = UI()
78
+ win.show()
79
+ app.exec()
80
+ ```
@@ -0,0 +1,10 @@
1
+ README.md
2
+ setup.py
3
+ PySide6_PahoMqtt.egg-info/PKG-INFO
4
+ PySide6_PahoMqtt.egg-info/SOURCES.txt
5
+ PySide6_PahoMqtt.egg-info/dependency_links.txt
6
+ PySide6_PahoMqtt.egg-info/not-zip-safe
7
+ PySide6_PahoMqtt.egg-info/requires.txt
8
+ PySide6_PahoMqtt.egg-info/top_level.txt
9
+ src/PahoMqtt.py
10
+ src/__init__.py
@@ -0,0 +1,2 @@
1
+ paho-mqtt
2
+ PySide6
@@ -0,0 +1,65 @@
1
+ This is a wrapping class for using paho-mqtt(V2.x) in pyside6.
2
+
3
+ ### History
4
+ - V0.1.0
5
+ - Convert paho-mqtt callbacks to qt signal-slots
6
+ - Add wrapper method for paho-mqtt
7
+
8
+ ### Install
9
+ ```sh
10
+ pip install PySide6-PahoMqtt
11
+ ```
12
+
13
+ ### Example
14
+ ```python
15
+ from PySide6.QtWidgets import QApplication, QMainWindow
16
+ from PySide6.PahoMqtt import Client
17
+
18
+ class UI(QMainWindow):
19
+ def __init__(self):
20
+ super().__init__()
21
+
22
+ self.mqtt = Client()
23
+ self.mqtt.on_connect.connect(self.onConnect)
24
+ self.mqtt.on_connect_fail.connect(self.onConnectFail)
25
+ self.mqtt.on_disconnect.connect(self.onDisconnect)
26
+ self.mqtt.on_publish.connect(self.onPublish)
27
+ self.mqtt.on_subscribe.connect(self.onSubscribe)
28
+ self.mqtt.on_message.connect(self.onMessage)
29
+ self.mqtt.connection("mqtt.eclipseprojects.io")
30
+
31
+ def closeEvent(self, event):
32
+ print("Window is closing")
33
+ self.mqtt.disconnection()
34
+ event.accept()
35
+
36
+ def onConnect(self, connect_flags, reason_code, properties):
37
+ print(f"connect: {connect_flags}, {reason_code}, {properties}")
38
+
39
+ if reason_code == 0:
40
+ self.mqtt.subscribe("planxlabs/#")
41
+ self.mqtt.publish("planxlabs/test", {"data": "Hello World"})
42
+ else:
43
+ print("fail")
44
+
45
+ def onConnectFail(self):
46
+ print("connect fail")
47
+
48
+ def onDisconnect(self, disconnect_flags, reason_code):
49
+ print(f"disconnect: {disconnect_flags}, {reason_code}")
50
+
51
+ def onPublish(self, mid, reason_code):
52
+ print(f"publish: {mid}, {reason_code}")
53
+
54
+ def onSubscribe(self, mid, reason_code_list):
55
+ print(f"subscribe: {mid}, {reason_code_list}")
56
+
57
+ def onMessage(self, topic, payload, qos, retain, properties):
58
+ print(f"message: {topic}, {payload}, {qos}, {retain}, {properties}")
59
+
60
+ if __name__ == "__main__":
61
+ app = QApplication([])
62
+ win = UI()
63
+ win.show()
64
+ app.exec()
65
+ ```
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,33 @@
1
+ from setuptools import setup, find_packages
2
+
3
+
4
+ with open("README.md", "r", encoding="utf-8") as f:
5
+ long_description = f.read()
6
+
7
+
8
+ setup(
9
+ name='PySide6-PahoMqtt',
10
+ version='0.1.0',
11
+ description='This is a wrapping class for using paho-mqtt(V2.x) in pyside6.',
12
+ long_description=long_description,
13
+ long_description_content_type='text/markdown',
14
+ author='chanmin.park',
15
+ author_email='devcamp@gmail.com',
16
+ packages=find_packages(exclude=[]),
17
+ package_dir={'PySide6-PahoMqtt': 'src'},
18
+ install_requires=[
19
+ 'paho-mqtt',
20
+ 'PySide6'
21
+ ],
22
+ keywords=['PySide6', 'paho-mqtt'],
23
+ python_requires='>=3.8',
24
+ zip_safe=False,
25
+ data_files=[
26
+ ('Lib/site-packages/PySide6', ['src/PahoMqtt.py'])
27
+ ],
28
+ classifiers=[
29
+ "Programming Language :: Python :: 3",
30
+ "License :: OSI Approved :: MIT License",
31
+ "Operating System :: OS Independent",
32
+ ]
33
+ )
@@ -0,0 +1,88 @@
1
+ import json
2
+ from PySide6.QtCore import QObject, Signal
3
+ import paho.mqtt.client as mqtt
4
+ from paho.mqtt.properties import Properties
5
+ from paho.mqtt.packettypes import PacketTypes
6
+ import socket
7
+
8
+
9
+ class Client(QObject):
10
+ on_connect = Signal(int, int, object)
11
+ on_connect_fail = Signal()
12
+ on_subscribe = Signal(int, list)
13
+ on_message = Signal(str, object, int, bool, object)
14
+ on_publish = Signal(int, int)
15
+ on_unsubscribe = Signal(int, list)
16
+ on_disconnect = Signal(int, int)
17
+
18
+ def __init__(self, client_id="", clean_session=None, userdata=None, protocol=mqtt.MQTTv5, transport="tcp", reconnect_on_failure=True, manual_ack=False, parent=None):
19
+ super().__init__(parent)
20
+ self.__mqtt = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, client_id, clean_session, userdata, protocol, transport, reconnect_on_failure, manual_ack)
21
+
22
+ self.__mqtt.on_connect = self.__on_connect
23
+ self.__mqtt.on_connect_fail = self.__on_connect_fail
24
+ self.__mqtt.on_subscribe = self.__on_subscribe
25
+ self.__mqtt.on_message = self.__on_message
26
+ self.__mqtt.on_publish = self.__on_publish
27
+ self.__mqtt.on_unsubscribe = self.__on_unsubscribe
28
+ self.__mqtt.on_disconnect = self.__on_disconnect
29
+
30
+ def __del__(self):
31
+ if self.__mqtt.is_connected():
32
+ self.disconnect()
33
+
34
+ def connection(self, host, port=1883, keepalive=60, bind_address="", bind_port=0, clean_start=mqtt.MQTT_CLEAN_START_FIRST_ONLY, session_expiry_interval=60, request_problem_information=True, username=None, password=None):
35
+ try:
36
+ connect_properties = Properties(PacketTypes.CONNECT)
37
+ connect_properties.SessionExpiryInterval = session_expiry_interval
38
+ connect_properties.RequestProblemInformation = request_problem_information
39
+
40
+ self.__mqtt.username_pw_set(username, password)
41
+ self.__mqtt.connect(host, port, keepalive, bind_address, bind_port, clean_start, connect_properties)
42
+ self.__mqtt.loop_start()
43
+ except socket.gaierror:
44
+ if not self.__mqtt.on_connect:
45
+ raise ValueError("Unknown host")
46
+ else:
47
+ self.__mqtt.on_connect(None, None, None, 3, None)
48
+
49
+ def disconnection(self, reasoncode=None, properties=None):
50
+ self.__mqtt.loop_stop()
51
+ self.__mqtt.disconnect(reasoncode, properties)
52
+
53
+ def publish(self, topic, payload=None, qos=0, retain=False, properties=None):
54
+ self.__mqtt.publish(topic, json.dumps(payload), qos, retain, properties)
55
+
56
+ def subscribe(self, topic, qos=0, options=None, properties=None):
57
+ self.__mqtt.subscribe(topic, qos, options, properties)
58
+
59
+ def unsubscribe(self, topic, properties=None):
60
+ self.__mqtt.unsubscribe(topic, properties)
61
+
62
+ def will_set(self, topic, payload=None, qos=0, retain=False, properties=None):
63
+ self.__mqtt.will_set(topic, payload, qos, retain, properties)
64
+
65
+ def will_clear(self):
66
+ self.__mqtt.will_clear()
67
+
68
+ def __on_connect(self, client, userdata, flags, reason_code, properties):
69
+ self.on_connect.emit(flags, reason_code, properties)
70
+
71
+ def __on_connect_fail(self, client, userdata):
72
+ self.on_connect_fail.emit()
73
+
74
+ def __on_subscribe(self, client, userdata, mid, reason_code_list, properties):
75
+ self.on_subscribe.emit(mid, reason_code_list)
76
+
77
+ def __on_message(self, client, userdata, message):
78
+ self.on_message.emit(message.topic, json.loads(message.payload), message.qos, message.retain, message.properties)
79
+
80
+ def __on_publish(self, client, userdata, mid, reason_code, properties):
81
+ self.on_publish.emit(mid, reason_code)
82
+
83
+ def __on_unsubscribe(self, client, userdata, mid, reason_code_list, properties):
84
+ self.on_unsubscribe.emit(mid, reason_code_list)
85
+
86
+ def __on_disconnect(self, client, userdata, disconnect_flags, reason_code, properties):
87
+ self.on_disconnect.emit(disconnect_flags, reason_code)
88
+
@@ -0,0 +1 @@
1
+ __version__ = '0.1.0'