File: xbb_utils.py

package info (click to toggle)
python-biopython 1.64%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 44,416 kB
  • ctags: 12,472
  • sloc: python: 153,759; xml: 67,286; ansic: 9,003; sql: 1,488; makefile: 144; sh: 59
file content (50 lines) | stat: -rw-r--r-- 1,523 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
# Created: Thu Jul 13 12:09:58 2000
# Last changed: Time-stamp: <00/12/03 12:10:58 thomas>
# thomas@cbs.dtu.dk, http://www.cbs.dtu.dk/thomas
# File: xbb_utils.py

import sys
sys.path.insert(0, '.')

try:
    from Tkinter import * # Python 2
except ImportError:
    from tkinter import * # Python 3

try:
    import tkFileDialog as filedialog # Python 2
except ImportError:
    from tkinter import filedialog # Python 3


class NotePad(Toplevel):
    def __init__(self, master=None):
        Toplevel.__init__(self, master)
        self.menubar = Menu(self)
        self.filemenu = Menu(self.menubar)
        self.filemenu.add_command(label="Save", command=self.save)
        self.filemenu.add_separator()
        self.filemenu.add_command(label="Dismiss", command=self.destroy)

        self.menubar.add_cascade(label="File", menu=self.filemenu)
        self.configure(menu=self.menubar)
        self.yscroll = Scrollbar(self, orient=VERTICAL)
        self.tid = Text(self, yscrollcommand=self.yscroll.set)
        self.yscroll.configure(command=self.tid.yview)
        self.tid.pack(side=LEFT, fill=BOTH, expand=1)
        self.yscroll.pack(side=RIGHT, fill=Y)

    def text_id(self):
        return self.tid

    def insert(self, start, txt):
        self.tid.insert(start, txt)

    def save(self):
        fd = filedialog.SaveFileDialog(self)
        file = fd.go(key="test")
        if file:
            fid = open(file, 'w')
            fid.write(self.tid.get(0.0, END))
            fid.close()