Example #1
0
class Employee(HasTraits):
    name = Str('<unknown>')
    title = Str
    phone = Regex(regex=r'\d\d\d-\d\d\d\d')

    def default_title(self):
        self.title = 'Senior Engineer'
Example #2
0
class Employee(HasTraits):
    name = Str
    age = Int
    gender = Enum('Male', 'Female')
    phone = Regex(value='000-0000', regex='\d\d\d[-]\d\d\d\d')

    traits_view = View('name',
                       'age',
                       'phone',
                       title='Create new employee',
                       width=0.18,
                       buttons=['OK', 'Cancel'])
Example #3
0
class Person(HasStrictTraits):

    # Trait definitions:
    name = Str
    age = Int
    phone = Regex(value='000-0000', regex='\d\d\d[-]\d\d\d\d')

    # Traits view definition:
    traits_view = View('name',
                       'age',
                       'phone',
                       width=0.18,
                       buttons=['OK', 'Cancel'])
Example #4
0
class Employee(HasTraits):
    first_name = Str
    last_name = Str
    age = Int
    phone = Regex(value='000-0000', regex='\d\d\d[-]\d\d\d\d')

    traits_view = View('first_name',
                       'last_name',
                       'age',
                       'phone',
                       title='Create new employee',
                       width=0.18,
                       buttons=['OK', 'Cancel'])
Example #5
0
class Person(HasStrictTraits):

    #---------------------------------------------------------------------------
    #  Trait definitions:
    #---------------------------------------------------------------------------

    name = Str
    age = Int
    phone = Regex(value='000-0000', regex='\d\d\d[-]\d\d\d\d')

    #---------------------------------------------------------------------------
    #  Traits view definition:
    #---------------------------------------------------------------------------

    traits_view = View('name',
                       'age',
                       'phone',
                       title='Create new person',
                       width=0.18,
                       undo=False,
                       revert=False,
                       help=False)
Example #6
0
class Person(HasStrictTraits):

    #---------------------------------------------------------------------------
    #  Trait definitions:
    #---------------------------------------------------------------------------

    name = Str
    age = Int
    phone = Regex(value='000-0000', regex='\d\d\d[-]\d\d\d\d')
    state = Str

    #---------------------------------------------------------------------------
    #  Traits view definition:
    #---------------------------------------------------------------------------

    traits_view = View('name',
                       'age',
                       'phone',
                       'state',
                       title='Create new person',
                       width=0.18,
                       buttons=['OK', 'Cancel'])
Example #7
0
#------------------------------------------------------------------------------
#  Trait definitions
#------------------------------------------------------------------------------

# An ID is one of the following:
#  * Any string of alphabetic ([a-zA-Z\200-\377]) characters, underscores
#    ('_') or digits ([0-9]), not beginning with a digit;
#  * a number [-]?(.[0-9]+ | [0-9]+(.[0-9]*)? );
#  * any double-quoted string ("...") possibly containing escaped
#    quotes (\")1;
#  * an HTML string (<...>).
alphanum = "[a-zA-Z]"  #\200-\377] "# | [0-9] "#| [_]"
number = "[-]?(.[0-9]+ | [0-9]+(.[0-9]*)? ) "
dquote = '\" '
html = "<...>"
id_trait = Regex(regex=alphanum + "|" + number + "|" + dquote + "|" + html)

pointf_trait = Tuple(Float, Float, desc="the point (x,y)", graphviz=True)

point_trait = pointf_trait  #Either(
#    pointf_trait, Tuple(Float, Float, Float, desc="the point (x,y,z)")
#)

color_schemes = [
    "X11", "Accent", "Blues", "BRBG", "BUGN", "BUPU", "Dark", "GUBU", "Greens",
    "Greys", "Oranges", "OORD", "Paired", "Pastel", "PIYG", "PRGN", "PUBU",
    "PUBUGN", "PUOR", "PURD", "Purples", "RDBU", "RDGY", "RDPU", "RDYLBU",
    "RDYLGN", "Reds", "Set", "Spectral", "YLGN", "YLGNBU", "YLORBR", "YLORRD"
]

color_scheme_trait = Enum(color_schemes,
Example #8
0
class Person(HasStrictTraits):
    name = Str
    age = Int
    phone = Regex(value='000-0000', regex='\d\d\d[-]\d\d\d\d')

    traits_view = View('name', 'age', 'phone')
Example #9
0
class Position(HasTraits):
    """ Simple object to act as a data structure for a position 
    
        While all attributes (traits) are optional, classes that contain or
        collect instances of the Position class will require the following:
        symbol, trans_date, qty, price, total_amt
    
    """
    
    
    side = Enum("BUYTOOPEN", ["SELLTOCLOS", "BUYTOOPEN", "SELLTOOPEN", "BUYTOCLOSE"])
    symbol = Str
    id = Int
    description = Str
    trans_date = Float
    qty = Float
    price = Float
    multiplier = Float(1.0)
    fee = Float
    exchange_rate = Float(1.0)
    currency = Str("USD")
    total_amt = Float
    filled = Str
    exchange = Str
    
    # The following traits are for viewing and editing the datetime value
    #     of trans_date (which is a float of seconds since the Epoch)
    date_display = Property(Regex(value='11/17/1969',
                                  regex='\d\d[/]\d\d[/]\d\d\d\d'),
                                  depends_on='trans_date')
    time_display = Property(Regex(value='12:01:01',
                                  regex='\d\d[:]\d\d[:]\d\d'),
                                  depends_on='trans_date')
    
    # specify default view layout
    traits_view = View(Item('symbol', label="Symb"),
                       Item('date_display'),
                       Item('time_display'),
                       Item('qty'),
                       buttons=['OK', 'Cancel'], resizable=True)
    
    ###################################
    # Property methods
    def _get_date_display(self):
        return dt_from_timestamp(self.trans_date, tz=Eastern).strftime("%m/%d/%Y")
        
    def _set_date_display(self, val):
        tm = self._get_time_display()
        trans_date = datetime.strptime(val+tm, "%m/%d/%Y%H:%M:%S" )
        trans_date = trans_date.replace(tzinfo=Eastern)
        self.trans_date = dt_to_timestamp(trans_date)
        return 
        
    def _get_time_display(self):
        t = dt_from_timestamp(self.trans_date, tz=Eastern).strftime("%H:%M:%S")
        return t
        
    def _set_time_display(self, val):
        trans_time = datetime.strptime(self._get_date_display()+val, "%m/%d/%Y%H:%M:%S")
        trans_time = trans_time.replace(tzinfo=Eastern)
        self.trans_date = dt_to_timestamp(trans_time)
        return

    ###################################
    # Override default class methods
    
    # cleaner, more reasonable representation of the object
    def __repr__(self):
        return "<Position %s %s>" % (self.symbol, self.qty)
    
    # support reasonable sorting based on trans_date
    def __cmp__(self, other):
        if self.trans_date < other.trans_date:
            return -1
        elif self.trans_date > other.trans_date:
            return 1
        else: return 0

#### EOF ####################################################################