Пример #1
0
 def __init__(self, master, exc, val, tb):
     self.master = master
     self.exc = exc
     self.val = val
     self.tb = tb
     self.root = tktools.make_toplevel(self.master,
                                       title="Traceback Dialog")
     close = self.close_command
     self.close_button = Button(self.root,
                                text="Close",
                                command=close,
                                default="active")
     self.root.protocol("WM_DELETE_WINDOW", close)
     self.root.bind("<Alt-W>", close)
     self.root.bind("<Alt-w>", close)
     anchor = None
     if tktools._inTkStep(self.root):
         anchor = E
     self.close_button.pack(side=BOTTOM,
                            pady='1m',
                            padx='1m',
                            anchor=anchor)
     self.close_button.focus_set()
     self.label = Label(self.root, text="%s: %s" % (exc, str(val)))
     self.label.pack(fill=X)
     self.text, self.text_frame = tktools.make_text_box(self.root, width=90)
     lines = traceback.format_exception(exc, val, tb)
     lines.append('')
     tb = string.join(map(string.rstrip, lines), '\n')
     self.text.insert(END, tb)
     self.text.yview_pickplace(END)
     self.text["state"] = DISABLED
Пример #2
0
 def __init__(self, master, exc, val, tb):
     self.master = master
     self.exc = exc
     self.val = val
     self.tb = tb
     self.root = tktools.make_toplevel(self.master,
                                       title="Traceback Dialog")
     close = self.close_command
     self.close_button = Button(self.root, text="Close",
                                command=close, default="active")
     self.root.protocol("WM_DELETE_WINDOW", close)
     self.root.bind("<Alt-W>", close)
     self.root.bind("<Alt-w>", close)
     anchor = None
     if tktools._inTkStep(self.root):
         anchor = E
     self.close_button.pack(side=BOTTOM, pady='1m', padx='1m',
                            anchor=anchor)
     self.close_button.focus_set()
     self.label = Label(self.root, text="%s: %s" % (exc, str(val)))
     self.label.pack(fill=X)
     self.text, self.text_frame = tktools.make_text_box(self.root, width=90)
     lines = traceback.format_exception(exc, val, tb)
     lines.append('')
     tb = string.join(map(string.rstrip, lines), '\n')
     self.text.insert(END, tb)
     self.text.yview_pickplace(END)
     self.text["state"] = DISABLED
Пример #3
0
    def PrefsEntry(self, parent, label, group, component,
                   typename='string',
                   label_width=25, entry_height=1, entry_width=None,
                   composite=0, variable=None):
        """Convenience for creating preferences entry or text widget.

        A frame is built within the specified parent, and packed with a
        specified label and an entry widget, created for the purpose.  The
        value of the entry widget is coupled with the designated
        preference.

        The label is apportioned a specified number of characters, default
        25, on the left side of the frame, to enable lining up nicely with
        other, similarly constructed widgets.

        The entry widget may optionally have a height greater than 1, in
        which case a text widget of that height is used."""

        if not composite:
            use_expand = 1
            use_fill = X
            use_side = TOP
            if not entry_width:
                entry_width = 40
        else:
            use_expand = 0
            use_fill = NONE
            use_side = LEFT
        # Assemble the widget:
        frame = Frame(parent, borderwidth=1)
        self.PrefsWidgetLabel(frame, label, label_width=label_width)
        if entry_height == 1:
            entry = Entry(frame, relief=SUNKEN, border=1, width=entry_width,
                          textvariable=(variable and variable or None))
            # note that the variable setting is stripped if None, so this is ok
            entry.pack(side=use_side, expand=use_expand, fill=use_fill)
            if not variable:
                getter, setter = entry.get, self.widget_set_func(entry)
            else:
                getter, setter = variable.get, variable.set
        else:
            if variable:
                raise ValueError, \
                      "multi-line entry fields may not specify a variable"
            entry, garbage = tktools.make_text_box(frame,
                                                   width=entry_width,
                                                   height=entry_height,
                                                   vbar=1)
            def getter(entry=entry):
                return entry.get('1.0', entry.index("end-1char"))
            def setter(chars, entry=entry):
                entry.delete('1.0', entry.index(END))
                entry.insert('1.0', chars)

        frame.pack(fill=use_fill, side=use_side, expand=use_expand)
        parent.pack(fill=use_fill, side=use_side)
        # Couple the entry with the pref:
        self.RegisterUI(group, component, typename, getter, setter)
        return frame
