Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've made my application for Ubuntu App Showdown. When I start it from terminal using quickly run it works well. I've packaged it with quickly package and installed locally. Unfortunately it does not start. I think it's a problem with linking to css file inside my python code, but I don't know how should I link properly, so it will work after install. Output from terminal when starting installed app:

michal@michal-Inspiron-530-11:~$ easy-stopwatch
/usr/lib/python2.7/dist-packages/gi/overrides/Gtk.py:391: Warning: g_object_set_property: construct property "type" for object `Window' can't be set after construction
  Gtk.Window.__init__(self, type=type, **kwds)

(easy-stopwatch:10446): Gtk-CRITICAL **: gtk_css_section_get_file: assertion `section != NULL' failed

(easy-stopwatch:10446): Gtk-CRITICAL **: gtk_css_section_get_end_position: assertion `section != NULL' failed

(easy-stopwatch:10446): Gtk-CRITICAL **: gtk_css_section_get_end_line: assertion `section != NULL' failed
Traceback (most recent call last):
  File "/usr/bin/easy-stopwatch", line 33, in <module>
    easy_stopwatch.main()
  File "/usr/lib/python2.7/dist-packages/easy_stopwatch/__init__.py", line 33, in main
    window = EasyStopwatchWindow.EasyStopwatchWindow()
  File "/usr/lib/python2.7/dist-packages/easy_stopwatch_lib/Window.py", line 35, in __new__
    new_object.finish_initializing(builder)
  File "/usr/lib/python2.7/dist-packages/easy_stopwatch/EasyStopwatchWindow.py", line 56, in finish_initializing
    css_provider.load_from_path('data/ui/gtk-style.css')
  File "/usr/lib/python2.7/dist-packages/gi/types.py", line 43, in function
    return info.invoke(*args, **kwargs)
gi._glib.GError: <unknown>:1:0: Failed to import: Error opening file: No such file or directory
michal@michal-Inspiron-530-11:~$ 

Part of my python code:

    # Styling via CSS file
    screen = Gdk.Screen.get_default()
    css_provider = Gtk.CssProvider()
    css_provider.load_from_path('data/ui/gtk-style.css')
    style_context = Gtk.StyleContext()
    style_context.add_provider_for_screen(screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER)

-------------EDIT----------------

After some searching I realized that quickly package does not make app to install in /opt but quickly package --extras does. After installing in /opt I've edited my python file so the link to css file looks like this:

css_provider.load_from_path('/opt/extras.ubuntu.com/easy-stopwatch/share/easy-stopwatch/ui/gtk-style.css')

After that my app works. I'm not sure if I can do that in the code I'd like to submit to Ubuntu App Showdown.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Don't hardcode the path in the following call, use the generic function to load media files. That will allow you to correctly load the file either during development or on an installed system.

So instead of this:

css_provider.load_from_path('/opt/extras.ubuntu.com/easy-stopwatch/share/easy-stopwatch/ui/gtk-style.css')

Do something along these lines:

from foo_lib.helpers import get_media_file

css_provider.load_from_path(get_media_file('gtk-style.css'))
share|improve this answer
    
Thanks for the answer. –  mivoligo Jul 5 '12 at 12:03
    
If you're happy with the answer, don't forget to mark it as the accepted one with the checkbox icon on the left ;) –  David Planella Jul 5 '12 at 12:04
    
Sorry, but I pressed Enter and didn't post my all comment. Thanks for the answer. I've changed the code so it looks like: ` from easy_stopwatch_lib.helpers import get_media_file css_provider.load_from_path(get_media_file("gtk-style.css"))` and moved "gtk-style.css" to /data/media but after running quickly run I get: paste2.org/p/2066295 –  mivoligo Jul 5 '12 at 12:10
    
Try to add a print get_media_file("gtk-style.css") statement and see if that returns the right CSS file path. –  David Planella Jul 5 '12 at 12:52
    
It returns: file:////home/michal/easy-stopwatch/data/media/gtk-style.css so it looks O.K. I don't know if there should be as many //// after file:But I get the same error: paste2.org/p/2066322 –  mivoligo Jul 5 '12 at 13:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.