def syntaxerror(self): try: value, (filename, lineno, charno, line) = self.value except: filename = "" lineno = None value = self.value if not filename and self.lastwindowtitle: filename = self.lastwindowtitle elif not filename: filename = "<unknown>" if filename and os.path.exists(filename): filename = os.path.split(filename)[1] if lineno and charno is not None: charno = charno - 1 text = str(value) + '\rFile: "' + str(filename) + '", line ' + str( lineno) + '\r\r' + line[:charno] + "\xa5" + line[charno:-1] else: text = str(value) + '\rFile: "' + str(filename) + '"' self.syntaxdialog = W.ModalDialog((360, 120), "Syntax Error") self.syntaxdialog.text = W.TextBox((10, 10, -10, -40), text) self.syntaxdialog.cancel = W.Button((-190, -32, 80, 16), "Cancel", self.syntaxclose) self.syntaxdialog.edit = W.Button((-100, -32, 80, 16), "Edit", self.syntaxedit) self.syntaxdialog.setdefaultbutton(self.syntaxdialog.edit) self.syntaxdialog.bind("cmd.", self.syntaxdialog.cancel.push) self.syntaxdialog.open()
def __init__(self): self.editmodules = [] self.modules = [] self.window = W.Window((210, 1000), "Module Browser", minsize=(210, 160), maxsize=(340, 20000)) self.window.openbutton = W.Button((10, 8, 90, 16), "Open", self.openbuttonhit) self.window.browsebutton = W.Button((110, 8, 90, 16), "Browse\xc9", self.browsebuttonhit) self.window.reloadbutton = W.Button((10, 32, 90, 16), "Reload", self.reloadbuttonhit) self.window.openotherbutton = W.Button( (110, 32, 90, 16), "Open other\xc9", self.openother) self.window.openbutton.enable(0) self.window.reloadbutton.enable(0) self.window.browsebutton.enable(0) self.window.setdefaultbutton(self.window.browsebutton) self.window.bind("cmdr", self.window.reloadbutton.push) self.window.bind("cmdb", self.window.browsebutton.push) self.window.bind("<activate>", self.activate) self.window.bind("<close>", self.close) self.window.list = W.List((-1, 56, 1, -14), [], self.listhit) self.window.open() self.checkbuttons()
def __init__(self, title_1, title_2, value1=1, value2=1, title='RoboFab'): import W self.check1 = value1 self.check2 = value2 self.w = W.ModalDialog((200, 100)) self.w.check1 = W.CheckBox((10, 10, -10, 16), title_1, value=value1) self.w.check2 = W.CheckBox((10, 35, -10, 16), title_2, value=value2) self.w.l = W.HorizontalLine((10, 60, -10, 1), 1) self.w.cancel = W.Button((10, 70, 85, 20), 'Cancel', self.cancel) self.w.ok = W.Button((105, 70, 85, 20), 'OK', self.ok) self.w.setdefaultbutton(self.w.ok) self.w.bind('cmd.', self.w.cancel.push) self.w.open()
def __init__(self, list, message='Make a selection'): import W self.list = list self.selected = None self.w = W.ModalDialog((200, 240)) self.w.message = W.TextBox((10, 10, -10, 30), message) self.w.list = W.List((10, 35, -10, -50), list) self.w.l = W.HorizontalLine((10, -40, -10, 1), 1) self.w.cancel = W.Button((10, -30, 87, -10), 'Cancel', self.cancel) self.w.ok = W.Button((102, -30, 88, -10), 'OK', self.ok) self.w.setdefaultbutton(self.w.ok) self.w.bind('cmd.', self.w.cancel.push) self.w.open()
def __init__(self): self.template = "%s, %d point" self.fontsettings, self.tabsettings, self.windowsize = geteditorprefs() self.w = W.Dialog((328, 120), "Editor default settings") self.w.setfontbutton = W.Button((8, 8, 80, 16), "Set font\xc9", self.dofont) self.w.fonttext = W.TextBox((98, 10, -8, 14), self.template % (self.fontsettings[0], self.fontsettings[2])) self.w.picksizebutton = W.Button((8, 50, 80, 16), "Front window", self.picksize) self.w.xsizelabel = W.TextBox((98, 32, 40, 14), "Width:") self.w.ysizelabel = W.TextBox((148, 32, 40, 14), "Height:") self.w.xsize = W.EditText((98, 48, 40, 20), repr(self.windowsize[0])) self.w.ysize = W.EditText((148, 48, 40, 20), repr(self.windowsize[1])) self.w.cancelbutton = W.Button((-180, -26, 80, 16), "Cancel", self.cancel) self.w.okbutton = W.Button((-90, -26, 80, 16), "Done", self.ok) self.w.setdefaultbutton(self.w.okbutton) self.w.bind('cmd.', self.w.cancelbutton.push) self.w.open()
def setupwidgets(self): DESCRIPTION_HEIGHT = 140 INSTALL_POS = -30 STATUS_POS = INSTALL_POS - (70 + DESCRIPTION_HEIGHT) self.w = W.Window((580, 600), "Python Install Manager", minsize=(400, 400), tabbable=0) self.w.titlebar = W.TextBox((4, 8, 60, 18), 'Packages:') self.w.hidden_button = W.CheckBox((-100, 4, 0, 18), 'Show Hidden', self.updatestatus) data = self.getbrowserdata() self.w.packagebrowser = W.MultiList((4, 24, 0, STATUS_POS - 2), data, self.listhit, cols=3) self.w.installed_l = W.TextBox((4, STATUS_POS, 70, 12), 'Installed:') self.w.installed = W.TextBox((74, STATUS_POS, 0, 12), '') self.w.message_l = W.TextBox((4, STATUS_POS + 20, 70, 12), 'Status:') self.w.message = W.TextBox((74, STATUS_POS + 20, 0, 12), '') self.w.homepage_button = W.Button((4, STATUS_POS + 40, 96, 18), 'View homepage', self.do_homepage) self.w.description_l = W.TextBox((4, STATUS_POS + 70, 70, 12), 'Description:') self.w.description = W.EditText( (74, STATUS_POS + 70, 0, DESCRIPTION_HEIGHT - 4)) self.w.divline = W.HorizontalLine((0, INSTALL_POS - 4, 0, 0)) self.w.verbose_button = W.CheckBox((84, INSTALL_POS + 4, 60, 18), 'Verbose') self.w.recursive_button = W.CheckBox((146, INSTALL_POS + 4, 120, 18), 'Install dependencies', self.updatestatus) self.w.recursive_button.set(1) self.w.force_button = W.CheckBox((268, INSTALL_POS + 4, 70, 18), 'Overwrite', self.updatestatus) self.w.user_button = W.CheckBox((340, INSTALL_POS + 4, 140, 18), 'For Current User Only', self.do_user) self.w.install_button = W.Button((4, INSTALL_POS + 4, 56, 18), 'Install:', self.do_install) self.w.open() self.w.description.enable(0)
def buildinterface(self): buttonwidth = 120 glyphlistwidth = 150 hmargin = 10 vmargin = 8 title = self.filename tables = self.ttFont.keys() tables.sort() self.w = w = W.Window((500, 300), title, minsize=(400, 200)) w.browsetablebutton = W.Button((hmargin, 32, buttonwidth, 16), "Browse tableŠ", self.browsetable) w.browsefontbutton = W.Button((hmargin, vmargin, buttonwidth, 16), "Browse fontŠ", self.browsefont) w.tablelist = W.List((hmargin, 56, buttonwidth, -128), tables, self.tablelisthit) w.divline1 = W.VerticalLine((buttonwidth + 2 * hmargin, vmargin, 1, -vmargin)) gleft = buttonwidth + 3 * hmargin + 1 hasGlyfTable = self.ttFont.has_key('glyf') glyphnames = self.ttFont.getGlyphNames2() # caselessly sorted glyph names if hasGlyfTable: w.glyphlist = GlyphList((gleft, 56, glyphlistwidth, -vmargin), glyphnames, self.glyphlisthit) w.divline2 = W.VerticalLine((buttonwidth + glyphlistwidth + 4 * hmargin + 2, vmargin, 1, -vmargin)) yMin = self.ttFont['head'].yMin yMax = self.ttFont['head'].yMax w.gviewer = GlyphViewer((buttonwidth + glyphlistwidth + 5 * hmargin + 3, vmargin, -hmargin, -vmargin), yMin, yMax) w.showpoints = W.CheckBox((gleft, vmargin, glyphlistwidth, 16), "Show points", self.w.gviewer.toggleshowpoints) w.showpoints.set(self.w.gviewer.showpoints) w.showlines = W.CheckBox((gleft, vmargin + 24, glyphlistwidth, 16), "Show lines", self.w.gviewer.toggleshowlines) w.showlines.set(self.w.gviewer.showlines) else: w.glyphlist = GlyphList((gleft, 56, glyphlistwidth, -vmargin), glyphnames) w.noGlyphTable = W.TextBox((gleft, vmargin, -20, 20), "no 'glyf' table found") w.setdefaultbutton(w.browsetablebutton) w.tocurrentfont = W.Button((hmargin, -120, buttonwidth, 16), "Copy to current font", self.copytocurrentfont) w.fromcurrentfont = W.Button((hmargin, -96, buttonwidth, 16), "Copy from current font", self.copyfromcurrentfont) w.saveflat = W.Button((hmargin, -72, buttonwidth, 16), "Save as flat fileŠ", self.saveflat) w.savesuitcasebutton = W.Button((hmargin, -48, buttonwidth, 16), "Save as suitcaseŠ", self.savesuitcase) w.savexmlbutton = W.Button((hmargin, -24, buttonwidth, 16), "Save as XMLŠ", self.saveXML) w.open() w.browsetablebutton.enable(0)
def setupwidgets(self): self.w = W.Window(self.bounds, self.title, minsize=(316, 168)) self.w.text = W.TextBox((10, 10, -10, 30)) self.w.tbtitle = W.TextBox((10, 40, -10, 10), "Traceback (innermost last):") self.w.list = W.TwoLineList((10, 60, -10, -40), callback=self.listhit) self.w.editbutton = W.Button((10, -30, 60, 16), "Edit", self.edit) self.w.editbutton.enable(0) self.w.browselocalsbutton = W.Button( (80, -30, 100, 16), "Browse locals\xc9", self.browselocals) self.w.browselocalsbutton.enable(0) self.w.postmortembutton = W.Button((190, -30, 100, 16), "Post mortem\xc9", self.postmortem) self.w.setdefaultbutton(self.w.editbutton) self.w.bind("cmdb", self.w.browselocalsbutton.push) self.w.bind("<close>", self.close) self.w.bind("<activate>", self.activate)
def __init__(self, creator, eoln): self.rv = None self.eoln = eoln self.w = w = W.ModalDialog((260, 160), 'Save options') radiobuttons = [] w.label = W.TextBox((8, 8, 80, 18), "File creator:") w.ide_radio = W.RadioButton((8, 22, 160, 18), "PythonIDE", radiobuttons, self.ide_hit) w.interp_radio = W.RadioButton((8, 42, 160, 18), "MacPython-OS9 Interpreter", radiobuttons, self.interp_hit) w.interpx_radio = W.RadioButton((8, 62, 160, 18), "PythonLauncher", radiobuttons, self.interpx_hit) w.other_radio = W.RadioButton((8, 82, 50, 18), "Other:", radiobuttons) w.other_creator = W.EditText((62, 82, 40, 20), creator, self.otherselect) w.none_radio = W.RadioButton((8, 102, 160, 18), "None", radiobuttons, self.none_hit) w.cancelbutton = W.Button((-180, -30, 80, 16), "Cancel", self.cancelbuttonhit) w.okbutton = W.Button((-90, -30, 80, 16), "Done", self.okbuttonhit) w.setdefaultbutton(w.okbutton) if creator == 'Pyth': w.interp_radio.set(1) elif creator == W._signature: w.ide_radio.set(1) elif creator == 'PytX': w.interpx_radio.set(1) elif creator == '\0\0\0\0': w.none_radio.set(1) else: w.other_radio.set(1) w.eolnlabel = W.TextBox((168, 8, 80, 18), "Newline style:") radiobuttons = [] w.unix_radio = W.RadioButton((168, 22, 80, 18), "Unix", radiobuttons, self.unix_hit) w.mac_radio = W.RadioButton((168, 42, 80, 18), "Macintosh", radiobuttons, self.mac_hit) w.win_radio = W.RadioButton((168, 62, 80, 18), "Windows", radiobuttons, self.win_hit) if self.eoln == '\n': w.unix_radio.set(1) elif self.eoln == '\r\n': w.win_radio.set(1) else: w.mac_radio.set(1) w.bind("cmd.", w.cancelbutton.push) w.open()
def __init__(self, fondlist): import W if not fondlist: raise ValueError, "expected at least one FOND entry" if len(fondlist) == 1: self.choice = 0 return fonds = [] for fond in fondlist: fonds.append(fond.name) self.w = W.ModalDialog((200, 200), "aaa") self.w.donebutton = W.Button((-70, -26, 60, 16), "Done", self.close) self.w.l = W.List((10, 10, -10, -36), fonds, self.listhit) self.w.setdefaultbutton(self.w.donebutton) self.w.l.setselection([0]) self.w.open()
def show(self): self.visible = 1 if self.w: self.w.wid.ShowWindow() self.w.wid.SelectWindow() self.w.find.edit.select(1) self.w.find.edit.selectall() return self.w = W.Dialog((420, 150), "Find") self.w.find = TitledEditText((10, 4, 300, 36), "Search for:") self.w.replace = TitledEditText((10, 100, 300, 36), "Replace with:") self.w.boxes = W.Group((10, 50, 300, 40)) self.w.boxes.casesens = W.CheckBox((0, 0, 100, 16), "Case sensitive") self.w.boxes.wholeword = W.CheckBox((0, 20, 100, 16), "Whole word") self.w.boxes.wrap = W.CheckBox((110, 0, 100, 16), "Wrap around") self.buttons = [ ("Find", "cmdf", self.find), ("Replace", "cmdr", self.replace), ("Replace all", None, self.replaceall), ("Don't find", "cmdd", self.dont), ("Cancel", "cmd.", self.cancel) ] for i in range(len(self.buttons)): bounds = -90, 22 + i * 24, 80, 16 title, shortcut, callback = self.buttons[i] self.w[title] = W.Button(bounds, title, callback) if shortcut: self.w.bind(shortcut, self.w[title].push) self.w.setdefaultbutton(self.w["Don't find"]) self.w.find.edit.bind("<key>", self.key) self.w.bind("<activate>", self.activate) self.w.bind("<close>", self.close) self.w.open() self.setparms() self.w.find.edit.select(1) self.w.find.edit.selectall() self.checkbuttons()
import W from Carbon.Controls import * w = W.Window((200, 200), "Test") w.c = W.Button((5, 5, 100, 50), "Test") w.open() print repr(w.c._control.GetControlData(0, 'dflt')) str = '\001' w.c._control.SetControlData(0, 'dflt', str)
"""Simple W demo -- shows how to make a window, and bind a function to a "key" event.""" import W # key callback function def tester(char, event): text = ` char ` + "\r" + ` ord(char) ` + "\r" + hex( ord(char)) + "\r" + oct(ord(char)) window.keys.set(text) # close callback def close(): window.close() # new window window = W.Dialog((180, 100), "Type a character") # make a frame (a simple rectangle) window.frame = W.Frame((5, 5, -5, -33)) # some labels, static text window.captions = W.TextBox((10, 9, 43, -36), "char:\rdecimal:\rhex:\roctal:") # another static text box window.keys = W.TextBox((60, 9, 40, -36)) # a button window.button = W.Button((-69, -24, 60, 16), "Done", close) # bind the callbacks window.bind("<key>", tester) window.bind("cmdw", window.button.push) # open the window window.open()
import W from Carbon import Windows w = W.ModalDialog((100, 100)) w.ed = W.EditText((10, 10, 80, 50)) w.ok = W.Button((10, 70, 80, 16), "Ok", w.close) w.setdefaultbutton(w.ok) w.open()
import W w = W.Window((600, 400), "Ha!", minsize=(240, 200)) w.panes = W.HorizontalPanes((8, 8, -8, -20), (0.6, 0.4)) w.panes.panes = W.VerticalPanes(None, (0.3, 0.4, 0.3)) w.panes.panes.blah1 = W.EditText(None, "eehhh...") w.panes.panes.blah2 = W.EditText(None, "nou...") w.panes.panes.blah3 = W.List(None, ["eehhh...", 'abc', 'def']) w.panes.group = W.Group(None) w.panes.group.mytext = W.EditText((0, 24, 0, 0), "eehhh...") w.panes.group.button1 = W.Button((0, 0, 80, 16), "A Button") w.open()
EasyDialogs.Message("Cancel!") # make a non-sizable window #window = W.Window((200, 300), "Fixed Size") # make a sizable window window = W.Window((200, 300), "Variable Size!", minsize=(200, 300)) # make some edit text widgets window.et1 = W.EditText((10, 10, 110, 110), "Hallo!", textcallback) window.et2 = W.EditText((130, 40, 60, 30), "one!") window.et3 = W.EditText((130, 80, -10, 40), "two?") # a button window.button = W.Button((-70, 10, 60, 16), "Close", callback) # a checkbox window.ch = W.CheckBox((10, 130, 160, 16), "Check (command \xa4)", checkcallback) # set of radio buttons (should become easier/nicer) thebuttons = [] window.r1 = W.RadioButton((10, 150, 180, 16), "Radio 1 (cmd 1)", thebuttons) window.r2 = W.RadioButton((10, 170, 180, 16), "Radio 2 (cmd 2)", thebuttons) window.r3 = W.RadioButton((10, 190, 180, 16), "Radio 3 (cmd 3)", thebuttons, radiocallback) window.r1.set(1) # a normal button window.cancelbutton = W.Button((10, 220, 60, 16), "Cancel", cancel)
import W # define some callbacks def callback(): window.close() def checkcallback(value): print "hit the checkbox", value def radiocallback(value): print "hit radiobutton #3", value def scrollcallback(value): widget = window.hbar if value == "+": widget.set(widget.get() - 1) elif value == "-": widget.set(widget.get() + 1) elif value == "++": widget.set(widget.get() - 10) elif value == "--": widget.set(widget.get() + 10) else: # in thumb widget.set(value) print "scroll...", widget.get() def textcallback(): window.et3.set(window.et1.get()) def cancel():
def __init__(self, fontsettings, tabsettings): leftmargin = 60 leftmargin2 = leftmargin - 16 self.w = W.ModalDialog((440, 180), 'Font settings') self.w.fonttitle = W.TextBox((10, 12, leftmargin2, 14), "Font:", TextEdit.teJustRight) self.w.pop = W.FontMenu((leftmargin, 10, 16, 16), self.setfont) self.w.fontname = W.TextBox((leftmargin + 20, 12, 150, 14)) self.w.sizetitle = W.TextBox((10, 38, leftmargin2, 14), "Size:", TextEdit.teJustRight) self.w.sizeedit = W.EditText((leftmargin, 35, 40, 20), "", self.checksize) styletop = 64 self.w.styletitle = W.TextBox((10, styletop + 2, leftmargin2, 14), "Style:", TextEdit.teJustRight) for i in range(len(_stylenames)): top = styletop + (i % 4) * 20 left = leftmargin + 80 * (i > 3) - 2 if i: self.w[i] = W.CheckBox((left, top, 76, 16), _stylenames[i], self.dostyle) else: self.w[i] = W.CheckBox((left, top, 70, 16), _stylenames[i], self.doplain) if tabsettings: self.lasttab, self.tabmode = tabsettings self.w.tabsizetitle = W.TextBox((10, -26, leftmargin2, 14), "Tabsize:", TextEdit.teJustRight) self.w.tabsizeedit = W.EditText((leftmargin, -29, 40, 20), "", self.checktab) self.w.tabsizeedit.set(repr(self.lasttab)) radiobuttons = [] self.w.tabsizechars = W.RadioButton((leftmargin + 48, -26, 55, 14), "Spaces", radiobuttons, self.toggletabmode) self.w.tabsizepixels = W.RadioButton( (leftmargin + 110, -26, 55, 14), "Pixels", radiobuttons, self.toggletabmode) if self.tabmode: self.w.tabsizechars.set(1) else: self.w.tabsizepixels.set(1) else: self.tabmode = None self.w.cancelbutton = W.Button((-180, -26, 80, 16), "Cancel", self.cancel) self.w.donebutton = W.Button((-90, -26, 80, 16), "Done", self.done) sampletext = "Sample text." self.w.sample = W.EditText((230, 10, -10, 130), sampletext, fontsettings=fontsettings, tabsettings=tabsettings) self.w.setdefaultbutton(self.w.donebutton) self.w.bind('cmd.', self.w.cancelbutton.push) self.w.bind('cmdw', self.w.donebutton.push) self.lastsize = fontsettings[2] self._rv = None self.set(fontsettings) self.w.open()
def __init__(self): prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath) try: (docpath, kind, case, word, tut, lib, ref, ext, api) = prefs.docsearchengine except: (docpath, kind, case, word, tut, lib, ref, ext, api) = prefs.docsearchengine = \ ("", 0, 0, 0, 1, 1, 0, 0, 0) if docpath and not verifydocpath(docpath): docpath = "" self.w = W.Window((400, 200), "Search the Python Documentation") self.w.searchtext = W.EditText((10, 10, -100, 20), callback=self.checkbuttons) self.w.searchbutton = W.Button((-90, 12, 80, 16), "Search", self.search) buttons = [] gutter = 10 width = 130 bookstart = width + 2 * gutter self.w.phraseradio = W.RadioButton((10, 38, width, 16), "As a phrase", buttons) self.w.allwordsradio = W.RadioButton((10, 58, width, 16), "All words", buttons) self.w.anywordsradio = W.RadioButton((10, 78, width, 16), "Any word", buttons) self.w.casesens = W.CheckBox((10, 98, width, 16), "Case sensitive") self.w.wholewords = W.CheckBox((10, 118, width, 16), "Whole words") self.w.tutorial = W.CheckBox((bookstart, 38, -10, 16), "Tutorial") self.w.library = W.CheckBox((bookstart, 58, -10, 16), "Library reference") self.w.langueref = W.CheckBox((bookstart, 78, -10, 16), "Lanuage reference manual") self.w.extending = W.CheckBox((bookstart, 98, -10, 16), "Extending & embedding") self.w.api = W.CheckBox((bookstart, 118, -10, 16), "C/C++ API") self.w.setdocfolderbutton = W.Button((10, -30, 100, 16), "Set doc folder", self.setdocpath) if docpath: self.w.setdefaultbutton(self.w.searchbutton) else: self.w.setdefaultbutton(self.w.setdocfolderbutton) self.docpath = docpath if not docpath: docpath = "(please select the Python html documentation folder)" self.w.docfolder = W.TextBox((120, -28, -10, 16), docpath) [self.w.phraseradio, self.w.allwordsradio, self.w.anywordsradio][kind].set(1) self.w.casesens.set(case) self.w.wholewords.set(word) self.w.tutorial.set(tut) self.w.library.set(lib) self.w.langueref.set(ref) self.w.extending.set(ext) self.w.api.set(api) self.w.open() self.w.wholewords.enable(0) self.w.bind('<close>', self.close) self.w.searchbutton.enable(0)
ord(char))) window.keys.set(text) # close callback def close(): window.close() # new window window = W.Dialog((180, 100), "Type a character") # make a frame (a simple rectangle) window.frame = W.Frame((5, 5, -5, -33)) # some labels, static text window.captions = W.TextBox((10, 9, 43, -36), "char:\rdecimal:\rhex:\roctal:") # another static text box window.keys = W.TextBox((60, 9, 40, -36)) # a button window.button = W.Button((-69, -24, 60, 16), "Done", close) # bind the callbacks window.bind("<key>", tester) window.bind("cmdw", window.button.push) # open the window window.open()