class JumpToLineWindow(BaseWindowController): lineNumber = None def __init__(self, callback): super(JumpToLineWindow, self).__init__() self.callback = callback # init the window self.w = FloatingWindow((WINDOW_WIDTH, 0), 'Jump to line') # edit text caption jumpingY = MARGIN_TOP self.w.caption = TextBox((MARGIN_LFT, jumpingY + 3, NET_WIDTH * .6, vanillaControlsSize['TextBoxRegularHeight']), 'Jump to line:') self.w.lineEdit = EditText( (MARGIN_LFT + NET_WIDTH * .6, jumpingY, -MARGIN_RGT, vanillaControlsSize['EditTextRegularHeight']), continuous=False) jumpingY += vanillaControlsSize['EditTextRegularHeight'] + MARGIN_INT self.w.cancelButton = Button( (-(BUTTON_WIDTH * 2 + MARGIN_INT + MARGIN_RGT), jumpingY, BUTTON_WIDTH, vanillaControlsSize['ButtonRegularHeight']), 'Cancel', callback=self.cancelButtonCallback) self.w.okButton = Button( (-(BUTTON_WIDTH + MARGIN_RGT), jumpingY, BUTTON_WIDTH, vanillaControlsSize['ButtonRegularHeight']), 'Ok', callback=self.okButtonCallback) jumpingY += vanillaControlsSize['ButtonRegularHeight'] + MARGIN_BTM self.setUpBaseWindowBehavior() self.w.resize(WINDOW_WIDTH, jumpingY) def get(self): try: self.lineNumber = int(self.w.lineEdit.get()) except ValueError: self.w.lineEdit.set('') self.lineNumber = None return self.lineNumber def enable(self, value): if value is True: self.w.center() self.w.show() else: self.w.hide() def cancelButtonCallback(self, sender): self.w.show(False) def okButtonCallback(self, sender): self.callback(self)
class ChooseExceptionWindow(BaseWindowController): lastEvent = None def __init__(self, options, callback): super(ChooseExceptionWindow, self).__init__() self.options = options self.callback = callback self.whichException = options[0] self.w = FloatingWindow((300, 120), 'Choose exception') self.w.optionsRadio = RadioGroup( (MARGIN, MARGIN, -MARGIN, len(options) * 20), options, callback=self.optionsCallback) self.w.optionsRadio.set(0) self.w.cancel = Button( (-(90 * 2 + MARGIN * 2), -(vanillaControlsSize['ButtonRegularHeight'] + MARGIN), 90, vanillaControlsSize['ButtonRegularHeight']), 'Cancel', callback=self.cancelCallback) self.w.submit = Button( (-(90 + MARGIN), -(vanillaControlsSize['ButtonRegularHeight'] + MARGIN), 90, vanillaControlsSize['ButtonRegularHeight']), 'Submit', callback=self.submitCallback) self.setUpBaseWindowBehavior() def set(self, exception): self.whichException = exception self.lastEvent = 'submit' def trigger(self): self.callback(self) def get(self): return self.whichException def enable(self, value): if value is True: self.w.center() self.w.show() else: self.w.hide() def close(self): self.whichException = None self.w.close() def setOptions(self, options): self.options = options optionsRepresentation = [] for lft, rgt in self.options: row = [] for eachSide in [lft, rgt]: if eachSide.startswith('@') is True: groupRepr = encloseClassTitleInBrackets(eachSide) row.append(groupRepr) else: row.append(eachSide) optionsRepresentation.append(', '.join(row)) if hasattr(self.w, 'optionsRadio') is True: delattr(self.w, 'optionsRadio') self.w.optionsRadio = RadioGroup( (MARGIN, MARGIN, -MARGIN, len(options) * 20), optionsRepresentation, callback=self.optionsCallback) def optionsCallback(self, sender): self.whichException = self.options[sender.get()] def cancelCallback(self, sender): self.lastEvent = 'cancel' self.whichException = None self.callback(self) self.w.hide() def submitCallback(self, sender): self.lastEvent = 'submit' self.callback(self) self.w.hide()