def __init__(self, filepath=None): """Creates a new person object from the xml file at filepath.""" self.height = 0.0 self.measurements = AllDatasets() self.plan = AllDatasets() self.backend = get_backend('xml') if filepath is not None: self._read_from_file(filepath)
def _read_from_file(self, filepath): """Reads data from the xml-file in filepath and adds it to the person object.""" # if the standard file or the custom file exists, read from it if os.path.isfile(filepath): self._merge(self.backend.read(filepath)) return # if using a custom file, that does not exist, start with empty data elif parameters.use_custom_file: return # if none of the above, try to import from the legacy data structure elif os.path.isfile(parameters.datafile_old): backend = get_backend('xml_old') self._merge(backend.read(parameters.datafile_old, parameters.planfile_old)) return
def __init__(self, title, data_label_text, file_label_text): self.dialog = gtk.Dialog(flags=gtk.DIALOG_NO_SEPARATOR) self.dialog.set_title(title) self.datasets = parameters.user.measurements self.backend = get_backend('csv') databox = gtk.VBox() databox.set_border_width(5) data_label = gtk.Label(data_label_text) data_label.set_alignment(xalign=0, yalign=0.5) databox.pack_start(data_label) self.data_button = gtk.RadioButton(label=_('Weight Measurements')) self.data_button.set_active(True) self.data_button.connect('toggled', self.on_data_change, 'meas') databox.pack_start(self.data_button) self.data_button = gtk.RadioButton( group=self.data_button, label=_('Weight Plan')) self.data_button.connect('toggled', self.on_data_change, 'plan') if not parameters.config['preferences.use_weight_plan']: self.data_button.set_sensitive(False) databox.pack_start(self.data_button) self.dialog.vbox.pack_start(databox) filebox = gtk.VBox() filebox.set_border_width(5) file_label = gtk.Label(file_label_text) file_label.set_alignment(xalign=0, yalign=0.5) filebox.pack_start(file_label) filehbox = gtk.HBox(homogeneous=False, spacing=5) self.file_entry = gtk.Entry() self.file_entry.set_text(self.backend.default_filename) filehbox.pack_start(self.file_entry) choose_button = gtk.Button(stock=gtk.STOCK_OPEN) filehbox.pack_start(choose_button) filebox.pack_start(filehbox) self.dialog.vbox.pack_start(filebox) # buttons in action area self.dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) self.dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK) # connect the signals choose_button.connect('clicked', self.select_file) # show the content self.dialog.show_all()
def __init__(self, title, data_label_text, file_label_text): self.dialog = gtk.Dialog(flags=gtk.DIALOG_NO_SEPARATOR) self.dialog.set_title(title) self.datasets = parameters.user.measurements self.backend = get_backend('csv') databox = gtk.VBox() databox.set_border_width(5) data_label = gtk.Label(data_label_text) data_label.set_alignment(xalign=0, yalign=0.5) databox.pack_start(data_label) self.data_button = gtk.RadioButton(label=_('Weight Measurements')) self.data_button.set_active(True) self.data_button.connect('toggled', self.on_data_change, 'meas') databox.pack_start(self.data_button) self.data_button = gtk.RadioButton(group=self.data_button, label=_('Weight Plan')) self.data_button.connect('toggled', self.on_data_change, 'plan') if not parameters.config['preferences.use_weight_plan']: self.data_button.set_sensitive(False) databox.pack_start(self.data_button) self.dialog.vbox.pack_start(databox) filebox = gtk.VBox() filebox.set_border_width(5) file_label = gtk.Label(file_label_text) file_label.set_alignment(xalign=0, yalign=0.5) filebox.pack_start(file_label) filehbox = gtk.HBox(homogeneous=False, spacing=5) self.file_entry = gtk.Entry() self.file_entry.set_text(self.backend.default_filename) filehbox.pack_start(self.file_entry) choose_button = gtk.Button(stock=gtk.STOCK_OPEN) filehbox.pack_start(choose_button) filebox.pack_start(filehbox) self.dialog.vbox.pack_start(filebox) # buttons in action area self.dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) self.dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK) # connect the signals choose_button.connect('clicked', self.select_file) # show the content self.dialog.show_all()