def __init__ (self, converter=None, unitModel=None, amt1=None, unit1=None, item=None, okcb=None ): self.possible_conversions = None self.ui = gtk.Builder() self.ui.add_from_file(os.path.join(uibase,'converter.ui')) self.conv = convert.get_converter() self.changing_item = False self.okcb = okcb self.widget_names = ['window','amt1Entry', 'amt2Label', 'unit1ComboBox', 'unit2ComboBox', 'itemComboBox', 'densitySpinButton', 'useDensityCheckButton', 'statusbar','expander1','messageLabel'] # grab all our widgets for w in self.widget_names: setattr(self,w,self.ui.get_object(w)) # HACK FOR READABILITY w/o glade change self.resultLabel = self.amt2Label self.resultLabel.set_use_markup(True) self.resultLabel.set_line_wrap(True) if unitModel: self.unitModel=unitModel else: self.unitModel=UnitModel(self.conv) #self.unit2Model = self.unitModel.filter_new() self.unit1ComboBox.set_model(self.unitModel) self.unit1ComboBox.set_wrap_width(3) self.unit2ComboBox.set_wrap_width(3) #self.unit2Model.set_visible_func(self.unit_filter) #self.unit2ComboBox.set_model(self.unit2Model) self.unit2ComboBox.set_model(self.unitModel) for combobox in [self.unit1ComboBox, self.unit2ComboBox]: cell = gtk.CellRendererText() combobox.pack_start(cell, True) combobox.add_attribute(cell, 'text', 1) setup_typeahead(combobox) #self.itemComboBox.append_text('None') ikeys = self.conv.density_table.keys() ikeys.sort() for itm in ikeys: self.itemComboBox.append_text(itm) if len(self.conv.density_table.keys()) > 8: self.itemComboBox.set_wrap_width(3) setup_typeahead(self.itemComboBox) if amt1: self.amt1Entry=self.conv.float_to_frac(amt1) self.ui.connect_signals({ 'amt1changed':self.changed, 'unit1changed':self.changed, 'unit2changed':self.changed, 'itemChanged':self.density_itm_changed, 'densitySpinChanged':self.density_spin_changed, 'densityChecked':self.density_toggled, 'close':self.close, }) self.last_amt1 = None self.last_amt2 = None self.last_unit1 = None self.last_unit2 = None if unit1 and self.conv.unit_dict.has_key[unit1]: u = self.conv.unit_dict[unit1] cb_set_active_text(self.unit1ComboBox,u) if amt1: self.amt1Entry.set_text("%s"%amt1) if item: cb_set_active_text(self.itemComboBox,item)
def hash_recipe (rec, rd, conv=None): if not conv: conv = convert.get_converter() rechash = get_recipe_hash(rec) inghash = get_ingredient_hash(rd.get_ings(rec),conv) return rechash,inghash
def setUp(self): self.c = convert.get_converter()
def init_converter (self): #self.cnv = DatabaseConverter(self.db) if not self.cnv: self.cnv = convert.get_converter()
def setUp (self): self.c = convert.get_converter()
self.get_buffer().get_slice(start_sentence, end_sentence)) return True def show_timer_cb(tv, l, note, c): """Callback that expects a widget, a time string, and a converter instance""" timer.show_timer(c.timestring_to_seconds(l), note) if gtk.pygtk_version[1] < 8: gobject.type_register(LinkedTimeView) if __name__ == '__main__': import gtk c = convert.get_converter() tv = LinkedTimeView() tv.connect('time-link-activated', show_timer_cb, c) tv.get_buffer().set_text("""Cook potatoes for 1/2 hour. When you are finished, leave in the refrigerator for up to three days. After that, boil onions for 20 to 30 minutes. When finished, bake everything for two and a half hours. 15-25 seconds. """) w = gtk.Window() w.add(tv)
def init_converter(self): self.cnv = convert.get_converter()
def hash_recipe(rec, rd, conv=None): if not conv: conv = convert.get_converter() rechash = get_recipe_hash(rec) inghash = get_ingredient_hash(rd.get_ings(rec), conv) return rechash, inghash
def init_converter (self): self.cnv = convert.get_converter()
def init_converter(self): #self.cnv = DatabaseConverter(self.db) if not self.cnv: self.cnv = convert.get_converter()
start_sentence.backward_sentence_start() end_sentence = iter.copy() if not end_sentence.ends_sentence(): end_sentence.forward_sentence_end() self.emit('time-link-activated',href,self.get_buffer().get_slice(start_sentence,end_sentence)) return True def show_timer_cb (tv,l,note,c): """Callback that expects a widget, a time string, and a converter instance""" timer.show_timer(c.timestring_to_seconds(l), note) if __name__ == '__main__': import gtk c = convert.get_converter() tv = LinkedTimeView() tv.connect('time-link-activated',show_timer_cb,c) tv.get_buffer().set_text( """Cook potatoes for 1/2 hour. When you are finished, leave in the refrigerator for up to three days. After that, boil onions for 20 to 30 minutes. When finished, bake everything for two and a half hours. 15-25 seconds. """ )