Changeset 109 for trunk/chavier/gui.py

Show
Ignore:
Timestamp:
10/27/08 16:49:58 (4 years ago)
Author:
lgs
Message:

Some refactoring and support for negative values in line and bar charts. Inspired by Nicolas patch

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/chavier/gui.py

    r108 r109  
    2222from chavier.dialogs import ( 
    2323    TextInputDialog, PointDialog, OptionDialog, RandomGeneratorDialog, 
    24     AboutDialog, 
     24    AboutDialog, warning 
    2525    ) 
    2626 
     
    2929        self.app = app 
    3030 
     31        self.chart = None 
    3132        self.surface = None 
    3233 
     
    123124                 '<ctrl>g', 'Generate random points', 
    124125                 self.generate_random_points), 
     126                ('dump-chart-state', gtk.STOCK_CONVERT, '_Dump chart state', 
     127                 '<ctrl>d', 'Dump internal chart variables', 
     128                 self.dump_chart_state), 
    125129                ('help', None, '_Help', None, 'Help', None), 
    126130                ('about', gtk.STOCK_ABOUT, None, None, 'About this program', 
     
    168172    <menu action="tools"> 
    169173      <menuitem action="random-points"/> 
     174      <menuitem action="dump-chart-state"/> 
    170175    </menu> 
    171176    <menu action="help"> 
     
    357362 
    358363    def drawing_area_expose_event(self, widget, event, data=None): 
    359         if self.surface is None: 
     364        if self.chart is None: 
    360365            return 
    361366 
     
    364369                     event.area.width, event.area.height) 
    365370        cr.clip() 
    366         cr.set_source_surface(self.surface, 0, 0) 
     371        cr.set_source_surface(self.chart.surface, 0, 0) 
    367372        cr.paint() 
    368373 
    369374    def drawing_area_size_allocate_event(self, widget, event, data=None): 
    370         if self.surface is not None: 
     375        if self.chart is not None: 
    371376            self.refresh() 
    372377 
    373378    def on_chart_type_change(self, action, current, data=None): 
    374         if self.surface is not None: 
     379        if self.chart is not None: 
    375380            self.refresh() 
    376381 
     
    478483            chart_type = self._get_chart_type() 
    479484            alloc = self.drawing_area.get_allocation() 
    480             self.surface = self.app.get_chart(datasets, options, chart_type, 
    481                                               alloc.width, alloc.height) 
     485            self.chart = self.app.get_chart(datasets, options, chart_type, 
     486                                            alloc.width, alloc.height) 
    482487            self.drawing_area.queue_draw() 
    483488        else: 
    484             self.surface = None 
     489            self.chart = None 
    485490 
    486491    def generate_random_points(self, action=None): 
     
    500505        dialog.destroy() 
    501506 
     507    def dump_chart_state(self, action=None): 
     508        if self.chart is None: 
     509            return 
     510 
     511        alloc = self.drawing_area.get_allocation() 
     512 
     513        print 'CHART STATE' 
     514        print '-' * 70 
     515        print 'surface: %d x %d' % (alloc.width, alloc.height) 
     516        print 'area   :', self.chart.area 
     517        print 
     518        print 'minxval:', self.chart.minxval 
     519        print 'maxxval:', self.chart.maxxval 
     520        print 'xrange :', self.chart.xrange 
     521        print 
     522        print 'minyval:', self.chart.minyval 
     523        print 'maxyval:', self.chart.maxyval 
     524        print 'yrange :', self.chart.yrange 
     525 
    502526    def about(self, action=None): 
    503527        dialog = AboutDialog(self.main_window)