本文整理汇总了Python中Config.Settings类的典型用法代码示例。如果您正苦于以下问题:Python Settings类的具体用法?Python Settings怎么用?Python Settings使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Settings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setPalettes
def setPalettes(self):
self.palettes = {
"wrong": QPalette(
Qt.black,
Qt.lightGray,
Qt.lightGray,
Qt.darkGray,
Qt.gray,
Settings.getColor("quiz_wrong_fg"),
Qt.white,
Settings.getColor("quiz_wrong_bg"),
Qt.yellow,
),
"right": QPalette(
Qt.black,
Qt.lightGray,
Qt.lightGray,
Qt.darkGray,
Qt.gray,
Settings.getColor("quiz_right_fg"),
Qt.yellow,
Settings.getColor("quiz_right_bg"),
Qt.yellow,
),
"inactive": QPalette(
Qt.black,
Qt.lightGray,
Qt.lightGray,
Qt.darkGray,
Qt.gray,
Qt.black,
Qt.lightGray,
),
}
self.setPalette(self.palettes["inactive"])
示例2: update_typer_html
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)
示例3: to_lessons
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)
示例4: setPalettes
def setPalettes(self):
self.palettes = {
'wrong': QPalette(Qt.black,
Qt.lightGray, Qt.lightGray, Qt.darkGray, Qt.gray,
Settings.getColor("quiz_wrong_fg"), Qt.white, Settings.getColor("quiz_wrong_bg"), Qt.yellow),
'right': QPalette(Qt.black,
Qt.lightGray, Qt.lightGray, Qt.darkGray, Qt.gray,
Settings.getColor("quiz_right_fg"), Qt.yellow, Settings.getColor("quiz_right_bg"), Qt.yellow),
'inactive': QPalette(Qt.black, Qt.lightGray, Qt.lightGray, Qt.darkGray,
Qt.gray, Qt.black, Qt.lightGray)}
self.setPalette(self.palettes['inactive'])
示例5: color_position
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
示例6: generate_automatic_insertion_regex
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
示例7: paras
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
示例8: __init__
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')
示例9: readjust
def readjust(self):
f = Settings.getFont("typer_font")
f.setKerning(False)
#TODO: get rid of "vertical kerning"
# f.setFixedPitch(True) didn't work
self.label.setFont(f)
self.typer.setFont(f)
示例10: __init__
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()
示例11: __init__
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)
示例12: getWaitText
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"
示例13: paras
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
示例14: updateLabel
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)
示例15: checkText
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'])