def __init__(self, master, netloc, realmvalue):
        self.root = tktools.make_toplevel(master,
                                          title="Authentication Dialog")
        self.prompt = Label(self.root,
                            text="Enter user authentication\nfor %s on %s" %
                            (realmvalue, netloc))
        self.prompt.pack(side=TOP)
        self.user_entry, dummy = tktools.make_form_entry(self.root, "User:"******"Password:"******"*")
        self.passwd_entry.bind('<Return>', self.ok_command)
        self.ok_button = Button(self.root, text="OK", command=self.ok_command)
        self.ok_button.pack(side=LEFT)
        self.cancel_button = Button(self.root, text="Cancel",
                                    command=self.cancel_command)
        self.cancel_button.pack(side=RIGHT)

        self.user_passwd = None

        tktools.set_transient(self.root, master)

        self.root.grab_set()
Example #2
0
 def __init__(self, context, url, title, infp):
     self.__context = context
     self.__url = url
     self.__title = title
     self.__infp = infp
     top = self.__top = tktools.make_toplevel(context.browser.root)
     top.title("Print Action")
     fr, topfr, botfr = tktools.make_double_frame(top)
     Label(topfr, bitmap="warning", foreground='red').pack(side=LEFT,
                                                           fill=Y,
                                                           padx='2m')
     # font used by the Tk4 dialog.tcl script:
     font = "-Adobe-Times-Medium-R-Normal--*-180-*-*-*-*-*-*"
     try:
         label = Label(topfr,
                       text=self.UNKNOWN_TYPE_MESSAGE,
                       font=font,
                       justify=LEFT)
     except TclError:
         # font not found, use one we are sure exists:
         font = context.browser.viewer.text.tag_cget('h2_b', '-font')
         label = Label(topfr,
                       text=self.UNKNOWN_TYPE_MESSAGE,
                       font=font,
                       justify=LEFT)
     label.pack(side=RIGHT, fill=BOTH, expand=1, padx='1m')
     b1 = Button(botfr, text="Cancel", command=self.skipit)
     b1.pack(side=RIGHT)
     b2 = Button(botfr, text="Print", command=self.doit)
     b2.pack(side=LEFT)
     tktools.unify_button_widths(b1, b2)
     tktools.set_transient(top, context.browser.root)
 def __init__(self, old_context, filename, reader, restart=1):
     url = old_context.get_url()
     headers = old_context.get_headers()
     self.app = old_context.browser.app
     self.root = tktools.make_toplevel(
         old_context.browser.master, class_="GrailTransfer")
     self.root.protocol("WM_DELETE_WINDOW", self.stop)
     import Context
     self.context = Context.SimpleContext(self, self)
     self.context._url = self.context._baseurl = url
     reader.last_context = self.context
     self.__filename = filename
     self.__reader = reader
     self.__save_file = reader.save_file
     reader.save_file = self
     if filename:
         self.root.title("Grail: Downloading "
                        + os.path.basename(filename))
     else:
         self.root.title("Grail Download")
     self.root.iconname("Download")
     #
     self.content_length = None
     if headers.has_key('content-length'):
         self.content_length = int(headers['content-length'])
     self.create_widgets(url, filename, self.content_length)
     #
     if restart:
         reader.restart(reader.url)
     reader.bufsize = 8096
     tktools.set_transient(self.root, old_context.browser.master)
     history = old_context.app.global_history
     if not history.inhistory_p(url):
         history.remember_url(url)
     self.root.update_idletasks()
Example #4
0
    def create_widget(self):
        widget = self.widget = tktools.make_toplevel(
            self.frame, class_='Preferences')
        widget.title(self.title)
        widget.iconname("Grail Prefs")
        tktools.install_keybindings(widget)
        widget.bind('<Return>', self.done_cmd)
        widget.bind('<Key>', self.poll_modified)
        widget.bind("<Alt-w>", self.cancel_cmd)
        widget.bind("<Alt-W>", self.cancel_cmd)
        widget.bind("<Alt-Control-r>", self.reload_panel_cmd)
        widget.bind("<Alt-Control-d>", self.toggle_debugging)
        widget.bind('<ButtonPress>', self.poll_modified) # same as <Button>
        widget.bind('<ButtonRelease>', self.poll_modified)
        widget.protocol('WM_DELETE_WINDOW', self.cancel_cmd)

        width=80                        # Of the settings frame.

        fr, container, self.dispose_bar = tktools.make_double_frame(widget)

        # Do this before the panel container, so the buttons are squoze last:
        self.create_disposition_bar(self.dispose_bar)

        # Frame for the user to build within:
        self.framework_widget = container
        container.pack(side=TOP, fill=BOTH, expand=1, padx='2m', pady='2m') 

        # Do the user's setup:
        self.CreateLayout(self.name, container)

        # And now initialize the widget values:
        self.set_widgets()

        if self.app.prefs.GetBoolean('preferences', 'panel-debugging'):
            self.toggle_debugging(enable=1)
 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
