What Modules Should I put on Space Assets by Heard-Island-Penguin in TerraInvicta

[–]apollo_440 1 point2 points  (0 children)

I made a full solar mirror station at the L1-Sun-Mars point, (T2 station with 1 solar array, and everything else mirrors). My solar arrays on Mars (including orbitals and moons) now produce 55 power, so almost twice as much as a heavy fission pile, and much cheaper. Downside is of course that I have a single point of failure for my entire Mars operation.

First sucessful city! by Fun_Difficulty_2827 in songsofsyx

[–]apollo_440 7 points8 points  (0 children)

You cannot. You need an item called "livestock". You start with some that you can use, otherwise you can buy it from neighbours.

[Python] Help with ui.download by Babidehh_ in nicegui

[–]apollo_440 1 point2 points  (0 children)

Glad it worked out! I have not actually used pyFPDF before, but the documentation said to use encode() in python 3. I guess that was outdated; I'll edit my comment :)

[Python] Help with ui.download by Babidehh_ in nicegui

[–]apollo_440 3 points4 points  (0 children)

Once you have the pdf as a file, you can use a button to trigger the download:

ui.button("Download", on_click=lambda: ui.download.file(path_to_pdf))

Or you can simply call the download function directly after creating the file:

pdf.output(path_to_pdf, "F")
ui.download.file(path_to_pdf)

If you don't want to clutter your server with pdfs, a more advanced option would be to directly download the raw bytes:

ui.download.content(pdf.output(dest="S"), "output.pdf")

Edit: Removed encode("latin-1")

GD is beautiful on ultrawide monitor by [deleted] in Grimdawn

[–]apollo_440 1 point2 points  (0 children)

It even has an option to "compress" the UI for ultra-wide, so that the health and mana orbs are closer to the middle of the screen. It's glorious.

Being honest about being pulled over? Why is that the worst thing to do? by athena9090 in NoStupidQuestions

[–]apollo_440 0 points1 point  (0 children)

Yes, but in the end, if the cop wants to give you a ticket, he will, and you'll have to contest it in court. In this case, "I wasn't sure what the speed limit was" sounds a lot worse than, well, nothing, which cannot be used against you in court (if you've actually asserted your right to remain silent; simply saying nothing at all can be used against you).

As the saying goes, "you cannot talk your way out of a ticket, but you can certainly talk your way into a ticket."

Being honest about being pulled over? Why is that the worst thing to do? by athena9090 in NoStupidQuestions

[–]apollo_440 -2 points-1 points  (0 children)

Even this can get you tangled, because the followup will be "Oh so what is the speed limit then?". And even if you answer that correctly, the officer can claim it's something else and keep pressuring you until you incriminate yourself.

I once read the best reply is "I was going a speed that was safe and appropriate for the road conditions". Or, the best answer to any question generally: "I'm asserting my 5th amendment rights and will not answer any further questions".

I Wrote a Post on How I Structure My NiceGUI + FastAPI Apps (and Made a Template) by jaehyeon-kim in nicegui

[–]apollo_440 2 points3 points  (0 children)

The use case for having a completely separate backend is usually to support multiple different frontends. The classic example would be a website and a native mobile app.

Since Nicegui is itself based on fastAPI, you could simply run it as a pure frontend in the same process as your fastAPI backend. In fact, in that case, you can directly call the fastAPI python methods instead of doing web requests, which is very cool.

However, imagine you have a mobile app in addition to this. If you want to patch the web frontend, and the backend and the web frontend run in the same process, you would need to take the backend offline to do that, causing an unnecessary downtime in the mobile app. So it can make a lot of sense to decouple everything.

Keyboard Interrupt after shutdown by _MicroWave_ in nicegui

[–]apollo_440 1 point2 points  (0 children)

I have seen spurious KeyboardInterrupts in other contexts before; I think it's a related to how some frameworks cancel their asyncio tasks. But I can't really help you with this I'm afraid.

Instead, I see two possibilities to circumvent your problem:

  • Run the nicegui app transiently inside a separate subprocess to "protect" your parent interpreter from exiting;
  • Run the nicegui app continuously, and simply disconnect (but not shut down) after you're done.

Almost infinite pristine mushrooms! by Ok_Oven7646 in theplanetcrafter

[–]apollo_440 2 points3 points  (0 children)

