def _selectoption(d, optionlist, idx): if idx < 0 or idx >= len(optionlist): MacOS.SysBeep() return option = optionlist[idx] if type(option) == type(()): if len(option) == 4: help = option[2] elif len(option) > 1: help = option[-1] else: help = '' else: help = '' h = d.GetDialogItemAsControl(ARGV_OPTION_EXPLAIN) if help and len(help) > 250: help = help[:250] + '...' Dlg.SetDialogItemText(h, help) hasvalue = 0 if type(option) == type(()): label = option[0] else: label = option if label[-1] == '=' or label[-1] == ':': hasvalue = 1 h = d.GetDialogItemAsControl(ARGV_OPTION_VALUE) Dlg.SetDialogItemText(h, '') if hasvalue: d.ShowDialogItem(ARGV_OPTION_VALUE) d.SelectDialogItemText(ARGV_OPTION_VALUE, 0, 0) else: d.HideDialogItem(ARGV_OPTION_VALUE)
def recalc(self): scale = 1 x, y, w, h = self.outerrect fullrect = self.control.GetControlRect() x0, y0, x1, y1 = fullrect ## print 'outer', x, y, w, h ## print 'ctl', x0, y0, x1, y1 if x0 >= x1 or y0 >= y1: return while scale * (x1 - x0) < w: scale = scale * 2 while scale * (y1 - y0) < h: scale = scale * 2 w_extra = (x1 - x0) - w / scale h_extra = (y1 - y0) - h / scale self.rect = (x0 + w_extra / 2, y0 + h_extra / 2, x1 - w_extra / 2, y1 - h_extra / 2) self.scale = scale ## print 'self.rect', self.rect ## print 'scale', self.scale self.wid.InvalWindowRect(fullrect) if self.scaleitem != None: if self.scale == 1: text = '' else: text = '(scale 1:%d, %dx%d)' % (self.scale, w, h) h = self.dlg.GetDialogItemAsControl(self.scaleitem) Dlg.SetDialogItemText(h, text)
def dolookup(self): """Get text entered in the lookup entry area. Place result of the call to dnslookup in the result entry area.""" tp, h, rect = self.dlg.GetDialogItem(ITEM_LOOKUP_ENTRY) txt = Dlg.GetDialogItemText(h) tp, h, rect = self.dlg.GetDialogItem(ITEM_RESULT) Dlg.SetDialogItemText(h, self.dnslookup(txt))
class EditDialogWindow(DialogWindow): """Include/exclude editor (modeless dialog window)""" def open(self, id, (src, dst), callback, cancelrv): self.id = id self.callback = callback self.cancelrv = cancelrv DialogWindow.open(self, id) tp, h, rect = self.dlg.GetDialogItem(DLG_SRCPATH) Dlg.SetDialogItemText(h, src) self.dlg.SetDialogDefaultItem(DLG_OK) self.dlg.SetDialogCancelItem(DLG_CANCEL) if id == ID_INCLUDE: tp, h, rect = self.dlg.GetDialogItem(DLG_DSTPATH) if dst == None: dst = '' Dlg.SetDialogItemText(h, dst) self.dlg.DrawDialog()
def _setdialoginfo(self, idx): htext = self._dlg.GetDialogItemAsControl(ITEM_TEMPLATE_DESCRIPTION) if 0 <= idx < len(self.descriptions): text = self.descriptions[idx][0] image = self.descriptions[idx][1] else: text = '' image = None Dlg.SetDialogItemText(htext, text) self.snapshot.setfromfile(image)
def _settext(self, text): text = _string2dialog(text) h = self._dlg.GetDialogItemAsControl(ITEM_INPUT_TEXT) if self._is_passwd_dialog: ControlAccessor.SetControlData( h, Controls.kControlEditTextPart, Controls.kControlEditTextPasswordTag, text) Ctl.SetKeyboardFocus(self._onscreen_wid, h, Controls.kControlEditTextPart) else: Dlg.SetDialogItemText(h, text) self._dlg.SelectDialogItemText(ITEM_INPUT_TEXT, 0, 32767)
def do_dialog(): """Post dialog and handle user interaction until quit""" my_dlg = Dlg.GetNewDialog(ID_MAIN, -1) while 1: n = Dlg.ModalDialog(None) if n == ITEM_LOOKUP_BUTTON: tp, h, rect = my_dlg.GetDialogItem(ITEM_LOOKUP_ENTRY) txt = Dlg.GetDialogItemText(h) tp, h, rect = my_dlg.GetDialogItem(ITEM_RESULT) Dlg.SetDialogItemText(h, dnslookup(txt)) elif n == ITEM_QUIT_BUTTON: break
def do_itemhit(self, item, event): if item == ITEM_INPUTURL_BROWSE: # XXXX This is an error in Python: ##fss, ok = macfs.StandardGetFile('TEXT') fss, ok = macfs.StandardGetFile() if ok: pathname = fss.as_pathname() url = MMurl.pathname2url(pathname) h = self._dlg.GetDialogItemAsControl(ITEM_INPUT_TEXT) Dlg.SetDialogItemText(h, _string2dialog(url)) self._dlg.SelectDialogItemText(ITEM_INPUT_TEXT, 0, 32767) return 1 return InputDialog.do_itemhit(self, item, event)
def __init__(self, prompt, default, types, cb, cancelCallback=None, parent=None): # First create dialogwindow and set static items DialogWindow.__init__(self, self.DIALOG_ID, title=prompt, default=ITEM_INPUT_OK, cancel=ITEM_INPUT_CANCEL) h = self._dlg.GetDialogItemAsControl(ITEM_INPUT_TEXT) Dlg.SetDialogItemText(h, _string2dialog(default)) self._dlg.SelectDialogItemText(ITEM_INPUT_TEXT, 0, 32767) self.type_select = self.SelectWidget(ITEM_NEWCHANNEL_TYPE, types) self._cb = cb self._cancel = cancelCallback
def _ModalDialog(title, dialogid, text, okcallback, cancelcallback=None, identity=None): d = Dlg.GetNewDialog(dialogid, -1) d.SetDialogDefaultItem(ITEM_QUESTION_OK) if cancelcallback: d.SetDialogCancelItem(ITEM_QUESTION_CANCEL) h = d.GetDialogItemAsControl(ITEM_QUESTION_TEXT) if not identity: d.HideDialogItem(ITEM_QUESTION_NOTAGAIN) text = _string2dialog(text) Dlg.SetDialogItemText(h, text) d.AutoSizeDialog() w = d.GetDialogWindow() w.ShowWindow() while 1: n = Dlg.ModalDialog(None) if n == ITEM_QUESTION_OK: if identity: ctl = d.GetDialogItemAsControl(ITEM_QUESTION_NOTAGAIN) if ctl.GetControlValue(): _dont_show_again_identities[identity] = 1 del d del w if okcallback: func, arglist = okcallback apply(func, arglist) return elif n == ITEM_QUESTION_CANCEL: del d del w if cancelcallback: func, arglist = cancelcallback apply(func, arglist) return elif n == ITEM_QUESTION_NOTAGAIN: ctl = d.GetDialogItemAsControl(ITEM_QUESTION_NOTAGAIN) ctl.SetControlValue(not ctl.GetControlValue()) else: print 'Unknown modal dialog item', n
def __init__(self, listprompt, itemlist, default=None, hascancel=1, show=1, multi=0): # First create dialogwindow and set static items if hascancel: DialogWindow.__init__(self, self.DIALOG_ID, default=ITEM_SELECT_OK, cancel=ITEM_SELECT_CANCEL) else: DialogWindow.__init__(self, self.DIALOG_ID, default=ITEM_SELECT_OK) if not hascancel: self._dlg.HideDialogItem(ITEM_SELECT_CANCEL) h = self._dlg.GetDialogItemAsControl(ITEM_SELECT_LISTPROMPT) Dlg.SetDialogItemText(h, _string2dialog(listprompt)) # Now setup the scrolled list self._itemlist = itemlist self._listwidget = self.ListWidget(ITEM_SELECT_ITEMLIST, itemlist, multi=multi) self._listwidget.setkeyboardfocus() # And the default value and ok button ctl = self._dlg.GetDialogItemAsControl(ITEM_SELECT_OK) if multi: ctl.ActivateControl() elif default is None: ctl.DeactivateControl() else: ctl.ActivateControl() self._listwidget.select(default) # And show it if show: self.show()
"""Easy to use dialogs.
def _dialogsetfile(d, item, file): if len(file) > 32: file = '\311:' + os.path.split(file)[1] tp, h, rect = d.GetDialogItem(item) Dlg.SetDialogItemText(h, file)
"""Sample program performing domain name lookups and showing off EasyDialogs,
import FrameWork
def setitem(item, value): htext = _dialog.GetDialogItemAsControl(item) Dlg.SetDialogItemText(htext, value)
#
"""macfreezegui - The GUI for macfreeze"""
def _setlabel(self, item, text): """Set the text of a static text or edit text""" text = _string2dialog(text) ## print 'DBG: setlabel', item, text h = self._dialog.GetDialogItemAsControl(item) Dlg.SetDialogItemText(h, text)
def GetArgv(optionlist=None, commandlist=None, addoldfile=1, addnewfile=1, addfolder=1, id=ARGV_ID): _initialize() _interact() d = GetNewDialog(id, -1) if not d: print "EasyDialogs: Can't get DLOG resource with id =", id, ' (missing resource file?)' return else: if optionlist: _setmenu(d.GetDialogItemAsControl(ARGV_OPTION_GROUP), optionlist) _selectoption(d, optionlist, 0) else: d.GetDialogItemAsControl(ARGV_OPTION_GROUP).DeactivateControl() if commandlist: _setmenu(d.GetDialogItemAsControl(ARGV_COMMAND_GROUP), commandlist) if type(commandlist[0]) == type(()) and len(commandlist[0]) > 1: help = commandlist[0][-1] h = d.GetDialogItemAsControl(ARGV_COMMAND_EXPLAIN) Dlg.SetDialogItemText(h, help) else: d.GetDialogItemAsControl(ARGV_COMMAND_GROUP).DeactivateControl() if not addoldfile: d.GetDialogItemAsControl(ARGV_ADD_OLDFILE).DeactivateControl() if not addnewfile: d.GetDialogItemAsControl(ARGV_ADD_NEWFILE).DeactivateControl() if not addfolder: d.GetDialogItemAsControl(ARGV_ADD_FOLDER).DeactivateControl() d.SetDialogDefaultItem(ARGV_ITEM_OK) d.SetDialogCancelItem(ARGV_ITEM_CANCEL) d.GetDialogWindow().ShowWindow() d.DrawDialog() if hasattr(MacOS, 'SchedParams'): appsw = MacOS.SchedParams(1, 0) try: while 1: stringstoadd = [] n = ModalDialog(None) if n == ARGV_ITEM_OK: break elif n == ARGV_ITEM_CANCEL: raise SystemExit elif n == ARGV_OPTION_GROUP: idx = d.GetDialogItemAsControl( ARGV_OPTION_GROUP).GetControlValue() - 1 _selectoption(d, optionlist, idx) elif n == ARGV_OPTION_VALUE: pass elif n == ARGV_OPTION_ADD: idx = d.GetDialogItemAsControl( ARGV_OPTION_GROUP).GetControlValue() - 1 if 0 <= idx < len(optionlist): option = optionlist[idx] if type(option) == type(()): option = option[0] if option[-1] == '=' or option[-1] == ':': option = option[:-1] h = d.GetDialogItemAsControl(ARGV_OPTION_VALUE) value = Dlg.GetDialogItemText(h) else: value = '' if len(option) == 1: stringtoadd = '-' + option else: stringtoadd = '--' + option stringstoadd = [stringtoadd] if value: stringstoadd.append(value) else: MacOS.SysBeep() elif n == ARGV_COMMAND_GROUP: idx = d.GetDialogItemAsControl( ARGV_COMMAND_GROUP).GetControlValue() - 1 if 0 <= idx < len(commandlist) and type( commandlist[idx]) == type( ()) and len(commandlist[idx]) > 1: help = commandlist[idx][-1] h = d.GetDialogItemAsControl(ARGV_COMMAND_EXPLAIN) Dlg.SetDialogItemText(h, help) elif n == ARGV_COMMAND_ADD: idx = d.GetDialogItemAsControl( ARGV_COMMAND_GROUP).GetControlValue() - 1 if 0 <= idx < len(commandlist): command = commandlist[idx] if type(command) == type(()): command = command[0] stringstoadd = [command] else: MacOS.SysBeep() elif n == ARGV_ADD_OLDFILE: pathname = AskFileForOpen() if pathname: stringstoadd = [pathname] elif n == ARGV_ADD_NEWFILE: pathname = AskFileForSave() if pathname: stringstoadd = [pathname] elif n == ARGV_ADD_FOLDER: pathname = AskFolder() if pathname: stringstoadd = [pathname] elif n == ARGV_CMDLINE_DATA: pass else: raise RuntimeError, 'Unknown dialog item %d' % n for stringtoadd in stringstoadd: if '"' in stringtoadd or "'" in stringtoadd or ' ' in stringtoadd: stringtoadd = repr(stringtoadd) h = d.GetDialogItemAsControl(ARGV_CMDLINE_DATA) oldstr = GetDialogItemText(h) if oldstr and oldstr[-1] != ' ': oldstr = oldstr + ' ' oldstr = oldstr + stringtoadd if oldstr[-1] != ' ': oldstr = oldstr + ' ' SetDialogItemText(h, oldstr) d.SelectDialogItemText(ARGV_CMDLINE_DATA, 32767, 32767) h = d.GetDialogItemAsControl(ARGV_CMDLINE_DATA) oldstr = GetDialogItemText(h) tmplist = string.split(oldstr) newlist = [] while tmplist: item = tmplist[0] del tmplist[0] if item[0] == '"': while item[-1] != '"': if not tmplist: raise RuntimeError, 'Unterminated quoted argument' item = item + ' ' + tmplist[0] del tmplist[0] item = item[1:-1] if item[0] == "'": while item[-1] != "'": if not tmplist: raise RuntimeError, 'Unterminated quoted argument' item = item + ' ' + tmplist[0] del tmplist[0] item = item[1:-1] newlist.append(item) return newlist finally: if hasattr(MacOS, 'SchedParams'): MacOS.SchedParams(*appsw) del d return
def _settext(self, item, str): h = self._dlg.GetDialogItemAsControl(item) Dlg.SetDialogItemText(h, str)