Example #6
0
 def __init__(self, rootwin, searchable):
     self._searchable = searchable
     from utils import tktools
     self._root = tktools.make_toplevel(rootwin,
                                        title="Search Dialog",
                                        class_="Search")
     self.create_widgets()
     tktools.set_transient(self._root, rootwin, rely=0.0)
     self.__rootwin = rootwin
 def create_widgets(self):
     self.top = tktools.make_toplevel(self.app.root,
                                      title="Grail: I/O Status",
                                      class_="IOStatusPanel")
     self.closebutton = Button(self.top, name="close", command=self.close,
                               default="active")
     self.closebutton.pack(side=BOTTOM, pady='1m', padx='1m', anchor=E)
     self.closebutton.focus_set()
     self.infobox, self.frame = tktools.make_list_box(self.top, width=40)
     self.infobox.pack(expand=1, fill=BOTH, side=TOP)
     self.top.protocol('WM_DELETE_WINDOW', self.close)
     self.top.bind("<Alt-w>", self.close)
     self.top.bind("<Alt-W>", self.close)
Example #8
0
 def create_widgets(self, width, height, geometry):
     # I'd like to be able to set the widget name here, but I'm not
     # sure what the correct thing to do is.  Setting it to `grail'
     # is definitely *not* the right thing to do since this causes
     # all sorts of problems.
     self.root = tktools.make_toplevel(self.master, class_='Grail')
     self._window_title("Grail: New Browser")
     if geometry:
         self.root.geometry(geometry)
     self.root.protocol("WM_DELETE_WINDOW", self.on_delete)
     self.topframe = Frame(self.root)
     self.topframe.pack(fill=X)
     self.create_logo()
     self.create_menubar()
     self.create_urlbar()
     self.create_statusbar()
     self.viewer = Viewer(self.root,
                          browser=self,
                          width=width,
                          height=height)
     self.context = self.viewer.context
     if self.app.prefs.GetBoolean('browser', 'show-logo'):
         self.logo_init()
Example #9
0
 def __init__(self, master, title=None, new=1):
     # create widgets
     self.__frame = tktools.make_toplevel(
         master, title=title or "Open Location Dialog")
     #
     fr, top, btnframe = tktools.make_double_frame(
         self.__frame, relief=FLAT)
     #
     self.__entry, frame, label = tktools.make_labeled_form_entry(
         top, 'URI:', 40)
     self.__entry.insert(0, self.__lasturi)
     #
     okbtn = Button(btnframe, text='Open', command=self.okaycmd)
     newbtn = Button(btnframe, text='New', command=self.newcmd)
     clearbtn = Button(btnframe, text='Clear', command=self.clearcmd)
     cancelbtn = Button(btnframe, text='Cancel', command=self.cancelcmd)
     tktools.unify_button_widths(okbtn, newbtn, clearbtn, cancelbtn)
     #
     okbtn.pack(side=LEFT)
     if new:
         newbtn.pack(side=LEFT, padx='1m')
     cancelbtn.pack(side=RIGHT)
     clearbtn.pack(side=RIGHT, padx='1m')
     #
     tktools.set_transient(self.__frame, master)
     #
     self.__entry.bind('<Return>', self.okaycmd)
     self.__entry.bind('<Control-C>', self.cancelcmd)
     self.__entry.bind('<Control-c>', self.cancelcmd)
     if new:
         self.__frame.bind('<Alt-n>', self.newcmd)
         self.__frame.bind('<Alt-N>', self.newcmd)
     self.__frame.bind("<Alt-w>", self.cancelcmd)
     self.__frame.bind("<Alt-W>", self.cancelcmd)
     #
     self.__frame.protocol('WM_DELETE_WINDOW', self.cancelcmd)
 def __init__(self, master, context, class_="DocumentInfo"):
     root = tktools.make_toplevel(master,
                                  class_=class_,
                                  title="Document Info")
     self.root = root
     self.app = context.app
     page_title = context.page.title()
     if page_title:
         root.title("Document Info: " + page_title)
     destroy = self.destroy
     for seq in ("<Alt-W>", "<Alt-w>", "<Return>"):
         root.bind(destroy)
     root.protocol("WM_DELETE_WINDOW", destroy)
     frame, self.__topfr, botfr = tktools.make_double_frame(root)
     #
     # Info display
     #
     url = context.page.url()
     scheme, netloc, path, params, query, fragment = urlparse(url)
     url = urllib.urlunparse((scheme, netloc, path, '', '', ''))
     self.add_label_field("Title", page_title or "(unknown)", "title")
     self.add_label_field("URI", url, "uri")
     if fragment:
         self.add_label_field("Fragment", fragment, "fragment")
     headers = context.get_headers()
     if headers.has_key("date") and type(headers["date"]) is type(self):
         self.add_label_field("", "(Loaded from local cache.)", "cached")
     items = headers.items()
     items.sort()
     s = ""
     for k, v in items:
         if k == 'date' and type(v) is type(self):
             from . import ht_time
             v = ht_time.unparse(v.get_secs())
         s = "%s%s:\t%s\n" % (s, k, v)
     stretch = self.add_text_field("Response headers", s, "headers")
     if query:
         query = str.translate(query, FIELD_BREAKER)
         stretch = stretch or \
                   self.add_text_field("Query fields", query, "query")
     postdata = context.get_postdata()
     if postdata:
         postdata = str.translate(postdata, FIELD_BREAKER)
         stretch = stretch or \
                   self.add_text_field("POST fields", postdata, "postdata")
     #
     # Bottom button
     #
     fr = tkinter.Frame(botfr, borderwidth=1, relief=tkinter.SUNKEN)
     fr.pack()
     btn = tkinter.Button(fr, text="OK", command=destroy)
     # '2m' is the value from the standard Tk 'tk_dialog' command
     btn.pack(padx='2m', pady='2m')
     btn.focus_set()
     #
     del self.__topfr  # loose the reference
     tktools.set_transient(root, master)
     root.update_idletasks()
     reqwidth = root.winfo_reqwidth()
     reqheight = root.winfo_reqheight()
     root.minsize(reqwidth, reqheight)
     if not stretch:
         root.maxsize(reqwidth, reqheight)
