代码之家  ›  专栏  ›  技术社区  ›  AFoeee

python库“urwid”是否包含用于读取日期的小部件(datepicker)?

  •  1
  • AFoeee  · 技术社区  · 6 年前

    npyscreen 有小部件吗 "DateCombo" and "TitleDateCombo" 用于挑选日期。

    如果没有,是否有推荐的第三方库?

    下面是一个使用npyscreen的示例:

    enter image description here

    #! /usr/bin/env python3
    # -*- coding: utf-8 -*-
    
    import npyscreen
    
    class DateForm(npyscreen.Form):
        def afterEditing(self):
            self.parentApp.setNextForm(None)
    
        def create(self):
            self.date = self.add(npyscreen.TitleDateCombo, name="Date")
    
    class TestApplication(npyscreen.NPSAppManaged):
        def onStart(self):
            new_user = self.addForm("MAIN", DateForm, name="Read Date")
    
    if __name__ == "__main__":
        TestApplication().run()
    
    2 回复  |  直到 6 年前
        1
  •  2
  •   AFoeee    6 年前

    似乎python库 urwid

    additional_urwid_widgets.DatePicker pip .

    Demonstration of date picker #1 Demonstration of date picker #2


    为了一个 独立示例 ,它演示了小部件的功能,请参见 here .

    更多(更简单) ,请参见 here .

    再来一次 详细说明 有关参数和选项的详细信息,请参见 the corresponding github wiki entry .



    一些例子

    最小

    #! /usr/bin/env python3
    # -*- coding: utf-8 -*-
    
    from additional_urwid_widgets import DatePicker, MODIFIER_KEY      # installed via pip
    import urwid                                                       # installed via pip
    
    # Color schemes that specify the appearance off focus and on focus.
    PALETTE = [("reveal_focus", "black", "white")]
    
    dp = DatePicker(highlight_prop=("reveal_focus", None))        # By default, the focused picker is not highlighted!
    
    pile = urwid.Pile([urwid.Text("press additionally the key modifier (default is 'ctrl')."),
                       urwid.Divider(" "),
                       dp])
    
    loop = urwid.MainLoop(urwid.Filler(pile, "top"),
                          PALETTE)
    loop.run()
    

    Demonstration of example 'Minimal'


    今天不行

    #! /usr/bin/env python3
    # -*- coding: utf-8 -*-
    
    import datetime
    from additional_urwid_widgets import DatePicker, MODIFIER_KEY      # installed via pip
    import urwid                                                       # installed via pip
    
    # Color schemes that specify the appearance off focus and on focus.
    PALETTE = [("reveal_focus", "black", "white")]
    
    not_today = datetime.date(2018, 2, 20)
    
    dp = DatePicker(initial_date=not_today,
                    highlight_prop=("reveal_focus", None))        # By default, the focused picker is not highlighted!
    
    pile = urwid.Pile([urwid.Text("press additionally the key modifier (default is 'ctrl')."),
                       urwid.Divider(" "),
                       dp])
    
    loop = urwid.MainLoop(urwid.Filler(pile, "top"),
                          PALETTE)
    loop.run()
    

    Demonstration of example 'Not today'


    ISO-8601+样式+紧凑型

    #! /usr/bin/env python3
    # -*- coding: utf-8 -*-
    
    import calendar
    from additional_urwid_widgets import DatePicker, MODIFIER_KEY      # installed via pip
    import urwid                                                       # installed via pip
    
    # Color schemes that specify the appearance off focus and on focus.
    PALETTE = [("dp_barActive_focus",       "light gray",       ""),
               ("dp_barActive_offFocus",    "black",            ""),
               ("dp_barInactive_focus",     "dark gray",        ""),
               ("dp_barInactive_offFocus",  "black",            ""),
               ("dp_highlight_focus",       "black",            "brown",   "standout"),
               ("dp_highlight_offFocus",    "white",            "black")]
    
    dp = DatePicker(month_names=[str(i).zfill(2) for i in range(13)],
                    day_format=[DatePicker.DAY_FORMAT.DAY_OF_MONTH_TWO_DIGIT],
                    columns=((6, DatePicker.PICKER.YEAR), (4, DatePicker.PICKER.MONTH), (4, DatePicker.PICKER.DAY)),
                    min_width_each_picker=4,
                    space_between=1,
                    topBar_endCovered_prop=("ᐃ", "dp_barActive_focus", "dp_barActive_offFocus"),
                    topBar_endExposed_prop=("───", "dp_barInactive_focus", "dp_barInactive_offFocus"),
                    bottomBar_endCovered_prop=("ᐁ", "dp_barActive_focus", "dp_barActive_offFocus"),
                    bottomBar_endExposed_prop=("───", "dp_barInactive_focus", "dp_barInactive_offFocus"),
                    highlight_prop=("dp_highlight_focus", "dp_highlight_offFocus"))
    
    pile = urwid.Pile([urwid.Text("press additionally the key modifier (default is 'ctrl')."),
                       urwid.Divider(" "),
                       dp])
    
    loop = urwid.MainLoop(urwid.Filler(pile, "top"),
                          PALETTE)
    loop.run()
    

    Demonstration of example 'ISO-8601 + Styled + Compact'

        2
  •  1
  •   Elias Dorneles    6 年前

    不,urwid没有datepicker,它是一个需要实现的复杂的小部件,应该有自己的项目,因为这些小部件通常需要考虑日期格式、语言环境等。

    我不知道有哪一个urwid库实现了它,通过快速扫描我知道的那些库也找不到。

    您可以尝试购买一个库,但您可能会有更好的运气实现一个自己的具体需要。

    推荐文章