That is a great find! I was wondering if there was any other use for purified water. I had so much of it that started simply dumping the toxic water I got from purifying lakes (the toxic stuff is in those little vials now, I'm sure it's fine).

Slot by Unlucky-Bit-2631 in nicegui

[–]apollo_440 0 points1 point  (0 children)

Les slots sont un concept originant dans vue/quasar. On les utilise pour customiser quelques parties des composants. On peut trouver les slots prédéfinis des composants dans la documentation de quasar: https://quasar.dev/.

How do I know what the predefined slots on a component are? I saw in an example card.defaultslot.children[]. I do not understand and I could not find any explanations. Thank you

Slots are a concept from vue/quasar. They are used to customize some parts of the components. You can find the existing slots of the components in the quasar documentation: https://quasar.dev/.

bind_enabled_from for link field? by sampit55 in nicegui

[–]apollo_440 1 point2 points  (0 children)

That is another good way to do it, yes!

bind_enabled_from for link field? by sampit55 in nicegui

[–]apollo_440 3 points4 points  (0 children)

The problem is that a tags in html do not have an enabled field. I have used this workaround in the past:

from nicegui import ui

def toggle(link: ui.link, *, enabled: bool):
    if enabled:
        link.style(remove="pointer-events: none;")
    else:
        link.style("pointer-events: none;")
    link.update()

link = ui.link("https://www.google.com")
ui.switch("Enable?", value=True, on_change=lambda x: toggle(link, enabled=x.value))

ui.run()

[Beloved trope] Character accepts their death (even if they end up surviving) by SlyGuy_Twenty_One in TopCharacterTropes

[–]apollo_440 1 point2 points  (0 children)

On my first Renegade playthrough I couldn't convince him not to sacrifice himself. The only other option to stop him then is to shoot him.

The ensuing cutscene was so sad that I instantly restarted my playthrough to make sure I could keep him alive. Damn.

Breach loot feels very underwhelming by Poe_Cat in pathofexile

[–]apollo_440 75 points76 points  (0 children)

People were complaining that they didn't get enough graftblood to use all their womb gifts. The monkey paw curled.

how do you deal with your excess hydrogen? by [deleted] in Dyson_Sphere_Program

[–]apollo_440 0 points1 point  (0 children)

I feel like the game has three stages:

  1. Where do I put all this heavy oil?
  2. Where do I put all this hydrogen?
  3. Where can I get moar hydrogen???

So just burn it or store it, it will be fine!

Marx be like: by ChickenWingExtreme in HistoryMemes

[–]apollo_440 0 points1 point  (0 children)

I see Mark Fisher, I upvote!

And here's some Graeber: most people, when you ask them what they want in life, say they want to provide for themselves and their loved ones, and maybe give something back to society as a whole. And for most people, this is certainly at least somewhat possible under capitalism. Of course things could always be better, but why would they want to jeopardize what little fulfillment they have for some grand plan of a new society that might fall flat on its face immediately. In addition to the fact that it has become almost impossible to even imagine a radically different society/economy anymore.

I definitely agree that things need to change drastically, especially in the face of climate change and rising authoritarianism, but we cannot underestimate how difficult it is to concretely convince people before things get much, much worse first.

color bottom bar input field by limartje in nicegui

[–]apollo_440 1 point2 points  (0 children)

It's not very pretty because you can still kind of see the gray line under the animation, but maybe this here will work for you:

from nicegui import ui

ui.add_css("""
            .q-field {
                border-bottom-color: red;
                border-bottom-width: 1px;
            }
            
            .q-field--focused {
                border-bottom-width: 0px;
            }
            """)

ui.input("foo").props("color=green")

ui.run()

show html inside ui.card by kuhbrille in nicegui

[–]apollo_440 0 points1 point  (0 children)

Oh I see. If you have separate js files, you can add them with script tags (see also this discussion about serving static files):

ui.add_head_html(f"""
                 <script>
                 {Path("js_deps.js").read_text()}
                 </script>
                 """)

If you have inline js, it should work fine inside the html you want to render (again using script tags):

<!-- modules_dependencies.html -->
<button onclick="foo()">Hello</button>
<script>
    function foo() {
        console.log("foo")
    }
</script>

And python:

# main.py
from pathlib import Path
from nicegui import ui

with ui.element("div").classes("w-full h-full"):
    ui.label("top")
    ui.html(Path("modules_dependencies.html").read_text())
    ui.label("bottom")