Example #11
0
    def __init__(self, context, url, title, infp, ctype):
        from utils import tktools
        #
        self.infp = infp
        self.ctype = ctype
        self.context = context
        self.baseurl = context.get_baseurl()
        self.prefs = context.app.prefs
        self.settings = printing.settings.get_settings(context.app.prefs)
        if USER_DATA_DIR not in self.settings.user_data_dirs:
            self.settings.user_data_dirs.append(USER_DATA_DIR)
        settings = self.settings
        #
        self.title = title
        self.master = self.context.root
        self.root = tktools.make_toplevel(self.master,
                                          title="Print Dialog",
                                          class_="PrintDialog")
        # do this early in case we're debugging:
        self.root.protocol('WM_DELETE_WINDOW', self.cancel_command)
        self.root.bind("<Alt-w>", self.cancel_event)
        self.root.bind("<Alt-W>", self.cancel_event)
        self.cursor_widgets = [self.root]

        fr, top, botframe = tktools.make_double_frame(self.root)

        #  Print to file controls:
        generalfr = tktools.make_group_frame(top,
                                             "general",
                                             "General options:",
                                             fill=X)

        self.cmd_entry, dummyframe = tktools.make_form_entry(
            generalfr, "Print command:")
        self.cmd_entry.insert(END, settings.printcmd)
        self.add_entry(self.cmd_entry)
        self.printtofile = IntVar(self.root)
        self.printtofile.set(settings.fileflag)
        fr = Frame(generalfr)
        fr.pack(fill=X)
        self.file_check = Checkbutton(fr,
                                      text="Print to file:",
                                      command=self.check_command,
                                      variable=self.printtofile)
        self.file_check.pack(side=LEFT)
        self.file_entry = Entry(fr)
        self.file_entry.pack(side=RIGHT, fill=X)
        self.file_entry.insert(END, settings.printfile)
        self.add_entry(self.file_entry)

        if self.ctype != "application/postscript":
            # page orientation
            Frame(generalfr, height=2).pack()
            fr = Frame(generalfr)
            fr.pack(fill=X)
            self.orientation = StringVar(top)
            self.orientation.set(str.capitalize(settings.orientation))
            opts = printing.paper.paper_rotations.keys()
            opts.sort()
            opts = tuple(map(str.capitalize, opts))
            Label(fr, text="Orientation: ", width=13, anchor=E).pack(side=LEFT)
            Frame(fr, width=3).pack(side=LEFT)
            menu = OptionMenu(fr, self.orientation) + opts
            width = reduce(max, map(len, opts), 6)
            menu.config(anchor=W, highlightthickness=0, width=width)
            menu.pack(expand=1, fill=NONE, anchor=W, side=LEFT)
            Frame(generalfr, height=2).pack()
            # font size
            fr = Frame(generalfr)
            fr.pack(fill=X)
            Label(fr, text="Font size: ", width=13, anchor=E).pack(side=LEFT)
            Frame(fr, width=3).pack(side=LEFT)
            e = self.fontsize = Entry(fr, width=12)
            e.insert(END, settings.get_fontspec())
            e.pack(side=LEFT)
            self.add_entry(e)

        self.mod = self.get_type_extension()
        if self.mod.add_options:
            Frame(top, height=8).pack()
            self.mod.add_options(self, settings, top)

        #  Command buttons:
        ok_button = Button(botframe, text="OK", command=self.ok_command)
        ok_button.pack(side=LEFT)
        cancel_button = Button(botframe,
                               text="Cancel",
                               command=self.cancel_command)
        cancel_button.pack(side=RIGHT)
        tktools.unify_button_widths(ok_button, cancel_button)

        tktools.set_transient(self.root, self.master)
        self.check_command()
