Page 1 of 1
Pick date
Posted: Fri Mar 22, 2024 9:33 am
by GMKai
Is there a nice way to let the user pick a date?
I searched forum and the way to go on AOS/MOS seems to be kind of old and dated (haha).
Of course an option is to setup a special string, or even 3 strings for YMD.
How do you guys let a user pick a date for input with RapaGui?
Re: Pick date
Posted: Fri Mar 22, 2024 2:51 pm
by evil
I wrote a smalll "plugin" for this purpuse.
It includes the GUI, which will be created on demand, and some functions.
This Main-function needs 3 arguments:
The minimum and maximum dates, which are possible and a date, which should be used as default.
The "plugin" opens the gui, and returns the date, selected by the user.
Re: Pick date
Posted: Fri Mar 22, 2024 11:04 pm
by airsoftsoftwair
The reason why RapaGUI doesn't offer a date picker class yet is mostly because AFAIR the OS3/OS4 MUI doesn't have one. MorphOS MUI has one and it's also easily possible on Windows/macOS/Linux but I think MUI on OS3 and OS4 doesn't have it.
Re: Pick date
Posted: Sat Mar 23, 2024 4:13 am
by Redlion
@ all,
Here is a date selection program I did last year ( This is the proof of concept version - the full version has a few more features but is inbedded in a large project and is hard to extract)
Hope you find it helpful.
Code: Select all
/*** Make sure we have at least Hollywood 9.0!*/
@VERSION 9,0
/*** Enable DPI-awareness so that our GUI looks sharp even on high DPI monitors ****************************/
@OPTIONS {DPIAware = True}
/*** This script requires the RapaGUI plugin*/
@REQUIRE "RapaGUI", {Link = True}
/*** Program Information ****************************************************************************/
@APPTITLE "Date Selector"
@APPVERSION "$VER: Date Selector 1.0.0 (16.04.23)"
@APPCOPYRIGHT "(C) 2023 by Leo den Hollander"
@APPAUTHOR "George Leo den Hollander"
@APPDESCRIPTION "Date Selector Example"
Version$ = "1.0.0"
Build$ = "230416"
/*** Setup ESC to exit program ***************************************************************************/
EscapeQuit(True)
/*** Setup Constants ***************************************************************************************/
Const #DAY = 1
/*** Date setup ********************************************************************************************/
LoadBrush(2, "autobutton_lfarrow", {loadalpha=True})
LoadBrush(3, "autobutton_rtarrow", {loadalpha=True})
day$ = GetWeekday()
daynumb = GetDateNum(#DATEDAY)
monthnumb = GetDateNum(#DATEMONTH)
yearnumb = GetDateNum(#DATEYEAR)
currentdate$ = GetDate(True)
currentdate$ = LeftStr(currentdate$, 11)
selday = daynumb
selmonth = monthnumb
selyear = yearnumb
seldate$ = currentdate$
/*** Setup GUI ********************************************************************************************/
moai.CreateApp([[<?xml version="1.0" encoding="iso-8859-1"?>
<application id="app">
<menubar id="mymenubar">
<menu title=" Date ">
<item id="date-select"> Date Selection </item>
</menu>
</menubar>
<window id="mainwin" title=" Date Selector V1.0.0 " margin="0" width="800" height="600" notify="closerequest" menubar="mymenubar">
<vgroup color="#99D2CB">
<rectangle/>
<hgroup>
<hspace width="75"/>
<button id= "clear-select"> Clear </button>
<hspace width="75"/>
<text id="showdate" frame="1"> </text>
<hspace width="75"/>
</hgroup>
<rectangle/>
</vgroup>
</window>
<window title="Calendar" width="200" id="calendar" margin="1" sizegadget="False" closegadget="False" open="false" minimizegadget="False" maximizegadget="False">
<vgroup color="#99D2CB">
<hgroup>
<hspace width="2"/>
<vgroup>
<vspace height="2"/>
<hgroup>
<button id="monthback" fixwidth="true" width="40" icon="2"></button>
<rectangle/>
<text id="calmonth" frame="true" fixwidth="true" width="150" align="Center"></text>
<rectangle/>
<button id="monthforward" fixwidth="true" width="40" icon="3"></button>
</hgroup>
<hline/>
<colgroup columns="7">
<label align="Center" fixwidth="true" width="40">S</label>
<label align="Center" fixwidth="true" width="40">M</label>
<label align="Center" fixwidth="true" width="40">T</label>
<label align="Center" fixwidth="true" width="40">W</label>
<label align="Center" fixwidth="true" width="40">T</label>
<label align="Center" fixwidth="true" width="40">F</label>
<label align="Center" fixwidth="true" width="40">S</label>
<button id="cal_1" fixwidth="true" width="40"></button>
<button id="cal_2" fixwidth="true" width="40"></button>
<button id="cal_3" fixwidth="true" width="40"></button>
<button id="cal_4" fixwidth="true" width="40"></button>
<button id="cal_5" fixwidth="true" width="40"></button>
<button id="cal_6" fixwidth="true" width="40"></button>
<button id="cal_7" fixwidth="true" width="40"></button>
<button id="cal_8" fixwidth="true" width="40"></button>
<button id="cal_9" fixwidth="true" width="40"></button>
<button id="cal_10" fixwidth="true" width="40"></button>
<button id="cal_11" fixwidth="true" width="40"></button>
<button id="cal_12" fixwidth="true" width="40"></button>
<button id="cal_13" fixwidth="true" width="40"></button>
<button id="cal_14" fixwidth="true" width="40"></button>
<button id="cal_15" fixwidth="true" width="40"></button>
<button id="cal_16" fixwidth="true" width="40"></button>
<button id="cal_17" fixwidth="true" width="40"></button>
<button id="cal_18" fixwidth="true" width="40"></button>
<button id="cal_19" fixwidth="true" width="40"></button>
<button id="cal_20" fixwidth="true" width="40"></button>
<button id="cal_21" fixwidth="true" width="40"></button>
<button id="cal_22" fixwidth="true" width="40"></button>
<button id="cal_23" fixwidth="true" width="40"></button>
<button id="cal_24" fixwidth="true" width="40"></button>
<button id="cal_25" fixwidth="true" width="40"></button>
<button id="cal_26" fixwidth="true" width="40"></button>
<button id="cal_27" fixwidth="true" width="40"></button>
<button id="cal_28" fixwidth="true" width="40"></button>
<button id="cal_29" fixwidth="true" width="40"></button>
<button id="cal_30" fixwidth="true" width="40"></button>
<button id="cal_31" fixwidth="true" width="40"></button>
<button id="cal_32" fixwidth="true" width="40"></button>
<button id="cal_33" fixwidth="true" width="40"></button>
<button id="cal_34" fixwidth="true" width="40"></button>
<button id="cal_35" fixwidth="true" width="40"></button>
</colgroup>
<hline/>
<text id="selecteddate" align="Center" weight="50"></text>
<hline/>
<hgroup>
<button id="calok" weight="25">OK</button>
<button id="calcancel" weight="25">Cancel</button>
</hgroup>
</vgroup>
<hspace width="2"/>
</hgroup>
<vspace height="3"/>
</vgroup>
</window>
</application>]])
/***********************************************************************************************************/
/*** Date & Calendar ***************************************************************************************/
/***********************************************************************************************************/
/************************************************************************************************ Calendar */
Function Display_Calendar()
selmonth = GetDateNum(#DATEMONTH)
selYear = GetDateNum(#DATEYEAR)
Update_Calendar()
EndFunction
/************************************************************************************************ Calendar */
Function Update_Calendar()
dy = 0
If selmonth = 1
yearday = 0
monthdays =31
EndIf
If selmonth = 2
yearday = 31
monthdays = 28
EndIf
If selmonth = 3
yearday = 59
monthdays = 31
EndIf
If selmonth = 4
yearday = 90
monthdays = 30
EndIf
If selmonth = 5
yearday = 120
monthdays = 31
EndIf
If selmonth = 6
yearday = 151
monthdays = 30
EndIf
If selmonth = 7
yearday = 181
monthdays = 31
EndIf
If selmonth = 8
yearday = 212
monthdays = 31
EndIf
If selmonth = 9
yearday = 243
monthdays = 30
EndIf
If selmonth = 10
yearday = 273
monthdays = 31
EndIf
If selmonth = 11
yearday = 304
monthdays = 30
EndIf
If selmonth = 12
yearday = 334
monthdays = 31
EndIf
yr = selyear
yr = yr - 2000
leapyear = Int(yr/4)
If Mod(yr,4) = 0
If yearday >= 59
yearday = yearday + 1
EndIf
Else
leapyear = leapyear + 1
EndIf
totaldays = (yr*365) + leapyear + dy + yearday
an = Mod(totaldays,7)
If an = 0 Then an = 7
For dd = 1 To 35
moai.Set("cal_"..StrStr(dd), "Text", "")
Next
For dd = 1 To monthdays
xx = (an-1) + dd
If xx > 35 Then xx = xx -35
moai.Set("cal_" .. StrStr(xx), "Text", PadNum(StrStr(dd),2))
Next
If selmonth = 1 Then CalMonth$ = "January"
If selmonth = 2 Then CalMonth$ = "Februrary"
If selmonth = 3 Then CalMonth$ = "March"
If selmonth = 4 Then CalMonth$ = "April"
If selmonth = 5 Then CalMonth$ = "May"
If selmonth = 6 Then CalMonth$ = "June"
If selmonth = 7 Then CalMonth$ = "July"
If selmonth = 8 Then CalMonth$ = "August"
If selmonth = 9 Then CalMonth$ = "September"
If selmonth = 10 Then CalMonth$ = "October"
If selmonth = 11 Then CalMonth$ = "November"
If selmonth = 12 Then CalMonth$ = "December"
moai.Set("calmonth", "Text", CalMonth$ .. " " .. StrStr(selyear))
moai.Set("selecteddate", "Text", SelDate$)
EndFunction
/*************************************************************************************** Set Selected Date */
Function Selected_Date(Button$)
SelectedDate$ = selday .. "-" .. LeftStr(CalMonth$, 3) .. "-" .. selyear
If Button$ = "qmonconclude"
moai.Set("qmonconclude", "Text", SelectedDate$)
moai.Set("qmonstatus", "Text", "CONCLUDED")
moai.Set("qmonreviewer", "Text", CurrentUser$)
ElseIf Button$ = "qmonstart"
moai.Set("qmonstart", "Text", SelectedDate$)
ElseIf Button$ = "DueDate"
moai.Set("showdate","text", SelectedDate$)
EndIf
EndFunction
/***********************************************************************************************************/
/*** RAPAGUI Events ****************************************************************************************/
/***********************************************************************************************************/
Function Rapa_Events(msg)
Switch msg.action
Case "RapaGUI"
Switch msg.attribute
Case "Pressed":
If LeftStr(msg.id,4) = "cal_"
selday = moai.Get(msg.id, "text")
moai.Set("selecteddate", "Text", selday .. " " .. LeftStr(CalMonth$,3) .. " "..selyear)
EndIf
Switch msg.id
Case "clear"
SelectedDate$ = ""
moai.Set("showdate","text", SelectedDate$)
;Calendar Screen Buttons - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Case "cal1"
Button$ = "qmonstart"
moai.Set("calendar", "open", True)
moai.Set("calendar", "Title", " MONITORING START DATE - " .. CIMDATA[2])
Display_Calendar()
Case "cal2"
Button$ = "qmonconclude"
moai.Set("calendar", "open", True)
moai.Set("calendar", "Title", " MONITORING CONCLUDE DATE - " .. CIMDATA[2])
Display_Calendar()
Case "calok"
Selected_Date(Button$)
moai.Set("calendar", "open", False)
Case "calcancel"
moai.Set("calendar", "open", False)
SelDate$ = ""
Case "monthback"
If selyear < 2001
D_Message(" Calendar Input Limit ! ", "Sorry", "Calendar only goes back To 2001.")
Else
selmonth = selmonth -1
If selmonth = 0
selmonth = 12
selyear = selyear -1
EndIf
monthnumb = selmonth
Update_Calendar()
EndIf
Case "monthforward"
selmonth = selmonth +1
If selmonth = 13
selmonth = 1
selyear = selyear +1
EndIf
monthnumb = selmonth
Update_Calendar()
EndSwitch
Case "Selected"
Switch Msg.id
;Date - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Case "date-select"
moai.Set("calendar", "open", True)
moai.Set("calendar", "Title", " CHANGE DUE DATE " )
Button$ = "DueDate"
Display_Calendar()
EndSwitch
Case "CloseRequest"
Switch msg.id
Case "mainwin"
moai.Set("mainwin", "Open", False)
End
EndSwitch
EndSwitch
EndSwitch
EndFunction
/*** listen to these events ********************************************************************************/
InstallEventHandler({RapaGUI = Rapa_Events})
Date$ = GetDate(#DATELOCAL)
ToDaysDate$ = LeftStr(Date$, 11)
/*** main loop ********************************************************************************************/
Repeat
WaitEvent
Forever
Have fun
Cheers
Leo
Re: Pick date
Posted: Sun Aug 04, 2024 5:21 pm
by Yvan_Amiga
Thank you for sharing this date selector code. I integrated it in a ToDo-List program I am developin, stil lwork in progress.
Here some screenshots
https://drive.proton.me/urls/KNEZ5ZAGZ0#GJE0wQVNmF7H
I added sliders for time selection.
I mentioned you in the 'About' window to give you credit. Hope this is okay. I only had you User name.
https://drive.proton.me/urls/EXHBQPZRT4#zdMCUDVJAOfm
Re: Pick date
Posted: Mon Aug 05, 2024 5:25 pm
by plouf
airsoftsoftwair wrote: ↑Fri Mar 22, 2024 11:04 pm
The reason why RapaGUI doesn't offer a date picker class yet is mostly because AFAIR the OS3/OS4 MUI doesn't have one. MorphOS MUI has one and it's also easily possible on Windows/macOS/Linux but I think MUI on OS3 and OS4 doesn't have it.
imho a single Os should let the rest "grabbed to the past"
as i understand a date picker exist for
Morphos
windows
linux
macos
android
but NOT aos3
so i think fuction should be implemended, and (optionally) in 68k version date picker can be a simple text input
this way we can have date picker in all oses, and in 68k somthing compatible...