Пример #4
0
    def PrefsEntry(self, parent, label, group, component,
                   typename='string',
                   label_width=25, entry_height=1, entry_width=None,
                   composite=0, variable=None):
        """Convenience for creating preferences entry or text widget.

        A frame is built within the specified parent, and packed with a
        specified label and an entry widget, created for the purpose.  The
        value of the entry widget is coupled with the designated
        preference.

        The label is apportioned a specified number of characters, default
        25, on the left side of the frame, to enable lining up nicely with
        other, similarly constructed widgets.

        The entry widget may optionally have a height greater than 1, in
        which case a text widget of that height is used."""

        if not composite:
            use_expand = 1
            use_fill = X
            use_side = TOP
            if not entry_width:
                entry_width = 40
        else:
            use_expand = 0
            use_fill = NONE
            use_side = LEFT
        # Assemble the widget:
        frame = Frame(parent, borderwidth=1)
        self.PrefsWidgetLabel(frame, label, label_width=label_width)
        if entry_height == 1:
            entry = Entry(frame, relief=SUNKEN, border=1, width=entry_width,
                          textvariable=(variable and variable or None))
            # note that the variable setting is stripped if None, so this is ok
            entry.pack(side=use_side, expand=use_expand, fill=use_fill)
            if not variable:
                getter, setter = entry.get, self.widget_set_func(entry)
            else:
                getter, setter = variable.get, variable.set
        else:
            if variable:
                raise ValueError, \
                      "multi-line entry fields may not specify a variable"
            entry, garbage = tktools.make_text_box(frame,
                                                   width=entry_width,
                                                   height=entry_height,
                                                   vbar=1)
            def getter(entry=entry):
                return entry.get('1.0', entry.index("end-1char"))
            def setter(chars, entry=entry):
                entry.delete('1.0', entry.index(END))
                entry.insert('1.0', chars)

        frame.pack(fill=use_fill, side=use_side, expand=use_expand)
        parent.pack(fill=use_fill, side=use_side)
        # Couple the entry with the pref:
        self.RegisterUI(group, component, typename, getter, setter)
        return frame
Пример #5
0
 def add_text_field(self, label, value, name):
     """Add a text field; return true if it can be stretched vertically."""
     fr = self.add_field(label, name)
     if value and value[-1] != "\n":
         value = value + "\n"
     maxlines = 1 + map(None, value).count("\n")
     text, frame = tktools.make_text_box(
         fr, takefocus=0, width=60, vbar=1,
         height=min(MAX_TEXT_FIELD_LINES, maxlines))
     frame.pack(side=Tkinter.LEFT, expand=1, fill=Tkinter.BOTH)
     fr.pack(expand=1, fill=Tkinter.BOTH)
     text.insert(Tkinter.END, value)
     text["state"] = Tkinter.DISABLED
     return maxlines > MAX_TEXT_FIELD_LINES
Пример #6
0
 def add_text_field(self, label, value, name):
     """Add a text field; return true if it can be stretched vertically."""
     fr = self.add_field(label, name)
     if value and value[-1] != "\n":
         value = value + "\n"
     maxlines = 1 + map(None, value).count("\n")
     text, frame = tktools.make_text_box(fr,
                                         takefocus=0,
                                         width=60,
                                         vbar=1,
                                         height=min(MAX_TEXT_FIELD_LINES,
                                                    maxlines))
     frame.pack(side=Tkinter.LEFT, expand=1, fill=Tkinter.BOTH)
     fr.pack(expand=1, fill=Tkinter.BOTH)
     text.insert(Tkinter.END, value)
     text["state"] = Tkinter.DISABLED
     return maxlines > MAX_TEXT_FIELD_LINES
Пример #7
0
    def CreateLayout(self, name, frame):
        # Create GUI elements in order of preference (the ones created
        # last disappear first when there's not enough space)

        self.loadvar = StringVar(frame)

        self.loadnone = Radiobutton(frame,
                                    text="Load no applets",
                                    variable=self.loadvar,
                                    value="none")
        self.loadnone.pack(anchor=W, side=BOTTOM)

        self.loadsome = Radiobutton(
            frame,
            text="Load applets in indicated groups only",
            variable=self.loadvar,
            value="some")
        self.loadsome.pack(anchor=W, side=BOTTOM)

        self.loadall = Radiobutton(frame,
                                   text="Load all applets",
                                   variable=self.loadvar,
                                   value="all")
        self.loadall.pack(anchor=W, side=BOTTOM)

        self.label = Label(frame, text=LABEL, anchor=W)
        self.label.pack(fill=X)

        self.textbox, self.textframe = tktools.make_text_box(frame,
                                                             width=40,
                                                             height=10)
        self.textbox.bind('<Return>', self.return_in_textbox)

        self.RegisterUI("applets", "groups", "string", self.getgroups,
                        self.setgroups)
        self.RegisterUI("applets", "load", "string", self.loadvar.get,
                        self.loadvar.set)