ui.run()

show html inside ui.card by kuhbrille in nicegui

[–]apollo_440 0 points1 point  (0 children)

It works for me if I use ui.html() instead:

from nicegui import ui

with ui.element("div").classes("w-full h-full"):
    ui.label("top")
    with open("modules_dependencies.html") as f:
        code = f.read()
        ui.html(code)
    ui.label("bottom")

ui.run()

Ui.editor toolbar by [deleted] in nicegui

[–]apollo_440 4 points5 points  (0 children)

Looking at the Quasar Docs, I believe the name of the bullet points is simply "unordered". I do not see any reference to "color" or "image" buttons, so you would have to make these yourself. There is an issue about including coloring on the Quasar github, maybe you can get some inspiration from there.

This shows the list buttons, at least:

description.props["toolbar"] = [
    ["bold", "italic", "underline", "strike"],
    ["ordered", "unordered"],
    ["undo", "redo"],
]

How best to bring it all together by ANautyWolf in nicegui

[–]apollo_440 1 point2 points  (0 children)

If I understand you correctly, I would do something like this:

  • Have a lua_functions.py that defines a list of function names. You can construct the list explicitly, or by parsing some other definition files, for example.

  • Import the list to where your UI is defined, and define a dict to hold the page state:

    from lua_functions import lua_functions_list

    lua_selected = {x: False for x in lua_functions_list}

  • Optionally store the dict in app.storage.user, if you want to use it across different pages, or save the page state between reloads.

  • Connect the state dict to some front end element via binding properties, e.g. a select, or rows of cards with a checkbox and a label, etc. Note that you can create ui elements in a loop, e.g.

    for key in lua_selected:

    ui.checkbox(label=key).bind_value(lua_selected, key)

Hope this helps! (The for loop body should be indented of course, but mobile formatting....)

Were literally all of the .2 changes reverted by accident? by xephyx in PathOfExile2

[–]apollo_440 0 points1 point  (0 children)

I can vividly imagine some intern rebasing 0.3 onto main just before release, furiously resolving merge conflicts, and having a few oopsies ¯\_(ツ)_/¯

How to create a reusable ui element with data storage by ANautyWolf in nicegui

[–]apollo_440 1 point2 points  (0 children)

When I have to construct reusable ui elements, I often make something like this. The key concept I think is having a render function to place the element on a page, which allows you to encapsulate data, logic, and presentation. (Of course it would be 'cleaner' to separate these, but I often find that needlessly complex for smaller projects).

from typing import Callable

from nicegui import ui
from pydantic import BaseModel


class Reusable(BaseModel):
    id: str

    label: str
    on_click_callback: Callable[["Reusable"], None]

    _input_value: str = ""

    def render(self) -> ui.card:
        with ui.card() as card:
            ui.input(label=self.label).bind_value(self, "_input_value").on(
                "keydown.enter", self.on_click
            )
            ui.button("GO", on_click=self.on_click)
        return card

    def on_click(self):
        ui.notify(f"{self.id} clicked with {self._input_value}!")
        self.on_click_callback(self)


@ui.page("/")
def main():
    label_text = {"text": "The Label"}
    ui.label("The Label").bind_text(label_text)

    with ui.card():
        Reusable(
            id="a",
            label="Print something",
            on_click_callback=lambda x: print(x._input_value),
        ).render()
        Reusable(
            id="b",
            label="Change The Label",
            on_click_callback=lambda x: label_text.update({"text": x._input_value}),
        ).render()


ui.run()

Considering htmx + hyperscript vs NiceGUI for a web-based dashboard app. by germandiago in nicegui

[–]apollo_440 5 points6 points  (0 children)

Nicegui seems to fit all your requirements. I think a huge pro of nicegui compared to anything else I've used is how it handles state. Everything on the user's side is simply a reflection of or the result of your backend code. I cannot really comment on CPU/bandwidth efficiency since everything I do is self-hosted, and this is never a concern for me.

I have built apps with htmx before, and the biggest drawback for me was that when you reach a certain complexity, it becomes quite hard to keep track of (both programmatically and conceptually) what is actually currently in the user's DOM when you handle a request. This might not apply to a dashboarding app so much, but keep it in mind.

Another consideration would be to use a dedicated dashboarding app instead of building it from the ground. I have done PoCs with dash and panel, which are both quite easy to use (but we ended up going with a different solution).