本文整理汇总了Python中termsaverlib.i18n._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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,
}
开发者ID:NMLOR10N,项目名称:termsaver,代码行数:34,代码来源:filereader.py
示例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()
开发者ID:AkBKukU,项目名称:termsaver,代码行数:25,代码来源:__init__.py
示例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
开发者ID:NMLOR10N,项目名称:termsaver,代码行数:60,代码来源:sysmon.py
示例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)
开发者ID:NMLOR10N,项目名称:termsaver,代码行数:27,代码来源:sysmon.py
示例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,
}
开发者ID:AkBKukU,项目名称:termsaver,代码行数:34,代码来源:dot.py
示例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
开发者ID:AkBKukU,项目名称:termsaver,代码行数:25,代码来源:asciiartfarts.py
示例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."))
开发者ID:NMLOR10N,项目名称:termsaver,代码行数:32,代码来源:rssfeed.py
示例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)
开发者ID:brunobraga,项目名称:termsaver-figlet,代码行数:35,代码来源:fly.py
示例9: __init__
def __init__(self):
"""
Creates a new instance of this class.
"""
UrlFetcherBase.__init__(self,
"urlfetcher",
_("displays url contents with typing animation"))
开发者ID:AkBKukU,项目名称:termsaver,代码行数:7,代码来源:urlfetcher.py
示例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,
}
开发者ID:AkBKukU,项目名称:termsaver,代码行数:26,代码来源:rssfeed.py
示例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."))
开发者ID:AkBKukU,项目名称:termsaver,代码行数:32,代码来源:dot.py
示例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."))
开发者ID:brunobraga,项目名称:termsaver,代码行数:26,代码来源:clock.py
示例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)
开发者ID:AkBKukU,项目名称:termsaver,代码行数:59,代码来源:matrix.py
示例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()
开发者ID:brunobraga,项目名称:termsaver-figlet,代码行数:17,代码来源:__init__.py
示例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
开发者ID:AkBKukU,项目名称:termsaver,代码行数:9,代码来源:rfc.py
示例16: _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:
-g, --granularity
an integer value to define how dirt should the screen be.
Default value is [%(granularity)s]. Use something like [1]
for clean style, or a [100] for total dirt.
-d, --delay Defines the speed (in seconds) of the character movement
Default value is [%(line_delay)s] (in seconds).
-k, --kana-only
Displays only Japanese characters (excludes alpha numeric).
-z, --zenkaku
Displays full-width (fattish) Japanese characters.
By default it displays half-width characters.
-h, --help Displays this help message
Examples:
$ %(app_name)s %(screen)s -g 100
This will print out random characters in maximum dirt (using almost the
entire screen space). Try [1] for very clean results.
$ %(app_name)s %(screen)s -g 5 -d 0.001 -k
This will give a cleaner print than the default, much faster with only
Japanese characters.
""") % {
'screen': self.name,
'app_name': constants.App.NAME,
'granularity': self.granularity,
'line_delay': self.line_delay,
}
开发者ID:AkBKukU,项目名称:termsaver,代码行数:43,代码来源:matrix.py
示例17: __init__
def __init__(self):
"""
The constructor of this class.
"""
ScreenBase.__init__(self,
"clock",
_("displays a digital clock on screen"),
{'opts': 'hf', 'long_opts': ['help', 'format']},
)
self.cleanup_per_cycle = True
开发者ID:AkBKukU,项目名称:termsaver,代码行数:10,代码来源:clock.py
示例18: _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:
-w, --word Sets the word to be displayed
default is the name of this application (if you need to use
spaces, don't forget to place the word with quotes)
-d, --delay Sets how long the word will be displayed before
randomized again. Default is %(default_delay)s second(s)
-f, --font the figlet font to be used, default is the figlet default
(see `figlet -I3` command for details or figler man pages)
-h, --help Displays this help message
--help-fonts
Displays the available fonts that can be used with
the -f/--font option.
Example:
$ %(app_name)s %(screen)s
This will trigger the screensaver to display the default word
%(app_title)s in random locations of the screen
$ %(app_name)s %(screen)s -w FooBar -f lean -d 5
This will trigger the screensaver to display the word FooBar
in random locations of the screen, using the "lean" figlet font with
a delay of 5 seconds.
""") % {
'app_name': constants.App.NAME,
'app_title': constants.App.TITLE,
'screen': self.name,
'default_delay': self.FREEZE_WORD_DELAY,
}
开发者ID:brunobraga,项目名称:termsaver-figlet,代码行数:42,代码来源:stat.py
示例19: _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:
-h, --help Displays this help message
-f, --format Shows the clock in 12 hour format
""")
开发者ID:AkBKukU,项目名称:termsaver,代码行数:20,代码来源:clock.py
示例20: fix_uri
def fix_uri(self, text):
"""
Validates a text as URL format, also adjusting necessary stuff for a
clearer URL that will be fetched here.
Code based on Django source:
https://code.djangoproject.com/browser/django/trunk/django/forms/
fields.py?rev=17430#L610
Arguments:
* text: the URL string that is to be validated and fixed
"""
if not text:
raise exception.UrlException(text, _("URL can not be blank"))
try:
url_fields = list(urlparse.urlsplit(text))
except ValueError:
raise exception.UrlException(text, _("URL does not seem valid"))
if not url_fields[0]:
# If no URL scheme given, assume http://
url_fields[0] = 'http'
if not url_fields[1]:
# Assume that if no domain is provided, that the path segment
# contains the domain.
url_fields[1] = url_fields[2]
url_fields[2] = ''
# Rebuild the url_fields list, since the domain segment may now
# contain the path too.
try:
url_fields = list(urlparse.urlsplit(
urlparse.urlunsplit(url_fields)))
except ValueError:
raise exception.UrlException(text,
_("URL does not seem valid"))
if not url_fields[2]:
# the path portion may need to be added before query params
url_fields[2] = '/'
return urlparse.urlunsplit(url_fields)
开发者ID:AkBKukU,项目名称:termsaver,代码行数:41,代码来源:urlfetcher.py
注:本文中的termsaverlib.i18n._函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论