Python Forum
Is there a datepicker which can be used in combination with the python library urwid? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Is there a datepicker which can be used in combination with the python library urwid? (/thread-12981.html)



Is there a datepicker which can be used in combination with the python library urwid? - AFoeee - Sep-21-2018

Hello,
the module 'npyscreen' has two widgets to pick dates ('DateCombo' and 'TitleDateCombo').

I was told that the python library 'urwid' does not have a date picker, which is due to the complexity.
Unfortunately I could not find such a third-party library.

Although there are projects like 'khal', these are mostly designed as stand-alone applications and not as 'urwid' widgets.

Does anyone know such a project?
If there is no such thing, with which approaches can this lack be compensated?


'urwid.Edit' (basically a text field) has the problem that invalid data can be entered. Although a conversion to 'datetime.date' and exception handling does the trick, this is very clunky.

Here is the 'npyscreen' date picker and the associated source code:

[Image: hpkhL.png]

#! /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()
This question has also been posted on stackoverflow.

Best regards

AFoeee


RE: Is there a datepicker which can be used in combination with the python library urwid? - nilamo - Sep-21-2018

Let me see if I understand the question...

1) You're using urwid for something, which is a console library that emulates windows, sort of like curses.

2) You want a datepicker, that works with urwid, since you're using urwid.

3) I don't know what npyscreen/khal contribute to the question, since they're unrelated to urwid. Unless they're not unrelated to urwid? Was this info provided just so we had a screenshot of what you wish the hypothetical urwid widget looked like?


RE: Is there a datepicker which can be used in combination with the python library urwid? - metulburr - Sep-21-2018

(Sep-21-2018, 08:20 PM)AFoeee Wrote: If there is no such thing, with which approaches can this lack be compensated?
make one yourself for urwid. Once i needed a date picker for Tkinter and there isnt a default one for that. So i was going to make it, but i found one i modified online. See if you can find one that is completed or somewhat completed to modify to have base work already laid out. Then if you do finish it, i would push that to their repo. Im sure they would be happy to merge it.

Im not sure how advanced that is compared to curses. But it seems they have at least a list box at bare minimum. Ideally you would select from the text itself. You can always utilize the calendar module and then select from it.

>>> import calendar as cal
>>> c = cal.TextCalendar(cal.SUNDAY)
>>> s = c.formatmonth(2018,9)
>>> print(s)
   September 2018
Su Mo Tu We Th Fr Sa
                   1
 2  3  4  5  6  7  8
 9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30

>>>



RE: Is there a datepicker which can be used in combination with the python library urwid? - woooee - Sep-21-2018

Quote:Once i (I) needed a date picker for Tkinter and there isnt a default one for that

Thinking that there has to be at least one third party available, activestate was my first stop. There is this program http://code.activestate.com/recipes/580725-tkinter-datepicker-like-the-jquery-ui-datepicker/ No point in reinventing when you can just modify existing code.


RE: Is there a datepicker which can be used in combination with the python library urwid? - AFoeee - Sep-22-2018

Hello,

(Sep-21-2018, 08:50 PM)nilamo Wrote: 3) I don't know what npyscreen/khal contribute to the question, since they're unrelated to urwid. Unless they're not unrelated to urwid? Was this info provided just so we had a screenshot of what you wish the hypothetical urwid widget looked like?

I think I've read somewhere that 'khal' uses 'urwid' (could be wrong). That's why I mentioned it.
The screenshot was included because I'm looking for something visual and thought an image of it would be helpful.

Sorry, I should have made that clearer.

(Sep-21-2018, 09:29 PM)metulburr Wrote: make one yourself for urwid.

I believe that such a project is going to get quite complex and I do not know if I can handle that.
The project would probably also suffer for a long time from teething troubles , that matured projects have already overcome.

(Sep-21-2018, 10:28 PM)woooee Wrote: There is this program http://code.activestate.com/recipes/5807...atepicker/ No point in reinventing when you can just modify existing code.

Thank you, I will evaluate the code and see what I can reuse, in the case that there is no existing date picker project.

Best regards

AFoeee


RE: Is there a datepicker which can be used in combination with the python library urwid? - AFoeee - Nov-18-2018

Hello,

since it seems that the python library urwid does not include a date picker, I wrote one.

It can be installed via pip.

For more information see above linked github wiki entry and the original question on stackoverflow.

Best regards
AFoeee