Skip to content

Commit

Permalink
Use rec_editor in RecCard
Browse files Browse the repository at this point in the history
  • Loading branch information
cydanil committed Jun 24, 2020
1 parent a30c793 commit c842f6e
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions gourmet/reccard.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ def __init__ (self, refid, title):
class RecCard (object):

def __init__ (self, rg=None, recipe=None, manual_show=False):
if not rg:
if rg is None:
from .GourmetRecipeManager import get_application
rg = get_application()
self.rg = rg
self.re: Optional[RecEditor] = None
self.rec_editor: Optional[RecEditor] = None
self.conf = []
self.new = False
if not recipe:
Expand All @@ -73,8 +73,8 @@ def __init__ (self, rg=None, recipe=None, manual_show=False):

def set_current_rec (self, rec):
self.__current_rec = rec
if self.re is not None:
self.re.current_rec = rec
if self.rec_editor is not None:
self.rec_editor.current_rec = rec
if hasattr(self,'recipe_display'):
self.recipe_display.current_rec = rec

Expand All @@ -87,13 +87,13 @@ def get_current_rec (self):
"Recipe in the recipe card")

def get_edited(self) -> bool:
if self.re is not None and self.re.edited:
if self.rec_editor is not None and self.rec_editor.edited:
return True
return False

def set_edited (self, val):
if self.re is not None and self.re.edited:
self.re.edited = bool(val)
def set_edited(self, val) -> None:
if self.rec_editor is not None and self.rec_editor.edited:
self.rec_editor.edited = bool(val)
edited = property(get_edited,set_edited)

def show_display (self):
Expand All @@ -106,11 +106,12 @@ def show_edit(self, module: Optional[str] = None) -> None:
`module` is the string definition of one of the RecEditor's tabs, as
defined in RecEditor.module_tab_by_name."""
if self.re is None:
self.re = RecEditor(self, self.rg, self.current_rec, new=self.new)
if self.rec_editor is None:
self.rec_editor = RecEditor(self, self.rg,
self.current_rec, new=self.new)
if module:
self.re.show_module(module)
self.re.present()
self.rec_editor.show_module(module)
self.rec_editor.present()


def delete (self, *args):
Expand All @@ -120,8 +121,9 @@ def update_recipe (self, recipe):
self.current_rec = recipe
if hasattr(self,'recipe_display'):
self.recipe_display.update_from_database()
if self.re is not None and not self.re.window.is_visible():
self.re = None
if (self.rec_editor is not None and
not self.rec_editor.window.is_visible()):
self.rec_editor = None

def show (self):
if self.new:
Expand All @@ -131,8 +133,9 @@ def show (self):

def hide (self):
if ((not (hasattr(self,'recipe_display') and self.recipe_display.window.get_property('visible')))
and
(self.re is not None and not self.re.window.is_visible())):
and
(self.rec_editor is not None and
not self.rec_editor.window.is_visible())):
self.rg.del_rc(self.current_rec.id)

# end RecCard
Expand Down Expand Up @@ -2839,9 +2842,9 @@ def inverse (self):
self.inverse_action()


def add_with_undo(rc: 'RecCard', method: Callable):
idx = rc.re.module_tab_by_name["ingredients"]
ing_controller = rc.re.modules[idx].ingtree_ui.ingController
def add_with_undo(editor_module: IngredientEditorModule, method: Callable):
idx = editor_module.re.module_tab_by_name["ingredients"]
ing_controller = editor_module.re.modules[idx].ingtree_ui.ingController
uts = UndoableTreeStuff(ing_controller)

def do_it ():
Expand Down

0 comments on commit c842f6e

Please sign in to comment.