Skip to content

Commit

Permalink
Merge pull request #324 from cydanil/fix/315
Browse files Browse the repository at this point in the history
Update Gtk API calls in KeyEditor plugin
  • Loading branch information
cydanil authored May 3, 2021
2 parents 95907ab + 7b556a8 commit 57e97a5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 49 deletions.
43 changes: 13 additions & 30 deletions src/gourmet/backends/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,27 +226,14 @@ def on_connect (dbapi_con, con_record):
Session.configure(bind=self.db)
debug('Done initializing DB connection',1)

def save (self):
"""Save our database (if we have a separate 'save' concept)"""
def save(self):
"""Save our database (if there is a separate 'save')"""
row = self.fetch_one(self.info_table)
if row:
self.do_modify(
self.info_table,
row,
{'last_access':time.time()},
id_col = None
)
self.do_modify(self.info_table, row,
{'last_access': time.time()}, id_col=None)
else:
self.do_add(
self.info_table,
{'last_access':time.time()}
)
try:
#self.base_connection.commit()
pass
except IndexError:
print('Ignoring sqlalchemy problem')
import traceback; traceback.print_exc()
self.do_add(self.info_table, {'last_access': time.time()})

def _setup_object_for_table (self, table, klass):
self.__table_to_object__[table] = klass
Expand Down Expand Up @@ -1263,7 +1250,8 @@ def add_rec (self, dic, accept_ids=False):
del dic['servings']
except:
del dic['servings']
if 'deleted' not in dic: dic['deleted']=False
if 'deleted' not in dic:
dic['deleted'] = False
self.validate_recdic(dic)
try:
ret = self.do_add_rec(dic)
Expand Down Expand Up @@ -1416,7 +1404,7 @@ def do_modify(self,
try:
table_val = getattr(table.c, id_col)
row_val = getattr(row, id_col)
qr: 'ResultProxy' = table.update(table_val == row_val).execute(**d)
table.update(table_val == row_val).execute(**d)
except Exception as e:
print('do_modify failed with args')
print('table=',table,'row=',row)
Expand All @@ -1425,7 +1413,7 @@ def do_modify(self,
raise
select = table.select(getattr(table.c,id_col)==getattr(row,id_col))
else:
qr: 'ResultProxy' = table.update().execute(**d)
table.update().execute(**d)
select = table.select()
return select.execute().fetchone()

Expand Down Expand Up @@ -1500,17 +1488,12 @@ def delete_rec (self, rec):
self.delete_by_criteria(self.ingredients_table,{'recipe_id':rec})
debug('deleted recipe ID %s'%rec,0)

def new_rec (self):
def new_rec(self):
"""Create and return a new, empty recipe"""
blankdict = {'title':_('New Recipe'),
#'servings':'4'}
}
return self.add_rec(blankdict)
return self.add_rec({'title': _('New Recipe')})

def new_id (self):
#raise NotImplementedError("WARNING: NEW_ID IS NO LONGER FUNCTIONAL, FIND A NEW WAY AROUND THE PROBLEM")
#rec = self.new_rec()
rec = self.do_add_rec({'deleted':1})
def new_id(self) -> int:
rec = self.do_add_rec({'deleted': 1})
self.new_ids.append(rec.id)
return rec.id

Expand Down
25 changes: 15 additions & 10 deletions src/gourmet/plugins/key_editor/recipeEditorPlugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any, Dict, Optional

from gettext import gettext as _

from gi.repository import GObject, Gtk, Pango
Expand Down Expand Up @@ -128,10 +130,9 @@ def setup_tree (self):
instant_apply=False):
self.tv.append_column(tvc)


def auto_wrap_columns (self):
def auto_wrap_columns(self):
for col in self.tv.get_columns():
renderers = col.get_cell_renderers()
renderers = col.get_cells()
for r in renderers:
if isinstance(r,Gtk.CellRendererText):
r.set_property('wrap-mode',Pango.WrapMode.WORD)
Expand Down Expand Up @@ -256,10 +257,14 @@ def activate (self, pluggable):
pluggable.add_hook(POST,'get_extra_ingredient_attributes',
self.get_extra_ingattributes_post_hook)

def get_extra_ingattributes_post_hook (self, retval, ic, ing_obj, ingdict):
recipe_editor = ic.ingredient_editor_module.re
key_editor = [m for m in recipe_editor.modules if isinstance(m,IngredientKeyEditor)][0]
ingkey = key_editor.get_key_for_object(ing_obj)
if ingkey:
ingdict['ingkey'] = ingkey
return ingdict
def get_extra_ingattributes_post_hook (self,
retval: Optional[Any],
controller: 'IngredientController',
ing_obj: int,
ingdict: Dict[str, Any]) -> Dict[str, Any]: # noqa
recipe_editor = controller.ingredient_editor_module.re
for module in recipe_editor.modules:
if isinstance(module, IngredientKeyEditor):
ingdict['ingkey'] = module.get_key_for_object(ing_obj)
break
return ingdict
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,11 @@ def offers_edit_widget (self):
'''
return True

def setup_edit_widget (self):
'''Return an edit widget to let users edit your data.
'''
def setup_edit_widget(self):
"""Return an edit widget to let users edit your data"""
self.cb = cb = Gtk.ComboBox.new_with_entry()
cb.set_model(self.shopcat_model)
cb.set_text_column(0)
cb.set_entry_text_column(0)
entry = cb.get_child()
completion = Gtk.EntryCompletion()
completion.set_model(self.shopcat_model)
Expand Down
13 changes: 8 additions & 5 deletions src/gourmet/reccard.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(self,
self.__rec_editor: Optional[RecEditor] = None
self.__rec_display: Optional[RecCardDisplay] = None
self.__new: bool = True if recipe is None else False
self.__current_rec: 'RowProxy' = recipe if recipe else rec_gui.rd.new_rec()
self.__current_rec: 'RowProxy' = recipe if recipe else rec_gui.rd.new_rec() # noqa

self.conf = [] # This list is unused, and should be refactored out

Expand Down Expand Up @@ -183,8 +183,10 @@ class RecCardDisplay (plugin_loader.Pluggable):
'category', 'instructions', 'modifications']

def __init__ (self, reccard, recGui, recipe=None):
self.reccard = reccard; self.rg = recGui; self.current_rec = recipe
self.mult = 1 # parameter
self.reccard = reccard
self.rg = recGui
self.current_rec = recipe
self.mult = 1 # parameter
self.conf: List[Gtk.Widget] = []
self.prefs = prefs.Prefs.instance()
self.setup_ui()
Expand Down Expand Up @@ -331,7 +333,8 @@ def reflow_on_allocate_cb (self, sw, allocation):
widget.set_label(t)
# Flow our image...
image_width = int(xsize * 0.75)
if not hasattr(self,'orig_pixbuf') or not self.orig_pixbuf: return
if not hasattr(self, 'orig_pixbuf') or not self.orig_pixbuf:
return
pb = self.imageDisplay.get_pixbuf()
iwidth = pb.get_width()
origwidth = self.orig_pixbuf.get_width()
Expand Down Expand Up @@ -1031,7 +1034,7 @@ def save_cb (self, *args):
f'{self.current_rec.title.strip()}')
self.set_edited(False)
self.reccard.new = False
self.reccard.update_recipe(self.current_rec) # update display (if any)
self.reccard.update_recipe(self.current_rec) # update display (if any)
self.rg.update_go_menu()
self.rg.rd.save()

Expand Down

0 comments on commit 57e97a5

Please sign in to comment.