Пример #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 = str.join(map(str.rstrip, lines), '\n')
     self.text.insert(END, tb)
     self.text.yview_pickplace(END)
     self.text["state"] = DISABLED
Пример #2
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
Пример #3
0
 def create_widgets(self, width, height):
     bars = self.scrolling == "auto" or self.scrolling
     self.smoothscroll = bars and self.context.app.prefs.GetBoolean(
         "browser", "smooth-scroll-hack")
     if self.smoothscroll:
         from utils.supertextbox import make_super_text_box
         self.text, self.frame = make_super_text_box(self.master,
                                                     width=width,
                                                     height=height,
                                                     hbar=bars,
                                                     vbar=bars)
     else:
         self.text, self.frame = tktools.make_text_box(self.master,
                                                       width=width,
                                                       height=height,
                                                       hbar=bars,
                                                       vbar=bars,
                                                       class_="Viewer")
     if self.parent:
         self.text.config(background=self.parent.text['background'],
                          foreground=self.parent.text['foreground'])
     self.text.config(padx=10,
                      cursor=self.current_cursor,
                      selectbackground='yellow',
                      insertwidth=0)
     self.default_bg = self.text['background']
     self.default_fg = self.text['foreground']
     self.configure_styles()
     if self.parent:
         link = self.parent.text.tag_configure('a', 'foreground')[-1]
         vlink = self.parent.text.tag_configure('ahist', 'foreground')[-1]
         alink = self.parent.text.tag_configure('atemp', 'foreground')[-1]
         hover_fg = self.parent.text.tag_configure('hover',
                                                   'foreground')[-1]
         hover_un = self.parent.text.tag_configure('hover', 'underline')[-1]
         self.text.tag_configure('a', foreground=link)
         self.text.tag_configure('ahist', foreground=vlink)
         self.text.tag_configure('atemp', foreground=alink)
         self.text.tag_configure('hover',
                                 foreground=hover_fg,
                                 underline=hover_un)
     self.configure_tags_fixed()
     if self.context.viewer is self:
         self.text.config(takefocus=1)
     self.text.bind("<Tab>", self.tab_event)
     self.text.bind("<Shift-Tab>", self.shift_tab_event)
     self.text.bind("<Button-1>", self.button_1_event)
     self.text.bind("<Button-2>", self.button_2_event)
     self.text.bind("<Button-3>", self.button_3_event)
     self.frame.bind("<Button-3>", self.button_3_event)
Пример #4
0
 def done(self):
     data = self.parser.save_end()
     self.parser.pop_nofill()
     if data[:1] == '\n': data = data[1:]
     if data[-1:] == '\n': data = data[:-1]
     self.w, self.frame = tktools.make_text_box(self.viewer.text,
                                                width=self.cols,
                                                height=self.rows,
                                                hbar=1,
                                                vbar=1,
                                                pack=0)
     self.w['wrap'] = NONE
     self.data = data
     self.reset()
     self.fi.inputs.append(self)
     self.parser.add_subwindow(self.frame)
 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
    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)
Пример #7
0
 def __init__(self, master, address, data):
     # query semantics may be used to identify header field values
     scheme, netloc, path, params, query, fragment = urllib(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 = str.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" \
                 % (str.title(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()