コード例 #1
0
ファイル: pyglet_window.py プロジェクト: obspy/branches
 def on_mouse_drag(x, y, dx, dy, buttons, modifiers):
     """
     Actual handler needed for pushing.
     """
     geo = self.geometry
     height = self.window.height - 2 * geo.vertical_margin - 3 -\
         geo.status_bar_height
     start = geo.horizontal_margin + geo.graph_start_x
     end =  self.window.width - 2 * geo.horizontal_margin - \
             geo.scroll_bar_width - geo.menu_width - 3
     # If the box already exists, update it.
     if self.zoom_box:
         if x < start:
             x = start
         elif x > end:
             x = end
         self.zoom_box.begin_update()
         self.zoom_box.resize(x - self.zoom_start - 2, height - 2)
         self.zoom_box.end_update()
         self.zoom_frame.begin_update()
         self.zoom_frame.resize(x - self.zoom_start, height)
         self.zoom_frame.end_update()
         self.zoom_box_min_x = self.zoom_start
         self.zoom_box_max_x = self.zoom_start + x - self.zoom_start
         self.zoom_box_max_y = self.window.height - geo.vertical_margin\
                               - 3
         self.zoom_box_min_y = self.zoom_box_max_y - height
         if self.zoom_box_min_x > self.zoom_box_max_x:
             self.zoom_box_min_x, self.zoom_box_max_x = \
             self.zoom_box_max_x, self.zoom_box_min_x
     # Otherwise create a new box.
     else:
         self.zoom_start = x
         self.zoom_box = glydget.Rectangle(x + 1, self.window.height -\
                           self.geometry.vertical_margin - 5, 1,
                           height - 2, [255,255,255,155,255,255,255,100,
                                    255,255,255,200,255,255,255,120])
         self.zoom_frame = glydget.Rectangle(x, self.window.height -\
                           self.geometry.vertical_margin - 3, 1,
                           height, (0,0,0,200), filled = False)
         self.zoom_box.build(batch=self.batch, group=self.groups[-1])
         self.zoom_frame.build(batch=self.batch, group=self.groups[-1])
         self.zoom_box_min_x = x
         self.zoom_box_max_x = x + 1
         # Push the handlers for the box.
         self.zoom_handlers = \
                 self.win.window.push_handlers(on_mouse_motion, on_mouse_press)
コード例 #2
0
    def createPlot(self):
        """
        Create and bind to batch and group. Each WaveformPlot object will have
        its own WaveformGroup for handling all the transforms needed.

        Therefore scrolling and placement of the plot will be entirely handled
        by the graphics card. Only the width and height need to be handled by
        the CPU.

        The plot will go from (0,0) to (self.win.window.width - 2 *
        self.win.geometry.horizontal_margin - self.win.geometry.scroll_bar_width, self.height).
        """
        self.width = self.win.window.width - 3 * self.win.geometry.horizontal_margin - \
                self.win.geometry.scroll_bar_width - self.win.geometry.menu_width
        # The box is slighty smaller than the border.
        self.plot = glydget.Rectangle(1, -1, self.width-2,
                        self.height-2,
                        [255, 255, 255, 250, 255, 255, 255, 240,
                        255, 255, 255, 230, 255, 255, 255, 215])
        # also create a box around it.
        self.box = glydget.Rectangle(0, 0, self.width,
                        self.height,
                        (205, 55, 55, 250), filled=False)
        # Add to batch.
        self.plot.build(batch = self.batch, group = self.group1)
        self.box.build(batch = self.batch, group = self.group1)
        # Add actual graph. Also set class variables for later easier access.
        self.graph_start_x = self.win.geometry.graph_start_x
        self.graph_start_y = -self.pad
        self.graph_width = self.width - self.graph_start_x - self.pad - 1
        # Set the scaling factor of the plot accordingly.
        self.plot_group.plot = (self.graph_width/100.0, (self.height-6.0)/100.0)
        self.plot_group.plot_offset = self.graph_start_x
        self.graph_height = self.height - 2*self.pad
        self.graph_box = glydget.Rectangle(self.graph_start_x,
                         self.graph_start_y, self.graph_width + 1,
                         self.graph_height,
                        (0, 0, 0, 250), filled=False)
        self.graph_box.build(batch = self.batch, group = self.group2)
        # Create a delete Button.
        self.addDeleteButton()
        # Add to object_list.
        self.win.object_list.append(self)
