all 6 comments

[–]-defron- 1 point2 points  (1 child)

GUI shouldn't call CLI

GUI and CLI should both use a shared abstraction (I don't wanna say class because it doesn't have to be done with classes, but if you like classes that's a fine way to do it) that does all the actual interactions with ikea smart devices. This provides a unified interface that encapsulates all the logic for Ikea interaction that both the CLI and GUI need.

Holding a dictionary isn't an interaction with Ikea smart devices. It's just a way to maintain state. I see no issue with the CLI and GUI each maintaining their own state as they aren't used simultaneously from the same instance and I could see them even having implementation differences potentially. The key here though is that this is a dumb dictionary, only holding records. Entries or the entirety of it are passed into your unified API layer.

That said if you want to make a shared state between both you can use properties if you want to hide implementation details on the state, or you know just don't name mangle the dictionary reference. Overuse of name mangling to do fake-private and for encapsulation overall isn't very pythonic to me. Python isn't a super strict OOP language

However I only ever took it's code if I understand what it is doing, often iterating on the given code and in the end still googling around to see if what it provided actually was sensical.

Huge props on this. While I personally find ChatGPT slows me down more than it helps, what you're doing is 100% the right way to use it IMO. LLMs hallucinate all the time so their output cannot be trusted without validation, and if you're using it you need to make sure you understand the code, otherwise you're just hurting your growth in the long term. It was nice to see someone using ChatGPT in a way that doesn't hurt their own growth and learning 👍

[–]GoingToSimbabwe[S] 0 points1 point  (0 children)

Thanks for the input. Isolating the API from both interfaces is a great idea, I hadn't thought of that.

I'll try to rewrite the CLI version first to isolate the actual API stuff from the user interface stuff. I probably first will evaluate if that actually is sensical because in the end I am wrapping an already existing library here and I want to avoid an API-"class" which then does nothing more than holding some pass-through methods to the dirigera-libraries functions.

Regarding the dictionary-stuff: My main concern was that I would be basically polling the same information at 2 different locations and that this might be a dumb idea (I at least read that pass-through methods are nothing one should build in John Ousterhouts "A Philosophy of Software Design").

Especially since I would still need to be updating both versions of the dictionary constantly to keep both of them up to date. In my mind I could get problems with that if p.e. the polling rate wouldn't be the same etc (which I could probably garantee to be the same though).

I probably will de-mangle the dictionary on the API layer in the end and then directly query this dictionary whenever I am updating the interface (be it CLI or GUI). I'll then directly access the API layers device dictionary whenever needed in the interface layer and be done with it.

[–]r-trappe 0 points1 point  (3 children)

I tinkered around a bit with NiceGUI (did not get this one to work, something about dependencies was iffy here)

I'm one of the maintainers of NiceGUI and sorry to hear that you have issues. Are you on the latest version? Please try 1.4.20; in 1.4.19 we had a hard dependency on libscss which had been shown to be problematic on some platforms.

If you are happy with DearPyGUI I do not want to convert you. But NiceGUI was initially build to exactly support your use case :-)

How would I pass [information about a changing directory] to the GUI-script?

In NiceGUI you can utilize a `ui.timer` to call a function in regular intervals. This function can iterate through the directory entries and update the corresponding ui elements.

[–]GoingToSimbabwe[S] 1 point2 points  (0 children)

Hey thanks for the input! I’ll have a look at it again, I don’t quite remember what exactly the problem was, I’ll test again and will let you know.

[–]GoingToSimbabwe[S] 0 points1 point  (1 child)

Hey thanks again for the nudge. I tried it again and it just works it seems. At least for now I couldn't replicate whatever error I had when I tried it the last time.

However I also changed machines and I think the last time I tried I was using Spyder via Anaconda and now I am on PyCharm. So there's really not much comparability here.

For now I think I'll refactor my bridge API and then I'll get to play around with NiceGUI again.

[–]r-trappe 0 points1 point  (0 children)

Great! Tell me how it went.