summaryrefslogtreecommitdiff
path: root/misc/pylib/robofab/test/test_dialogs.py
blob: c296a6bd7717bae106cf519806223d71586758a6 (plain)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import robofab.interface.all.dialogs
reload(robofab.interface.all.dialogs)
from robofab.interface.all.dialogs import *

import unittest


__all__ = [
    "AskString",            #x
    "AskYesNoCancel",       #x
    "FindGlyph",
    "GetFile",              #x
    "GetFolder",            #x
    "GetFileOrFolder",      #x
    "Message",              #x
    "OneList",
    "PutFile",              #x
    "SearchList",
    "SelectFont",
    "SelectGlyph",
    "TwoChecks",
    "TwoFields",
    "ProgressBar",          
]

class DialogRunner(object):
    def __init__(self):
        prompt = "The prompt for %s."
        message = "The message for %s."
        title = "The title for %s."
        informativeText = "The informative text for %s."
        fileTypes = ['ufo']
        fileName = "The_filename.txt"
        
        self.fonts = fonts = [self.makeTestFont(n) for n in range(4)]
        
        t = "AskString"
        try:
            print "About to try", t
            print "\t>>>", AskString(
                message=prompt%t,
                value='',
                title=title%t
        )
        except NotImplementedError:
            print t, "is not implemented."
        
        t = "AskYesNoCancel"
        try:
            print "About to try", t
            print "\t>>>", AskYesNoCancel(
                message=prompt%t+" default set to 0",
                title=title%t,
                default=0,
                informativeText=informativeText%t
            )
            print "\t>>>", AskYesNoCancel(
                message=prompt%t+" default set to 1",
                title=title%t,
                default=1,
                informativeText=informativeText%t
            )
        except NotImplementedError:
            print t, "is not implemented."
        
        t = "GetFile"
        try:
            print "About to try", t
            print "\t>>>", GetFile(
                message=message%t+" Only fileTypes "+`fileTypes`,
                title=title%t,
                directory=None,
                fileName=fileName,
                allowsMultipleSelection=False,
                fileTypes=fileTypes
            )
            print "\t>>>", GetFile(
                message=message%t+" All filetypes, allow multiple selection.",
                title=title%t,
                directory=None,
                fileName=fileName,
                allowsMultipleSelection=True,
                fileTypes=None
            )
        except NotImplementedError:
            print t, "is not implemented."
        
        t = "GetFolder"
        try:
            print "About to try", t
            print "\t>>>", GetFolder(
                message=message%t,
                title=title%t,
                directory=None,
                allowsMultipleSelection=False
            )
            print "\t>>>", GetFolder(
                message=message%t + " Allow multiple selection.",
                title=title%t,
                directory=None,
                allowsMultipleSelection=True
            )
        except NotImplementedError:
            print t, "is not implemented."
         
        t = "GetFileOrFolder"
        try:
            print "About to try", t
            print "\t>>>", GetFileOrFolder(
                message=message%t+" Only fileTypes "+`fileTypes`,
                title=title%t,
                directory=None,
                fileName=fileName,
                allowsMultipleSelection=False,
                fileTypes=fileTypes
            )
            print "\t>>>", GetFileOrFolder(
                message=message%t + " Allow multiple selection.",
                title=title%t,
                directory=None,
                fileName=fileName,
                allowsMultipleSelection=True,
                fileTypes=None
            )
        except NotImplementedError:
            print t, "is not implemented."
        
        t = "Message"
        try:
            print "About to try", t
            print "\t>>>", Message(
                message=message%t,
                title=title%t,
                informativeText=informativeText%t
            )
        except NotImplementedError:
            print t, "is not implemented."
        
        t = "PutFile"
        try:
            print "About to try", t
            print "\t>>>", PutFile(
                message=message%t,
                fileName=fileName,
            )
        except NotImplementedError:
            print t, "is not implemented."
        
    #   t = "SelectFont"
    #   try:
            #print "About to try", t
    #       print "\t>>>", SelectFont(
    #           message=message%t,
    #           title=title%t,
    #           allFonts=fonts,
    #       )
    #   except NotImplementedError:
    #       print t, "is not implemented."
        
    #   t = 'SelectGlyph'
    #   try:
            #print "About to try", t
    #       print "\t>>>", SelectGlyph(
    #           font=fonts[0],
    #           message=message%t,
    #           title=title%t,
    #       )
    #   except NotImplementedError:
    #       print t, "is not implemented."
    
    print 'No more tests.'
            
    def makeTestFont(self, number):
        from robofab.objects.objectsRF import RFont as _RFont
        f = _RFont()
        f.info.familyName = "TestFamily"
        f.info.styleName = "weight%d"%number
        f.info.postscriptFullName = "%s %s"%(f.info.familyName, f.info.styleName)
        # make some glyphs
        for name in ['A', 'B', 'C']:
            g = f.newGlyph(name)
            pen = g.getPen()
            pen.moveTo((0,0))
            pen.lineTo((500, 0))
            pen.lineTo((500, 800))
            pen.lineTo((0, 800))
            pen.closePath()
        return f


class DialogTests(unittest.TestCase):
    def setUp(self):
        from robofab.interface.all.dialogs import test
        test()
        
    def tearDown(self):
        pass
        
    def testDialogs(self):
        import robofab.interface.all.dialogs
        dialogModuleName = robofab.interface.all.dialogs.platformApplicationModuleName
        application = robofab.interface.all.dialogs.application
        
        if application is None and dialogModuleName == "dialogs_mac_vanilla":
            # in vanilla, but not in a host application, run with executeVanillaTest
            print
            print "I'm running these tests with executeVanillaTest"
            from vanilla.test.testTools import executeVanillaTest
            executeVanillaTest(DialogRunner)
        else:
            print
            print "I'm running these tests natively in"
            DialogRunner()
        

if __name__ == "__main__":
    from robofab.test.testSupport import runTests
    runTests()