Ubuntu Pastebin

Paste from ioria at Wed, 8 Feb 2017 20:02:40 +0000

Download as text
  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
#!/usr/bin/env python3

# install python-gtk2  python-gtk2-dev   and python-appindicator

#          Server Side


import socket
import subprocess
import os
import signal
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, AppIndicator3, GObject
import time
from threading import Thread

dum = " "

class Indicator():
    def __init__(self):
        self.app = 'test123'
        iconpath = "/usr/share/icons/hicolor/24x24/status/indicator-messages.png"
        self.indicator = AppIndicator3.Indicator.new(
            self.app, iconpath,
            AppIndicator3.IndicatorCategory.OTHER)
        self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE)       
        self.indicator.set_menu(self.create_menu())
        self.indicator.set_label(" No Msg", self.app)

        # the thread:
        self.update = Thread(target=self.show_seconds)
        # daemonize the thread to make the indicator stopable
        self.update.setDaemon(True)
        self.update.start()
                

    def create_menu(self):
        menu = Gtk.Menu()
        # menu item 1
        item_1 = Gtk.MenuItem('READ')
        item_1.connect('activate', self.about)
        menu.append(item_1)
        # separator
        menu_sep = Gtk.SeparatorMenuItem()
        menu.append(menu_sep)
        # quit
        item_quit = Gtk.MenuItem('Quit')
        item_quit.connect('activate', self.stop)
        menu.append(item_quit)

        menu.show_all()
         
        return menu
        
    def show_seconds(self):
          global dum          
          serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
          serversocket.bind(('localhost', 8089))
          serversocket.listen(5) #  max 5 connections
          while True:
              connection, address = serversocket.accept()
              dum = connection.recv(64).decode()
              if len(dum) > 0:
                 
            
                 mention = ' New Msg'
                 #men = "/home/ioria/Pictures/brightness.png"
                 men  ="/usr/share/icons/hicolor/16x16/status/indicator-messages-new.png"

                 GObject.idle_add(
                         self.indicator.set_label,
                         mention, self.app,
                         priority=GObject.PRIORITY_DEFAULT
                         )


                 GObject.idle_add(
                         self.indicator.set_icon,
                         men
                         )
                 #break
    # In the function below you can choose what you do with the data sent by the client    
    # In this case, it display the msg in a bubble notification
    def func_B(self, source):
        var = dum
        os.system("notify-send %s" %  var) 
        # you can also use  xmessage  "$(command)"  if the output it's too long
        #os.system("xmessage  %s" % var)

    def stop(self, source):
        Gtk.main_quit()

    def about(self, source):
        self.func_B(source) 
        self.indicator.set_icon  ("/usr/share/icons/hicolor/24x24/status/indicator-messages.png")
        self.indicator.set_label (" No Msg", self.app)

Indicator()

GObject.threads_init()
signal.signal(signal.SIGINT, signal.SIG_DFL)
Gtk.main()
#
#
#
#
#
#
#

#!/usr/bin/env python3

#      Client Side


import socket
import os
import signal
import socket
import sys
 

#to send a command use this format : "\"$(ls)\""
#to execute a script this format :  "\"$(./myscript)\"" 
# Get the arguments list 
cmdargs = str(sys.argv)


clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientsocket.connect(('localhost', 8089))
#data =  str(sys.argv[1:])
data =input('Enter in quotes " " : ')
 
clientsocket.send(data.encode())
Download as text