Пример #8
0
    def CreateLayout(self, name, frame):
        # Create GUI elements in order of preference (the ones created
        # last disappear first when there's not enough space)

        self.loadvar = StringVar(frame)

        self.loadnone = Radiobutton(frame,
                                    text="Load no applets",
                                    variable=self.loadvar,
                                    value="none")
        self.loadnone.pack(anchor=W, side=BOTTOM)

        self.loadsome = Radiobutton(
            frame,
            text="Load applets in indicated groups only",
            variable=self.loadvar,
            value="some")
        self.loadsome.pack(anchor=W, side=BOTTOM)

        self.loadall = Radiobutton(frame,
                                   text="Load all applets",
                                   variable=self.loadvar,
                                   value="all")
        self.loadall.pack(anchor=W, side=BOTTOM)

        self.label = Label(frame, text=LABEL, anchor=W)
        self.label.pack(fill=X)

        self.textbox, self.textframe = tktools.make_text_box(frame,
                                                             width=40,
                                                             height=10)
        self.textbox.bind('<Return>', self.return_in_textbox)

        self.RegisterUI("applets", "groups", "string",
                        self.getgroups, self.setgroups)
        self.RegisterUI("applets", "load", "string",
                        self.loadvar.get, self.loadvar.set)
Пример #9
0
 def __init__(self, mp, name):
     self.mp = mp
     self.name = name
     self.panel = mp.addpanel(name)
     self.text, self.frame = tktools.make_text_box(self.panel, height=10)
     self.text.config(wrap=NONE)
Пример #10
0
 def __init__(self, mp, name):
     self.mp = mp
     self.name = name
     self.panel = mp.addpanel(name)
     self.text, self.frame = tktools.make_text_box(self.panel, height=10)
     self.text.config(wrap=NONE)
Пример #11
0
 def __init__(self, master, address, data):
     # query semantics may be used to identify header field values
     scheme, netloc, path, params, query, fragment = urlparse(address)
     address = urlunparse((scheme, netloc, path, '', '', ''))
     headers = cgi.parse_qs(query)
     # create widgets
     self.master = master
     self.root = tktools.make_toplevel(self.master,
                                       title="Mail Dialog")
     self.root.protocol("WM_DELETE_WINDOW", self.cancel_command)
     self.root.bind("<Alt-w>", self.cancel_command)
     self.root.bind("<Alt-W>", self.cancel_command)
     fr, top, botframe = tktools.make_double_frame(self.root)
     self.text, fr = tktools.make_text_box(top, 80, 24)
     self.text.tag_config('SUSPICIOUS_HEADER', foreground='red')
     self.send_button = Button(botframe,
                               text="Send",
                               command=self.send_command)
     self.send_button.pack(side=LEFT)
     self.cancel_button = Button(botframe,
                                 text="Cancel",
                                 command=self.cancel_command)
     self.cancel_button.pack(side=RIGHT)
     tktools.unify_button_widths(self.send_button, self.cancel_button)
     hinfo = _make_sequence_dict(COMMON_HEADERS)
     variables = {
         'to':       address,
         'subject':  data and 'Form posted from Grail' or '',
         'mime-version': '1.0',
         'x-mailer': GRAILVERSION,
         'x-url':    LAST_CONTEXT and LAST_CONTEXT.get_baseurl() or ''
         }
     if data:
         variables["content-type"] = "application/x-www-form-urlencoded"
     else:
         variables["content-type"] = "text/plain; charset=us-ascii"
         variables["content-transfer-encoding"] = "7bit"
     # move default set of query'd headers into variables
     for header, vlist in headers.items():
         header = string.lower(header)
         if header != 'body':
             if header not in DISALLOWED_HEADERS:
                 variables[header] = vlist[0]        # toss duplicates
                 if not hinfo.has_key(header):
                     hinfo[header] = 15
             del headers[header]
     # insert user-specified extra headers
     variables = self.add_user_headers(variables)
     for header in variables.keys():
         if not hinfo.has_key(header):
             hinfo[header] = 19
     # write the headers into the buffer
     variables['date'] = time.ctime(time.time())
     hseq = _make_dict_sequence(hinfo)
     for x, header in hseq:
         if variables.has_key(header):
             s = "%s: %s\n" \
                 % (string.capwords(header, '-'), variables[header])
             self.text.insert(END, s)
     # insert newline
     self.text.insert(END, '\n', ())
     # insert data
     if data:
         self.text.insert(END, data)
     elif headers.has_key('body'):
         self.text.insert(END, headers['body'][0] + '\n')
     else:
         self.add_user_signature()
     self.text.focus_set()
Пример #12
0
#! /usr/bin/env python
Пример #13
0
#! /usr/bin/env python