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, 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 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 create_widgets(self): import tktools x, f, self.bot_frame = tktools.make_double_frame(self._root) self.pat_entry, self.pat_frame = tktools.make_form_entry(f, None, name="entry") self.pat_entry["exportselection"] = 0 self.pat_entry.bind("<Return>", self.return_event) self.pat_entry.focus_set() self.mid_frame = Frame(f) self.mid_frame.pack(fill=X) self.regexp_var = BooleanVar(f) self.case_var = BooleanVar(f) self.backwards_var = BooleanVar(f) self.regexp_checkbutton = Checkbutton(self._root, name="regexp", variable=self.regexp_var) self.regexp_checkbutton.pack(side=LEFT, in_=self.mid_frame) self.case_checkbutton = Checkbutton(self._root, name="casesens", variable=self.case_var) self.case_checkbutton.pack(side=LEFT, expand=1, in_=self.mid_frame) self.backwards_checkbutton = Checkbutton(self._root, name="backwards", variable=self.backwards_var) self.backwards_checkbutton.pack(side=RIGHT, in_=self.mid_frame) # buttons along the bottom self.search_button = Button(self._root, name="search", width=12, command=self.search_command) self.search_button.pack(side=LEFT, in_=self.bot_frame) self.search_close_button = Button(self._root, name="searchclose", command=self.search_close_command) self.search_close_button.pack(side=LEFT, expand=1, padx="1m", in_=self.bot_frame) # Center self.close_button = Button(self._root, name="close", width=12, command=self.close_command) self.close_button.pack(side=RIGHT, in_=self.bot_frame) self._root.protocol("WM_DELETE_WINDOW", self.close_command) self._root.bind("<Alt-w>", self.close_event) self._root.bind("<Alt-W>", self.close_event)
def create_widgets(self): import tktools x, f, self.bot_frame = tktools.make_double_frame(self._root) self.pat_entry, self.pat_frame = \ tktools.make_form_entry(f, None, name="entry") self.pat_entry['exportselection'] = 0 self.pat_entry.bind('<Return>', self.return_event) self.pat_entry.focus_set() self.mid_frame = Frame(f) self.mid_frame.pack(fill=X) self.regexp_var = BooleanVar(f) self.case_var = BooleanVar(f) self.backwards_var = BooleanVar(f) self.regexp_checkbutton = Checkbutton(self._root, name="regexp", variable=self.regexp_var) self.regexp_checkbutton.pack(side=LEFT, in_=self.mid_frame) self.case_checkbutton = Checkbutton(self._root, name="casesens", variable=self.case_var) self.case_checkbutton.pack(side=LEFT, expand=1, in_=self.mid_frame) self.backwards_checkbutton = Checkbutton(self._root, name="backwards", variable=self.backwards_var) self.backwards_checkbutton.pack(side=RIGHT, in_=self.mid_frame) # buttons along the bottom self.search_button = Button(self._root, name="search", width=12, command=self.search_command) self.search_button.pack(side=LEFT, in_=self.bot_frame) self.search_close_button = Button(self._root, name="searchclose", command=self.search_close_command) self.search_close_button.pack(side=LEFT, expand=1, padx='1m', in_=self.bot_frame) # Center self.close_button = Button(self._root, name="close", width=12, command=self.close_command) self.close_button.pack(side=RIGHT, in_=self.bot_frame) self._root.protocol('WM_DELETE_WINDOW', self.close_command) self._root.bind("<Alt-w>", self.close_event) self._root.bind("<Alt-W>", self.close_event)
def create_widgets(self, url, filename, content_length): """Create the widgets in the Toplevel instance.""" fr, topfr, botfr = tktools.make_double_frame(self.root) Label(topfr, text="Downloading %s" % os.path.basename(filename) ).pack(anchor=W, pady='1m') Frame(topfr, borderwidth=1, height=2, relief=SUNKEN ).pack(fill=X, pady='1m') self.make_labeled_field(topfr, "Source:", url)['width'] = 45 self.make_labeled_field(topfr, "Destination:", filename) Button(botfr, command=self.stop, text="Stop").pack() if content_length: self.make_progress_bar(content_length, topfr) frame = Frame(topfr) frame.pack(fill=X) self.__bytes = self.make_labeled_field(frame, "Bytes:", "0", LEFT) if content_length: self.__bytes['width'] = len(`content_length`) + 2 self.__percent = self.make_labeled_field( frame, "Complete:", self.__bytespat % 0.0, LEFT) else: self.__percent = None
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, 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.urlparse(url) url = urlparse.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): 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 = string.translate(query, FIELD_BREAKER) stretch = stretch or \ self.add_text_field("Query fields", query, "query") postdata = context.get_postdata() if postdata: postdata = string.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)
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()
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.urlparse(url) url = urlparse.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): 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 = string.translate(query, FIELD_BREAKER) stretch = stretch or \ self.add_text_field("Query fields", query, "query") postdata = context.get_postdata() if postdata: postdata = string.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 # lose 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)
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()