Gtkdialog calendar widget - sort of

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

Gtkdialog calendar widget - sort of

#1 Post by MochiMoppel »

Recent threads here and here covered the (busybox) cal command and attempts to replace this tool or find a meaningful purpose for it. I always wondered why this little tool even exists as I could never see a reason to use this CLI calendar. I finally do.

There are plenty of GUI based calendars and most of them use the GtkCalendar widget. Dialog programs like Xdialog and yad support it with their --calendar options. Not so gtkdialog. Though most standard dialogs like file chooser, font chooser and color picker are implemented, the calendar dialog is not.

I therefore tried to construct a gtkdialog based calendar, as a replacement for igucal, the program that pops up when I click on the clock in the JWM tray. Igucal is a variant of minixcal. Both are stable, simple and boring. I need a calendar that can be customized with additional functions.

Below is a barebone version of this exercise. The calendar does nothing more that show the current day and can be used as a first step for a more sophisticated version. It is designed to be opened and closed by clicking on the JWM clock but of course can be opened in any other way. It basically displays the output of the cal command. The script does not use tmp files. All tmp values are kept in hidden text widgets. The script also uses no button widgets, instead makes use of entry widgets and their primary/secondary buttons. Finally I restricted the mark for the current day on the current month/year. In GtkCalendar the day keeps marked even when month or year are changed. I find this odd.
Attachments
mm_cal.gz
Version 2019-01-30
To run script: Unzip script and make executable
(1.53 KiB) Downloaded 244 times
tray_calendars.png
(43.58 KiB) Downloaded 574 times
Last edited by MochiMoppel on Wed 30 Jan 2019, 10:50, edited 1 time in total.

some1
Posts: 117
Joined: Thu 17 Jan 2013, 11:07

#2 Post by some1 »

MM: I had a hunch/hope you would implement a calendar in GTKDIALOG. We need that.

Perhaps also a dropdown/notebook-calendar -variant.

I will take a look at the proto/barebone
---

goingnuts
Posts: 932
Joined: Sun 07 Dec 2008, 13:33
Contact:

#3 Post by goingnuts »

For inspiration: I played with the calendar widget and posted source here.
Source is gtk1 though... :)

wiak
Posts: 2040
Joined: Tue 11 Dec 2007, 05:12
Location: not Bulgaria

#4 Post by wiak »

goingnuts wrote:For inspiration: I played with the calendar widget and posted source here.
Source is gtk1 though... :)
I wish I hadn't found myself just downloading that source code... I'm worried I will decide not to retire from further programming afterall. The problem is, I feel that Puppy Linux in particular tends to use little C programs that are not otherwise well-maintained or supported, or only by their sole authors (such as JWM, ROX-Filer etc, mtpaint, and gtkdialog). I feel therefore that the more Puppy members that take the time to learn a bit C programming (with some, but not a lot Gtk-related knowledge) the better - but... so much effort goes into bash-only (with gtkdialog/yad scripting for gui); if only some of these scripters would put in even a little of their time to mastering a bit C/gtk then they could help future-proof these efficient little C/gtk programs (I'm sure some of these quite expert scripters could be equally good at C/GTK fiddling). I did a little core C-related stuff, but could (should?) have done more, whilst I was able (in terms of maintaining the C skills required..., which I tend to forget over medium-short time alas). Still, I love seeing a bit activity in this C/gtk-related area continuing here on the forum; I notice from other post that work still being done on ROX-filer too, though only one contributer to that too it seems. Team projects naturally inspire more longterm confidence so many thanks to those Puppyists out their that keep the C-programming flags flying!

Anyway, I'm too happy to be out of the programming mindset - have much more time for other pursuits obviously; still, programming was a bit of a drug/stimulant (though feedback not always exactly complimentary or encouraging - some negative attitudes out there too sadly; why? Shouldn't really need encouragement, I suppose... :-) and some feedback very polite and encouraging anyway! Thanks, especially when my own efforts/results were often very much less than perfect... ;-) ).

wiak

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#5 Post by MochiMoppel »

