forked from NavroopKaur/Notification-Junction
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathgui.py
395 lines (292 loc) · 10.8 KB
/
gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
#!/usr/bin/env python
import os
import pygtk
import gtk
import ctypes
import signal
import sys
import time
from ctypes.util import find_library
pygtk.require('2.0')
window_inotify = gtk.Window(gtk.WINDOW_TOPLEVEL)
window_tcpdump = gtk.Window(gtk.WINDOW_TOPLEVEL)
app_reg_arg_inotify = ""
get_notify_arg_inotify = "npname::inotify##"
flags = "flags::"
flag_check = 0
pid = os.getpid()
pidstr = str(pid)
app_reg_arg_inotify = app_reg_arg_inotify + pidstr + "::inotify"
i = 0
pidfilename = ""
arglist = []
times = 0
pidfd = 0
app_reg_arg_tcpdump = ""
get_notify_arg_tcpdump = "npname::tcpdump##"
def sigusrhandler(signum, stack):
print 'Received:', signum
if signum == signal.SIGUSR1:
print "SIGUSR1"
global times
global pidfilename
global pidfd
#md = gtk.MessageDialog(type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK)
times = times + 1;
filebuff = ""
if (times == 1): #open file for first instance of Notification
pidfd = open(pidfilename, "r+")
print "file opened for first time"
filebuff = pidfd.readline()
print "SignalHandler Notification is " + filebuff
#md.set_markup("Notification - " + filebuff)
#md.run()
shownotif(filebuff)
print times;
else:
print "someone else"
return;
def shownotif(filebuff):
message = gtk.MessageDialog(type=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_OK)
message.set_markup("Notification Received : " + filebuff)
response = message.run()
if response == gtk.BUTTONS_OK:
message.destroy()
class CheckButton(object):
# Our callback.
# The data passed to this method is printed to stdout
def callback(self, widget, data=None):
global window_inotify
global flags
global get_notify_arg_inotify
print "%s was toggled %s" % (data, ("OFF", "ON")[widget.get_active()])
flags = flags + data + "##"
get_notify_arg_inotify = get_notify_arg_inotify + flags
print "flags - " + flags
print "get notify - " + get_notify_arg_inotify
#gtk_widget_set_sensitive(self,FALSE);
#gtk_widget_set_sensitive(self, FALSE);
#self.gtk_widget_hide();
# This callback quits the program
def delete_event(self, widget, event, data=None):
gtk.main_quit()
return False
def __init__(self):
global flag_check
global window_inotify
# Create a vertical box
vbox = gtk.VBox(True, 2)
# Put the vbox in the main window_inotify
window_inotify.add(vbox)
fixed.put(vbox, 700, 10)
# Create first button
button = gtk.CheckButton("IN__CREATE ")
# When the button is toggled, we call the "callback" method
# with a pointer to "button" as its argument
button.connect("toggled", self.callback, "IN_CREATE")
# Insert button 1
vbox.pack_start(button, True, True, 2)
button.show()
# Create second button
button = gtk.CheckButton("IN__DELETE ")
# When the button is toggled, we call the "callback" method
# with a pointer to "button 2" as its argument
button.connect("toggled", self.callback, "IN_DELETE")
# Insert button 2
vbox.pack_start(button, True, True, 2)
button.show()
button = gtk.CheckButton("BOTH ")
# When the button is toggled, we call the "callback" method
# with a pointer to "button 2" as its argument
if flag_check == 1:
vbox.hide()
button.connect("toggled", self.callback, "IN_CREATE*IN_DELETE")
# Insert button 2
vbox.pack_start(button, True, True, 2)
button.show()
vbox.show()
class FileSelectionExample:
# Get the selected filename and print it to the console
def file_ok_sel(self, w):
print "%s" % self.filew.get_filename()
global get_notify_arg_inotify
global window_inotify
get_notify_arg_inotify = get_notify_arg_inotify + "dir::" + self.filew.get_filename() + "##"
print "get notify - " + get_notify_arg_inotify
self.filew.destroy()
return 0
def destroy(self, widget):
gtk.main_quit()
def __init__(self):
# Create a new file selection widget
self.filew = gtk.FileSelection("File selection")
# Connect the ok_button to file_ok_sel method
self.filew.ok_button.connect("clicked", self.file_ok_sel)
# Connect the cancel_button to destroy the widget
self.filew.cancel_button.connect("clicked",
lambda w: self.filew.destroy())
# Lets set the filename, as if this were a save dialog,
# and we are giving a default filename
self.filew.set_filename("")
self.filew.show()
class EntryExample(object):
def enter_callback(self, widget, entry):
global get_notify_arg_inotify
global window_inotify
entry_text = entry.get_text()
print "Entry contents: %s\n" % entry_text
get_notify_arg_inotify = get_notify_arg_inotify + "count::" + entry_text + "##"
print "get notify - " + get_notify_arg_inotify
return 0
def entry_toggle_editable(self, checkbutton, entry):
entry.set_editable(checkbutton.get_active())
def entry_toggle_visibility(self, checkbutton, entry):
entry.set_visibility(checkbutton.get_active())
def __init__(self):
# create a new window_inotify
global window_inotify
vbox = gtk.VBox(False, 0)
window_inotify.add(vbox)
fixed.put(vbox, 200, 10)
vbox.show()
entry = gtk.Entry()
entry.set_max_length(50)
entry.connect("activate", self.enter_callback, entry)
#entry.set_text("hello")
entry.insert_text("Enter count here", len(entry.get_text()))
entry.select_region(0, len(entry.get_text()))
vbox.pack_start(entry, True, True, 0)
entry.show()
hbox = gtk.HBox(False, 0)
vbox.add(hbox)
hbox.show()
check = gtk.CheckButton("Editable")
hbox.pack_start(check, True, True, 0)
check.connect("toggled", self.entry_toggle_editable, entry)
check.set_active(True)
check.show()
check = gtk.CheckButton("Visible")
hbox.pack_start(check, True, True, 0)
check.connect("toggled", self.entry_toggle_visibility, entry)
check.set_active(True)
check.show()
class RadioButtons(object):
def callback(self, widget, data=None):
print "%s was toggled %s" % (data, ("OFF", "ON")[widget.get_active()])
return 0
def __init__(self):
global window_inotify
box1 = gtk.VBox(False, 0)
window_inotify.add(box1)
fixed.put(box1, 10, 10)
box1.show()
box2 = gtk.VBox(False, 10)
box2.set_border_width(10)
box1.pack_start(box2, True, True, 0)
box2.show()
button = gtk.RadioButton(None, "inotify")
button.connect("toggled", self.callback, "inotify")
button.set_active(True)
box2.pack_start(button, True, True, 0)
button.show()
button = gtk.RadioButton(button, "NP 2")
button.connect("toggled", self.callback, "NP 2")
box2.pack_start(button, True, True, 0)
button.show()
button = gtk.RadioButton(button, "NP 3")
button.connect("toggled", self.callback, "NP 3")
box2.pack_start(button, True, True, 0)
button.show()
separator = gtk.HSeparator()
box1.pack_start(separator, False, True, 0)
separator.show()
box2 = gtk.VBox(False, 10)
box2.set_border_width(10)
box1.pack_start(box2, False, True, 0)
box2.show()
#self.window_inotify.show()
class Buttons(object):
# Our usual callback method
def callback(self, widget, data=None):
FileSelectionExample()
def __init__(self):
global window_inotify
# Create a new button
button = gtk.Button(label="Select the directory to be monitored")
# Connect the "clicked" signal of the button to our callback
button.connect("clicked", self.callback, "Browse")
# Pack and show all our widgets
box1 = gtk.VBox(False, 0)
window_inotify.add(box1)
fixed.put(box1, 400, 10)
box1.show()
box1.pack_start(button, False, True, 0)
box1.show()
button.show()
class Submit(object):
# Our usual callback method
def callback(self, widget, data=None):
print "app reg arg - " + app_reg_arg_inotify
print "Getnotify arg in main - end - " + get_notify_arg_inotify
global flag_check
flag_check = 99
main()
def __init__(self):
global window_inotify
# Create a new button
button = gtk.Button(label="Submit")
# Connect the "clicked" signal of the button to our callback
button.connect("clicked", self.callback, "Submit")
# Pack and show all our widgets
box1 = gtk.VBox(False, 0)
window_inotify.add(box1)
fixed.put(box1, 500, 100)
box1.show()
box1.pack_start(button, False, True, 0)
box1.show()
button.show()
def main():
print "Inside main"
#signal.signal(signal.SIGUSR1, sigusrhandler)
global flag_check
if flag_check == 99 :
#write function calls
print "app reg arg - " + app_reg_arg_inotify
print "Getnotify arg in main - end - " + get_notify_arg_inotify
libra.appRegister(app_reg_arg_inotify)
print "Called app register"
get_notify_arg_inotify_new = get_notify_arg_inotify[0:-2]
print "Getnotify arg after -2 " + get_notify_arg_inotify_new
pid = os.getpid()
libra.appGetnotify(int(pid), get_notify_arg_inotify_new,ord('N'))
print "Called getnotify"
while 1:
time.sleep(3)
return 0
gtk.main()
return 0
#entry = gtk.Entry(max=50)
#entry.set_visibility(True)
if __name__ == "__main__":
print "1"
signal.signal(signal.SIGUSR1, sigusrhandler)
libra = ctypes.CDLL("./nj_nonblocklib.so")
global window_inotify
print "*********************************************************************"
pid = os.getpid()
print 'My PID is:', pid
window_inotify.connect("delete_event", gtk.main_quit)
window_inotify.set_title("App with pid = " + str(pid))
window_inotify.set_border_width(0)
fixed = gtk.Fixed()
window_inotify.add(fixed)
RadioButtons()
EntryExample()
Buttons()
Submit()
CheckButton()
window_inotify.show_all()
pidfilename = (str(pid) + ".txt")
# hbox.pack_start(RadioButtons(window_inotify))
# hbox.pack_start(EntryExample(window_inotify))
main()