コード例 #3
0
ファイル: dialog.py プロジェクト: obspy/branches
 def darkenWindow(self):
     """
     Creates a semi-transparent box that covers the whole view.
     """
     self.darkBox = glydget.Rectangle(0, self.win.window.height,
                                      self.win.window.width,
                                      self.win.window.height,
                                      (0, 0, 0, 155))
     self.darkBox.build(batch=self.batch, group=self.group1)
     self.win.object_list.append(self)
コード例 #4
0
ファイル: background.py プロジェクト: obspy/branches
 def create(self):
     """
     Creates the background.
     """
     self.background = glydget.Rectangle(0, self.win.window.height,
                         self.win.window.width, self.win.window.height,
                         colors = self.bg_colors, filled = True)
     # Add to batch and safe in the windows batch list to keep track of
     # objects.
     self.win.object_list.append(self)
     self.background.build(batch = self.batch, group = self.group)
コード例 #5
0
ファイル: scroll_bar.py プロジェクト: obspy/branches
 def createScrollBar(self):
     """
     Creates a scroll bar on the right side.
     """
     top = self.win.window.height
     bottom = self.win.status_bar.height
     x_start = self.win.window.width - self.win.geometry.scroll_bar_width
     self.bar = glydget.Rectangle(x_start, top,
                                  self.win.geometry.scroll_bar_width,
                                  top - bottom, self.active_color)
     # Create little box to show the current position. This will currently
     # just create a grey box because the real box can only be shown after
     # the rest of all the GUI Elements has been rendered.
     self.box = glydget.Rectangle(x_start, top,
                                  self.win.geometry.scroll_bar_width,
                                  top - bottom, self.inactive_color)
     # Add to batch.
     self.bar.build(batch=self.batch, group=self.group)
     self.box.build(batch=self.batch, group=self.group)
     # Add to object_list.
     self.win.object_list.append(self)
コード例 #6
0
ファイル: status_bar.py プロジェクト: obspy/branches
 def createBar(self):
     """
     Create the status bar and add it to self.batch.
     """
     self.bar = glydget.Rectangle(0, self.height-1,
                     self.win.window.width, self.height-1,
                     [255, 255, 255, 250, 255, 255, 255, 240,
                     255, 255, 255, 230, 255, 255, 255, 215])
     # Add line to separate the status bar.
     self.line  = self.batch.add(2, pyglet.gl.GL_LINES,
                               self.group,
                               ('v2i', (0, self.height,
                                        self.win.window.width, self.height)),
                               ('c3B', (0, 0, 0, 0, 0, 0)))
     # Add to batch.
     self.bar.build(batch = self.batch, group = self.group)
     # Add to object_list.
     self.win.object_list.append(self)
コード例 #7
0
ファイル: dialog.py プロジェクト: obspy/branches
 def createMenu(self):
     """
     Creates very basic menu.
     """
     buttons = [
         glydget.Button('Apply', self.apply),
         glydget.Button('Cancel', self.cancel),
         glydget.Button('OK', self.ok)
     ]
     self.buttons = glydget.HBox(buttons, homogeneous=False)
     self.dialog_box = glydget.VBox([self.buttons], homogeneous=False)
     self.dialog_box.move(self.win.window.width / 2.0,
                          self.win.window.height / 2.0)
     self.dialog_box.show(batch=self.batch, group=self.group2)
     self.light = glydget.Rectangle(100, 100, 100, 100,
                                    (255, 255, 255, 255))
     self.light.build(batch=self.batch, group=self.group2)
     self.win.window.push_handlers(self.dialog_box)
