def __init__(self): self.dialog = gtk.Dialog(title=_('Plot Weight')) self.dialog.set_default_size(600, 450) # drawing area for the plot self.plot = Plot() self.canvas = FigureCanvas(self.plot.figure) self.dialog.vbox.set_spacing(5) self.dialog.vbox.pack_start(self.canvas) # date selection date_selection_box = gtk.HBox(homogeneous=False, spacing=5) date_label = gtk.Label(_('Select Date Range:')) date_selection_box.pack_start(date_label, False, False) # start date self.start_date_entry = gtk.Entry() self.start_date_entry.set_width_chars(10) self.start_date_entry.set_tooltip_text(_('Start date')) date_selection_box.pack_start(self.start_date_entry, False, False) date_selection_box.pack_start(gtk.Label('-'), False, False) # end date self.end_date_entry = gtk.Entry() self.end_date_entry.set_width_chars(10) self.end_date_entry.set_tooltip_text(_('End date')) date_selection_box.pack_start(self.end_date_entry, False, False) # preset date ranges self.dateselector = gtk.combo_box_new_text() self.dateselector.set_tooltip_text(_('Select date range of plot')) self.dateselector.append_text(_('All Time')) self.dateselector.append_text(_('Last Year')) self.dateselector.append_text(_('Last 6 Months')) self.dateselector.append_text(_('Last Month')) self.dateselector.append_text(_('Custom')) self.set_dateselector_default() date_selection_box.pack_start(self.dateselector, False, False) self.dialog.vbox.pack_start(date_selection_box, False, False) # select data to plot plot_options_box = gtk.HBox(homogeneous=False, spacing=5) # left data type selector data_label_left = gtk.Label(_('Data Left:')) plot_options_box.pack_start(data_label_left, False, False) self.plotselector_left = gtk.combo_box_new_text() self.plotselector_left.set_name('left') self.plotselector_left.append_text(_('Weight')) self.plotselector_keys = ['weight'] if parameters.config['preferences.use_bodyfat']: self.plotselector_left.append_text(_('Bodyfat')) self.plotselector_keys.append('bodyfat') if parameters.config['preferences.use_muscle']: self.plotselector_left.append_text(_('Muscle')) self.plotselector_keys.append('muscle') if parameters.config['preferences.use_water']: self.plotselector_left.append_text(_('Water')) self.plotselector_keys.append('water') if parameters.user.height < 30: self.plotselector_left.set_tooltip_text( _('To plot your BMI, \ you need to enter your height in the preferences dialog.')) else: self.plotselector_left.append_text(_('Body Mass Index')) self.plotselector_keys.append('bmi') self.plotselector_left.set_active(0) plot_options_box.pack_start(self.plotselector_left, False, False) # right data type selector data_label_right = gtk.Label(_('Right:')) plot_options_box.pack_start(data_label_right, False, False) self.plotselector_right = gtk.combo_box_new_text() self.plotselector_right.set_name('right') self.plotselector_right.append_text(_('Weight')) if parameters.config['preferences.use_bodyfat']: self.plotselector_right.append_text(_('Bodyfat')) self.plotselector_right.set_active(1) if parameters.config['preferences.use_muscle']: self.plotselector_right.append_text(_('Muscle')) if parameters.config['preferences.use_water']: self.plotselector_right.append_text(_('Water')) if parameters.user.height < 30: self.plotselector_right.set_tooltip_text( _('To plot your BMI, \ you need to enter your height in the preferences dialog.')) else: self.plotselector_right.append_text(_('Body Mass Index')) self.plotselector_right.append_text(_('None')) self.plotselector_keys.append(None) if not parameters.config['preferences.use_bodyfat']: self.plotselector_right.set_active( \ self.plotselector_keys.index(None)) plot_options_box.pack_start(self.plotselector_right, False, False) # smooth data checkbox self.smooth_data = gtk.CheckButton(_('Smooth')) self.smooth_data.set_active(self.plot.get_smooth()) plot_options_box.pack_start(self.smooth_data, True, False) # plot plan checkbox self.plot_plan = gtk.CheckButton(_('Show Plan')) self.plot_plan.set_active(self.plot.get_show_plan()) self.plot_plan.set_sensitive(self.plot.get_show_plan()) if not self.plot.get_show_plan(): self.plot_plan.set_tooltip_text( _('The weight planner can be \ enabled in the preferences dialog.')) plot_options_box.pack_start(self.plot_plan, True, False) self.dialog.vbox.pack_start(plot_options_box, False, False) # buttons in action field save_button = gtk.Button(label=_('Save Plot')) self.dialog.action_area.pack_start(save_button, False, False) self.dialog.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE) # initialize text entries and format plot self.update_daterange(self.dateselector) # connect the signals self.start_date_entry.connect('key-press-event', self.on_keypress_in_entry) self.end_date_entry.connect('key-press-event', self.on_keypress_in_entry) self.dateselector.connect('changed', self.update_daterange) self.plotselector_left.connect('changed', self.update_plot_type) self.plotselector_right.connect('changed', self.update_plot_type) self.smooth_data.connect('toggled', self.on_toggle_smooth_data) self.plot_plan.connect('toggled', self.on_toggle_plot_plan) save_button.connect('clicked', self.save_plot) # show the content self.dialog.show_all()