def preview_updated(self, cslist, total, *args): if total is None: info = gtklib.markup(_('Unknown revision!'), weight='bold', color=gtklib.DRED) else: inner = gtklib.markup(_('%s changesets') % total, weight='bold') info = _('%s will be stripped') % inner self.resultlbl.set_markup(info) self.buttons['strip'].set_sensitive(bool(total))
def revline_markup(revnum, revid, summary, highlight=None, branch=None): revnum = gtklib.markup(revnum) summary = gtklib.markup(summary) if revid: revid = revid_markup(revid) if branch: return '%s (%s) %s %s' % (revnum, revid, branch, summary) return '%s (%s) %s' % (revnum, revid, summary) else: if branch: return '%s - %s %s' % (revnum, branch, summary) return '%s - %s' % (revnum, summary)
def update_status(self, count): if count: inner = gtklib.markup(_("%s patches") % count, weight="bold") if self.mqloaded: info = _("%s will be imported to the") % inner else: info = _("%s will be imported to the repository") % inner else: info = gtklib.markup(_("Nothing to import"), weight="bold", color=gtklib.DRED) self.infolbl.set_markup(info) if self.mqloaded: self.dest_combo.set_property("visible", bool(count)) self.buttons["import"].set_sensitive(bool(count))
def __init__(self, title, message, parent, choices, default=None, esc=None, files=None): gtk.MessageDialog.__init__(self, parent, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION) self.set_title(hglib.toutf(title)) if files: msg = '' for i, file in enumerate(files): msg += ' %s\n' % file if i == 9: msg += ' ...\n' break message += '\n\n' + msg self.format_secondary_markup(gtklib.markup(hglib.toutf(message), weight='bold')) accel_group = gtk.AccelGroup() self.add_accel_group(accel_group) for i, s in enumerate(choices): button = self.add_button(s.replace('&', '_'), i) try: char = s[s.index('&')+1].lower() button.add_accelerator('clicked', accel_group, ord(char), 0, gtk.ACCEL_VISIBLE) except ValueError: pass if default: self.set_default_response(default) self.esc = esc
def hunk_unmarkup(text): 'Format a diff hunk for display in a TreeView row without markup' hunk = '' # don't use splitlines, should split with only LF for the patch lines = hglib.tounicode(text).split(u'\n') for line in lines: hunk += gtklib.markup(hglib.toutf(line[:512])) + '\n' return hunk
def hunk_markup(text): 'Format a diff hunk for display in a TreeView row with markup' hunk = '' # don't use splitlines, should split with only LF for the patch lines = hglib.tounicode(text).split(u'\n') for line in lines: line = hglib.toutf(line[:512]) + '\n' if line.startswith('---') or line.startswith('+++'): hunk += gtklib.markup(line, color=gtklib.DBLUE) elif line.startswith('-'): hunk += gtklib.markup(line, color=gtklib.DRED) elif line.startswith('+'): hunk += gtklib.markup(line, color=gtklib.DGREEN) elif line.startswith('@@'): hunk = gtklib.markup(line, color=gtklib.DORANGE) else: hunk += gtklib.markup(line) return hunk
def linkwidget(revnum, revid, summary, highlight=None, branch=None): # revision label opts = dict(underline='single', color=gtklib.BLUE) if highlight: opts['weight'] = 'bold' rev = '%s (%s)' % (gtklib.markup(revnum, **opts), revid_markup(revid, **opts)) revlabel = gtk.Label() revlabel.set_markup(rev) revlabel.set_selectable(True) revlabel.connect('button-release-event', self.link_event, revnum) # summary & branch label sum = gtklib.markup(summary) if branch: sum = gtklib.markup(branch, color=gtklib.NORMAL, background=gtklib.PGREEN) + ' ' + sum sumlabel = gtk.Label() sumlabel.set_markup(sum) sumlabel.set_selectable(True) box = gtk.HBox() box.pack_start(revlabel, False, False) box.pack_start(sumlabel, True, True, 4) return box
def __init__(self, title, message, parent, type=gtk.MESSAGE_INFO): SimpleMessage.__init__(self, parent, gtk.DIALOG_MODAL, type, gtk.BUTTONS_CLOSE) self.set_title('TortoiseHg') self.set_markup(gtklib.markup(hglib.toutf(title), weight='bold')) self.format_secondary_text(hglib.toutf(message)) mod = gtklib.get_thg_modifier() key, modifier = gtk.accelerator_parse(mod+'Return') accel_group = gtk.AccelGroup() self.add_accel_group(accel_group) try: buttons = self.get_children()[0].get_children()[1].get_children() buttons[0].add_accelerator('clicked', accel_group, key, modifier, gtk.ACCEL_VISIBLE) except IndexError: pass
def __init__(self, title, files, parent, primary): SimpleMessage.__init__(self, parent, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO) self.set_title(hglib.toutf(title)) self.set_markup(gtklib.markup(hglib.toutf(primary), weight='bold')) message = '' for i, f in enumerate(files): message += ' ' + f + '\n' if i == 9: message += ' ...\n' break self.format_secondary_text(hglib.toutf(message)) accel_group = gtk.AccelGroup() self.add_accel_group(accel_group) buttons = self.get_children()[0].get_children()[1].get_children() buttons[1].add_accelerator('clicked', accel_group, ord('y'), 0, gtk.ACCEL_VISIBLE) buttons[0].add_accelerator('clicked', accel_group, ord('n'), 0, gtk.ACCEL_VISIBLE)
def preset_func(widget, item, value): if item == "rev": revnum, revid = value revid = gtklib.markup(revid, **mono) if revnum is not None and revid is not None: return "%s (%s)" % (revnum, revid) return "%s" % revid elif item in ("revid", "transplant"): return gtklib.markup(value, **mono) elif item in ("revnum", "p4", "svn"): return str(value) elif item in ("rawbranch", "branch"): return gtklib.markup(" %s " % value, color=gtklib.BLACK, background=gtklib.PGREEN) elif item in ("rawtags", "tags"): opts = dict(color=gtklib.BLACK, background=gtklib.PYELLOW) tags = [gtklib.markup(" %s " % tag, **opts) for tag in value] return " ".join(tags) elif item in ("desc", "summary", "user", "shortuser", "date", "age"): return gtklib.markup(value) elif item == "dateage": return gtklib.markup("%s (%s)" % value) raise UnknownItem(item)
def on_get_value(self, rowref, column): (revid, graphnode, lines, path) = self.graphdata[rowref] if column == REVID: return revid if column == LINES: return lines if column == LAST_LINES: if rowref>0: return self.graphdata[rowref-1][2] return [] if column == WFILE: return path or '' try: ctx = self.repo[revid] except IndexError: return None # non-cached columns if column in (HEXID, REVHEX, BRANCH, LOCALTIME, UTC): if column == HEXID: return str(ctx) if column == REVHEX: hexid = gtklib.markup(str(ctx), face='monospace') return '%s: %s' % (revid, hexid) if column == BRANCH: return ctx.branch() if column == LOCALTIME: return hglib.displaytime(ctx.date()) if column == UTC: return hglib.utctime(ctx.date()) # cached columns if revid not in self.revisions: self.revisions[revid] = {} cache = self.revisions[revid] if cache.has_key(column): return cache[column] if column in (COMMITER, FGCOLOR): cache[COMMITER] = hglib.toutf(hglib.username(ctx.user())) if column == TAGS: tags = self.repo.nodetags(ctx.node()) cache[TAGS] = hglib.toutf(', '.join(tags)) elif column == SVNREV: extra = ctx.extra() cvt = extra.get('convert_revision', '') if cvt.startswith('svn:'): rev = cvt.split('/', 1)[-1] rev = rev.split('@', 1)[-1] else: rev = None cache[SVNREV] = rev and hglib.toutf('r%s' % rev) or '' elif column == AGE: cache[AGE] = hglib.age(ctx.date()) elif column == FGCOLOR: cache[FGCOLOR] = self.color_func(revid, cache[COMMITER]) elif column == CHANGES: parent = self.parents.get(revid, None) if parent is None: parent = ctx.parents()[0].node() M, A, R = self.repo.status(parent, ctx.node())[:3] common = dict(color=gtklib.BLACK) M = M and gtklib.markup(' %s ' % len(M), background=gtklib.PORANGE, **common) or '' A = A and gtklib.markup(' %s ' % len(A), background=gtklib.PGREEN, **common) or '' R = R and gtklib.markup(' %s ' % len(R), background=gtklib.PRED, **common) or '' cache[CHANGES] = ''.join((M, A, R)) elif column in (MESSAGE, GRAPHNODE): # convert to Unicode for valid string operations summary = hglib.tounicode(ctx.description()).replace(u'\0', '') if self.longsummary: limit = 80 lines = summary.splitlines() if lines: summary = lines.pop(0) while len(summary) < limit and lines: summary += u' ' + lines.pop(0) summary = summary[0:limit] else: summary = '' else: lines = summary.splitlines() summary = lines and lines[0] or '' escape = gtklib.markup_escape_text summary = escape(hglib.toutf(summary)) tstr = '' for tag in ctx.tags(): if tag not in self.hidetags: if tag in self.mqpatches: bg = gtklib.PBLUE else: bg = gtklib.PYELLOW style = {'color': gtklib.BLACK, 'background': bg} tstr += gtklib.markup(' %s ' % tag, **style) + ' ' for mark in ctx.bookmarks(): if mark == self.curbookmark: bg = gtklib.PORANGE else: bg = gtklib.PLIME style = {'color': gtklib.BLACK, 'background': bg} tstr += gtklib.markup(' %s ' % mark, **style) + ' ' node = ctx.node() branch = ctx.branch() bstr = '' status = 0 if self.branchtags.get(branch) == node: bstr += gtklib.markup(' %s ' % branch, color=gtklib.BLACK, background=gtklib.PGREEN) + ' ' status = 8 if revid in self.wcparents: sumstr = bstr + tstr + '<b><u>' + summary + '</u></b>' status += 4 else: sumstr = bstr + tstr + summary status += 0 if node in self.outgoing: # outgoing if not self.showgraph: marker = hglib.toutf(u'\u2191 ') # up arrow sumstr = marker + sumstr status += 1 elif revid >= self.origtip: if revid >= len(self.repo) - self.npreviews: # incoming if not self.showgraph: marker = hglib.toutf(u'\u2193 ') # down arrow sumstr = marker + sumstr status += 3 else: # new status += 2 cache[MESSAGE] = sumstr gcolumn, gcolor = graphnode cache[GRAPHNODE] = (gcolumn, gcolor, status) return cache[column]
def revid_markup(revid, **kargs): opts = dict(face='monospace', size='9000') opts.update(kargs) return gtklib.markup(revid, **opts)
def markup_func(widget, item, value): if item == 'ishead' and value is False: text = _('Not a head revision!') return gtklib.markup(text, weight='bold') raise csinfo.UnknownItem(item)