コード例 #8
0
 def createTimeScale(self):
     """
     Actually creates the time_scale.
     """
     self.width = self.win.window.width - 3 * \
             self.win.geometry.horizontal_margin - \
             self.win.geometry.scroll_bar_width - \
             self.win.geometry.menu_width
     geo = self.win.geometry
     # Make thinner for the borders.
     self.top_box = glydget.Rectangle(geo.horizontal_margin + 2,
                     self.win.window.height - geo.vertical_margin - 2,
                     self.width - 4,
                     geo.time_scale - geo.vertical_margin - 4, 
                     (255, 255, 255, 255))
     #self.bottom_box = glydget.Rectangle(geo.horizontal_margin + 2,
     #                geo.status_bar_height + geo.time_scale - 2,
     #                self.width - 4,
     #                geo.time_scale - geo.vertical_margin - 4, 
     #                (255, 255, 255, 255))
     # Add two frames for a thick border.
     self.top_frame1 = glydget.Rectangle(geo.horizontal_margin,
                     self.win.window.height - geo.vertical_margin,
                     self.width,
                     geo.time_scale - geo.vertical_margin,
                     (0, 0, 0, 255), filled = False)
     #self.bottom_frame1 = glydget.Rectangle(geo.horizontal_margin,
     #                geo.status_bar_height + geo.time_scale, self.width,
     #                geo.time_scale - geo.vertical_margin,
     #                (0, 0, 0, 255), filled = False)
     self.top_frame2 = glydget.Rectangle(geo.horizontal_margin + 1,
                     self.win.window.height - geo.vertical_margin - 1,
                     self.width - 2,
                     geo.time_scale - geo.vertical_margin - 2,
                     (0, 0, 0, 255), filled = False)
     #self.bottom_frame2 = glydget.Rectangle(geo.horizontal_margin + 1,
     #                geo.status_bar_height + geo.time_scale - 1,
     #                self.width - 2,
     #                geo.time_scale - geo.vertical_margin - 2,
     #                (0, 0, 0, 255), filled = False)
     # Add every Rectangle to the batch of the window.
     self.top_box.build(batch = self.batch, group = self.group)
     #self.bottom_box.build(batch = self.batch, group = self.group)
     self.top_frame1.build(batch = self.batch, group = self.group)
     #self.bottom_frame1.build(batch = self.batch, group = self.group)
     self.top_frame2.build(batch = self.batch, group = self.group)
     #self.bottom_frame2.build(batch = self.batch, group = self.group)
     # Add boxes for year, month, day.
     self.year_frame_t = glydget.Rectangle(\
                         geo.horizontal_margin + geo.graph_start_x,
                         self.win.window.height - geo.vertical_margin - 3,
                         self.width - geo.graph_start_x - 3, self.subscale_height,
                         (100, 100, 100, 255), filled = False)
     self.month_frame_t = glydget.Rectangle(\
                         geo.horizontal_margin + geo.graph_start_x,
                         self.win.window.height - geo.vertical_margin -\
                         self.subscale_height - 4,
                         self.width - geo.graph_start_x - 3, self.subscale_height,
                         (100, 100, 100, 255), filled = False)
     self.day_frame_t = glydget.Rectangle(\
                         geo.horizontal_margin + geo.graph_start_x,
                         self.win.window.height - geo.vertical_margin -\
                         2*self.subscale_height - 5,
                         self.width - geo.graph_start_x - 3, self.subscale_height,
                         (100, 100, 100, 255), filled = False)
     #self.year_frame_b = glydget.Rectangle(\
     #                    geo.horizontal_margin + geo.graph_start_x,
     #                    geo.status_bar_height + geo.time_scale - 3,
     #                    self.width - geo.graph_start_x - 3, self.subscale_height,
     #                    (100, 100, 100, 255), filled = False)
     #self.month_frame_b = glydget.Rectangle(\
     #                    geo.horizontal_margin + geo.graph_start_x,
     #                    geo.status_bar_height + geo.time_scale - 14,
     #                    self.width - geo.graph_start_x - 3, self.subscale_height,
     #                    (100, 100, 100, 255), filled = False)
     #self.day_frame_b = glydget.Rectangle(\
     #                    geo.horizontal_margin + geo.graph_start_x,
     #                    geo.status_bar_height + geo.time_scale - 25,
     #                    self.width - geo.graph_start_x - 3, self.subscale_height,
     #                    (100, 100, 100, 255), filled = False)
     # Add boxes to batch.
     self.year_frame_t.build(batch = self.batch, group = self.group)
     self.month_frame_t.build(batch = self.batch, group = self.group)
     self.day_frame_t.build(batch = self.batch, group = self.group)
     #self.year_frame_b.build(batch = self.batch, group = self.group)
     #self.month_frame_b.build(batch = self.batch, group = self.group)
     #self.day_frame_b.build(batch = self.batch, group = self.group)
     # Add to object_list.
     self.win.object_list.append(self)
