1from fontParts.world import _EnvironmentDispatcher
2
3
4def AskString(message, value='', title='FontParts'):
5    """
6    An ask a string dialog, a `message` is required.
7    Optionally a `value` and `title` can be provided.
8
9    ::
10
11        from fontParts.ui import AskString
12        print(AskString("who are you?"))
13
14    """
15    return dispatcher["AskString"](message=message, value=value, title=title)
16
17
18def AskYesNoCancel(message, title='FontParts', default=0, informativeText=""):
19    """
20    An ask yes, no or cancel dialog, a `message` is required.
21    Optionally a `title`, `default` and `informativeText` can be provided.
22    The `default` option is to indicate which button is the default button.
23
24    ::
25
26        from fontParts.ui import AskYesNoCancel
27        print(AskYesNoCancel("who are you?"))
28
29    """
30    return dispatcher["AskYesNoCancel"](message=message, title=title,
31                                        default=default, informativeText=informativeText)
32
33
34def FindGlyph(aFont, message="Search for a glyph:", title='FontParts'):
35    """
36    A dialog to search a glyph for a provided  font.
37    Optionally a `message`, `title` and `allFonts` can be provided.
38
39
40        from fontParts.ui import FindGlyph
41        from fontParts.world import CurrentFont
42        glyph = FindGlyph(CurrentFont())
43        print(glyph)
44
45    """
46    return dispatcher["FindGlyph"](aFont=aFont, message=message, title=title)
47
48
49def GetFile(message=None, title=None, directory=None, fileName=None,
50            allowsMultipleSelection=False, fileTypes=None):
51    """
52    An get file dialog.
53    Optionally a `message`, `title`, `directory`, `fileName` and
54    `allowsMultipleSelection` can be provided.
55
56    ::
57
58        from fontParts.ui import GetFile
59        print(GetFile())
60
61    """
62    return dispatcher["GetFile"](message=message, title=title, directory=directory,
63                                 fileName=fileName,
64                                 allowsMultipleSelection=allowsMultipleSelection,
65                                 fileTypes=fileTypes)
66
67
68def GetFileOrFolder(message=None, title=None, directory=None, fileName=None,
69                    allowsMultipleSelection=False, fileTypes=None):
70    """
71    An get file or folder dialog.
72    Optionally a `message`, `title`, `directory`, `fileName`,
73    `allowsMultipleSelection` and `fileTypes` can be provided.
74
75    ::
76
77        from fontParts.ui import GetFileOrFolder
78        print(GetFileOrFolder())
79
80    """
81    return dispatcher["GetFileOrFolder"](message=message, title=title,
82                                         directory=directory, fileName=fileName,
83                                         allowsMultipleSelection=allowsMultipleSelection,
84                                         fileTypes=fileTypes)
85
86
87def Message(message, title='FontParts', informativeText=""):
88    """
89    An message dialog.
90    Optionally a `message`, `title` and `informativeText` can be provided.
91
92    ::
93
94        from fontParts.ui import Message
95        print(Message("This is a message"))
96
97    """
98    return dispatcher["Message"](message=message, title=title,
99                                 informativeText=informativeText)
100
101
102def PutFile(message=None, fileName=None):
103    """
104    An put file dialog.
105    Optionally a `message` and `fileName` can be provided.
106
107    ::
108
109        from fontParts.ui import PutFile
110        print(PutFile())
111
112    """
113    return dispatcher["PutFile"](message=message, fileName=fileName)
114
115
116def SearchList(items, message="Select an item:", title='FontParts'):
117    """
118    A dialgo to search a given list.
119    Optionally a `message`, `title` and `allFonts` can be provided.
120
121    ::
122
123        from fontParts.ui import SearchList
124        result = SearchList(["a", "b", "c"])
125        print(result)
126
127    """
128    return dispatcher["SearchList"](items=items, message=message, title=title)
129
130
131def SelectFont(message="Select a font:", title='FontParts', allFonts=None):
132    """
133    Select a font from all open fonts.
134    Optionally a `message`, `title` and `allFonts` can be provided.
135    If `allFonts` is `None` it will list all open fonts.
136
137    ::
138
139        from fontParts.ui import SelectFont
140        font = SelectFont()
141        print(font)
142
143    """
144    return dispatcher["SelectFont"](message=message, title=title, allFonts=allFonts)
145
146
147def SelectGlyph(aFont, message="Select a glyph:", title='FontParts'):
148    """
149    Select a glyph for a given font.
150    Optionally a `message` and `title` can be provided.
151
152    ::
153
154        from fontParts.ui import SelectGlyph
155        font = CurrentFont()
156        glyph = SelectGlyph(font)
157        print(glyph)
158
159    """
160    return dispatcher["SelectGlyph"](aFont=aFont, message=message, title=title)
161
162
163def ProgressBar(title="RoboFab...", ticks=None, label=""):
164    """
165    A progess bar dialog.
166    Optionally a `title`, `ticks` and `label` can be provided.
167
168    ::
169
170        from fontParts.ui import ProgressBar
171
172        bar = ProgressBar()
173        # do something
174        bar.close()
175
176    """
177    return dispatcher["ProgressBar"](title=title, ticks=ticks, label=label)
178
179
180# ----------
181# Dispatcher
182# ----------
183
184dispatcher = _EnvironmentDispatcher([
185    "AskString",
186    "AskYesNoCancel",
187    "FindGlyph",
188    "GetFile",
189    "GetFolder",
190    "GetFileOrFolder",
191    "Message",
192    "OneList",
193    "PutFile",
194    "SearchList",
195    "SelectFont",
196    "SelectGlyph",
197    "ProgressBar",
198])
199