Beispiel #1
0
 def get_daterange(self):
     """Returns start and end date of the plot to be created,
     depending on the current setting of self.dateselector."""
     key = self.dateselector.get_active()
     if key == 0:
         dateoffset = timedelta(days=10)
         mindate = self.plot.get_mindate() - dateoffset
         maxdate = self.plot.get_maxdate() + dateoffset
     elif key == 1:
         # select last year
         dateoffset = timedelta(days=4)
         maxdate = date.today() + dateoffset
         mindate = maxdate - timedelta(days=365) - 2 * dateoffset
     elif key == 2:
         # select last 6 months
         dateoffset = timedelta(days=2)
         maxdate = date.today() + dateoffset
         mindate = maxdate - timedelta(days=182) - 2 * dateoffset
     elif key == 3:
         # select last month
         dateoffset = timedelta(days=1)
         maxdate = date.today() + dateoffset
         mindate = maxdate - timedelta(days=31) - 2 * dateoffset
     else:
         mindate = util.str2date(self.start_date_entry.get_text())
         maxdate = util.str2date(self.end_date_entry.get_text())
     return mindate, maxdate
Beispiel #2
0
 def get_daterange(self):
     """Returns start and end date of the plot to be created,
     depending on the current setting of self.dateselector."""
     key = self.dateselector.get_active()
     if key == 0:
         dateoffset = timedelta(days=10)
         mindate = self.plot.get_mindate() - dateoffset
         maxdate = self.plot.get_maxdate() + dateoffset
     elif key == 1:
         # select last year
         dateoffset = timedelta(days=4)
         maxdate = date.today() + dateoffset
         mindate = maxdate - timedelta(days=365) - 2 * dateoffset
     elif key == 2:
         # select last 6 months
         dateoffset = timedelta(days=2)
         maxdate = date.today() + dateoffset
         mindate = maxdate - timedelta(days=182) - 2 * dateoffset
     elif key == 3:
         # select last month
         dateoffset = timedelta(days=1)
         maxdate = date.today() + dateoffset
         mindate = maxdate - timedelta(days=31) - 2 * dateoffset
     else:
         mindate = util.str2date(self.start_date_entry.get_text())
         maxdate = util.str2date(self.end_date_entry.get_text())
     return mindate, maxdate
Beispiel #3
0
 def set_custom_date_range(self):
     """Redraws the plot with the current start/end dates."""
     try:
         start_date = util.str2date(self.start_date_entry.get_text())
         end_date = util.str2date(self.end_date_entry.get_text())
     except ValueError:
         title = _('Error: Wrong Format')
         message = _('The data entered is not in the correct format!')
         MessageDialog(type_='error', title=title, message=message).run()
         return
     if start_date >= end_date:
         title = _('Error: Wrong Format')
         message = _('The start date has to be before the end date!')
         MessageDialog(type_='error', title=title, message=message).run()
         return
     self.plot.set_date_range(start_date, end_date)
     self.dateselector.set_active(4)
Beispiel #4
0
 def set_custom_date_range(self):
     """Redraws the plot with the current start/end dates."""
     try:
         start_date = util.str2date(self.start_date_entry.get_text())
         end_date = util.str2date(self.end_date_entry.get_text())
     except ValueError:
         title = _("Error: Wrong Format")
         message = _("The data entered is not in the correct format!")
         MessageDialog(type_="error", title=title, message=message).run()
         return
     if start_date >= end_date:
         title = _("Error: Wrong Format")
         message = _("The start date has to be before the end date!")
         MessageDialog(type_="error", title=title, message=message).run()
         return
     self.plot.set_date_range(start_date, end_date)
     self.dateselector.set_active(4)
Beispiel #5
0
def _dataset_from_element(dataset_el):
    """Parses a dataset xml-element and returns it as a Dataset object."""
    try:
        id_ = int(dataset_el.find('id').text)
    except AttributeError:
        id_ = int(dataset_el.get('id'))
    dataset = Dataset(id_, util.str2date(dataset_el.find('date').text),
                      float(dataset_el.find('weight').text))
    return dataset
def _dataset_from_element(dataset_el):
    """Parses a dataset xml-element and returns it as a Dataset object."""
    try:
        id_ = int(dataset_el.find('id').text)
    except AttributeError:
        id_ = int(dataset_el.get('id'))
    dataset = Dataset(id_,
                  util.str2date(dataset_el.find('date').text),
                  float(dataset_el.find('weight').text))
    return dataset
 def read(self, filename):
     """Reads the sportstracker weights file at filename and returns a
     list of datasets."""
     st_tree = parse(filename)
     datasets = []
     id_ = 1
     st_datasets = st_tree.findall('weight')
     for st_dataset in st_datasets:
         date = util.str2date(st_dataset.find('date').text[0:10])
         weight = round(float(st_dataset.find('value').text), 1)
         note = st_dataset.find('comment').text
         datasets.append(Dataset(id_, date, weight, note=note))
         id_ += 1
     return datasets
 def read(self, filename):
     """Reads the sportstracker weights file at filename and returns a
     list of datasets."""
     st_tree = parse(filename)
     datasets = []
     id_ = 1
     st_datasets = st_tree.findall('weight')
     for st_dataset in st_datasets:
         date = util.str2date(st_dataset.find('date').text[0:10])
         weight = round(float(st_dataset.find('value').text), 1)
         note = st_dataset.find('comment').text
         datasets.append(Dataset(id_, date, weight, note=note))
         id_ += 1
     return datasets
