本文整理汇总了Python中Config.Settings.get方法的典型用法代码示例。如果您正苦于以下问题:Python Settings.get方法的具体用法?Python Settings.get怎么用?Python Settings.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Config.Settings
的用法示例。
在下文中一共展示了Settings.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_typer_html
# 需要导入模块: from Config import Settings [as 别名]
# 或者: from Config.Settings import get [as 别名]
def update_typer_html(typer,errors):
'''Organizational function.
Given a Typer, updates its html based on settings (not including invisible mode)'''
#dict : str -> str ; original and displacement strs in error region (for easier display)
v = unicode(typer.toPlainText())
v_err_replacements = {}
if Settings.get('text_area_replace_spaces'):
#if want to make replacements change spaces in text area as well (risky!)
v_err_replacements.update(space_replacement_dict_from_setting('text_area_mistakes_space_char'))
if Settings.get('text_area_replace_return'):
#want to make replacements change returns in text area as well (a little less risky since there's usually fewer)
v_err_replacements["\n"] = Settings.get('text_area_return_replacement')
error_colors = {} #dict : int -> str, mapping errors to color
v_replaced_list = list(v) #list of strs, initially one char each, to operate on
v_replaced_list = html_list_process_spaces(v_replaced_list)
if Settings.get("show_text_area_mistakes"):
error_colors = dict(map(lambda i : (i,Settings.get('text_area_mistakes_color')),errors))
v_replaced_list = replace_at_locs(v_replaced_list,v_err_replacements,errors)
v_colored_list = html_color_strs(v_replaced_list,error_colors)
htmlized = "".join(v_colored_list).replace("\n","<BR>")
set_typer_html(typer,htmlized)
示例2: to_lessons
# 需要导入模块: from Config import Settings [as 别名]
# 或者: from Config.Settings import get [as 别名]
def to_lessons(sentences):
backlog = []
backlen = 0
min_chars = Settings.get('min_chars')
max_chars = Settings.get('max_chars')
sweet_size = 3*(min_chars + max_chars) // 4
for s in sentences:
ssplit = []
while len(s) > sweet_size:
idx = s.find(' ', sweet_size)
if idx == -1:
break
if idx != -1:
ssplid.append(s[:idx])
s = s[idx+1:]
ssplit.append(s)
for xs in ssplit:
backlog.append(xs)
backlen += len(xs)
if backlen >= min_chars:
yield u' '.join(backlog)
backlog = []
backlen = 0
if backlen > 0:
yield u' '.join(backlog)
示例3: color_position
# 需要导入模块: from Config import Settings [as 别名]
# 或者: from Config.Settings import get [as 别名]
def color_position(settings_color_var, use_space_var, space_var):
'''Colors position with the color stored in settings_color_var.
strs use_space_var and space_var are settings variables to look up.
If [setting] use_space_var, space at position is replaced with [setting] space_var
Returns the new text_strs list (for assignment).'''
colors[position] = Settings.get(settings_color_var)
if Settings.get(use_space_var):
return replace_at_locs(text_strs,space_replacement_dict_from_setting(space_var),[position])
else:
return text_strs
示例4: generate_automatic_insertion_regex
# 需要导入模块: from Config import Settings [as 别名]
# 或者: from Config.Settings import get [as 别名]
def generate_automatic_insertion_regex():
'''From settings info, returns the regex for which to re.match the automatically inserted chars
Or None if no chars are to be automatically inserted.'''
#the str of characters (in regex-escaped form, but not regex) to automatically insert
automatically_inserted_chars = ""
if Settings.get('use_automatic_other_insertion'):
automatically_inserted_chars += re.escape(Settings.get('automatic_other_insertion'))
for s,c in ('automatic_space_insertion',u" "),('automatic_return_insertion',u"\n"):
if Settings.get(s):
automatically_inserted_chars += re.escape(c)
return "[{0}]+".format(automatically_inserted_chars) if automatically_inserted_chars else None
示例5: paras
# 需要导入模块: from Config import Settings [as 别名]
# 或者: from Config.Settings import get [as 别名]
def paras(self, f):
p = []
ps = []
previous_line_empty = True
for l in f:
#designated replacements for unicode text
if Settings.get('transliteration_manual_unicode'):
for orig, repl in unicode_replacements:
l = l.replace(orig, repl)
ascii_line = l
if unidecode_imported and Settings.get('transliteration_method') == INDEX_TRANSLITERATION_UNIDECODE:
#tries to use unidecode if it exists
ascii_line = unidecode.unidecode(ascii_line)
elif Settings.get('transliteration_method') == INDEX_TRANSLITERATION_DELETE:
#deletes all remaining non-ascii chars
try:
ascii_line = ascii_line.decode('ascii')
except UnicodeEncodeError:
ascii_line = ''
for c in l:
if ord(c) < 128:
ascii_line += c
else:
ascii_line += ""
#replaces any 1+ adjacent whitespace chars (spaces, tabs, newlines, etc) with one ascii space
if Settings.get('single_space_only'):
ascii_line = re.sub("\s+"," ",ascii_line)
#designated replacements for ascii text
if Settings.get('transliteration_manual_ascii'):
for orig, repl in ascii_replacements:
ascii_line = ascii_line.replace(orig, repl)
l = ascii_line.strip()
current_line_empty = not l
#the current line is empty: insert empty line
#or the current line and previous line both nonempty: need to insert empty line between them
if (current_line_empty or not previous_line_empty) and len(p) > 0:
ps.append(SentenceSplitter(u" ".join(p)))
p = []
if not current_line_empty:
p.append(l)
previous_line_empty = current_line_empty
if len(p) > 0:
ps.append(SentenceSplitter(u" ".join(p)))
return ps
示例6: __init__
# 需要导入模块: from Config import Settings [as 别名]
# 或者: from Config.Settings import get [as 别名]
def __init__(self, *args):
super(Quizzer, self).__init__(*args)
self.result = QLabel()
self.typer = Typer()
self.label = WWLabel()
self.result.setVisible(Settings.get("show_last"))
#self.label.setFrameStyle(QFrame.Raised | QFrame.StyledPanel)
#self.typer.setBuddy(self.label)
#self.info = QLabel()
self.connect(self.typer, SIGNAL("done"), self.done)
self.connect(self.typer, SIGNAL("textChanged"), self.checkText)
self.connect(self.typer, SIGNAL("cancel"), SIGNAL("wantText"))
self.connect(Settings, SIGNAL("change_typer_font"), self.readjust)
self.connect(Settings, SIGNAL("change_show_last"), self.result.setVisible)
self.text = ('','', 0, None)
layout = QVBoxLayout()
#layout.addWidget(self.info)
#layout.addSpacing(20)
layout.addWidget(self.result, 0, Qt.AlignRight)
layout.addWidget(self.label, 1, Qt.AlignBottom)
layout.addWidget(self.typer, 1)
self.setLayout(layout)
self.readjust()
示例7: __init__
# 需要导入模块: from Config import Settings [as 别名]
# 或者: from Config.Settings import get [as 别名]
def __init__(self, fname):
super(LessonMiner, self).__init__()
#print time.clock()
with codecs.open(fname, "r", "utf_8_sig") as f:
self.paras = self.paras(f)
self.lessons = None
self.min_chars = Settings.get('min_chars')
示例8: __init__
# 需要导入模块: from Config import Settings [as 别名]
# 或者: from Config.Settings import get [as 别名]
def __init__(self, x, y, *args):
super(Plot, self).__init__(*args)
# self.connect(self, SIGNAL("sceneRectChanged(QRectF)"), self.setSceneRect)
if len(x) < 2:
return
min_x, max_x = min(x), max(x)
min_y, max_y = min(y), max(y)
p = QPen(Qt.blue)
p.setCosmetic(True)
p.setWidthF(2.0)
p.setCapStyle(Qt.RoundCap)
for i in range(0, len(x) - 1):
self.addLine(x[i], -y[i], x[i + 1], -y[i + 1], p)
# Add axes
if Settings.get("show_xaxis"):
if min_y > 0:
min_y = 0
elif max_y < 0:
max_y = 0
if min_y <= 0 <= min_y:
self.addLine(min_x, 0, max_x, 0)
if min_x <= 0 <= max_x:
self.addLine(0, -min_y, 0, -max_y)
w, h = max_x - min_x, max_y - min_y
if h <= 0 or w <= 0:
return
# Add background lines
spc = math.pow(10.0, math.ceil(math.log10(h) - 1))
while h / spc < 5:
spc /= 2
ns = int(min_y / spc) * spc
start = ns
qp = QPen(QColor(Qt.lightGray))
qp.setStyle(Qt.DotLine)
while start < max_y + spc:
lin = self.addLine(min_x, -start, max_x, -start, qp)
lin.setZValue(-1.0)
lbl = QGraphicsSimpleTextItem("%g" % start)
th, tw = lbl.boundingRect().height(), lbl.boundingRect().width()
lbl.scale(0.026 * w / tw, spc / th)
lbl.setPos(QPointF(min_x - 0.03 * w, -start - spc / 2))
self.addItem(lbl)
start += spc
qr = QRectF(min_x - 0.03 * w, -start + spc / 2, 1.03 * w, start - ns)
self.setSceneRect(qr)
示例9: getWaitText
# 需要导入模块: from Config import Settings [as 别名]
# 或者: from Config.Settings import get [as 别名]
def getWaitText(self):
if Settings.get("req_space"):
return (
"Press SPACE and then immediately start typing the text\n"
+ "Press ESCAPE to restart with a new text at any time"
)
else:
return "Press ESCAPE to restart with a new text at any time"
示例10: paras
# 需要导入模块: from Config import Settings [as 别名]
# 或者: from Config.Settings import get [as 别名]
def paras(self, f):
p = []
ps = []
previous_line_empty = True
for l in f:
#designated replacements for unicode text
if Settings.get('transliteration_manual_unicode'):
for orig, repl in unicode_replacements:
l = l.replace(orig, repl)
ascii_line = l
if unidecode_imported and Settings.get('transliteration_method') == INDEX_TRANSLITERATION_UNIDECODE:
#tries to use unidecode if it exists
ascii_line = unidecode.unidecode(ascii_line)
elif Settings.get('transliteration_method') == INDEX_TRANSLITERATION_DELETE:
#deletes all remaining non-ascii chars
try:
ascii_line = ascii_line.decode('ascii')
except UnicodeEncodeError:
ascii_line = filter(lambda c : ord(c) < 128, ascii_line)
#replaces any 1+ adjacent whitespace chars (spaces, tabs, newlines, etc) with one ascii space
if Settings.get('single_space_only'):
ascii_line = re.sub("\s+"," ",ascii_line)
#TODO: newlines doesn't work since all this is done line-by-line
#replaces multiple adjacent instances (possibly including spaces, newlines) of those characters
#in list multiple_replacements (e.g. "start ! !!!!! ! ! !!\n !\nend" might get replaced with
#"start !\nend")
if Settings.get('multiple_replacement_enabled'):
additional_chars = (" " if Settings.get('multiple_replacement_allow_spaces') else "") + ("\n" if Settings.get('multiple_replacement_allow_newlines') else "")
for m in Settings.get('multiple_replacement_chars'):
ascii_line = re.sub("{0}[{0}{1}]*{0}".format(re.escape(m),additional_chars), m, ascii_line)
#designated replacements for ascii text
if Settings.get('transliteration_manual_ascii'):
for orig, repl in ascii_replacements:
ascii_line = ascii_line.replace(orig, repl)
l = ascii_line.strip()
current_line_empty = not l
#the current line is empty: insert empty line
#or the current line and previous line both nonempty: need to insert empty line between them
if (current_line_empty or not previous_line_empty) and len(p) > 0:
ps.append(SentenceSplitter(u" ".join(p)))
p = []
if not current_line_empty:
p.append(l)
previous_line_empty = current_line_empty
if len(p) > 0:
ps.append(SentenceSplitter(u" ".join(p)))
return ps
示例11: updateLabel
# 需要导入模块: from Config import Settings [as 别名]
# 或者: from Config.Settings import get [as 别名]
def updateLabel(self,position,errors):
'''Populates the label with colors depending on current position and errors.'''
#dict : str -> str ; original and displacement strs in error region (for easier display)
err_replacements = {"\n":u"{0}<BR>".format(Settings.get('label_return_symbol'))}
colors = {} #dict : int -> str, mapping errors to color
if Settings.get('show_label_mistakes'):
#showing mistakes; need to populate color
colors = dict([(i,Settings.get('label_mistakes_color')) for i in errors])
if Settings.get('label_replace_spaces_in_mistakes'):
err_replacements.update(space_replacement_dict_from_setting('label_mistakes_space_char'))
text_strs = list(self.text[2]) #list of strs, initially one char each, to operate on
text_strs = html_list_process_spaces(text_strs)
text_strs = replace_at_locs(text_strs,err_replacements,errors)
def color_position(settings_color_var, use_space_var, space_var):
'''Colors position with the color stored in settings_color_var.
strs use_space_var and space_var are settings variables to look up.
If [setting] use_space_var, space at position is replaced with [setting] space_var
Returns the new text_strs list (for assignment).'''
colors[position] = Settings.get(settings_color_var)
if Settings.get(use_space_var):
return replace_at_locs(text_strs,space_replacement_dict_from_setting(space_var),[position])
else:
return text_strs
#designates colors and replacements of position
if Settings.get('show_label_position_with_prior_mistake') and position - 1 in errors:
text_strs = color_position('label_position_with_prior_mistake_color',
'label_replace_spaces_in_position_with_prior_mistake',
'label_position_with_prior_mistake_space_char')
elif Settings.get('show_label_position_with_mistakes') and errors:
text_strs = color_position('label_position_with_mistakes_color',
'label_replace_spaces_in_position_with_mistakes',
'label_position_with_mistakes_space_char')
elif Settings.get('show_label_position'):
text_strs = color_position('label_position_color',
'label_replace_spaces_in_position',
'label_position_space_char')
htmlized = "".join(html_color_strs(text_strs,colors))
htmlized = htmlized.replace(u"\n", u"{0}<BR>".format(Settings.get('label_return_symbol')))
self.label.setText(htmlized)
示例12: checkText
# 需要导入模块: from Config import Settings [as 别名]
# 或者: from Config.Settings import get [as 别名]
def checkText(self):
if self.target is None or self.editflag:
return
v = unicode(self.toPlainText())
if self.when[0] == 0:
space = len(v) > 0 and v[-1] == u" "
req = Settings.get('req_space')
self.editflag = True
if space:
self.when[0] = timer()
self.clear()
self.setPalette(self.palettes['right'])
elif req:
self.setText(self.getWaitText())
self.selectAll()
self.editflag = False
if req or space:
return
else:
self.when[0] = -1
y = 0
for y in xrange(min(len(v), len(self.target)), -1, -1):
if v[0:y] == self.target[0:y]:
break
lcd = v[0:y]
self.where = y
if self.when[y] == 0 and y == len(v):
self.when[y] = timer()
if y > 0:
self.times[y-1] = self.when[y] - self.when[y-1]
if lcd == self.target:
self.emit(SIGNAL("done"))
return
if y < len(v) and y < len(self.target):
self.mistake[y] = True
self.mistakes[y] = self.target[y] + v[y]
if v == lcd:
self.setPalette(self.palettes['right'])
else:
self.setPalette(self.palettes['wrong'])
示例13: __init__
# 需要导入模块: from Config import Settings [as 别名]
# 或者: from Config.Settings import get [as 别名]
def __init__(self, *args):
super(Quizzer, self).__init__(*args)
self.result = QLabel()
self.typer = Typer()
self.label = WWLabel()
self.tryout_label = QLabel()
self.tryout_label.setText("Tryout layout: ")
self.tryout_layout = QComboBox()
self.result.setVisible(Settings.get("show_last"))
#self.label.setFrameStyle(QFrame.Raised | QFrame.StyledPanel)
#self.typer.setBuddy(self.label)
#self.info = QLabel()
self.connect(self.typer, SIGNAL("done"), self.done)
self.connect(self.typer, SIGNAL("cancel"), SIGNAL("wantText"))
self.connect(Settings, SIGNAL("change_typer_font"), self.readjust)
self.connect(Settings, SIGNAL("change_show_last"), self.result.setVisible)
self.connect(self.tryout_layout, SIGNAL("currentIndexChanged(int)"), self.changeTryoutLayout)
self.text = ('','', '', None)
self.originalText = ('','', '', None)
self.keyboardLayouts = []
layout = QVBoxLayout()
#layout.addWidget(self.info)
#layout.addSpacing(20)
hlayout = QHBoxLayout()
hlayout.addWidget(self.tryout_label, 0, Qt.AlignLeft)
hlayout.addWidget(self.tryout_layout, 0, Qt.AlignLeft)
hlayout.addStretch()
hlayout.addWidget(self.result, 0, Qt.AlignRight)
layout.addLayout(hlayout)
layout.addWidget(self.label, 1, Qt.AlignBottom)
layout.addWidget(self.typer, 1)
self.setLayout(layout)
self.readjust()
self.addLayouts()
示例14: activate_invisibility
# 需要导入模块: from Config import Settings [as 别名]
# 或者: from Config.Settings import get [as 别名]
def activate_invisibility(self):
'''Turns on invisible mode'''
self.setPalette(self.palettes['invisible'])
set_colored_typer_text(self,Settings.get('quiz_invisible_color')) #flushes out html with plaintext
示例15: done
# 需要导入模块: from Config import Settings [as 别名]
# 或者: from Config.Settings import get [as 别名]
def done(self):
now = time.time()
elapsed, chars, times, mis, mistakes = self.typer.getStats()
assert chars == len(self.text[2])
accuracy = 1.0 - len(filter(None, mis)) / chars
spc = elapsed / chars
viscosity = sum(map(lambda x: ((x-spc)/spc)**2, times)) / chars
DB.execute('insert into result (w,text_id,source,wpm,accuracy,viscosity) values (?,?,?,?,?,?)',
(now, self.text[0], self.text[1], 12.0/spc, accuracy, viscosity))
v2 = DB.fetchone("""select agg_median(wpm),agg_median(acc) from
(select wpm,100.0*accuracy as acc from result order by w desc limit %d)""" % Settings.get('def_group_by'), (0.0, 100.0))
self.result.setText("Last: %.1fwpm (%.1f%%), last 10 average: %.1fwpm (%.1f%%)"
% ((12.0/spc, 100.0*accuracy) + v2))
self.emit(SIGNAL("statsChanged"))
stats = collections.defaultdict(Statistic)
visc = collections.defaultdict(Statistic)
text = self.text[2]
for c, t, m in zip(text, times, mis):
stats[c].append(t, m)
visc[c].append(((t-spc)/spc)**2)
def gen_tup(s, e):
perch = sum(times[s:e])/(e-s)
visc = sum(map(lambda x: ((x-perch)/perch)**2, times[s:e]))/(e-s)
return (text[s:e], perch, len(filter(None, mis[s:e])), visc)
for tri, t, m, v in [gen_tup(i, i+3) for i in xrange(0, chars-2)]:
stats[tri].append(t, m > 0)
visc[tri].append(v)
regex = re.compile(r"(\w|'(?![A-Z]))+(-\w(\w|')*)*")
for w, t, m, v in [gen_tup(*x.span()) for x in regex.finditer(text) if x.end()-x.start() > 3]:
stats[w].append(t, m > 0)
visc[w].append(v)
def type(k):
if len(k) == 1:
return 0
elif len(k) == 3:
return 1
return 2
vals = []
for k, s in stats.iteritems():
v = visc[k].median()
vals.append( (s.median(), v*100.0, now, len(s), s.flawed(), type(k), k) )
is_lesson = DB.fetchone("select discount from source where rowid=?", (None,), (self.text[1], ))[0]
if Settings.get('use_lesson_stats') or not is_lesson:
DB.executemany_('''insert into statistic
(time,viscosity,w,count,mistakes,type,data) values (?,?,?,?,?,?,?)''', vals)
DB.executemany_('insert into mistake (w,target,mistake,count) values (?,?,?,?)',
[(now, k[0], k[1], v) for k, v in mistakes.iteritems()])
if is_lesson:
mins = (Settings.get("min_lesson_wpm"), Settings.get("min_lesson_acc"))
else:
mins = (Settings.get("min_wpm"), Settings.get("min_acc"))
if 12.0/spc < mins[0] or accuracy < mins[1]/100.0:
self.setText(self.text)
elif not is_lesson and Settings.get('auto_review'):
ws = filter(lambda x: x[5] == 2, vals)
if len(ws) == 0:
self.emit(SIGNAL("wantText"))
return
ws.sort(key=lambda x: (x[4],x[0]), reverse=True)
i = 0
while ws[i][4] != 0:
i += 1
i += (len(ws) - i) // 4
self.emit(SIGNAL("wantReview"), map(lambda x:x[6], ws[0:i]))
else:
self.emit(SIGNAL("wantText"))