~artfwo/indicator-cpufreq/trunk

« back to all changes in this revision

Viewing changes to indicator_cpufreq/helpers.py

  • Committer: Launchpad Translations on behalf of artfwo
  • Date: 2011-02-27 06:20:00 UTC
  • Revision ID: launchpad_translations_on_behalf_of_artfwo-20110227062000-mzvxcltka2vcwfui
Launchpad automatic translations update.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
### BEGIN LICENSE
 
3
# Copyright (C) 2010 Артём Попов <artfwo@gmail.com>
 
4
# This program is free software: you can redistribute it and/or modify it 
 
5
# under the terms of the GNU General Public License version 3, as published 
 
6
# by the Free Software Foundation.
 
7
 
8
# This program is distributed in the hope that it will be useful, but 
 
9
# WITHOUT ANY WARRANTY; without even the implied warranties of 
 
10
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
 
11
# PURPOSE.  See the GNU General Public License for more details.
 
12
 
13
# You should have received a copy of the GNU General Public License along 
 
14
# with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
### END LICENSE
 
16
 
 
17
"""Helpers for an Ubuntu application."""
 
18
 
 
19
import os
 
20
import gtk
 
21
 
 
22
from indicator_cpufreq.indicator_cpufreqconfig import get_data_file
 
23
 
 
24
import gettext
 
25
from gettext import gettext as _
 
26
gettext.textdomain('indicator-cpufreq')
 
27
 
 
28
def get_builder(builder_file_name):
 
29
    """Return a fully-instantiated gtk.Builder instance from specified ui 
 
30
    file
 
31
    
 
32
    :param builder_file_name: The name of the builder file, without extension.
 
33
        Assumed to be in the 'ui' directory under the data path.
 
34
    """
 
35
    # Look for the ui file that describes the user interface.
 
36
    ui_filename = get_data_file('ui', '%s.ui' % (builder_file_name,))
 
37
    if not os.path.exists(ui_filename):
 
38
        ui_filename = None
 
39
 
 
40
    builder = gtk.Builder()
 
41
    builder.set_translation_domain('indicator-cpufreq')
 
42
    builder.add_from_file(ui_filename)
 
43
    return builder
 
44
 
 
45
 
 
46
# Owais Lone : To get quick access to icons and stuff.
 
47
def get_media_file(media_file_name):
 
48
    media_filename = get_data_file('media', '%s' % (media_file_name,))
 
49
    if not os.path.exists(media_filename):
 
50
        media_filename = None
 
51
 
 
52
    return "file:///"+media_filename
 
53
 
 
54
 
 
55
def parse_options():
 
56
    """Support for command line options"""
 
57
    import logging
 
58
    import optparse
 
59
    parser = optparse.OptionParser(version="%prog %ver")
 
60
    parser.add_option(
 
61
        "-v", "--verbose", action="store_true", dest="verbose",
 
62
        help=_("Show debug messages"))
 
63
    (options, args) = parser.parse_args()
 
64
 
 
65
    # Set the logging level to show debug messages.
 
66
    if options.verbose:
 
67
        logging.basicConfig(level=logging.DEBUG)
 
68
        logging.debug('logging enabled')
 
69
 
 
70
def get_help_uri(page=None):
 
71
    # help_uri from source tree - default language
 
72
    here = os.path.dirname(__file__)
 
73
    help_uri = os.path.abspath(os.path.join(here, '..', 'help', 'C'))
 
74
 
 
75
    if not os.path.exists(help_uri):
 
76
        # installed so use gnome help tree - user's language
 
77
        help_uri = 'indicator-cpufreq'
 
78
 
 
79
    # unspecified page is the index.page
 
80
    if page is not None:
 
81
        help_uri = '%s#%s' % (help_uri, page)
 
82
 
 
83
    return help_uri
 
84
 
 
85
def show_uri(parent, link):
 
86
    screen = parent.get_screen()
 
87
    gtk.show_uri(screen, link, gtk.get_current_event_time())