# Path: magnate/order.py
# class Order:
#     """Information needed to complete a transaction.
# 
#     * :py:attr:`location` The location at which the sale is occuring
#     * :py:attr:`commodity`: the name of the commodity being bought or sold
#     * :py:attr:`price`: the price at which the user is agreeing to buy or sell
#     * :py:attr:`hold_quantity`: The amount of the commodity to place in or
#         take from the ship's hold
#     * :py:attr:`warehouse_quantity`: The amount of the commodity to place in
#         or take from the player's warehouse space at the location
#     * :py:attr:`buy`: if True, the user is asking to buy the commodity.
#         Otherwise, the user is selling the commodity
#     * :py:attr:`status`: Status of the transaction.  May be any one of the EnumTypes
#     """
#     location = attr.ib(validator=attr.validators.instance_of(str))
#     commodity = attr.ib(validator=attr.validators.instance_of(str))
#     price = attr.ib(validator=attr.validators.instance_of(int))
#     hold_quantity = attr.ib(validator=attr.validators.instance_of(int), default=0)
#     warehouse_quantity = attr.ib(validator=attr.validators.instance_of(int), default=0)
#     buy = attr.ib(validator=attr.validators.instance_of(bool), default=True)
#     status = attr.ib(default=OrderStatusType.presale,
#                      validator=partial(enum_validator, OrderStatusType),
#                      convert=partial(enum_converter, OrderStatusType))
# 
# Path: magnate/ui/urwid/abcwidget.py
# class ABCWidget(urwid.WidgetMeta, ABCMeta):
#     """Combine ABCMeta and Widgetmeta together so that we can have a metaclass with both"""
#     pass
# 
# Path: magnate/ui/urwid/message_win.py
# class MessageWindow(urwid.WidgetWrap):
#     _MAX_MESSAGES = 3
#     _MIN_TIME_BETWEEN_MESSAGES = 0.7
#     def __init__(self, pubpen):
#     def height(self):
#     def handle_market_event(self, location, commodity, price, msg):
#     def add_message(self, msg, severity=MsgType.info):
# 
# Path: magnate/ui/urwid/numbers.py
# def format_number(number, max_chars=7):
#     """
#     Format a number in a human readable form.  This adds locale-specific separators.
# 
#     If the number is too long, se scientific notation.
# 
#     :kwarg max_chars: The maximum number of characters a number can take on
#         the screen before it is turned into scientific notation.
#     """
#     formatted_number = locale.format('%d', number, grouping=True)
#     if len(formatted_number) > max_chars:
#         formatted_number = '{:.1E}'.format(number)
# 
#     return formatted_number


from abc import abstractmethod
from ...order import Order
from .abcwidget import ABCWidget
from .message_win import MsgType
from .numbers import format_number
import urwid
            # Set the quantity and total sale fields to the maximum we # can sell
            self.quantity.set_edit_text('{}'.format(self.max_sell_quantity))
            total_sale = self.order.price * self.max_sell_quantity
            self.sale_info.set_text('Total Sale: ${}'.format(format_number(total_sale)))

    def finalize(self):
        """
        This cleans up the event notifications that the dialog is subscribed to.

        This method is appropriate for both internal and external callers to use
        when they close the dialog.

        Implementations should extend this if they have any cleanup to perform.
        """
        for sub_id in self._sub_ids.values():
            self.pubpen.unsubscribe(sub_id)
        self._sub_ids.clear()

    #
    # Event handlers for processing the transaction
    #
    def create_new_transaction(self, commodity, price, location):
        """Reset the dialog box whenever a new sale is started

        :arg commodity: The commodity that is being bought or sold
        :arg price: The amount that the commodity is selling for
        :arg location: The location the transaction is taking place

        Implementations extend this in order to reset their extra_widgets
        """

# Path: magnate/order.py
# class Order:
#     """Information needed to complete a transaction.
# 
#     * :py:attr:`location` The location at which the sale is occuring
#     * :py:attr:`commodity`: the name of the commodity being bought or sold
#     * :py:attr:`price`: the price at which the user is agreeing to buy or sell
#     * :py:attr:`hold_quantity`: The amount of the commodity to place in or
#         take from the ship's hold
#     * :py:attr:`warehouse_quantity`: The amount of the commodity to place in
#         or take from the player's warehouse space at the location
#     * :py:attr:`buy`: if True, the user is asking to buy the commodity.
#         Otherwise, the user is selling the commodity
#     * :py:attr:`status`: Status of the transaction.  May be any one of the EnumTypes
#     """
#     location = attr.ib(validator=attr.validators.instance_of(str))
#     commodity = attr.ib(validator=attr.validators.instance_of(str))
#     price = attr.ib(validator=attr.validators.instance_of(int))
#     hold_quantity = attr.ib(validator=attr.validators.instance_of(int), default=0)
#     warehouse_quantity = attr.ib(validator=attr.validators.instance_of(int), default=0)
#     buy = attr.ib(validator=attr.validators.instance_of(bool), default=True)
#     status = attr.ib(default=OrderStatusType.presale,
#                      validator=partial(enum_validator, OrderStatusType),
#                      convert=partial(enum_converter, OrderStatusType))
# 
# Path: magnate/ui/urwid/abcwidget.py
# class ABCWidget(urwid.WidgetMeta, ABCMeta):
#     """Combine ABCMeta and Widgetmeta together so that we can have a metaclass with both"""
#     pass
# 
# Path: magnate/ui/urwid/message_win.py
# class MessageWindow(urwid.WidgetWrap):
#     _MAX_MESSAGES = 3
#     _MIN_TIME_BETWEEN_MESSAGES = 0.7
#     def __init__(self, pubpen):
#     def height(self):
#     def handle_market_event(self, location, commodity, price, msg):
#     def add_message(self, msg, severity=MsgType.info):
# 
# Path: magnate/ui/urwid/numbers.py
# def format_number(number, max_chars=7):
#     """
#     Format a number in a human readable form.  This adds locale-specific separators.
# 
#     If the number is too long, se scientific notation.
# 
#     :kwarg max_chars: The maximum number of characters a number can take on
#         the screen before it is turned into scientific notation.
#     """
#     formatted_number = locale.format('%d', number, grouping=True)
#     if len(formatted_number) > max_chars:
#         formatted_number = '{:.1E}'.format(number)
# 
#     return formatted_number


# Path: magnate/ui/urwid/order_dialog.py
from abc import abstractmethod
from ...order import Order
from .abcwidget import ABCWidget
from .message_win import MsgType
from .numbers import format_number
import urwid

            # Set the quantity and total sale fields to the maximum we # can sell
            self.quantity.set_edit_text('{}'.format(self.max_sell_quantity))
            total_sale = self.order.price * self.max_sell_quantity
            self.sale_info.set_text('Total Sale: ${}'.format(format_number(total_sale)))

    def finalize(self):
        """
        This cleans up the event notifications that the dialog is subscribed to.

        This method is appropriate for both internal and external callers to use
        when they close the dialog.

        Implementations should extend this if they have any cleanup to perform.
        """
        for sub_id in self._sub_ids.values():
            self.pubpen.unsubscribe(sub_id)
        self._sub_ids.clear()

    #
    # Event handlers for processing the transaction
    #
    def create_new_transaction(self, commodity, price, location):
        """Reset the dialog box whenever a new sale is started

        :arg commodity: The commodity that is being bought or sold
        :arg price: The amount that the commodity is selling for
        :arg location: The location the transaction is taking place

        Implementations extend this in order to reset their extra_widgets
        """

        self.order = Order(location, commodity, price)