some1 wrote:Perhaps also a dropdown/notebook-calendar -variant.
Frankly, I have no clue what you have in mind. Maybe you can explain.

Speaking of "dropdown": I just want to mention that the GtkCalendar widget (the one in Xdialog, yad, igucal etc.) allows drag&drop of dates. Don't know if many people have noticed that. Individual dates in the calendar can not only be clicked (which makes little sense for the current tray calendars), they can also be dragged out and dropped into another application. The dragged date is formatted according to the locale's date representation (e.g., 01/27/2019). This is a trick that my poor-man's calendar is unable to do.

Another feature not implement in mm_cal are the the grayed out dates of the preceding and following month. It wouldn't be impossible but I figured that the considerable amount of code required is not worth the result. I suspect that their main purpose is to fill the gaps rather than being useful. A full 2 months calendar may be more useful and probably easier to achieve.

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#6 Post by zigbert »

Great stuff MochiMoppel!
I've made a link in the tips and tricks thread.

Thank you!

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#7 Post by MochiMoppel »

You're welcome and thanks for the link.

Now a shock :shock: : Today I discovered that I can't switch the calendar label to February. Now it's "Jan" and it is supposed to switch to "Feb" when I click on the arrow button, but it switches to "Mar". Calendar is updated correctly to February and other labels work fine, only "Feb" doesn't work. Strange because I swear it worked before. Is it only me?

The problem is the busybox date command. In line 39
It is supposed to convert a month number to the locale's abbreviated month name. Works for all numbers - except the number 2:
  • # busybox date -d 1 -D %m +%b
    Jan
    # busybox date -d 2 -D %m +%b
    Mar
    # busybox date -d 3 -D %m +%b
    Mar
    # busybox date -d 4 -D %m +%b
    Apr
What's going on here?

Before someone asks: The reason why I use busybox date is the nice -D option, which is not available in the GNU date version. However it is possible to use GNU date and it even works correctly, so I will change the command once I have confirmed that it is indeed a busybox bug.

[Edit] With different options busybox seems to work fine:
  • # busybox date -d 1999-1-1 -D %F +%b
    Jan
    # busybox date -d 1999-2-1 -D %F +%b
    Feb
    # busybox date -d 1999-3-1 -D %F +%b
    Mar

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#8 Post by SFR »

It seems that when you're using %m alone, the day is automatically assumed to be today and since there is no 2019-02-29:
# busybox date -d 1 -D %m
Tue Jan 29 00:00:00 CET 2019
#
# busybox date -d 2 -D %m
Fri Mar 1 00:00:00 CET 2019
#
# busybox date -d 3 -D %m
Fri Mar 29 00:00:00 CET 2019
#
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#9 Post by MochiMoppel »

:!: Thanks SFR.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#10 Post by MochiMoppel »

The problem I see with busybox date is that it tends to convert unrecognized formats into unpredictable dates instead of honestly reporting an "invalid date" error:
  • # date -d "1999-2-1"
    Mon Feb 1 00:00:00 JST 1999
    # busybox date -d "1999-2-1"
    Tue Oct 6 21:59:00 JST 2020
    # busybox date -d "1999-100"
    Tue Oct 6 23:00:00 JST 2020
    # busybox date -d "1999-99"
    date: invalid date '1999-99'
I think I'll settle for a format that is acceptable to busybox and GNU versions alike. This should work even in cases when date is symlinked to busybox:
  • # date -d "1999-1-1 00:00" +%b
    Jan
    # date -d "1999-2-1 00:00" +%b
    Feb
    # date -d "1999-3-1 00:00" +%b
    Mar
I have updated the script accordingly (see initial post).

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#11 Post by Argolance »

Hello,
Thank you MochiMoppel!
Just for fun: displaying your calendar as desktop application using gtk2desklet...

Cordialement.
Attachments
190202_120024_230x177_easyshot.jpg
(6.41 KiB) Downloaded 210 times

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#12 Post by don570 »

mm_cal.gz worked in Tazpuppy beta19 with gtkdialog 0.8.4

________________________________________________

Post Reply