Example #12
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()
 def __init__(self, context, historyobj=None):
     if not historyobj:
         # XXX I guess this is here for testing?  (It's used nowhere.)
         self._history = History()
     else:
         self._history = historyobj
     #
     self._context = context
     self._history.set_dialog(self)
     self._frame = tktools.make_toplevel(self._context.viewer.frame,
                                         class_="History",
                                         title="History Dialog")
     self._frame.protocol("WM_DELETE_WINDOW", self._close)
     # get preferences
     self._viewby = StringVar(self._frame)
     self._prefs = prefs = get_grailapp().prefs
     prefs.AddGroupCallback(HISTORY_PREFGROUP, self._notify)
     try:
         viewby = prefs.Get(HISTORY_PREFGROUP, VIEW_BY_PREF)
         if viewby not in [VIEW_BY_TITLES, VIEW_BY_URLS]:
             raise TypeError
     except (KeyError, TypeError):
         viewby = VIEW_BY_TITLES
     self._viewby.set(viewby)
     # add a couple of buttons
     btnbar = Frame(self._frame)
     btnbar.pack(fill=BOTH, side=BOTTOM)
     gotobtn = Button(self._frame, name='goto', command=self._goto)
     gotobtn.pack(side=LEFT, padx='1m', pady='1m', in_=btnbar)
     closebtn = Button(self._frame, name='close', command=self._close)
     closebtn.pack(side=LEFT, in_=btnbar)
     tktools.unify_button_widths(gotobtn, closebtn)
     # radio button for view option
     rbframe = Frame(btnbar)
     rbframe.pack()
     rb1 = Radiobutton(self._frame,
                       name='titles',
                       command=self._viewby_command,
                       variable=self._viewby,
                       value=VIEW_BY_TITLES)
     rb2 = Radiobutton(self._frame,
                       name='uris',
                       command=self._viewby_command,
                       variable=self._viewby,
                       value=VIEW_BY_URLS)
     rb1.pack(anchor='w', in_=rbframe)
     rb2.pack(anchor='w', in_=rbframe)
     # create listbox
     self._listbox, frame = tktools.make_list_box(self._frame,
                                                  40,
                                                  24,
                                                  1,
                                                  1,
                                                  name="list")
     self.refresh()
     self._listbox.config(takefocus=0, exportselection=0)
     self._listbox.bind('<Double-Button-1>', self._goto)
     self._listbox.bind('<Double-Button-2>', self._goto_new)
     self._listbox.bind('<ButtonPress-2>', self._highlight)
     # Yes, yes, the mapping seems inverted, but it has to do with
     # the way history elements are displayed in reverse order in
     # the listbox.  These mappings mirror those used in the Bookmarks
     # dialog.
     self._frame.bind("<Right>", self.next_cmd)
     self._frame.bind("<Alt-Right>", self.next_cmd)
     self._frame.bind("<Left>", self.previous_cmd)
     self._frame.bind("<Alt-Left>", self.previous_cmd)
     self._frame.bind("<Up>", self.up_cmd)
     self._frame.bind("p", self.up_cmd)
     self._frame.bind("P", self.up_cmd)
     self._frame.bind("<Down>", self.down_cmd)
     self._frame.bind("n", self.down_cmd)
     self._frame.bind("N", self.down_cmd)
     self._frame.bind("g", self._goto)
     self._frame.bind("G", self._goto)
     self._frame.bind("<Return>", self._goto)
     self._frame.bind('<Alt-W>', self._close)
     self._frame.bind('<Alt-w>', self._close)
     tktools.set_transient(self._frame, self._context.root)