~jconti/recent-notifications/trunk

« back to all changes in this revision

Viewing changes to unity/Main.py

  • Committer: Jason Conti
  • Date: 2011-03-26 21:20:00 UTC
  • Revision ID: jason.conti@gmail.com-20110326212000-48rj1zased29tne4
Ported Notification.py to gobject introspection, everything except dbus. Going to attempt that next, but may revert if it doesn't work so well yet.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
"""
 
3
Main.py
 
4
March 26, 2011
 
5
 
 
6
The main recent-notifications-unity application.
 
7
"""
 
8
 
 
9
import logging
 
10
import os
 
11
 
 
12
from gi.repository import GObject, Gtk, Unity
 
13
 
 
14
from Notification import Notification
 
15
 
 
16
logger = logging.getLogger("Main")
 
17
 
 
18
class MainWindow(Gtk.Window):
 
19
  def __init__(self):
 
20
    GObject.GObject.__init__(self)
 
21
    self.set_title("Recent Notifications")
 
22
    self.set_default_size(400, 400)
 
23
    self.connect("destroy", Gtk.main_quit)
 
24
 
 
25
    self._button = Gtk.Button("Test")
 
26
    self._button.connect("clicked", self.on_button_clicked)
 
27
    self.add(self._button)
 
28
 
 
29
    self._message_count = 0
 
30
 
 
31
    self._launcher = Unity.LauncherEntry.get_for_desktop_id("rn-unity.desktop")
 
32
 
 
33
    self._notify = Notification()
 
34
    self._notify.connect("message-received", self.on_message_received)
 
35
 
 
36
  def on_button_clicked(self, button):
 
37
    self._message_count += 1
 
38
    self._launcher.set_property("count", self._message_count)
 
39
    if self._message_count > 0:
 
40
      self._launcher.set_property("count_visible", True)
 
41
 
 
42
  def on_message_received(self, monitor, message):
 
43
    logger.debug("Message Received")
 
44
 
 
45
def main():
 
46
  logging.basicConfig(level=logging.DEBUG)
 
47
  window = MainWindow()
 
48
  window.show_all()
 
49
  Gtk.main()
 
50
 
 
51
if __name__ == "__main__":
 
52
  main()