コード例 #9
0
 def dayScale(self, top = True):
     """
     Creates the subdivisions of the month scale.
     """
     # Shortcut to window geometry.
     geo = self.win.geometry
     starttime = self.win.starttime
     endtime = self.win.endtime
     time_range = float(endtime - starttime)
     # Pixel counts.
     start_x = geo.horizontal_margin + geo.graph_start_x + 1
     end_x =  start_x + self.width - geo.graph_start_x - 4
     x_range = end_x - start_x
     # Top or bottom year scala.
     if top:
         start_y = self.win.window.height - geo.vertical_margin -\
                 2 * self.subscale_height - 6
     else:
         start_y = geo.status_bar_height + geo.time_scale - \
                 2 * self.subscale_height - 6
     end_y = start_y - self.subscale_height - 2
     y_range = self.subscale_height - 2
     # Get the number of months.
     days = int(round((endtime - starttime)/86400))
     days_count = range(days)
     # Loop over all years.
     even_color = (200,200,200,255)
     odd_color = (150,150,150,255)
     # Add a background to the month scale.
     self.day_bg = glydget.Rectangle(start_x, start_y,
                 x_range, y_range, even_color)
     self.day_bg.build(batch = self.batch, group = self.group)
     # Use the middle of the starting date to later calculate the current
     # day and account for leap seconds.
     noon_of_start = UTCDateTime(starttime.year, starttime.month, 
                     starttime.day, 12, 0, 0)
     # Only draw if there are less or equal than 150 days.
     if days > 150:
         return
     # Loop over every day.
     for day in days_count:
         today = noon_of_start + 86400 * day
         # Some variables.
         start_of_day = UTCDateTime(today.year, today.month, today.day, 0, 0, 0)
         end_of_day = start_of_day + 86400
         # Calculate boundaries.
         start_frac = (start_of_day - starttime) / time_range
         if start_frac < 0:
             start_frac = 0
         start = start_frac * x_range
         if start < 0:
             start = 0
         start += start_x
         end_frac = (endtime - end_of_day) / time_range
         end_frac = 1.0 - end_frac
         if end_frac > 1.0:
             end_frac = 1.0
         end = end_frac * x_range
         end = x_range - end
         if end > x_range:
             end = x_range
         end += start_x
         graph_width = (end_frac - start_frac) * x_range
         # Only draw every second box.
         if day%2:
             color = odd_color
             # Add half a pixel to avoid rounding issues.
             day_box = glydget.Rectangle(start, start_y,
                         graph_width, y_range, color)
             day_box.build(batch = self.batch, group = self.group)
             # Add to list for easier tracking.
             self.day_boxes.append((day_box, start_frac, end_frac))
         # If two narrow do not add a name.
         if graph_width < 13:
             continue
         # Add name.
         name = str(today.day)
         day_document = pyglet.text.decode_text(name)
         day_document.set_style(0, 5, dict(font_name='Arial', font_size=8.5, 
                                       color = (0,0,0,255), bold = False))
         self.day_layout = pyglet.text.DocumentLabel(document = day_document,
                            x = (end_frac + start_frac)/2 * x_range +\
                                                     start_x - 1,
                            y = start_y - 13.0,
                            batch = self.batch, anchor_x = 'center',
                            anchor_y = 'bottom', group = self.group)
         self.day_labels.append((self.day_layout, start_frac, end_frac))
