view sandbox/ttk.py @ 816:d137df18a8bf
structure: create method superimpose of SequenceMixin
Most of code of AlignmentMixin.superimpose was moved to SequenceMixin.
Structures of sequences can be superimposed manually (in custom order,
or with additions action such as loading/unloading of structure).
author |
boris (kodomo) <bnagaev@gmail.com> |
date |
Fri, 15 Jul 2011 02:06:23 +0400 |
parents |
4e6e85851133 |
children |
|
line source
1 from tkinter import ttk, filedialog
4 class Scrollbar(tkinter.Scrollbar):
6 def __init__(self, *args, **kw):
7 tkinter.Scrollbar.__init__(self, *args, **kw)
8 self['command'] = self._command
9 self._attached_widgets = set()
10 self._orient = {'horizontal': 'x', 'vertical': 'y'}[self['orient']]
12 def attach(self, widget):
13 self._attached_widgets.add(widget)
14 command = self._orient + 'scrollcommand'
15 widget[command] = lambda *args, **kw: self._set(widget, *args, **kw)
17 def _command(self, *args, **kw):
18 command = self._orient + 'view'
20 for widget in self._attached_widgets:
21 result = getattr(widget, command)(*args, **kw)
24 def _set(self, sender, *args, **kw):
25 command = self._orient + 'view'
27 for widget in self._attached_widgets:
30 getattr(widget, command)('moveto', args[0])
32 class MegaText(tkinter.Text):
34 def __init__(self, *args, **kw):
35 tkinter.Text.__init__(self, *args, **kw)
37 self.bind("<B1-Motion>", self._select)
38 self.bind("<B1-ButtonRelease>", self._select_end)
39 self.tag_configure('vselection', borderwidth=1, relief="solid", background='#ffbbbb')
41 def tag_clear(self, tag):
42 """Remove the tag from anywhere in the text."""
43 ranges = self.tag_ranges(tag)
44 for begin, end in zip(ranges[::2], ranges[1::2]):
45 self.tag_remove(tag, begin, end)
47 def insert(self, *args, **kw):
48 self['state'] = 'normal'
49 result = tkinter.Text.insert(self, *args, **kw)
50 self['state'] = 'disabled'
53 def _select (self, ev):
54 index = self.index("@%s,%s" % (ev.x, ev.y))
55 line, pos = map(int, index.split('.'))
56 if not hasattr(self, '_selection'):
57 self._selection = [line, line, pos, pos]
58 self._selection[1] = line
59 self._selection[3] = pos
61 self.tag_clear('vselection')
62 line0, line1 = sorted(self._selection[0:2])
63 pos0, pos1 = sorted(self._selection[2:4])
64 for line in range(line0, line1 + 1):
67 '%s.%s' % (line, pos0),
68 '%s.%s' % (line, pos1)
72 def _select_end(self, ev):
79 names.delete(0, 'end')
80 sequences.delete('1.0', 'end')
82 filename = filedialog.askopenfilename()
84 for item in open(filename).read().split('\n>'):
85 lines = item.split('\n')
86 name = lines[0].lstrip('>').strip()
87 body = "".join(map(str.strip, lines[1:]))
89 names.insert('end', name)
90 sequences.insert('end', body+'\n')
91 line = int(sequences.index('end - 1 line').split('.')[0])
92 seqs.add((name, body, line))
95 length = len(list(seqs)[0][1])
98 for pos in range(length):
100 for name, seq, _ in seqs:
102 weights[char] = weights.get(char, 0) + 1
104 weights[char] = weights[char] * 10 // num_seqs
105 seq_weights.append(weights)
107 for name, seq, line in seqs: