Skip to content

Commit 1ff9f51

Browse files
committed
update
1 parent 1b35c5c commit 1ff9f51

File tree

4 files changed

+70
-131
lines changed

4 files changed

+70
-131
lines changed

MQTTClient.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import about as about
2222
import new_connect as new_connect
2323
import open_connect as open_connect
24-
import search as search
2524
import subscriber
2625
from config_file import ConfigFile
2726
from main_window_frame_ui import MainWindowFrameUI
@@ -63,8 +62,7 @@ def button_connect(self):
6362
"state"] = tk.NORMAL
6463
self.main_window_frame_ui.button_publich_topic[
6564
"state"] = tk.NORMAL
66-
self.main_window_frame_ui.button_search[
67-
"state"] = tk.NORMAL
65+
6866
else:
6967
messagebox.showerror("showerror", "Please select broker.")
7068

@@ -84,10 +82,10 @@ def button_subscribe_topic(self):
8482
print("button_subscribe_topic")
8583
self.subscriber.subscribe_start(
8684
self.main_window_frame_ui.entry_subscribe_topic_text.get())
87-
88-
def search(self):
89-
print("search")
90-
search.SearchWindow(self.master, self.text_font, self.subscriber)
85+
self.main_window_frame_ui.button_filter_add[
86+
"state"] = tk.NORMAL
87+
self.main_window_frame_ui.button_filter_remove[
88+
"state"] = tk.DISABLED
9189

9290
def button_publish_topic(self):
9391
print("button_publish_topic")
@@ -110,6 +108,20 @@ def new_connect_window(self):
110108
def open_connect_window(self):
111109
open_connect.OpenConnect(self.main_window_frame_ui, self.text_font)
112110

111+
def add_filter(self):
112+
self.main_window_frame_ui.msg_filter = True
113+
self.main_window_frame_ui.button_filter_add[
114+
"state"] = tk.DISABLED
115+
self.main_window_frame_ui.button_filter_remove[
116+
"state"] = tk.NORMAL
117+
118+
def remove_filter(self):
119+
self.main_window_frame_ui.msg_filter = False
120+
self.main_window_frame_ui.button_filter_add[
121+
"state"] = tk.NORMAL
122+
self.main_window_frame_ui.button_filter_remove[
123+
"state"] = tk.DISABLED
124+
113125

114126
if __name__ == "__main__":
115127
app = App()

main_window_frame_ui.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def __init__(self, main_window_frame, main_window_self, font_size, *args,
2222
self.main_window_frame = main_window_frame
2323
self.main_window_self = main_window_self
2424

25+
self.msg_filter = False
26+
2527
row = 0
2628
column = 0
2729

@@ -106,26 +108,44 @@ def __init__(self, main_window_frame, main_window_self, font_size, *args,
106108
command=main_window_self.button_subscribe_topic)
107109
self.button_subscribe_topic.grid(row=row, column=column)
108110

111+
# filter msg
112+
row += 1
113+
column = 0
114+
115+
self.label_msg_filter = tk.Label(self, text="Filter Message",
116+
font=font_size)
117+
self.label_msg_filter.grid(row=row, column=column, sticky=tk.W)
118+
self.label_msg_filter.grid(row=row, column=column, sticky=tk.W)
119+
109120
column += 1
110-
self.button_search = tk.Button(self,
111-
text="Search", font=font_size,
112-
state=tk.DISABLED,
113-
command=main_window_self.search)
114-
self.button_search.grid(row=row, column=column)
121+
122+
self.entry_msg_filter_text = tk.StringVar(self)
123+
self.entry_msg_filter = tk.Entry(self,
124+
textvariable=self.entry_msg_filter_text,
125+
font=font_size)
126+
self.entry_msg_filter.grid(row=row, column=column)
127+
column += 1
128+
129+
self.button_filter_add = tk.Button(self,
130+
text="Add Filter", font=font_size,
131+
state=tk.DISABLED,
132+
command=main_window_self.add_filter)
133+
self.button_filter_add.grid(row=row, column=column)
134+
column += 1
135+
136+
self.button_filter_remove = tk.Button(self,
137+
text="Remove Filter",
138+
font=font_size,
139+
state=tk.DISABLED,
140+
command=main_window_self.remove_filter)
141+
self.button_filter_remove.grid(row=row, column=column)
115142

116143
row += 1
117144
column = 0
118145

119146
# subscribe list
120-
# self.listbox_message_scrollbar = tk.Scrollbar(self, orient=tk.VERTICAL)
121-
self.listbox_message = tk.Text(self, font=font_size, height=15)
122-
# self.listbox_message.config(
123-
# yscrollcommand=self.listbox_message_scrollbar.set)
147+
self.listbox_message = tk.Text(self, font=font_size, height=12)
124148
self.listbox_message.grid(row=row, column=column, columnspan=6)
125-
# self.listbox_message_scrollbar.config(
126-
# command=self.listbox_message.yview)
127-
# self.listbox_message_scrollbar.grid(row=row, column=column + 4,
128-
# ipady=70)
129149

130150
# menu
131151
menubar = tk.Menu(main_window_self)

search.py

Lines changed: 0 additions & 100 deletions
This file was deleted.

subscriber.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,27 @@ def on_disconnect(self, client, userdata, rc):
4242
def on_message(self, client, userdata, msg):
4343
self.topic = msg.topic
4444
self.message = msg.payload.decode('utf8')
45-
self.main_window_frame_ui.listbox_message.insert(tk.END,
46-
">{} {} {}\n".format(
47-
self.on_message_count,
48-
self.topic,
49-
self.message))
50-
self.main_window_frame_ui.listbox_message.see("end")
51-
self.on_message_count += 1
45+
if self.main_window_frame_ui.msg_filter:
46+
if self.main_window_frame_ui.entry_msg_filter_text.get() in self.message:
47+
self.main_window_frame_ui.listbox_message.insert(tk.END,
48+
">{} {} {}\n".format(
49+
self.on_message_count,
50+
self.topic,
51+
self.message))
52+
self.main_window_frame_ui.listbox_message.see("end")
53+
self.on_message_count += 1
54+
else:
55+
self.main_window_frame_ui.listbox_message.insert(tk.END,
56+
">{} {} {}\n".format(
57+
self.on_message_count,
58+
self.topic,
59+
self.message))
60+
self.main_window_frame_ui.listbox_message.see("end")
61+
self.on_message_count += 1
62+
5263
self.main_window_frame_ui.connect_status_text.set(
5364
"Connected | Message: %s | Publish: %s" % (
5465
self.on_message_count, self.publish_message_count))
55-
self.get_message()
5666

5767
def connect_start(self, broker, port, username, password):
5868
self.client.username_pw_set(username, password)
@@ -70,6 +80,3 @@ def subscribe_start(self, topic):
7080
def publish_start(self, topic, msg):
7181
self.client.publish(topic, msg)
7282
self.publish_message_count += 1
73-
74-
def get_message(self):
75-
return self.topic, self.message

0 commit comments

Comments
 (0)