本文整理汇总了Python中termsaverlib.i18n._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _usage_options_example
def _usage_options_example(self):
"""
Describe here the options and examples of this screen.
The method `_parse_args` will be handling the parsing of the options
documented here.
Additionally, this is dependent on the values exposed in `cli_opts`,
passed to this class during its instantiation. Only values properly
configured there will be accepted here.
"""
print _("""
Options:
-p, --path Sets the location to search for text-based source files.
this option is mandatory.
-d, --delay Sets the speed of the displaying characters
default is%(default_delay)s of a second
-h, --help Displays this help message
Examples:
$ %(app_name)s %(screen)s -p /path/to/my/code
This will trigger the screensaver to read all files in the path selected
$ %(app_name)s %(screen)s -p /path/to/my/code -d 0
This will trigger the screensaver to read all files in the path selected
with no delay (too fast for a screensaver, but it's your choice that
matters!)
""") % {
'screen': self.name,
'app_name': constants.App.NAME,
'default_delay': constants.Settings.CHAR_DELAY_SECONDS,
}
示例2: usage
def usage(self):
"""
Defines the usage information that is presented when a user hits the
help option.You should not directly override this method, instead, just
override the protected method `_usage_options_example`, created for
this purpose. All other stuff will be defined by the `usage_header` and
`usage_footer` methods.
"""
# header
self.usage_header()
print _("""Screen: %(screen)s
Description: %(description)s
Usage: %(app_name)s %(screen)s [options]""") % {
'app_name': constants.App.NAME,
'screen': self.name,
'description': self.description,
}
# any additional info in between (see other classes for reference)
self._usage_options_example()
#footer
self.usage_footer()
示例3: _run_cycle
def _run_cycle(self):
"""
Executes a cycle of this screen.
"""
# calculate random position based on screen size
self.get_terminal_size()
# update info data
if self.path:
#
# run the flow for external path
#
self.update_stats_extra()
if self.geometry["x"] > 16: # just to avoid unexpected exceptions
title = "%s: %s" % (
_("Monitoring"),
(self.path[: (self.geometry["x"] - 16)] + (self.path[(self.geometry["x"] - 16) :] and "...")),
)
else:
title = _("Monitoring file")
txt = self.get_xy_chart(title, "extra")
txt += self.center_text_horizontally(
"\n Load: %s%% %s "
% (("%02d" % self.info["db"][-1]["extra"]), self.get_chart(self.info["db"][-1]["extra"]))
)
else:
#
# run the flow for CPU/Mem as default
#
self.update_stats()
txt = self.get_xy_chart("CPU Monitor", "cpu")
txt += "\n"
txt += self.get_xy_chart("MEM Monitor", "mem")
txt += self.center_text_horizontally(
"\n%s CPU: %s%% %s MEM: %s%% (total %sMB)"
% (
self.get_chart(self.info["db"][-1]["cpu"]),
("%.1f" % self.info["db"][-1]["cpu"]),
self.get_chart(self.info["db"][-1]["mem"]),
self.info["db"][-1]["mem"],
int(self.info["total_mem"]),
)
)
#
# Due to a time delay to calculate CPU usage
# we need to clear the screen manually
#
self.clear_screen()
# just print the whole text
print txt
示例4: update_stats_extra
def update_stats_extra(self):
"""
Updates the info property with latest information on an extra path,
defined by --path argument option
Note: This also takes care of sleep (defined by delay property)
"""
f = open(self.path, "r")
try:
val = int(f.read())
except:
raise exception.TermSaverException(_("The file does not contain an integer as expected."))
if val < 0 or val > 100:
raise exception.TermSaverException(_("The file contains invalid data (must be between 0 and 100)."))
f.close()
# cut the data to keep only recent values
self.info["db"] = self.info["db"][-(self.geometry["x"] - 5) :]
max_extra = 0
for item in self.info["db"]:
if item["extra"] > max_extra:
max_extra = item["extra"]
self.info["max_extra"] = max_extra
self.info["db"].append({"time": time.time(), "extra": val})
time.sleep(self.delay)
示例5: _usage_options_example
def _usage_options_example(self):
"""
Describe here the options and examples of this screen.
The method `_parse_args` will be handling the parsing of the options
documented here.
Additionally, this is dependent on the values exposed in `cli_opts`,
passed to this class during its instantiation. Only values properly
configured there will be accepted here.
"""
print _("""
Options:
-c, --char Sets the character to be showing up
default is X
-d, --delay Sets the speed of the displaying characters
default is 0.05 of a second (advised to keep
between 0.1 and 0.01).
-h, --help Displays this help message
Example:
$ %(app_name)s %(screen)s
This will trigger the screensaver to display a dot on screen, with random
size increase.
$ %(app_name)s %(screen)s -c +
Overrides the default dot (.) character to be a plus sign (+)
""") % {
'app_name': constants.App.NAME,
'screen': self.name,
}
示例6: __init__
def __init__(self):
"""
The constructor of this class, using most default values from its super
class, `SimpleRSSFeedScreenBase`.
The display of the ascii arts here are basically based on getting the
description tag of the RSS feed, that constains a dirty HTML ascii art.
NOTE: Maybe NSFW (Not Safe For Work)
"""
super(AsciArtFartsScreen, self).__init__(
"asciiartfarts",
_("displays ascii images from asciiartfarts.com (NSFW)"),
'http://www.asciiartfarts.com/farts.rss',
["description"],
"%(description)s",
)
# set defaults for this screen
self.cleanup_per_cycle = True
self.sleep_between_items = 5
self.center_vertically = True
self.center_horizontally = True
self.clean_dirt = ['<pre>', '</pre>']
self.cleanup_per_item = True
示例7: _parse_args
def _parse_args(self, prepared_args):
"""
Handles the special command-line arguments available for this screen.
Although this is a base screen, having these options prepared here
can save coding for screens that will not change the default options.
See `_usage_options_example` method for documentation on each of the
options being parsed here.
Additionally, this is dependent on the values exposed in `cli_opts`,
passed to this class during its instantiation. Only values properly
configured there will be accepted here.
"""
for o, a in prepared_args[0]: # optlist, args
if o in ("-h", "--help"):
self.usage()
self.screen_exit()
elif o in ("-r", "--raw"):
self.clean_html = False
elif o in ("-f", "--format"):
# remove escaping
self.print_format = common.unescape_string(a)
elif o in ("-u", "--url"):
try:
# try to fix the url formatting
self.url = self.fix_uri(a)
except Exception, e:
raise exception.InvalidOptionException("url", e.message)
else:
# this should never happen!
raise Exception(_("Unhandled option. See --help for details."))
示例8: _run_cycle
def _run_cycle(self):
"""
Executes a cycle of this screen.
"""
# calculate random position based on screen size
self.get_terminal_size()
self.build_figlet_text(self.word)
# make sure the figlet output can be printed on available screen
if len(self.figlet_text.split("\n")) > self.geometry["y"]:
raise exception.InvalidOptionException("word", _("The word you are trying to print is just too big."))
if self.position["x"] == self.geometry["x"] + self.figlet_geometry["x"]:
self.position["x"] = 1
self.position["y"] = random.randint(1, self.geometry["y"] - self.figlet_geometry["y"])
self.position["x"] += 1
new_text = ""
for l in self.figlet_text.split("\n"):
# print start/end in pieces
if self.position["x"] < self.figlet_geometry["x"]:
txt = l[self.figlet_geometry["x"] - self.position["x"] :]
elif self.position["x"] > self.geometry["x"]:
txt = (
" " * (self.position["x"] - self.figlet_geometry["x"])
+ l[: self.geometry["x"] - self.position["x"]]
)
else:
txt = " " * (self.position["x"] - self.figlet_geometry["x"]) + l
new_text += "\n" + txt
print "\n" * self.position["y"] + new_text
time.sleep(self.delay)
示例9: __init__
def __init__(self):
"""
Creates a new instance of this class.
"""
UrlFetcherBase.__init__(self,
"urlfetcher",
_("displays url contents with typing animation"))
示例10: _message_no_url
def _message_no_url(self):
"""
Defines a method to be overriden by inheriting classes, with the
purpose to display extra help information for specific errors.
"""
return _("""
You just need to provide the URL of the RSS feed from where %(app_title)s will
read and display on screen.
If you do not have any idea which RSS to use, check out some examples here:
CNN
Top Stories - http://rss.cnn.com/rss/edition.rss
World - http://rss.cnn.com/rss/edition_world.rss
Technology - http://rss.cnn.com/rss/edition_technology.rss
See CNN's complete list of RSS syndication here:
http://edition.cnn.com/services/rss/
Lifehacker - http://www.lifehacker.com/index.xml
Note: Lifehacker uses HTML to deliver "description" contents in the RSS,
so you might need to change the format to something like:
--format "%%(title)s (%%(pubDate)s)\\n"
""") % {
'app_title': constants.App.TITLE,
}
示例11: _parse_args
def _parse_args(self, prepared_args):
"""
Handles the special command-line arguments available for this screen.
Although this is a base screen, having these options prepared here
can save coding for screens that will not change the default options.
See `_usage_options_example` method for documentation on each of the
options being parsed here.
Additionally, this is dependent on the values exposed in `cli_opts`,
passed to this class during its instantiation. Only values properly
configured there will be accepted here.
"""
for o, a in prepared_args[0]: # optlist, args
if o in ("-h", "--help"):
self.usage()
self.screen_exit()
elif o in ("-d", "--delay"):
try:
# make sure argument is a valid value (float)
self.delay = float(a)
except:
raise exception.InvalidOptionException("delay")
elif o in ("-c", "--char"):
# make sure argument is a valid value (single char)
if len(a) != 1:
raise exception.InvalidOptionException("char")
else:
self.char = a
else:
# this should never happen!
raise Exception(_("Unhandled option. See --help for details."))
示例12: _parse_args
def _parse_args(self, prepared_args):
"""
Handles the special command-line arguments available for this screen.
Although this is a base screen, having these options prepared here
can save coding for screens that will not change the default options.
See `_usage_options_example` method for documentation on each of the
options being parsed here.
Additionally, this is dependent on the values exposed in `cli_opts`,
passed to this class during its instantiation. Only values properly
configured there will be accepted here.
"""
for o, __ in prepared_args[0]: # optlist, args
if o in ("-h", "--help"):
self.usage()
self.screen_exit()
elif o in ("-m", "--ampm"):
self.ampm = True
elif o in ("-b", "--big"):
self.big = True
self.lineindigimap = 15
self.digmap = self.digimapbig
else:
# this should never happen!
raise Exception(_("Unhandled option. See --help for details."))
示例13: _parse_args
def _parse_args(self, prepared_args):
"""
Handles the special command-line arguments available for this screen.
Although this is a base screen, having these options prepared here
can save coding for screens that will not change the default options.
See `_usage_options_example` method for documentation on each of the
options being parsed here.
Additionally, this is dependent on the values exposed in `cli_opts`,
passed to this class during its instantiation. Only values properly
configured there will be accepted here.
"""
use_kana_only = False
for o, a in prepared_args[0]: # optlist, args
if o in ("-h", "--help"):
self.usage()
self.screen_exit()
elif o in ("-k", "--kana"):
use_kana_only = True
elif o in ("-z", "--zenkaku"):
self.use_zenkaku = True
elif o in ("-g", "--granularity"):
try:
# make sure argument is a valid value (int)
self.granularity = int(a)
except:
raise exception.InvalidOptionException("granularity")
if self.granularity <= 0:
raise exception.InvalidOptionException("granularity",
"Must be higher than zero")
elif o in ("-d", "--delay"):
try:
# make sure argument is a valid value (float)
self.line_delay = float(a)
except:
raise exception.InvalidOptionException("delay")
if self.line_delay <= 0:
raise exception.InvalidOptionException("delay",
"Must be higher than zero")
else:
# this should never happen!
raise Exception(_("Unhandled option. See --help for details."))
# fill in other important properties
if self.use_zenkaku:
digmap_kana = self.digmap_kana_zenkaku
digmap_alpha_num = self.digmap_alpha_num_zenkaku
self.space = self.space_zenkaku
self.proportion = 2
else:
digmap_kana = self.digmap_kana_hangaku
digmap_alpha_num = self.digmap_alpha_num_hangaku
self.space = self.space_hangaku
self.proportion = 1
self.digmap.extend(digmap_kana)
if not use_kana_only:
self.digmap.extend(digmap_alpha_num)
示例14: help_fonts
def help_fonts(self):
fonts = self.get_fonts()
ScreenBase.usage_header()
print _("""Here is the list of all available figlet fonts that are
supported in your system:
%(fonts)s
You may try to use them with the option -f/--font. See --help for details.
You may also refer to official figlet documentation for additional details
on how to deal with fonts.
""") % {
'fonts': "\t" + "\n\t".join(textwrap.wrap(", ".join(fonts), 50)),
}
ScreenBase.usage_footer()
示例15: __init__
def __init__(self):
"""
The constructor of this class, using most default values from its super
class, `SimpleUrlFetcherBase`.
"""
SimpleUrlFetcherBase.__init__(self,
"rfc",
_("randomly displays RFC contents"),
"localhost") # base class require a URL