Git Product home page Git Product logo

Comments (1)

tonycpsu avatar tonycpsu commented on June 28, 2024

@ok100 : With apologies for the necro-post here: I have prepared an example that displays what set_focus_valign is supposed to do:

import urwid

palette = [
    ('normal', 'light gray', 'black', '', "light gray", "black"),
    ('focused', 'light blue', 'black', '', "light blue", "black"),
]

class Ui:
    def __init__(self):
        self.header = urwid.Text('Hello World!')
        layout = [
            urwid.AttrMap(
                urwid.Padding(urwid.SelectableIcon(str(n)), left=1, right=1),
                attr_map={}, focus_map={None: "focused"}
            )
            for n in range(100)
        ]
        self.listbox = urwid.ListBox(layout)
        self.statusbar = urwid.Text('statusbar', align='right')
        self.main_frame = urwid.Frame(self.listbox)
        self.main_frame.set_footer(self.statusbar)
        self.mainloop = urwid.MainLoop(
            self.main_frame,
        palette=palette, unhandled_input=self.unhandled_input
        )

    def unhandled_input(self, key):
        if key in ('q', 'Q'):
            raise urwid.ExitMainLoop()
        elif key in ['G']:
            self.listbox.set_focus(2)
            self.listbox.set_focus_valign('bottom')
        elif key in ['0']:
            self.listbox.set_focus(5)
        elif key in ['1']:
            self.listbox.set_focus_valign('top')
            self.listbox._invalidate()
        elif key in ['2']:
            self.listbox.set_focus_valign('middle')
            self.listbox._invalidate()
        elif key in ['3']:
            self.listbox.set_focus_valign('bottom')
            self.listbox._invalidate()

if __name__ == '__main__':
    ui = Ui()
    ui.mainloop.run()

To use it, try to scroll through the lines in the listbox, then type "1", "2", and "3" to change the valign among "top", "middle", "bottom". I believe in your example, there just aren't enough entries in the listbox to fill it on your screen, and it won't fill in the rest with blank space.

from urwid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.