This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swing.py
148 lines (134 loc) 路 6.48 KB
/
swing.py
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
# Copyright (C) 2019
# Author: Cesar Roman
# Contact: thecesrom@gmail.com
"""Provides a set of "lightweight" (all-Java language) components
that, to the maximum degree possible, work the same on all platforms."""
__all__ = [
'JOptionPane'
]
class JOptionPane(object):
"""JOptionPane makes it easy to pop up a standard dialog box that
prompts users for a value or informs them of something. For
information about using JOptionPane, see How to Make Dialogs, a
section in The Java Tutorial.
"""
# messageType.
ERROR_MESSAGE = 0
INFORMATION_MESSAGE = 1
WARNING_MESSAGE = 2
QUESTION_MESSAGE = 3
PLAIN_MESSAGE = -1
# optionType.
DEFAULT_OPTION = -1
YES_NO_OPTION = 0
YES_NO_CANCEL_OPTION = 1
OK_CANCEL_OPTION = 2
# When one of the showXxxDialog methods returns an integer, the
# possible values are:
YES_OPTION = 0
NO_OPTION = 1
CANCEL_OPTION = 2
OK_OPTION = 0
CLOSED_OPTION = -1
@staticmethod
def showConfirmDialog(parentComponent, message, title=None,
optionType=None, messageType=None, icon=None):
"""Asks a confirming question, like yes/no/cancel.
Args:
parentComponent (Component): determines the Frame in which
the dialog is displayed; if None, or if the
parentComponent has no Frame, a default Frame is used.
message (object): The object to display.
title (str): The title string for the dialog. Optional.
optionType (int): An int designating the options available
on the dialog: YES_NO_OPTION, YES_NO_CANCEL_OPTION,
or OK_CANCEL_OPTION. Optional.
messageType (int): An integer designating the kind of
message this is; primarily used to determine the icon
from the pluggable Look and Feel: ERROR_MESSAGE,
INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE,
or PLAIN_MESSAGE. Optional.
icon (Icon): The icon to display in the dialog. Optional.
Returns:
int: An integer indicating the option selected by the user.
"""
print(parentComponent, message, title, optionType, messageType, icon)
return JOptionPane.YES_OPTION
@staticmethod
def showInputDialog(parentComponent, message, title=None,
messageType=None, icon=None, selectionValues=None,
initialSelectionValue=None):
"""Prompt for some input.
Args:
parentComponent (Component): determines the Frame in which
the dialog is displayed; if None, or if the
parentComponent has no Frame, a default Frame is used.
message (object): The object to display.
title (str): The title string for the dialog. Optional.
messageType (int): The type of message to be displayed:
ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE,
QUESTION_MESSAGE, or PLAIN_MESSAGE. Optional.
icon (Icon): The icon to display in the dialog. Optional.
selectionValues (list): An array of Objects that gives the
possible selections. Optional.
initialSelectionValue (object): The value used to
initialize the input field. Optional.
Returns:
object: An integer indicating the option selected by the
user.
"""
print(parentComponent, message, title, messageType, icon,
selectionValues, initialSelectionValue)
return 'Input'
@staticmethod
def showMessageDialog(parentComponent, message, title=None,
messageType=None, icon=None):
"""Tell the user about something that has happened.
Args:
parentComponent (Component): determines the Frame in which
the dialog is displayed; if None, or if the
parentComponent has no Frame, a default Frame is used.
message (object): The object to display.
title (str): The title string for the dialog. Optional.
messageType (int): The type of message to be displayed:
ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE,
QUESTION_MESSAGE, or PLAIN_MESSAGE. Optional.
icon (Icon): The icon to display in the dialog. Optional.
"""
print(parentComponent, message, title, messageType, icon)
@staticmethod
def showOptionDialog(parentComponent, message, title=None,
optionType=None, messageType=None, icon=None,
options=None, initialValue=None):
"""The Grand Unification of the above three.
Args:
parentComponent (Component): determines the Frame in which
the dialog is displayed; if None, or if the
parentComponent has no Frame, a default Frame is used.
message (object): The object to display.
title (str): The title string for the dialog. Optional.
optionType (int): An integer designating the options
available on the dialog: DEFAULT_OPTION, YES_NO_OPTION,
YES_NO_CANCEL_OPTION, or OK_CANCEL_OPTION. Optional.
messageType (int): An integer designating the kind of
message this is; primarily used to determine the icon
from the pluggable Look and Feel: ERROR_MESSAGE,
INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE,
or PLAIN_MESSAGE. Optional.
icon (Icon): The icon to display in the dialog. Optional.
options (list): An array of objects indicating the possible
choices the user can make; if the objects are
components, they are rendered properly; non-String
objects are rendered using their toString methods; if
this parameter is null, the options are determined by
the Look and Feel. Optional.
initialValue (object): The object that represents the
default selection for the dialog; only meaningful if
options is used; can be null. Optional.
Returns:
int: An integer indicating the option chosen by the user,
or CLOSED_OPTION if the user closed the dialog.
"""
print(parentComponent, message, title, optionType, messageType,
icon, options, initialValue)
return JOptionPane.YES_OPTION