File: insertDialog.py

package info (click to toggle)
pythoncard 0.8.1-8.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 5,352 kB
  • ctags: 4,594
  • sloc: python: 42,401; makefile: 55; sh: 22
file content (86 lines) | stat: -rw-r--r-- 2,855 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from PythonCard import dialog

alertDialogTemplate = """result = dialog.alertDialog(self, 'a message', 'a title')
if result.accepted:
    returned = result.returnedString
"""

colorDialogTemplate = """result = dialog.colorDialog(self)
if result.accepted:
    color = result.color
"""

directoryDialogTemplate = """result = dialog.directoryDialog(self, 'Choose a directory', '')
if result.accepted:
    path = result.path
"""

findDialogTemplate = """result = dialog.findDialog(self)
if result.accepted:
    searchText = result.searchText
    wholeWordsOnly = result.wholeWordsOnly
    caseSensitive = result.caseSensitive
"""

fontDialogTemplate = """result = dialog.fontDialog(self)
if result.accepted:
    color = result.color
    font = result.font
"""

messageDialogTemplate = """result = dialog.messageDialog(self, 'a message', 'a title',
    wx.ICON_INFORMATION | wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL)
if result.accepted:
    returned = result.returnedString
"""

multipleChoiceDialogTemplate = """result = dialog.multipleChoiceDialog(self, "message", "title", ['one', 'two', 'three'])
if result.accepted:
    sel = result.selection
"""

openFileDialogTemplate = """wildcard = "JPG files (*.jpg;*.jpeg)|*.jpg;*.jpeg;*.JPG;*.JPEG|GIF files (*.gif)|*.gif;*.GIF|All Files (*.*)|*.*"
result = dialog.openFileDialog(self, 'Open', '', '', wildcard )
if result.accepted:
    path = result.paths[0]
"""

saveFileDialogTemplate = """wildcard = "JPG files (*.jpg;*.jpeg)|*.jpg;*.jpeg;*.JPG;*.JPEG|GIF files (*.gif)|*.gif;*.GIF|All Files (*.*)|*.*"
result = dialog.saveFileDialog(self, 'Save', '', '', wildcard )
if result.accepted:
    path = result.paths[0]
"""

scrolledMessageDialogTemplate = """dialog.scrolledMessageDialog(self, 'message', 'title')
if result.accepted:
    # you don't really need the accepted test, since there isn't a result
    # to check for a scrolledMessageDialog
    pass
"""

singleChoiceDialogTemplate = """result = dialog.singleChoiceDialog(self, "message", "title", ['one', 'two', 'three'])
if result.accepted:
    sel = result.selection
"""

textEntryDialogTemplate = """result = dialog.textEntryDialog(self, 'message', 'title', 'text')
if result.accepted:
    returned = result.returnedString
    text = result.text
"""


dialogsList = ['alertDialog', 'colorDialog', 'directoryDialog', 
    'findDialog', 'fontDialog', 'messageDialog', 
    'multipleChoiceDialog', 'openFileDialog', 'saveFileDialog', 
    'scrolledMessageDialog', 'singleChoiceDialog', 
    'textEntryDialog']
dialogsList.sort()

result = dialog.singleChoiceDialog(None, "Pick a dialog:", "Dialogs", dialogsList)
if result.accepted:
    dialogText = eval(result.selection + 'Template')
    # could get the current indent and insert the appropriate
    # number of spaces before each line of the template here
    comp.document.ReplaceSelection(dialogText)