Codes divers: Check-in [a5368b497d]

Divers bouts de code de ma composition

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Create my own tray hubic client
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:a5368b497d6a6e612bc1ac10011832210de2f952
User & Date: milouse 2014-04-07 11:06:14
Context
2014-04-07
19:03
Cleanup hubic_client check-in: 456460e009 user: milouse tags: trunk
11:06
Create my own tray hubic client check-in: a5368b497d user: milouse tags: trunk
2014-03-05
17:53
Bump python2-catcher version check-in: e414a2e56a user: milouse tags: trunk
Changes

Added hubic_client/hubic.png.

cannot compute difference between binary files

Added hubic_client/hubic_client.















































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

import os
import gtk
import dbus
import signal

class SystrayIconApp:
    def __init__(self):
        self.tray = gtk.StatusIcon()
        # self.tray.set_from_stock(gtk.STOCK_ABOUT)
        self.tray.set_from_file(os.path.join(os.path.expanduser('~/Applis/divers/hubic_client'), 'hubic.png'))
        self.tray.connect('popup-menu', self.on_right_click)
        self.tray.set_tooltip('Starting')
        signal.signal(signal.SIGALRM, self.get_hubic_status)
        signal.alarm(5)


    def get_hubic_status(self, signum, frame):
        session_bus = dbus.SessionBus()
        hubic_general_info = session_bus.get_object('com.hubiC', '/com/hubic/General')
        hubic_state = hubic_general_info.Get('com.hubic.general', 'CurrentState')
        self.tray.set_tooltip(hubic_state)
        if hubic_state == 'Busy':
            self.tray.set_blinking(True)
        else:
            self.tray.set_blinking(False)
        signal.alarm(5)

                
    def on_right_click(self, icon, event_button, event_time):
        self.make_menu(event_button, event_time)
                
    def make_menu(self, event_button, event_time):
        menu = gtk.Menu()
                        
        # show about dialog
        about = gtk.MenuItem("About")
        about.show()
        menu.append(about)
        about.connect('activate', self.show_about_dialog)
                        
        # show about dialog
        stop_button = gtk.MenuItem('Stop')
        stop_button.show()
        menu.append(stop_button)
        stop_button.connect('activate', self.stop_hubic)

        # add quit item
        quit = gtk.MenuItem("Quit (without stoping)")
        quit.show()
        menu.append(quit)
        quit.connect('activate', self.bye)

        menu.popup(None, None, gtk.status_icon_position_menu,
                   event_button, event_time, self.tray)


    def stop_hubic(self, widget):
        session_bus = dbus.SessionBus()
        hubic_general_info = session_bus.get_object('com.hubiC', '/com/hubic/General')
        hubic_client = dbus.Interface(hubic_general_info, 'com.hubic.general')
        hubic_client.Stop()
        self.bye(self, widget)


    def  show_about_dialog(self, widget):
        about_dialog = gtk.AboutDialog()
        about_dialog.set_destroy_with_parent (True)
        about_dialog.set_icon_name ("HubicStatus")
        about_dialog.set_name('HubicStatus')
        about_dialog.set_version('0.1')
        about_dialog.set_copyright("(C) 2014 √Čtienne Deparis")
        about_dialog.set_comments(("Program to demonstrate a system tray icon"))
        about_dialog.set_authors(['√Čtienne Deparis <etienne@depar.is>'])
        about_dialog.run()
        about_dialog.destroy()

    def bye(self, widget):
        signal.alarm(0)
        gtk.main_quit()


if __name__ == "__main__":
    SystrayIconApp()
    gtk.main()