Example #1
0
 def test_hourly(self):
     ts = TimeScale(hours=1)
     start = DTS(2005, 3, 15, 10, 30)
     end = DTS(2005, 3, 15, 16, 59)
     desired_start = DTS(2005, 3, 15)
     desired = [desired_start + i*3600 for i in (11, 12, 13, 14, 15, 16)]
     self.check_ticks(ts.ticks(start, end), desired)
Example #2
0
 def test_minutes(self):
     ts = TimeScale(minutes=15)
     start = DTS(2005, 3, 15, 10, 20)
     end = DTS(2005, 3, 15, 11, 55)
     dstart = DTS(2005, 3, 15)
     desired = ((10, 30), (10, 45), (11, 00), (11, 15), (11, 30), (11, 45))
     self.check_ticks(ts.ticks(start, end), sec_from_hms(dstart, *desired))
Example #3
0
 def test_minutes(self):
     ts = TimeScale(minutes=15)
     start = DTS(2005, 3, 15, 10, 20)
     end = DTS(2005, 3, 15, 11, 55)
     dstart = DTS(2005, 3, 15)
     desired = ((10,30), (10,45), (11,00), (11,15), (11,30), (11,45))
     self.check_ticks(ts.ticks(start, end),
                             sec_from_hms(dstart, *desired))
Example #4
0
 def test_month_of_year(self):
     ts = TimeScale(month_of_year=(1, 4, 8))
     start = DTS(2005, 1, 1)
     end = DTS(2006, 5, 1)
     desired = list(
         starmap(DTS, ((2005, 1, 1), (2005, 4, 1), (2005, 8, 1),
                       (2006, 1, 1), (2006, 4, 1))))
     self.check_ticks(ts.ticks(start, end), desired)
Example #5
0
 def test_widths(self):
     fmt = TimeFormatter()
     scale = TimeScale(minutes = 5)
     test_intervals = ([(2005,3,15,10,30), (2005,3,15,10,50), 50],
                       )
     print
     for start, end, width in test_intervals:
         est_width = scale.label_width(DTS(*start), DTS(*end), char_width=width)
         print start, end,
         print " avail:", width, "est:", est_width[1], "numlabels:", est_width[0]
     return
Example #6
0
 def test_microsecond(self):
     # This test is dicey, because the values being tested are close to
     # machine precision. See the comment in TRangeTestCase.test_microseconds().
     ts = TimeScale(microseconds=1)
     base = DTS(1975, 3, 15, 10, 45, 10)
     start = base + 2.8e-6
     end = base + 9.2e-6
     ticks = ts.ticks(start, end)
     desired = [base+i for i in (3e-6, 4e-6, 5e-6, 6e-6, 7e-6, 8e-6, 9e-6)]
     print "ticks:   ", ticks
     print "desired: ", desired
     self.check_ticks(ticks, desired)
Example #7
0
    def test_day_of_month(self):
        ts = TimeScale(day_of_month=(1,8,15,22))
        start = DTS(2005,3,12)
        end = DTS(2005,5,3)
        desired = list(starmap(DTS, ((2005,3,15), (2005,3,22), (2005,4,1), (2005,4,8),
                                (2005,4,15), (2005,4,22), (2005,5,1))))
        self.check_ticks(ts.ticks(start,end), desired)

        # test adjacent months
        start = DTS(2005, 3, 12)
        end = DTS(2005, 4, 10)
        desired = list(starmap(DTS, ((2005,3,15), (2005,3,22), (2005,4,1), (2005,4,8))))
        self.check_ticks(ts.ticks(start,end), desired)
