Changeset 104
- Timestamp:
- 09/27/08 04:20:45 (4 years ago)
- Location:
- trunk/chavier
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/chavier/app.py
r103 r104 2 2 3 3 from pycha.chart import DEFAULT_OPTIONS 4 from pycha.bar import VerticalBarChart 4 import pycha.bar 5 import pycha.line 6 import pycha.pie 7 import pycha.scatter 5 8 6 9 from chavier.gui import GUI 7 10 8 11 class App(object): 12 13 CHART_TYPES = ( 14 pycha.bar.VerticalBarChart, 15 pycha.bar.HorizontalBarChart, 16 pycha.line.LineChart, 17 pycha.pie.PieChart, 18 pycha.scatter.ScatterplotChart, 19 ) 20 21 (VERTICAL_BAR_TYPE, 22 HORIZONTAL_BAR_TYPE, 23 LINE_TYPE, 24 PIE_TYPE, 25 SCATTER_TYPE) = range(len(CHART_TYPES)) 26 9 27 def __init__(self): 10 28 self.gui = GUI(self) … … 16 34 return DEFAULT_OPTIONS 17 35 18 def get_chart(self, datasets, options, width, height):36 def get_chart(self, datasets, options, chart_type, width, height): 19 37 surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) 20 chart = VerticalBarChart(surface, DEFAULT_OPTIONS) 38 chart_factory = self.CHART_TYPES[chart_type] 39 chart = chart_factory(surface, DEFAULT_OPTIONS) 21 40 chart.addDataset(datasets) 22 41 chart.render() -
trunk/chavier/gui.py
r103 r104 59 59 60 60 def _create_ui_manager(self): 61 uimanager = gtk.UIManager()62 accel_group = uimanager.get_accel_group()61 self.uimanager = gtk.UIManager() 62 accel_group = self.uimanager.get_accel_group() 63 63 self.main_window.add_accel_group(accel_group) 64 64 … … 92 92 'Update the chart', self.refresh), 93 93 ]) 94 uimanager.insert_action_group(action_group, -1) 94 action_group.add_radio_actions([ 95 ('verticalbar', None, '_Vertical bars', None, 96 'Use vertical bars chart', self.app.VERTICAL_BAR_TYPE), 97 ('horizontalbar', None, '_Horizontal bars', None, 98 'Use horizontal bars chart', self.app.HORIZONTAL_BAR_TYPE), 99 ('line', None, '_Line', None, 100 'Use lines chart', self.app.LINE_TYPE), 101 ('pie', None, '_Pie', None, 102 'Use pie chart', self.app.PIE_TYPE), 103 ('scatter', None, '_Scatter', None, 104 'Use scatter chart', self.app.SCATTER_TYPE), 105 ], self.app.VERTICAL_BAR_TYPE, self.on_chart_type_change) 106 self.uimanager.insert_action_group(action_group, -1) 95 107 96 108 ui = """<ui> … … 110 122 <menu action="view"> 111 123 <menuitem action="refresh"/> 124 <separator /> 125 <menuitem action="verticalbar"/> 126 <menuitem action="horizontalbar"/> 127 <menuitem action="line"/> 128 <menuitem action="pie"/> 129 <menuitem action="scatter"/> 112 130 </menu> 113 131 </menubar> … … 125 143 </ui> 126 144 """ 127 uimanager.add_ui_from_string(ui)128 uimanager.ensure_update()129 menubar = uimanager.get_widget('/MenuBar')130 toolbar = uimanager.get_widget('/ToolBar')145 self.uimanager.add_ui_from_string(ui) 146 self.uimanager.ensure_update() 147 menubar = self.uimanager.get_widget('/MenuBar') 148 toolbar = self.uimanager.get_widget('/ToolBar') 131 149 132 150 return menubar, toolbar … … 223 241 model = treeview.get_model() 224 242 points = [(x, y) for x, y in model] 225 datasets.append((name, points)) 243 if len(points) > 0: 244 datasets.append((name, points)) 226 245 return datasets 246 247 def _get_chart_type(self): 248 action_group = self.uimanager.get_action_groups()[0] 249 action = action_group.get_action('verticalbar') 250 return action.get_current_value() 227 251 228 252 def run(self): … … 247 271 248 272 def drawing_area_size_allocate_event(self, widget, event, data=None): 273 if self.surface is not None: 274 self.refresh() 275 276 def on_chart_type_change(self, action, current, data=None): 249 277 if self.surface is not None: 250 278 self.refresh() … … 261 289 name = dialog.get_name() 262 290 self._create_dataset(name) 291 self.datasets_notebook.set_current_page(n_pages) 263 292 dialog.destroy() 264 293 … … 334 363 def refresh(self, action=None): 335 364 datasets = self._get_datasets() 336 # options = self._get_options() 337 338 alloc = self.drawing_area.get_allocation() 339 self.surface = self.app.get_chart(datasets, None, 340 alloc.width, alloc.height) 341 self.drawing_area.queue_draw() 365 if datasets: 366 # options = self._get_options() 367 368 chart_type = self._get_chart_type() 369 alloc = self.drawing_area.get_allocation() 370 self.surface = self.app.get_chart(datasets, None, chart_type, 371 alloc.width, alloc.height) 372 self.drawing_area.queue_draw() 373 else: 374 self.surface = None 342 375 343 376
