Toma400 / Librerian

Universal library manager for all types of art
Other
3 stars 1 forks source link

Classpath issue and iteration over Entry values #12

Open Toma400 opened 2 years ago

Toma400 commented 2 years ago

So, as of creating DB3, I faced the issue of object comparisons wielding different outcomes. This means that this function:

def return_attr(entry: Entry.subclasses, limit: type = None):
    temp_instance = entry(); atrlist = [attr for attr in dir(temp_instance) if not callable(getattr(temp_instance, attr)) and not attr.startswith("__")]
    retlist = []
    if limit is not None:
        for i in atrlist:
            if type(temp_instance.return_val(i)) == limit: retlist.append(i)
        return retlist                              #| they are returned as strings, so use return_val to use fully
    return atrlist

returns two differently named classpaths, making comparison not possible (therefore, return always results in empty list) not because classes are different, but because they have weirdly different classpath. So, one cannot iterate in such way in layout menu:

def entryadd_layout(user, entry: Entry.subclasses):
    layvals = []; tempcl = entry()
    vallist = return_attr(entry, Value)
    for i in vallist: #| iterates over all Value typed attrs to make their own sections on window
        if "__" in entry.entry_langkey:                                                                                                      #------------------------
            layval = [                                                                                                                       # NATIVE ENTRIES HANDLING
                gui.Text(langtxt(tempcl.i.tr_key, lang), text_color=mn_text, background_color=mn_back),
                gui.In(size=(25, 1), enable_events=True, key=f":{tempcl.i.val_idf}EntryFileCreate")
            ]
        else:                                                                                                                                #------------------------
            layval = [                                                                                                                       # PLUGIN ENTRIES HANDLING
                gui.Text(tempcl.interior_langkey(self=tempcl, key=tempcl.i.tr_key, lang=lang), text_color=mn_text, background_color=mn_back),
                gui.In(size=(25, 1), enable_events=True, key=f":{tempcl.i.val_idf}EntryFileCreate")
            ]
        layvals.append(layval)
    layout = [
        [
            gui.Titlebar(m["name"], text_color=tt_text, background_color=tt_back, icon=fpath)
        ],
        [
            layvals
        ],
        [
            [gui.Button(langtxt("entry__confirm", lang), key=":EntryCreate")],
            [gui.Button(langtxt("entry__return", lang), key=f":{entry.folder_key}EntryButton")]
        ]
    ]
    return layout

because vallist is always empty.

The idea for now is a bit of workaround - we need to create another function which would behave like it iterates only through Value object, calling its unique variable (we would call it in special way), and to differentiate it from other objects, we will make it bound to try/except scheme. So, we will iterate over list of variables, but if except is risen, we skip it.

This will be put as next commit, with old function being @Deprecated, and nextly, removed. It is asked to put name of this issue for the commit, though, so it is easier to track the progress.

Eventually, there should be some sort of cleaning of the code - so, this issue will be closed when this parameter is set properly, not in such awful way.

Toma400 commented 2 years ago

This, eventually, failed. Look at those commits to see the difference (mostly on entries_manag module)

Toma400 commented 2 years ago

Current idea to implement: let's switch all Value objects into simple dictionary, and let's make return_attr use similar syntax as with open, meaning you input string to get specific return mode. Value Dict could have specific name part (just like "__" is done for separating vanilla and plugin translation keys) or just have one more value being readen, or whatever. It should be bitta different because we have already custom translation dict and any supporting dicts can appear later as well.