Example #8
0
 def __init__(self, env, **kwargs):
     """
     Init Method.
     """
     # Set environment.
     self.env = env
     # Create geometry instance.
     self.geometry = Geometry()
     geo = self.geometry
     # Read quarks and set default values.
     self._setDefaultValues(**kwargs)
     # Create the window.
     self.createWindow()
     # Set the OpenGL state.
     self.setOpenGLState()
     # Set the caption of the window.
     self.window.set_caption('OpenGL Waveform Database Viewer')
     # Create the ordered groups used to get a layer like drawing of the
     # window.
     self._createdOrderedGroups()
     # Add a background and add it to group 0.
     Background(parent=self, group=0)
     # Connect to SeisHub Server.
     self.seishub = Seishub(parent=self, group=1)
     # Create status bar if desired.
     if self.status_bar:
         # The status bar should always be seen. Add to a very high group.
         self.status_bar = StatusBar(parent=self,
                                     group=999,
                                     height=self.geometry.status_bar_height,
                                     error=self.default_error)
     # Create Utils class.
     self.utils = Utils(parent=self, group=1)
     # Add the Time Scale.
     self.time_scale = TimeScale(parent=self, group=999)
     # These cannot be created earlier as they need some already set up GUI
     # Elements.
     # XXX: Need to make more dynamic.
     # Maximum vertical span that is viewable.
     self.max_viewable = 0
     self.current_view_span = self.window.height - self.status_bar.height
     # Add a scroll bar. Should also always be on top.
     self.scroll_bar = ScrollBar(parent=self, group=999)
     # Add the menu.
     self.menu = Menu(parent=self,
                      group=999,
                      width=self.geometry.menu_width)
     geo.menu_width = self.menu.menu.width
     # Start of menu.
     self.menu_start = self.window.width - (geo.menu_width +\
                 geo.horizontal_margin + geo.scroll_bar_width)
     # Preload some cursors for faster access.
     self.default_cursor = \
                     self.window.get_system_mouse_cursor(self.window.CURSOR_DEFAULT)
     self.hand_cursor = self.window.get_system_mouse_cursor(
         self.window.CURSOR_HAND)
     # Init zoom box handler.
     self.zoomBox()
     # Start timers.
     self.Timers = Timers(parent=self, group=1)
Example #9
0
 def test_yearly_scales(self):
     ticker = ScaleSystem(TimeScale(month_of_year=1), default_scale=None)
     ticks = ticker.ticks(DTS(2000, 1, 1), DTS(2007, 1, 1), 10)
     desired = list(
         starmap(DTS,
                 ((2000, 1, 1), (2001, 1, 1), (2002, 1, 1), (2003, 1, 1),
                  (2004, 1, 1), (2005, 1, 1), (2006, 1, 1), (2007, 1, 1))))
     self.check_ticks(ticks, desired)
Example #10
0
class TimescaleScene(QtGui.QGraphicsScene):
    def __init__(self, env):
        QtGui.QGraphicsScene.__init__(self)
        #super(TimescaleScene, self).__init__()
        self.env = env

    def startup(self):
        # Add the time scale.
        self.time_scale = TimeScale(self.env, self, self.view.width())
        self.addItem(self.time_scale)

    def redraw(self):
        # Delete time scale.
        self.removeItem(self.time_scale)
        # Create new time scale.
        self.time_scale = TimeScale(self.env, self, self.width())
        self.addItem(self.time_scale)

    def resize(self, width, height):
        # Check if available.
        if hasattr(self, 'time_scale'):
            self.time_scale.resize(self.view.width(), height)
        # Manually update the scene Rectangle.
        self.setSceneRect(0, 0, width, 60)
Example #11
0
 def test_hourly_scales(self):
     scales = [TimeScale(seconds=dt) for dt in (1, 5, 15, 30)] + \
              [TimeScale(minutes=dt) for dt in (1, 5, 15, 30)] + \
              [TimeScale(hours=dt) for dt in (1, 2, 3, 4, 6, 12)]
Example #12
0
 def test_month_of_year(self):
     ts = TimeScale(month_of_year=(1,4,8))
     start = DTS(2005,1,1)
     end = DTS(2006,5,1)
     desired = list(starmap(DTS, ((2005,1,1), (2005,4,1), (2005,8,1), (2006,1,1), (2006,4,1))))
     self.check_ticks(ts.ticks(start,end), desired)
Example #13
0
 def redraw(self):
     # Delete time scale.
     self.removeItem(self.time_scale)
     # Create new time scale.
     self.time_scale = TimeScale(self.env, self, self.width())
     self.addItem(self.time_scale)
Example #14
0
 def startup(self):
     # Add the time scale.
     self.time_scale = TimeScale(self.env, self, self.view.width())
     self.addItem(self.time_scale)