source: moxy/trunk/src/moxy/m_settings.py @ 780

Last change on this file since 780 was 780, checked in by jemian, 11 years ago

consistency

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Rev Url
File size: 2.3 KB
Line 
1#!/usr/bin/env python
2
3########### SVN repository information ###################
4# $Date: 2012-02-02 20:36:47 +0000 (Thu, 02 Feb 2012) $
5# $Author: jemian $
6# $Revision: 780 $
7# $URL$
8# $Id: m_settings.py 780 2012-02-02 20:36:47Z jemian $
9########### SVN repository information ###################
10
11'''
12comment
13
14Copyright (c) 2009 - 2011, UChicago Argonne, LLC.
15See LICENSE file for details.
16'''
17
18
19# - - - - - - - - - - - - - - - - - - Imports
20
21
22import datetime
23
24
25# - - - - - - - - - - - - - - - - - - Global
26
27
28__svnid__ = "$Id: m_settings.py 780 2012-02-02 20:36:47Z jemian $"
29
30
31# - - - - - - - - - - - - - - - - - - class
32
33
34class Row:
35    '''a single labeled row of axes positions'''
36   
37    def __init__(self, label=None, values=[], axes_set=None):
38        '''
39        :param str label: description of this row
40        :param [number] values: list of values for this row
41        :param m_set.AxesSet axes_set: set of axes for this row
42        '''
43        self.label = label or str(datetime.datetime.now())
44        self.values = [r for r in values]
45        self.axes_set = axes_set
46   
47    def move(self):
48        '''send the axes to new values'''
49        if self.axes_set is not None:
50            self.axes_set.move(self.values)
51   
52    def stop(self):
53        '''stop moving the axes'''
54        if self.axes_set is not None:
55            self.axes_set.stopMotion()
56   
57    def set_values(self, values):
58        '''assign new values to this row'''
59        if len(values) != len(self.values) and len(self.values) != 0:
60            msg = "# of new values is different than # of known values"
61            raise RuntimeError, msg
62        self.values = [r for r in values]
63
64
65class Table:
66    '''a set of labeled rows of axes positions'''
67   
68    def __init__(self, label=None, rows=[]):
69        '''
70        :param str label: description of this table
71        :param [Row] rows: list of Row objects
72        '''
73        self.label = label or str(datetime.datetime.now())
74        self.rows = [r for r in rows]
75   
76    def add_row(self, row=None):
77        '''
78        add a row to the table
79       
80        :param Row row: Row object
81        '''
82        self.rows.append(row or Row())
83        # TODO: What about the number of values in the row?
84   
85
86# - - - - - - - - - - - - - - - - - - methods
87
88
89# - - - - - - - - - - - - - - - - - - main
90
91
92if __name__ == '__main__':
93    row = Row()
94    print row.label
95    tbl = Table('table', [row])
96    print tbl.label
97    print [r.label for r in tbl.rows]
98    tbl.add_row()
99    print [r.label for r in tbl.rows]
Note: See TracBrowser for help on using the repository browser.