Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    proskur1n
    @proskur1n
    I am thinking about sending a pull request to urwid, but as far as I am concerned, the signal() behaviour differs from platform to platform. Therefore, I don't know if my solution will work on other platforms.
    Neil Pilgrim
    @neiljp
    Some features don't work for us directly (something in windows for indirect screen updates? #240) so maybe that's not critical, or could be checked and handled better. We also have a workaround for WSL due to #264, though that seems to be terminal-specific. Some of these look like being fixed by something like #448 though?
    I'm not sure if that all assumes WSL(2 now?), which may support signals?
    proskur1n
    @proskur1n
    By other platforms, I meant MacOS and BSD. I do not support Windows at all, as my application relies heavily on urwid.Terminal, which will probably never get ported to Windows.
    Neil Pilgrim
    @neiljp
    Ah right, I forget there are those issues too.
    Sarthak Garg
    @Ezio-Sarthak

    Hi all! I'm working on adding something like a placeholder text to an edit box. (inheriting urwid.Edit). I'm finding it tricky to style the placeholder text, as the edit_text couldn't be styled as of now (?).

    I guess if we somehow revert the places of caption and edit_text as specified in the Edit widget, this might be resolved; The caption being placeholder text, simply handled through connect_signal locally.

    We could maybe add it as a boolean parameter, something like suffix_caption?

    I'm looking forward to opening an issue/PR for the same upon feedback :)

    voidtrance
    @voidtrance

    I am having trouble getting the Overlay widget to work. I want to use it to display a single question box and I am using the following code:

    text = urwid.Text(prompt)
    buttons = [("weight", 1, urwid.Button(x, get_selection, choices.index(x)) for x in choices]
    colums = urwid.Columns(buttons)
    pile = urwid.Pile([("pack", text), columns])
    box = urwid.LineBox(pile)
    overlay = urwid.Overlay(box, frame.contents["body"], "center", ("relative", 40), "middle", ("relative", 20))
    frame.contents["body"] = overlay

    However, I get an ValueError when urwid is trying to render the buttons in the Columns widget because the Text("<") widget for the button is a flow widget but size argument to its render() method is a two-element tuple. What is the proper way to use Overlay()?

    voidtrance
    @voidtrance
    I came up with a small working example of the issue that I am having with the Overlay() widget:
    import urwid
    
    selected = 0
    
    def get_selection(*args):
        selected = True
    
    def show_overlay(*args):
        prompt = "This is a test prompt"
        choices = ["OK", "Cancel"]
        text = urwid.Text(prompt)
        buttons = [("weight", 1, urwid.Button(x, get_selection, choices.index(x)))
                   for x in choices]
        columns = urwid.Columns(buttons)
        pile = urwid.Pile([("pack", text), columns])
        box = urwid.LineBox(pile)
        frame = args[1]
        overlay = urwid.Overlay(
            box, frame.contents["body"][0], "center", ("relative", 40), "middle", ("relative", 20))
        frame.contents["body"] = (overlay, None)
    
    
    show_button = urwid.Button("show")
    main_pile = urwid.Pile([urwid.Text("This is the main body"),
                            show_button])
    filler = urwid.Filler(main_pile)
    frame = urwid.Frame(filler)
    urwid.connect_signal(show_button, "click", show_overlay, frame)
    loop = urwid.MainLoop(frame, unhandled_input=urwid.ExitMainLoop)
    loop.run()
    voidtrance
    @voidtrance
    Well, it turns out that the issue is with the vertical sizing. pack works, ("relative", X) works if X <=7, and given height work if the height is <=3.
    voidtrance
    @voidtrance
    How can I make an Overlay widget modal? I want the even loop to continue running but I don't want my application to "block" until the Overlay is "destroyed".
    Neil Pilgrim
    @neiljp
    You can check out how we do it in zulip-terminal; it needs some tidying, but basically we toggle the loop.widget from a quick read of the code.
    voidtrance
    @voidtrance
    @neiljp I'll try to read the code. Can you give me a pointer on where that is handled?
    voidtrance
    @voidtrance
    Nvmd. Found it.
    voidtrance
    @voidtrance
    @neiljp I played with the loop.widget but that doesn't really do what I wanted. I guess what I meant is that I want something line Gnome's Dialog boxes that block the main application while the dialog is up. My guess is that they accomplish this with a separate event loop. Does zulip-terminal's implementation do the main application blocking that I am trying to describe?
    Neil Pilgrim
    @neiljp
    It seems to work for us, yes.
    voidtrance
    @voidtrance
    So, if I have a function calling controller.show_pop_up(), controller.show_pop_up() will not return until the popup is destroyed?
    Neil Pilgrim
    @neiljp
    I've not tested that directly, but the active UI becomes the "top" widget.
    voidtrance
    @voidtrance
    Yes, I can replicate the "active UI" behavior - only the popup is getting keystrokes. However, the "caller" is not blocked, which prevents a normal dialog sematics and would require some fancy signalling/callbacks.
    Mr-Mime
    @Mr-Mime_gitlab

    Hi all :)
    I am a bit lost, trying to get a key press for the following widget.
    In all previous widgets I had some kind of walkableList or Edit field, but this one only has "displaying" widgets.
    If I press ESC or "b" nothing happens.
    If I add an urwid.Edit in the msg_pile it works (pressing "b" adds a line).

    import urwid
    
    class TestWidget(urwid.WidgetWrap):
        def __init__(self):
            msg_pile =  urwid.Pile([urwid.Text("Connecting to emonio...")])
    
            content = urwid.BoxAdapter(urwid.LineBox(urwid.Filler(msg_pile, height="flow", valign="top"), title="Preparing"), 19)
            key_hints = urwid.Text("ESC - quit | b - back", align="center")
    
            self._w = urwid.Pile([content, key_hints])
            self.run()
    
        def run(self):
            self.add_new_line("Adding a test line...")
    
        def keypress(self, size, key):
            if key == "esc":
                raise urwid.ExitMainLoop()
            elif key == "b":
                self.add_new_line("Added a line via keypress()")
    
        def add_new_line(self, text):
            self._w.widget_list[0].original_widget.original_widget.original_widget.widget_list.append(urwid.Text(text))
    
    widget = urwid.Padding(urwid.Filler(TestWidget(), valign="top", height="flow", top=3), align="center", width=47)
    loop = urwid.MainLoop(widget)
    loop.run()

    I am thinking that it is because it has no widget, which reacts to any key, so no key event is passed all the way up to my TestWidget.

    PS: I am happy for each hint/ suggestion for improvement, as I am relatively new to urwid and still learning ;)

    mimansa-dev
    @mimansa-dev
    When I dynamically add more radio widgets to a group then should the display refresh automatically to show the newly added radio buttons
    ?
    r_button = urwid.RadioButton(g_radio_button_group, 'Hi', False, on_state_change=on_mode_button)
    locn_list_options = urwid.GridFlow(g_radio_button_group, 15, 3, 1, 'left')
    substitute_screen_pile = urwid.Pile([locn_list_options])
    For some reason, the only radio button is the one that i added in the beginning even though the program dynamically adds some more to g_radio_button_group (I confirmed it by logging the g_radio_button_group variable to file). What could be wrong?
    mimansa-dev
    @mimansa-dev
    I have created a simple minimum program to explain my error. The code is at https://pastebin.com/naK29hhR
    Anything can be entered on the first two input prompts to continue with the program flow. As we can see that on line 114 I am adding additional radio buttons to the group but they don't show up when we run the program and pass through the first two screens. Only the very first radio button with the text Hi shows up. Please guide.
    7 replies
    Mr-Mime
    @Mr-Mime_gitlab

    Hi all :)
    I am a bit lost, trying to get a key press for the following widget.
    In all previous widgets I had some kind of walkableList or Edit field, but this one only has "displaying" widgets.
    If I press ESC or "b" nothing happens.
    If I add an urwid.Edit in the msg_pile it works (pressing "b" adds a line).

    To answer my own question, I once again read the docs.
    This time I understood, that _selectable needs to be true, so that a keypress will be handled.

    So I set _selectable = True to for my widget and now it works :)

    mimansa-dev
    @mimansa-dev
    Could someone please help me with a urwid script? The code is at https://pastebin.com/zFzqTuGE
    I get an error AttributeError: 'ListBox' object has no attribute 'rows' and not sure why. Cannot seem to figure out. To run this script enter any value on the input field prompt.
    Niteesh Babu G S
    @gs-niteesh
    If I have to copy-paste multiline text in Edit widget what will be the right option?
    I tried using the Edit widget with multiline option, but then If I hit enter it adds a new line to the text inside of pushing the text
    If I disable the multiline option, on pasting the text on a new line it updates it.
    voidtrance
    @voidtrance
    If I have a ListBox of Buttons, the highlighted button decoration disappears when I change focus to a different widget. Is there a way to keep a button highlighted when the focus is on a different widget?
    raj86in
    @raj86in
    Hi I am new to urwid would appreciate any help. For our linux system we recently updated urwid library from 1.2.1 to 2.1.2 and python 2.7.9 to 3.7.8 . After that the output of the program is getting printed on serial port instead of LCD which was working fine before the updates. Is there any configuration/setup I am missing in urwid?
    milad.a
    @milad.a:matrix.org
    [m]
    are there good examples of how people handle prints in a urwid application for debugging purposes? I want the gui thread to halt when I call print in another thread otherwise I don't actually see the prints
    1 reply
    SquirrelCZE
    @SquirrelCZE
    hi folks, I am misunderstanding something, I have a 'Columns' widget of my custom widgets that are _selectable
    when I press left/right arrow the columns correctly changes the focus between the widgets
    the problem is: I try to change the way it renders if it is in focus by changing 'div_char' of Divider present there, but it is never redrawn
    any tips?
    the widget looks like this https://paste.vpsfree.cz/4JF78nAj/
    in the render() I try to change the way it renders by changing the char of divider, but no effect is visible
    SquirrelCZE
    @SquirrelCZE
    oh now I see it, I have to invalidate the divider
    SquirrelCZE
    @SquirrelCZE
    so, one more question: how to properly clear columns?
    I have a ListBox that contains three Columns widgets (effectively making thre rows of widgest on the screen)
    when event happens, I content.clear() all the columns and generate new set of widgets
    however, if one is not filled again and is empty, I get this error:
    IndexError: No focus_position, Columns is empty
    any ideas/
    ?
    Cielo
    @cielong
    Is there any example of how to properly use the event loop? And is it possible to add a callback (not watching a file descriptor and then trigger) after the main loop starts and in general how do one trigger data reload using the event loop?
    Dejan Lekic
    @dejlek_twitter
    Is there a generic implementation of a dialog that can show arbitrary form?