Beispiel #9
0
def _get_dataset_from_element(dataset_el):
    """Parses a dataset xml-element and returns it as a Dataset object."""
    dataset = Dataset(int(dataset_el.find('id').text),
                  util.str2date(dataset_el.find('date').text),
                  float(dataset_el.find('weight').text))
    for key in parameters.keys_optional:
        key_el = dataset_el.find(key)
        if key_el is not None:
            if key in ['note']:
                key_data = str(key_el.text)
            else:
                key_data = float(key_el.text)
            setattr(dataset, key, key_data)
    return dataset
Beispiel #10
0
 def run(self):
     """Runs the dialog and returns the new/updated dataset."""
     response = self.dialog.run()
     if response == gtk.RESPONSE_OK:
         # try to create a new dataset from the given data
         try:
             if parameters.config['preferences.use_calendar']:
                 updated_year, updated_month, updated_day = \
                         self.calendar.get_date()
                 self.dataset.date = \
                         date(updated_year, updated_month+1, updated_day)
             else:
                 self.dataset.date = \
                         util.str2date(self.date_entry.get_text())
             if parameters.config['preferences.unit_system'] == 'imperial':
                 self.dataset.weight_lbs = self.weight_entry.get_value()
             else:
                 self.dataset.weight = self.weight_entry.get_value()
             for key in ['bodyfat', 'muscle', 'water']:
                 if parameters.config['preferences.use_' + key]:
                     data = getattr(self, key + '_entry').get_value()
                     if data > 0.1:
                         setattr(self.dataset, key, data)
                     else:
                         setattr(self.dataset, key, None)
             if parameters.config['preferences.use_note']:
                 note = self.note_buffer.get_text(
                     self.note_buffer.get_start_iter(),
                     self.note_buffer.get_end_iter()).strip()
                 if note != '':
                     self.dataset.note = note
                 else:
                     self.dataset.note = None
         except:
             title = _('Error: Wrong Format')
             message = _('The data entered is not in the correct format!')
             MessageDialog(type_='error', title=title,
                           message=message).run()
             return self.run()
         self.dialog.hide()
         return self.dataset
     else:
         self.dialog.hide()
         return None
Beispiel #11
0
 def run(self):
     """Runs the dialog and returns the new/updated dataset."""
     response = self.dialog.run()
     if response == gtk.RESPONSE_OK:
         # try to create a new dataset from the given data
         try:
             if parameters.config['preferences.use_calendar']:
                 updated_year, updated_month, updated_day = \
                         self.calendar.get_date()
                 self.dataset.date = \
                         date(updated_year, updated_month+1, updated_day)
             else:
                 self.dataset.date = \
                         util.str2date(self.date_entry.get_text())
             if parameters.config['preferences.unit_system'] == 'imperial':
                 self.dataset.weight_lbs = self.weight_entry.get_value()
             else:
                 self.dataset.weight = self.weight_entry.get_value()
             for key in ['bodyfat', 'muscle', 'water']:
                 if parameters.config['preferences.use_' + key]:
                     data = getattr(self, key+'_entry').get_value()
                     if data > 0.1:
                         setattr(self.dataset, key, data)
                     else:
                         setattr(self.dataset, key, None)
             if parameters.config['preferences.use_note']:
                 note = self.note_buffer.get_text(
                         self.note_buffer.get_start_iter(),
                         self.note_buffer.get_end_iter()).strip()
                 if note != '':
                     self.dataset.note = note
                 else:
                     self.dataset.note = None
         except:
             title = _('Error: Wrong Format')
             message = _('The data entered is not in the correct format!')
             MessageDialog(
                     type_='error', title=title, message=message).run()
             return self.run()
         self.dialog.hide()
         return self.dataset
     else:
         self.dialog.hide()
         return None
Beispiel #12
0
 def read(self, filename):
     """Reads the csv-file at filename and returns a list of datasets."""
     csvfile = open(filename, 'r')
     csvreader = csv.reader(csvfile)
     datasets = []
     id_ = 1
     # try to read the datasets from the csv file
     try:
         for row in csvreader:
             date = util.str2date(row[0])
             weight = round(float(row[1]), 1)
             dataset = Dataset(id_, date, weight)
             if parameters.config['preferences.unit_system'] == 'imperial':
                 dataset.weight_lbs = weight
             datasets.append(dataset)
             id_ += 1
     except:
         return False
     return datasets
Beispiel #13
0
 def date_key_press(self, entry, text, position):
     """Tests, which key was pressed and increments/decrements the
     date in date entry by one day if possible."""
     try:
         date_ = util.str2date(entry.get_text())
     except ValueError:
         entry.handler_block(self.date_insert_signal)
         orig_text = entry.get_text()
         new_text = orig_text[:position] + text + orig_text[position:]
         entry.set_text(new_text)
         entry.set_position(position + 1)
         entry.handler_unblock(self.date_insert_signal)
         return
     else:
         if text == '+':
             date_ += timedelta(days=1)
         elif text == '-':
             date_ -= timedelta(days=1)
         entry.handler_block(self.date_insert_signal)
         entry.set_text(str(date_))
         entry.set_position(-1)
         entry.handler_unblock(self.date_insert_signal)
Beispiel #14
0
 def date_key_press(self, entry, text, position):
     """Tests, which key was pressed and increments/decrements the
     date in date entry by one day if possible."""
     try:
         date_ = util.str2date(entry.get_text())
     except ValueError:
         entry.handler_block(self.date_insert_signal)
         orig_text = entry.get_text()
         new_text = orig_text[:position] + text + orig_text[position:]
         entry.set_text(new_text)
         entry.set_position(position+1)
         entry.handler_unblock(self.date_insert_signal)
         return
     else:
         if text == '+':
             date_ += timedelta(days=1)
         elif text == '-':
             date_ -= timedelta(days=1)
         entry.handler_block(self.date_insert_signal)
         entry.set_text(str(date_))
         entry.set_position(-1)
         entry.handler_unblock(self.date_insert_signal)