Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
incendium.gui: added warning, modified error. Added java.lang, and ja…
Browse files Browse the repository at this point in the history
…vax.swing packages. Opting for JOptionPane over Ignition's own errorBox and warningBox.
  • Loading branch information
cesarcoatl committed Jul 6, 2018
1 parent 00de387 commit ff1c03e
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 2 deletions.
22 changes: 20 additions & 2 deletions python/incendium/gui.py
Expand Up @@ -12,6 +12,7 @@

import system.gui
import system.util
from javax.swing import JOptionPane


def confirm(message, title, show_cancel=False):
Expand Down Expand Up @@ -44,8 +45,10 @@ def error(message, title):
title (str): A title for the message box. This will be
translated to the selected Locale.
"""
system.gui.errorBox(system.util.translate(message),
system.util.translate(title))
JOptionPane.showMessageDialog(None,
system.util.translate(message),
system.util.translate(title),
JOptionPane.ERROR_MESSAGE)


def info(message, title, detail=None):
Expand All @@ -66,3 +69,18 @@ def info(message, title, detail=None):
msg = '%s %s' % (system.util.translate(message),
system.util.translate(detail))
system.gui.messageBox(msg, system.util.translate(title))


def warning(message, title):
"""Displays a message to the user in a warning style pop-up dialog.
Args:
message (str): The message to display in an warning box. This
will be translated to the selected Locale.
title (str): A title for the warning box. This will be translated
to the selected Locale.
"""
JOptionPane.showMessageDialog(None,
system.util.translate(message),
system.util.translate(title),
JOptionPane.WARNING_MESSAGE)
9 changes: 9 additions & 0 deletions python/java/__init__.py
@@ -0,0 +1,9 @@
# Copyright (C) 2018
# Author: Cesar Roman
# Contact: thecesrom@gmail.com

"""Java package."""

__all__ = [
'lang'
]
37 changes: 37 additions & 0 deletions python/java/lang.py
@@ -0,0 +1,37 @@
# Copyright (C) 2018
# Author: Cesar Roman
# Contact: thecesrom@gmail.com

"""Provides classes that are fundamental to the design of the Java
programming language."""

__all__ = [
'Exception'
]


class Exception(object):
"""The class Exception and its subclasses are a form of Throwable
that indicates conditions that a reasonable application might want
to catch.
The class Exception and any subclasses that are not also subclasses
of RuntimeException are checked exceptions. Checked exceptions need
to be declared in a method or constructor's throws clause if they
can be thrown by the execution of the method or constructor and
propagate outside the method or constructor boundary.
"""

# Static elements
cause = ''

def getCause(self):
"""Returns the cause of this throwable or null if the cause is
nonexistent or unknown. (The cause is the throwable that caused
this throwable to get thrown.)
Returns:
str: The cause of this throwable or null if the cause is
nonexistent or unknown.
"""
return self.cause
9 changes: 9 additions & 0 deletions python/javax/__init__.py
@@ -0,0 +1,9 @@
# Copyright (C) 2018
# Author: Cesar Roman
# Contact: thecesrom@gmail.com

"""Package of standard Java extensions."""

__all__ = [
'swing'
]
149 changes: 149 additions & 0 deletions python/javax/swing.py
@@ -0,0 +1,149 @@
# Copyright (C) 2018
# 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.
While the JOptionPane class may appear complex because of the large
number of methods, almost all uses of this class are one-line calls
to one of the static showXxxDialog methods shown below:
"""
# 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.
"""
pass

@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.
"""
pass

@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.
"""
pass

@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.
"""
pass

0 comments on commit ff1c03e

Please sign in to comment.