Guest User

Askubuntu question

a guest
Mar 24th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.63 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. ### BEGIN LICENSE
  4. # This file is in the public domain
  5. ### END LICENSE
  6.  
  7. import sys
  8. import os
  9. import gtk
  10.  
  11. import gettext
  12. from gettext import gettext as _
  13. gettext.textdomain('test')
  14.  
  15. # optional Launchpad integration
  16. # this shouldn't crash if not found as it is simply used for bug reporting
  17. try:
  18.     import LaunchpadIntegration
  19.     launchpad_available = True
  20. except:
  21.     launchpad_available = False
  22.  
  23. # Add project root directory (enable symlink, and trunk execution).
  24. PROJECT_ROOT_DIRECTORY = os.path.abspath(
  25.     os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0]))))
  26.  
  27. if (os.path.exists(os.path.join(PROJECT_ROOT_DIRECTORY, 'test'))
  28.     and PROJECT_ROOT_DIRECTORY not in sys.path):
  29.     sys.path.insert(0, PROJECT_ROOT_DIRECTORY)
  30.     os.putenv('PYTHONPATH', PROJECT_ROOT_DIRECTORY) # for subprocesses
  31.  
  32. from test import (
  33.     AboutTestDialog, PreferencesTestDialog)
  34. from test.helpers import get_builder
  35.  
  36.  
  37. class TestWindow(gtk.Window):
  38.     __gtype_name__ = "TestWindow"
  39.    
  40.     # To construct a new instance of this method, the following notable
  41.     # methods are called in this order:
  42.     # __new__(cls)
  43.     # __init__(self)
  44.     # finish_initializing(self, builder)
  45.     # __init__(self)
  46.     #
  47.     # For this reason, it's recommended you leave __init__ empty and put
  48.     # your inialization code in finish_intializing
  49.    
  50.     def __new__(cls):
  51.         """Special static method that's automatically called by Python when
  52.        constructing a new instance of this class.
  53.        
  54.        Returns a fully instantiated TestWindow object.
  55.        """
  56.         builder = get_builder('TestWindow')
  57.         new_object = builder.get_object("test_window")
  58.         new_object.finish_initializing(builder)
  59.         return new_object
  60.  
  61.     def finish_initializing(self, builder):
  62.         """Called while initializing this instance in __new__
  63.  
  64.        finish_initalizing should be called after parsing the UI definition
  65.        and creating a TestWindow object with it in order to finish
  66.        initializing the start of the new TestWindow instance.
  67.        
  68.        Put your initilization code in here and leave __init__ undefined.
  69.        """
  70.  
  71.         # Get a reference to the builder and set up the signals.
  72.         self.builder = builder
  73.         self.builder.connect_signals(self)
  74.  
  75.         global launchpad_available
  76.         if launchpad_available:
  77.             # see https://wiki.ubuntu.com/UbuntuDevelopment/Internationalisation/Coding for more information
  78.             # about LaunchpadIntegration
  79.             helpmenu = self.builder.get_object('helpMenu')
  80.             if helpmenu:
  81.                 LaunchpadIntegration.set_sourcepackagename('test')
  82.                 LaunchpadIntegration.add_items(helpmenu, 0, False, True)
  83.             else:
  84.                 launchpad_available = False
  85.  
  86.         # Uncomment the following code to read in preferences at start up.
  87.         #dlg = PreferencesTestDialog.PreferencesTestDialog()
  88.         #self.preferences = dlg.get_preferences()
  89.  
  90.         # Code for other initialization actions should be added here.
  91.     def on_openbutton_clicked(self, widget, data=None):
  92.         print "OPEN"
  93.    
  94.     def about(self, widget, data=None):
  95.         """Display the about box for test."""
  96.         about = AboutTestDialog.AboutTestDialog()
  97.         response = about.run()
  98.         about.destroy()
  99.  
  100.     def preferences(self, widget, data=None):
  101.         """Display the preferences window for test."""
  102.         prefs = PreferencesTestDialog.PreferencesTestDialog()
  103.         response = prefs.run()
  104.         if response == gtk.RESPONSE_OK:
  105.             # Make any updates based on changed preferences here.
  106.             pass
  107.         prefs.destroy()
  108.  
  109.     def quit(self, widget, data=None):
  110.         """Signal handler for closing the TestWindow."""
  111.         self.destroy()
  112.  
  113.     def on_destroy(self, widget, data=None):
  114.         """Called when the TestWindow is closed."""
  115.         # Clean up code for saving application state should be added here.
  116.         gtk.main_quit()
  117.  
  118. if __name__ == "__main__":
  119.     # Support for command line options.
  120.     import logging
  121.     import optparse
  122.     parser = optparse.OptionParser(version="%prog %ver")
  123.     parser.add_option(
  124.         "-v", "--verbose", action="store_true", dest="verbose",
  125.         help=_("Show debug messages"))
  126.     (options, args) = parser.parse_args()
  127.  
  128.     # Set the logging level to show debug messages.
  129.     if options.verbose:
  130.         logging.basicConfig(level=logging.DEBUG)
  131.         logging.debug('logging enabled')
  132.  
  133.     # Run the application.
  134.     window = TestWindow()
  135.     window.show()
  136.     gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment