Adding data_change to use to signal to Screenful that save button nedds a litle star
This commit is contained in:
parent
9f16aa999b
commit
1f038e177a
15
src/lib/screenful.py
Normal file
15
src/lib/screenful.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
from browser import window
|
||||
# interface to screenful
|
||||
|
||||
class ScreenfulEmptyShell:
|
||||
def __init__(self):
|
||||
func = lambda: None
|
||||
self.Editor = {"changed": func}
|
||||
|
||||
def screenful():
|
||||
return window.Screenful if window.Screenful else ScreenfulEmptyShell()
|
||||
|
||||
|
||||
def changed():
|
||||
console.log(Screenful, window.Screenful)
|
||||
screenful().Editor.changed();
|
|
@ -25,6 +25,9 @@ class Message:
|
|||
|
||||
return result
|
||||
|
||||
def data_change(self):
|
||||
return True
|
||||
|
||||
def add_arg(self, arg):
|
||||
self._args.append(arg)
|
||||
|
||||
|
@ -36,6 +39,9 @@ class ClickMessage(Message):
|
|||
def on_event(self, event):
|
||||
event.stopPropagation()
|
||||
|
||||
def data_change(self):
|
||||
return False
|
||||
|
||||
|
||||
def msg(message, params):
|
||||
if not issubclass(type(message), Message):
|
||||
|
|
|
@ -22,6 +22,9 @@ class AddToGenericList(NoReset):
|
|||
list_getter = self.get_arg(0)
|
||||
list_getter().append("")
|
||||
|
||||
def data_change(self):
|
||||
return False
|
||||
|
||||
|
||||
class AddToLabelList(NoReset):
|
||||
def update_model(self, model):
|
||||
|
@ -32,6 +35,9 @@ class AddToLabelList(NoReset):
|
|||
# just adding to the copy to show in the modal
|
||||
list_to_add_to.append(thing_to_add)
|
||||
|
||||
def data_change(self):
|
||||
return False
|
||||
|
||||
|
||||
class EditExampleTranslation(Message):
|
||||
def update_model(self, model):
|
||||
|
|
|
@ -20,10 +20,16 @@ class _ModalResetDelayed(Message):
|
|||
def update_model(self, model):
|
||||
model.modal_reset()
|
||||
|
||||
def data_change(self):
|
||||
return False
|
||||
|
||||
|
||||
class ModalNotOkClose(Reset):
|
||||
def update_model(self, model):
|
||||
# msg just creates a callback, need to actually run it!
|
||||
window.setTimeout(lambda: msg(_ModalResetDelayed())(None), 100)
|
||||
|
||||
def data_change(self):
|
||||
return False
|
||||
|
||||
|
||||
|
|
|
@ -13,7 +13,12 @@ def get_translation_location(entry, translation):
|
|||
return (si, ci, ti), (sense, cluster)
|
||||
|
||||
|
||||
class EditTranslation(ClickMessage):
|
||||
class TranslationEditMessage(ClickMessage):
|
||||
def data_change(self):
|
||||
return True
|
||||
|
||||
|
||||
class EditTranslation(TranslationEditMessage):
|
||||
def update_model(self, model):
|
||||
self.translation = self.get_arg(0, Translation)
|
||||
self.old_cluster_idx = self.get_arg(1, int)
|
||||
|
@ -60,7 +65,7 @@ class EditTranslation(ClickMessage):
|
|||
sense.translations.splice(cidx, 1)
|
||||
|
||||
|
||||
class MoveRight(ClickMessage):
|
||||
class MoveRight(TranslationEditMessage):
|
||||
def update_model(self, model):
|
||||
translation = self.get_arg(0, Translation)
|
||||
(_, _, idx), (_, cluster) = get_translation_location(model.entry, translation)
|
||||
|
@ -69,7 +74,7 @@ class MoveRight(ClickMessage):
|
|||
model.translation = None
|
||||
|
||||
|
||||
class MoveLeft(ClickMessage):
|
||||
class MoveLeft(TranslationEditMessage):
|
||||
def update_model(self, model):
|
||||
translation = self.get_arg(0, Translation)
|
||||
(_, _, idx), (_, cluster) = get_translation_location(model.entry, translation)
|
||||
|
@ -78,7 +83,7 @@ class MoveLeft(ClickMessage):
|
|||
model.translation = None
|
||||
|
||||
|
||||
class BinTranslation(ClickMessage):
|
||||
class BinTranslation(TranslationEditMessage):
|
||||
def update_model(self, model):
|
||||
translation = self.get_arg(0, Translation)
|
||||
(_, cidx, tidx), (sense, cluster) = get_translation_location(model.entry, translation)
|
||||
|
@ -90,7 +95,7 @@ class BinTranslation(ClickMessage):
|
|||
model.translation = None
|
||||
|
||||
|
||||
class AddTranslation(EditTranslation):
|
||||
class AddTranslation(TranslationEditMessage):
|
||||
def handle_cluster_change(self, new_cluster_idx, _):
|
||||
# we need to cheat here
|
||||
# sense was actually given in constructor in third place
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import lib.screenful as screenful
|
||||
|
||||
class Update:
|
||||
def __init__(self):
|
||||
self.message_queue = []
|
||||
|
@ -11,6 +13,10 @@ class Update:
|
|||
self.model.reset()
|
||||
break
|
||||
|
||||
for msg in self.message_queue:
|
||||
if msg.data_change():
|
||||
screenful.changed()
|
||||
|
||||
for msg in self.message_queue:
|
||||
msg.update_model(self.model)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user