1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
# This file is in the public domain
6
"""Helpers for an Ubuntu application."""
10
from . rdghacksignbotconfig import get_data_file
11
from . Builder import Builder
14
from gettext import gettext as _
15
gettext.textdomain('rdghacksignbot')
17
def get_builder(builder_file_name):
18
"""Return a fully-instantiated Gtk.Builder instance from specified ui
21
:param builder_file_name: The name of the builder file, without extension.
22
Assumed to be in the 'ui' directory under the data path.
24
# Look for the ui file that describes the user interface.
25
ui_filename = get_data_file('ui', '%s.ui' % (builder_file_name,))
26
if not os.path.exists(ui_filename):
30
builder.set_translation_domain('rdghacksignbot')
31
builder.add_from_file(ui_filename)
35
# Owais Lone : To get quick access to icons and stuff.
36
def get_media_file(media_file_name):
37
media_filename = get_data_file('media', '%s' % (media_file_name,))
38
if not os.path.exists(media_filename):
41
return "file:///"+media_filename
43
class NullHandler(logging.Handler):
44
def emit(self, record):
47
def set_up_logging(opts):
48
# add a handler to prevent basicConfig
49
root = logging.getLogger()
50
null_handler = NullHandler()
51
root.addHandler(null_handler)
53
formatter = logging.Formatter("%(levelname)s:%(name)s: %(funcName)s() '%(message)s'")
55
logger = logging.getLogger('rdghacksignbot')
56
logger_sh = logging.StreamHandler()
57
logger_sh.setFormatter(formatter)
58
logger.addHandler(logger_sh)
60
lib_logger = logging.getLogger('rdghacksignbot_lib')
61
lib_logger_sh = logging.StreamHandler()
62
lib_logger_sh.setFormatter(formatter)
63
lib_logger.addHandler(lib_logger_sh)
65
# Set the logging level to show debug messages.
67
logger.setLevel(logging.DEBUG)
68
logger.debug('logging enabled')
70
lib_logger.setLevel(logging.DEBUG)
72
def get_help_uri(page=None):
73
# help_uri from source tree - default language
74
here = os.path.dirname(__file__)
75
help_uri = os.path.abspath(os.path.join(here, '..', 'help', 'C'))
77
if not os.path.exists(help_uri):
78
# installed so use gnome help tree - user's language
79
help_uri = 'rdghacksignbot'
81
# unspecified page is the index.page
83
help_uri = '%s#%s' % (help_uri, page)
87
def show_uri(parent, link):
88
from gi.repository import Gtk # pylint: disable=E0611
89
screen = parent.get_screen()
90
Gtk.show_uri(screen, link, Gtk.get_current_event_time())
92
def alias(alternative_function_name):
93
'''see http://www.drdobbs.com/web-development/184406073#l9'''
94
def decorator(function):
95
'''attach alternative_function_name(s) to function'''
96
if not hasattr(function, 'aliases'):
98
function.aliases.append(alternative_function_name)