Ejemplo n.º 1
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)
Ejemplo n.º 2
0
    def create_disposition_bar(self, bar):
        bartop = Frame(bar)
        bartop.pack()
        Frame(bar, height='1m').pack()
        barbottom = Frame(bar)
        barbottom.pack()
        self.debug_bar = Frame(bar, relief=SUNKEN)

        done_btn = Button(bartop, text="OK", command=self.done_cmd)
        help_btn = Button(barbottom, text="Help", command=self.help_cmd)
        cancel_btn = Button(bartop, text="Cancel", command=self.cancel_cmd)
        self.apply_btn = Button(barbottom,
                                text="Apply",
                                command=self.apply_cmd)
        self.revert_btn = Button(barbottom,
                                 text="Revert",
                                 command=self.revert_cmd)
        self.factory_defaults_btn = Button(barbottom,
                                           command=self.factory_defaults_cmd,
                                           text="Defaults")
        tktools.unify_button_widths(done_btn, help_btn, cancel_btn,
                                    self.apply_btn, self.revert_btn,
                                    self.factory_defaults_btn)
        done_btn.pack(side=LEFT)
        # Can't just use anchor=CENTER to get help button centered - it'll
        # go to the TOP, above OK and Cancel buttons.  Expanding without
        # filling does what we want.
        self.apply_btn.pack(side=LEFT)
        Frame(barbottom).pack(side=LEFT, expand=1)
        help_btn.pack(side=LEFT)
        Frame(barbottom).pack(side=LEFT, expand=1)
        self.factory_defaults_btn.pack(side=LEFT)
        Frame(barbottom).pack(side=LEFT, expand=1)
        cancel_btn.pack(side=RIGHT)
        self.revert_btn.pack(side=RIGHT)

        bartop.pack(fill=BOTH)
        barbottom.pack(fill=BOTH)
        bar.pack(fill=BOTH, side=BOTTOM)

        reload_panel_btn = Button(self.debug_bar,
                                  text="Reload Panel",
                                  command=self.reload_panel_cmd)
        reload_preferences_btn = Button(self.debug_bar,
                                        text="Reload Preferences",
                                        command=self.reload_preferences_cmd)
        reload_panel_btn.pack(side=LEFT, expand=1)
        reload_preferences_btn.pack(side=RIGHT, expand=1)
        self.debugging = 0
Ejemplo n.º 3
0
    def create_disposition_bar(self, bar):
        bartop = Frame(bar)
        bartop.pack()
        Frame(bar, height='1m').pack()
        barbottom = Frame(bar)
        barbottom.pack()
        self.debug_bar = Frame(bar, relief=SUNKEN)

        done_btn = Button(bartop, text="OK", command=self.done_cmd)
        help_btn = Button(barbottom, text="Help",
                          command=self.help_cmd)
        cancel_btn = Button(bartop, text="Cancel",
                            command=self.cancel_cmd)
        self.apply_btn = Button(barbottom, text="Apply",
                                command=self.apply_cmd)
        self.revert_btn = Button(barbottom, text="Revert",
                                 command=self.revert_cmd)
        self.factory_defaults_btn = Button(barbottom,
                                           command=self.factory_defaults_cmd,
                                           text="Defaults")
        tktools.unify_button_widths(done_btn, help_btn, cancel_btn,
                                    self.apply_btn, self.revert_btn,
                                    self.factory_defaults_btn)
        done_btn.pack(side=LEFT)
        # Can't just use anchor=CENTER to get help button centered - it'll
        # go to the TOP, above OK and Cancel buttons.  Expanding without
        # filling does what we want.
        self.apply_btn.pack(side=LEFT)
        Frame(barbottom).pack(side=LEFT, expand=1)
        help_btn.pack(side=LEFT)
        Frame(barbottom).pack(side=LEFT, expand=1)
        self.factory_defaults_btn.pack(side=LEFT)
        Frame(barbottom).pack(side=LEFT, expand=1)
        cancel_btn.pack(side=RIGHT)
        self.revert_btn.pack(side=RIGHT)

        bartop.pack(fill=BOTH)
        barbottom.pack(fill=BOTH)
        bar.pack(fill=BOTH, side=BOTTOM)

        reload_panel_btn = Button(self.debug_bar, text="Reload Panel",
                                  command=self.reload_panel_cmd)
        reload_preferences_btn = Button(self.debug_bar,
                                        text="Reload Preferences",
                                        command=self.reload_preferences_cmd)
        reload_panel_btn.pack(side=LEFT, expand=1)
        reload_preferences_btn.pack(side=RIGHT, expand=1)
        self.debugging = 0
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
    def __init__(self, context, url, title, infp, ctype):
        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(string.capitalize(settings.orientation))
            opts = printing.paper.paper_rotations.keys()
            opts.sort()
            opts = tuple(map(string.capitalize, opts))
            Label(fr, text="Orientation: ", width=13, anchor=E).pack(side=LEFT)
            Frame(fr, width=3).pack(side=LEFT)
            menu = apply(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()
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
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()