コード例 #10
0
 def monthScale(self, top = True):
     """
     Creates the subdivisions of the month scale.
     """
     odd_color = (200,200,200,255)
     even_color = (150,150,150,255)
     # Shortcut to window geometry.
     geo = self.win.geometry
     starttime = self.win.starttime
     endtime = self.win.endtime
     time_range = float(endtime - starttime)
     # Pixel counts.
     start_x = geo.horizontal_margin + geo.graph_start_x + 1
     end_x =  start_x + self.width - geo.graph_start_x - 4
     x_range = end_x - start_x
     # Top or bottom year scala.
     if top:
         start_y = self.win.window.height - geo.vertical_margin -\
             self.subscale_height - 5
     else:
         start_y = geo.status_bar_height + geo.time_scale - \
             self.subscale_height - 5
     end_y = start_y - self.subscale_height - 2
     y_range = self.subscale_height - 2
     # Add a background to the month scale.
     self.month_bg = glydget.Rectangle(start_x, start_y,
                 x_range, y_range, odd_color)
     self.month_bg.build(batch = self.batch, group = self.group)
     # Get the number of months.
     if endtime.year == starttime.year:
         months = (endtime.month - starttime.month) + 1
     else:
         months = 0
         years = endtime.year - starttime.year
         # If more than one year add twelve months per year.
         if years > 1:
             months += 12 * (years -1)
         # Get boundaries.
         months += (12 - starttime.month) + 1
         months += endtime.month
     months_count = range(months)
     # Loop over all years.
     # Loop over every month.
     for month in months_count:
         # Get the year and month of the currently treated month.
         cur_month = starttime.month + month
         if cur_month > 12:
             cur_year = starttime.year + ((cur_month -1)//12)
         else:
             cur_year = starttime.year
         cur_month = cur_month % 12
         # Account for weird modulo operation.
         if cur_month == 0:
             cur_month = 12
         # Some variables.
         start_of_month = UTCDateTime(cur_year, cur_month, 1)
         if cur_month + 1> 12:
             cur_month = 1
             cur_year += 1
         else:
             cur_month += 1
         end_of_month = UTCDateTime(cur_year, cur_month, 1)
         # Calculate boundaries.
         start_frac = (start_of_month - starttime) / time_range
         if start_frac < 0:
             start_frac = 0
         start = start_frac * x_range
         if start < 0:
             start = 0
         start += start_x
         end_frac = (endtime - end_of_month) / time_range
         end_frac = 1.0 - end_frac
         if end_frac > 1.0:
             end_frac = 1.0
         end = end_frac * x_range
         end = x_range - end
         if end > x_range:
             end = x_range
         end += start_x
         graph_width = (end_frac - start_frac) * x_range
         # Only draw every second box.
         if not month%2:
             color = even_color
             # Add half a pixel to avoid rounding issues.
             month_box = glydget.Rectangle(start, start_y,
                         graph_width, y_range, color)
             month_box.build(batch = self.batch, group = self.group)
             # Add to list for easier tracking.
             self.month_boxes.append((month_box, start_frac, end_frac))
         # If two narrow do not add a name. This has to be set once and stay
         # valid for all following months, otherwise only the names of the
         # long months might appear.
         # XXX: This might result in only the larger months' labels being
         # drawn.
         if graph_width < 25:
             continue
         # Add name.
         name = start_of_month.strftime('%b')
         month_document = pyglet.text.decode_text(name)
         month_document.set_style(0, 5, dict(font_name='Arial', font_size=8.5, 
                                       color = (0,0,0,255), bold = True))
         self.month_layout = pyglet.text.DocumentLabel(document = month_document,
                            x = (end_frac + start_frac)/2 * x_range + start_x,
                            y = start_y - 13.0,
                            batch = self.batch, anchor_x = 'center',
                            anchor_y = 'bottom', group = self.group)
         self.month_labels.append((self.month_layout, start_frac, end_frac))
コード例 #11
0
 def yearScale(self, top = True):
     """
     Creates the subdivisions of the year scale.
     """
     even_color = (200,200,200,255)
     odd_color = (150,150,150,255)
     # Shortcut to window geometry.
     geo = self.win.geometry
     starttime = self.win.starttime
     endtime = self.win.endtime
     time_range = float(endtime - starttime)
     # Pixel counts.
     start_x = geo.horizontal_margin + geo.graph_start_x + 1
     end_x =  start_x + self.width - geo.graph_start_x - 4
     x_range = end_x - start_x
     # Top or bottom year scala.
     if top:
         start_y = self.win.window.height - geo.vertical_margin - 4
     else:
         start_y = geo.status_bar_height + geo.time_scale - 4
     end_y = start_y - self.subscale_height - 2
     y_range = self.subscale_height - 2
     # Add a background to the year scale.
     self.year_bg = glydget.Rectangle(start_x, start_y,
                 x_range, y_range, even_color)
     self.year_bg.build(batch = self.batch, group = self.group)
     # Get the number of years.
     year_count = endtime.year - starttime.year
     years = range(starttime.year, endtime.year + 1)
     # Loop over all years.
     for _i, year in enumerate(years):
         # Some variables.
         start_of_year = UTCDateTime(year, 1, 1)
         end_of_year = UTCDateTime(year+1, 1, 1)
         # Calculate boundaries.
         start_frac = (start_of_year - starttime) / time_range
         if start_frac < 0:
             start_frac = 0
         start = start_frac * x_range
         if start < 0:
             start = 0
         start += start_x
         end_frac = (endtime - end_of_year) / time_range
         end_frac = 1.0 - end_frac
         if end_frac > 1.0:
             end_frac = 1.0
         end = end_frac * x_range
         end = x_range - end
         if end > x_range:
             end = x_range
         end += start_x
         graph_width = (end_frac - start_frac) * x_range
         # Only draw every second box.
         if _i%2:
             color = odd_color
             year_box = glydget.Rectangle(start, start_y,
                         graph_width, y_range, color)
             year_box.build(batch = self.batch, group = self.group)
             # Add to list for easier tracking.
             self.year_boxes.append((year_box, start_frac, end_frac))
         # If two narrow do not add a name.
         if graph_width < 30:
             continue
         # Add name.
         year_document = pyglet.text.decode_text(str(year))
         year_document.set_style(0, 5, dict(font_name='Arial', font_size=8.5, 
                                       color = (0,0,0,255), bold = True))
         self.year_layout = pyglet.text.DocumentLabel(document = year_document,
                            x = (end_frac + start_frac)/2 * x_range + start_x,
                            y = start_y - 13.0,
                            batch = self.batch, anchor_x = 'center',
                            anchor_y = 'bottom', group = self.group)
         self.year_labels.append((self.year_layout, start_frac, end_frac))