Beispiel #1
0
 def run (self):
     old_pref = self.prefs.get('preferred_unit_groups',[])
     option = de.getRadio(label=_("Automatically adjust units"),
                          sublabel="Choose how you would like to adjust units for display and printing. The underlying ingredient data stored in the database will not be affected.",
                          options=self.options,
                          default=old_pref)
     self.prefs['preferred_unit_groups'] = option
     if option != old_pref:
         for rc in self.reccards:
             rc.ingredientDisplay.display_ingredients()
Beispiel #2
0
 def tree_edited (self, renderer, path_string, text, n, head):
     indices = path_string.split(':')
     path = tuple( map(int, indices))
     itr = self.treeModel.get_iter(path)
     curdic,field = self.get_dic_describing_iter(itr)
     value = curdic[field]
     if value == text: return
     if field=='ingkey':
         key = curdic['ingkey']
         if de.getBoolean(label=_('Change all keys "%s" to "%s"?')%(key,text),
                          sublabel=_("You won't be able to undo this action. If there are already ingredients with the key \"%s\", you won't be able to distinguish between those items and the items you are changing now."%text)
                          ):
             self.rd.update_by_criteria(
                 self.rd.ingredients_table,
                 curdic,
                 {'ingkey':text}
                 )
             self.rd.delete_by_criteria(
                 self.rd.keylookup_table,
                 {'ingkey':key}
                 )
     elif field=='item':
         if de.getBoolean(label=_('Change all items "%s" to "%s"?')%(curdic['item'],text),
                          sublabel=_("You won't be able to undo this action. If there are already ingredients with the item \"%s\", you won't be able to distinguish between those items and the items you are changing now.")%text
                          ):
             self.rd.update_by_criteria(
                 self.rd.ingredients_table,
                 curdic,
                 {'item':text}
                 ) 
     elif field=='unit':
         unit = curdic['unit']; key = curdic['ingkey']; item = curdic['item']
         val = de.getRadio(label='Change unit',
                             options=[
             [_('Change _all instances of "%(unit)s" to "%(text)s"')%locals(),1],
             [_('Change "%(unit)s" to "%(text)s" only for _ingredients "%(item)s" with key "%(key)s"')%locals(),2],
             ],
                           default = 2,
                           )
         if val==1:
             self.rd.update_by_criteria(
                 self.rd.ingredients_table,
                 {'unit':unit},
                 {'unit':text},
                 )
         elif val==2:
             self.rd.update_by_criteria(
                 self.rd.ingredients_table,
                 curdic,
                 {'unit':text}
                 )
     elif field=='amount':
         amount = curdic['amount']; unit = curdic['unit']; key = curdic['ingkey']; item = curdic['item']
         try:
             new_amount = convert.frac_to_float(text)
         except:
             de.show_amount_error(text)
             return
         val = de.getRadio(label='Change amount',
                     options=[
             [_('Change _all instances of "%(amount)s" %(unit)s to %(text)s %(unit)s')%locals(),1],
             [_('Change "%(amount)s" %(unit)s to "%(text)s" %(unit)s only _where the ingredient key is %(key)s')%locals(),2],
             [_('Change "%(amount)s" %(unit)s to "%(text)s" %(unit)s only where the ingredient key is %(key)s _and where the item is %(item)s')%locals(),3],
             ],
             default=3,
                           )
         if val == 1:
             cond = {'unit':unit,'amount':amount}
         elif val == 2:
             cond = {'unit':unit,'amount':amount,'ingkey':key}
         elif val == 3:
             cond = curdic
         self.rd.update_by_criteria(
             self.rd.ingredients_table,
             {'unit':unit,'amount':convert.frac_to_float(amount)},
             {'unit':unit,'amount':new_amount}
             )
     else:
         return
     self.treeModel.set_value(itr, n, text)
     return
Beispiel #3
0
 def tree_edited(self, renderer, path_string, text, n, head):
     indices = path_string.split(':')
     path = tuple(map(int, indices))
     itr = self.treeModel.get_iter(path)
     curdic, field = self.get_dic_describing_iter(itr)
     value = curdic[field]
     if value == text: return
     if field == 'ingkey':
         key = curdic['ingkey']
         if de.getBoolean(
                 label=_('Change all keys "%s" to "%s"?') % (key, text),
                 sublabel=_(
                     "You won't be able to undo this action. If there are already ingredients with the key \"%s\", you won't be able to distinguish between those items and the items you are changing now."
                     % text)):
             self.rd.update_by_criteria(self.rd.ingredients_table, curdic,
                                        {'ingkey': text})
             self.rd.delete_by_criteria(self.rd.keylookup_table,
                                        {'ingkey': key})
     elif field == 'item':
         if de.getBoolean(
                 label=_('Change all items "%s" to "%s"?') %
             (curdic['item'], text),
                 sublabel=
                 _("You won't be able to undo this action. If there are already ingredients with the item \"%s\", you won't be able to distinguish between those items and the items you are changing now."
                   ) % text):
             self.rd.update_by_criteria(self.rd.ingredients_table, curdic,
                                        {'item': text})
     elif field == 'unit':
         unit = curdic['unit']
         key = curdic['ingkey']
         item = curdic['item']
         val = de.getRadio(
             label='Change unit',
             options=[
                 [
                     _('Change _all instances of "%(unit)s" to "%(text)s"')
                     % locals(), 1
                 ],
                 [
                     _('Change "%(unit)s" to "%(text)s" only for _ingredients "%(item)s" with key "%(key)s"'
                       ) % locals(), 2
                 ],
             ],
             default=2,
         )
         if val == 1:
             self.rd.update_by_criteria(
                 self.rd.ingredients_table,
                 {'unit': unit},
                 {'unit': text},
             )
         elif val == 2:
             self.rd.update_by_criteria(self.rd.ingredients_table, curdic,
                                        {'unit': text})
     elif field == 'amount':
         amount = curdic['amount']
         unit = curdic['unit']
         key = curdic['ingkey']
         item = curdic['item']
         try:
             new_amount = convert.frac_to_float(text)
         except:
             de.show_amount_error(text)
             return
         val = de.getRadio(
             label='Change amount',
             options=[
                 [
                     _('Change _all instances of "%(amount)s" %(unit)s to %(text)s %(unit)s'
                       ) % locals(), 1
                 ],
                 [
                     _('Change "%(amount)s" %(unit)s to "%(text)s" %(unit)s only _where the ingredient key is %(key)s'
                       ) % locals(), 2
                 ],
                 [
                     _('Change "%(amount)s" %(unit)s to "%(text)s" %(unit)s only where the ingredient key is %(key)s _and where the item is %(item)s'
                       ) % locals(), 3
                 ],
             ],
             default=3,
         )
         if val == 1:
             cond = {'unit': unit, 'amount': amount}
         elif val == 2:
             cond = {'unit': unit, 'amount': amount, 'ingkey': key}
         elif val == 3:
             cond = curdic
         self.rd.update_by_criteria(self.rd.ingredients_table, {
             'unit': unit,
             'amount': convert.frac_to_float(amount)
         }, {
             'unit': unit,
             'amount': new_amount
         })
     else:
         return
     self.treeModel.set_value(itr, n, text)
     return