| 1 |
from dialogKit import * |
|---|
| 2 |
|
|---|
| 3 |
class AddItemDialog(object): |
|---|
| 4 |
|
|---|
| 5 |
def __init__(self, callback): |
|---|
| 6 |
self.callback = callback |
|---|
| 7 |
self.w = ModalDialog((300, 130), okCallback=self.okCallback, cancelCallback=self.cancelCallback) |
|---|
| 8 |
self.w.titleField = TextBox((10, 10, 280, 20), 'Enter some text') |
|---|
| 9 |
self.w.inputField = EditText((10, 35, 280, 27), '') |
|---|
| 10 |
self.w.open() |
|---|
| 11 |
|
|---|
| 12 |
def cancelCallback(self, sender): |
|---|
| 13 |
self.callback(None) |
|---|
| 14 |
|
|---|
| 15 |
def okCallback(self, sender): |
|---|
| 16 |
text = self.w.inputField.get() |
|---|
| 17 |
if text: |
|---|
| 18 |
self.callback(text) |
|---|
| 19 |
else: |
|---|
| 20 |
self.callback(None) |
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
class ListDemoDialog(object): |
|---|
| 24 |
|
|---|
| 25 |
def __init__(self): |
|---|
| 26 |
self.w = ModalDialog((200, 300), 'List Demo', okCallback=self.okCallback) |
|---|
| 27 |
self.w.list = List((10, 40, 180, 200), ['hello', 'there'], callback=self.listHitCallback) |
|---|
| 28 |
self.w.addButton = Button((10, 10, 85, 20), 'Add', callback=self.addCallback) |
|---|
| 29 |
self.w.removeButton = Button((105, 10, 85, 20), 'Remove', callback=self.removeCallback) |
|---|
| 30 |
self.w.open() |
|---|
| 31 |
|
|---|
| 32 |
def okCallback(self, sender): |
|---|
| 33 |
print 'this final list contains:', list(self.w.list) |
|---|
| 34 |
|
|---|
| 35 |
def listHitCallback(self, sender): |
|---|
| 36 |
selection = sender.getSelection() |
|---|
| 37 |
if not selection: |
|---|
| 38 |
selectedItem = None |
|---|
| 39 |
else: |
|---|
| 40 |
selectionIndex = selection[0] |
|---|
| 41 |
selectedItem = sender[selectionIndex] |
|---|
| 42 |
print 'selection:', selectedItem |
|---|
| 43 |
|
|---|
| 44 |
def addItemDialogCallback(self, result): |
|---|
| 45 |
if result is not None: |
|---|
| 46 |
self.w.list.append(result) |
|---|
| 47 |
self.w.list.setSelection([len(self.w.list)-1]) |
|---|
| 48 |
|
|---|
| 49 |
def addCallback(self, sender): |
|---|
| 50 |
AddItemDialog(self.addItemDialogCallback) |
|---|
| 51 |
|
|---|
| 52 |
def removeCallback(self, sender): |
|---|
| 53 |
if len(self.w.list): |
|---|
| 54 |
selectionIndex = self.w.list.getSelection()[0] |
|---|
| 55 |
selectedItem = self.w.list[selectionIndex] |
|---|
| 56 |
print 'removing:', selectedItem |
|---|
| 57 |
del self.w.list[selectionIndex] |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
ListDemoDialog() |
|---|