Improved data file loopkup; Improved exception handling

git-svn-id: svn+ssh://svn.marcochapeau.org/laditools/trunk@170 bfe161da-02ef-4cea-8c43-ae261ea21ac6
This commit is contained in:
nedko 2008-09-16 07:54:19 +00:00
parent b4352ab8c0
commit b031eab3a9
4 changed files with 40 additions and 9 deletions

13
ladilog
View File

@ -33,8 +33,8 @@ try:
import gtk.glade
import vte
import laditools
except:
error = gtk.MessageDialog (None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, "Wow dude...\n\nYou really need to get you dependencies right before you run this program. Ask your package maintainer why he didn't do his job properly")
except Exception, e:
error = gtk.MessageDialog (None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, "Wow dude...\n\nYou really need to get you dependencies right before you run this program. Ask your package maintainer why he didn't do his job properly\n%s" % repr(e))
error.run ()
exit (1)
@ -104,7 +104,7 @@ class ladilog (gtk.glade.XML):
max_lines_text, devnull = self.param_dict['max_lines']
self.max_lines = int (max_lines_text)
# Load the glade file
gtk.glade.XML.__init__ (self, "/usr/share/laditools/data/ladilog_ui.glade")
gtk.glade.XML.__init__(self, laditools.find_data_file("ladilog_ui.glade"))
# Get the ui ready for action
self.event_dict = {"on_ladilog_ui_destroy" : self.on_quit,
"on_close_button_clicked" : self.on_quit,
@ -168,4 +168,9 @@ class ladilog (gtk.glade.XML):
self.jacklog_config.set_as_dict ("ladilog", self.param_dict)
return 0
ladilog ().run ()
try:
ladilog().run()
except Exception, e:
error = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, "Unexpected error\n\n" + repr(e))
error.run()
exit(1)

View File

@ -38,9 +38,9 @@ class laditray (gtk.StatusIcon, laditools.manager):
laditools.manager.__init__(self, int(autostart))
gtk.StatusIcon.__init__ (self)
# Create the needed pixbufs to manage the status icon's look
self.stopped_pixbuf = gtk.gdk.pixbuf_new_from_file ("/usr/share/laditools/data/stopped.svg")
self.starting_pixbuf = gtk.gdk.pixbuf_new_from_file ("/usr/share/laditools/data/starting.svg")
self.started_pixbuf = gtk.gdk.pixbuf_new_from_file ("/usr/share/laditools/data/started.svg")
self.stopped_pixbuf = gtk.gdk.pixbuf_new_from_file(laditools.find_data_file("stopped.svg"))
self.starting_pixbuf = gtk.gdk.pixbuf_new_from_file(laditools.find_data_file("starting.svg"))
self.started_pixbuf = gtk.gdk.pixbuf_new_from_file(laditools.find_data_file("started.svg"))
self.set_from_pixbuf (self.stopped_pixbuf)
# Get the initial status
self.update ()
@ -90,4 +90,9 @@ class laditray (gtk.StatusIcon, laditools.manager):
self.jacktray_config.set_as_dict ('jacktray', self.param_dict)
return 0
laditray ().run ()
try:
laditray().run()
except Exception, e:
error = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, "Unexpected error\n\n" + repr(e))
error.run()
exit(1)

View File

@ -16,7 +16,7 @@
from jack_controller import jack_controller
from jack_configure import jack_configure
from jack_menu import manager
from jack_menu import manager, find_data_file
from a2j_controller import a2j_controller
from a2j_menu import a2j_menu
from lash_controller import lash_controller

View File

@ -14,6 +14,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
import pygtk
pygtk.require('2.0')
import gtk
@ -258,3 +260,22 @@ class manager:
menu = self.create_menu()
menu.popup(None, None, None, 3, 0)
menu.reposition()
def find_data_file(path):
start_dir = os.path.dirname(sys.argv[0])
if not start_dir:
start_dir = "."
paths = [
start_dir + os.sep + "data" + os.sep + path,
start_dir + os.sep + ".." + os.sep + "share"+ os.sep + "laditools" + os.sep + "data" + os.sep + path,
]
for path in paths:
#print 'Checking "%s"...' % path
if os.path.isfile(path):
#print 'Found data file in "%s"' % path
return path
raise Exception('Data file "%s" not found' % path)