UI/FBMessageBoxGetUserValue.py

UI/FBMessageBoxGetUserValue.py
1 # Copyright 2009 Autodesk, Inc. All rights reserved.
2 # Use of this software is subject to the terms of the Autodesk license agreement
3 # provided at the time of installation or download, or which otherwise accompanies
4 # this software in either electronic or hard copy form.
5 #
6 # Topic: FBMessageBoxGetUserValue, FBMessageBox, FBPopupInputType
7 #
8 
9 from pyfbsdk import FBMessageBoxGetUserValue, FBMessageBox, FBPopupInputType
10 
11 # First, let's have a utility function to test the different input types.
12 def TestMessageBox( pVal, pType ):
13 
14  # The result from the call will be a tuple containing the index of the
15  # button pressed (or -1 in case of error). The second element will be
16  # the value entered.
17  lRes = FBMessageBoxGetUserValue( "Value type: '%s'" % pType, "Value: ", pVal, pType, "Ok" )
18 
19  # Did the user press 'Ok'?
20  if lRes[0]:
21  # Show the value entered.
22  FBMessageBox( "Result", "Value entered: '%s'" % lRes[1], "Ok" )
23  else:
24  # Or tell that there was an error...
25  FBMessageBox( "Result", "Got an error", "Ok" )
26 
27  del( lRes )
28 
29 
30 # The message box does not handle booleans well... let's skip those for now.
31 # TestMessageBox( True, FBPopupInputType.kFBPopupBool )
32 # TestMessageBox( False, FBPopupInputType.kFBPopupBool )
33 
34 # Lets try to get a single character, no default value.
35 TestMessageBox( None, FBPopupInputType.kFBPopupChar )
36 
37 # Now with 'X' as a default value.
38 TestMessageBox( 'X', FBPopupInputType.kFBPopupChar )
39 
40 # Now with a string.
41 TestMessageBox( "Default string value", FBPopupInputType.kFBPopupString )
42 
43 # Now as if we were asking for a password. No default value for the password.
44 TestMessageBox( None, FBPopupInputType.kFBPopupPassword )
45 
46 # An integer...
47 TestMessageBox( 33, FBPopupInputType.kFBPopupInt )
48 
49 # A float...
50 TestMessageBox( 3.14e3, FBPopupInputType.kFBPopupFloat )
51 
52 # A double...
53 TestMessageBox( 3.1416, FBPopupInputType.kFBPopupFloat )
54 
55 # Cleanup.
56 del( TestMessageBox, FBMessageBoxGetUserValue, FBMessageBox, FBPopupInputType )