Skip to content
Browse files

Factored application out into a class

  • Loading branch information...
1 parent 135177e commit b6bba26a0e7c239c431d360ed654e9ceda2d11b6 @weavejester committed Apr 21, 2011
Showing with 44 additions and 30 deletions.
  1. +1 −0 .gitignore
  2. +40 −0 src/app.py
  3. +0 −30 src/indicator.py
  4. +3 −0 src/main.py
View
1 .gitignore
@@ -0,0 +1 @@
+*.pyc
View
40 src/app.py
@@ -0,0 +1,40 @@
+import gobject
+import gtk
+import appindicator
+
+class Application:
+ "Main application class. Use Application.main to start."
+
+ @classmethod
+ def main(cls):
+ "Create the application and start gtk.main()."
+ app = cls()
+ gtk.main()
+
+ def __init__(self):
+ "Create the application."
+ self.setup_indicator()
+
+ def setup_indicator(self):
+ "Create the indicator applet."
+ self.indicator = appindicator.Indicator(
+ "example-simple-client",
+ "indicator-messages",
+ appindicator.CATEGORY_APPLICATION_STATUS)
+
+ self.indicator.set_status(appindicator.STATUS_ACTIVE)
+ self.indicator.set_attention_icon("indicator-messages-new")
+ self.indicator.set_menu(self.setup_menu())
+
+ def setup_menu(self):
+ "Create the main menu on the indicator."
+ self.menu = gtk.Menu()
+ self.add_quit_item()
+ return self.menu
+
+ def add_quit_item(self):
+ "Add a quit item to the menu."
+ quit_item = gtk.MenuItem("Quit uBitcoin")
+ self.menu.append(quit_item)
+ quit_item.connect("activate", exit)
+ quit_item.show()
View
30 src/indicator.py
@@ -1,30 +0,0 @@
-import gobject
-import gtk
-import appindicator
-
-def append_quit_item(menu):
- quit_item = gtk.MenuItem("Quit uBitcoin")
- menu.append(quit_item)
- quit_item.connect("activate", exit)
- quit_item.show()
-
-def indicator_menu():
- "The menu on the indicator applet."
- menu = gtk.Menu()
- append_quit_item(menu)
- return menu
-
-def indicator():
- "The main indicator applet."
- indicator = appindicator.Indicator(
- "example-simple-client",
- "indicator-messages",
- appindicator.CATEGORY_APPLICATION_STATUS)
-
- indicator.set_status(appindicator.STATUS_ACTIVE)
- indicator.set_attention_icon("indicator-messages-new")
- indicator.set_menu(indicator_menu())
- gtk.main()
-
-if __name__ == "__main__":
- indicator()
View
3 src/main.py
@@ -0,0 +1,3 @@
+if __name__ == '__main__':
+ import app
+ app.Application.main()

0 comments on commit b6bba26

Please sign in to comment.
Something went wrong with that request. Please try again.