[Gambas-user] Re: Gambas-user digest, Vol 1 #1716 - 6 msgs
Marcel Beekman
marcel at ...1370...
Tue Feb 21 08:56:02 CET 2006
@GuruLounge - Runtime
> After a bit of futzing around I managed to get my apps to work on my
> other machines via YUM gambas-runtime* and gambas-gb-qt*. It installed
> quite a bit of extra packages though.
For Vector Linux Joe1962 has build a runtime package (Gambas 1.0.14 stable).
We could do that for the top 10 distro's.
Kind regards,
Marcel
@Benoit Minisini - DatePicker
> Does anyone have the time to make an equivalent of the DatePicker control, but
> entirely in Gambas?
>
> It would be cool :-)
You can use the code of the datepicker I've written for my latest project.
Create a form with a panel called pnlCalendar and four buttons for next/prev year and next/prev month.
Kind regards,
Marcel
Code:
' Gambas class file
PRIVATE iMonth AS Integer
PRIVATE iThisMonth AS Integer
PRIVATE iThisYear AS Integer
PRIVATE iYear AS Integer
PRIVATE iDay AS Integer
PRIVATE dToday AS Date
PUBLIC SelectedDate AS String
PUBLIC SUB btnDay_Click()
DIM sIdInfo AS String
sIdInfo = LAST.Text
SelectedDate = Right("0" & sIdInfo, 2) & "-" & Right("0" & Str(iMonth+1),2) & "-" & iYear
ME.Hide
END
PRIVATE FUNCTION GetMonthDays(iMonth AS Integer) AS Integer
DIM aiMonth[12] AS Integer
DIM bLeap AS Boolean
DIM iLeap AS Integer
aiMonth[0] = 31
aiMonth[1] = 28
aiMonth[2] = 31
aiMonth[3] = 30
aiMonth[4] = 31
aiMonth[5] = 30
aiMonth[6] = 31
aiMonth[7] = 31
aiMonth[8] = 30
aiMonth[9] = 31
aiMonth[10] = 30
aiMonth[11] = 31
iLeap = (iYear) MOD 4
bLeap = FALSE
IF iLeap = 0 THEN
bLeap = TRUE
ENDIF
IF iMonth = 1 AND bLeap = TRUE THEN
RETURN 29
ELSE
RETURN aiMonth[iMonth]
ENDIF
END
PRIVATE FUNCTION GetMonthName(iMonth AS Integer) AS String
DIM asMonth[13] AS String
asMonth[0] = "Januari"
asMonth[1] = "Februari"
asMonth[2] = "Maart"
asMonth[3] = "April"
asMonth[4] = "Mei"
asMonth[5] = "Juni"
asMonth[6] = "Juli"
asMonth[7] = "Augustus"
asMonth[8] = "September"
asMonth[9] = "Oktober"
asMonth[10] = "November"
asMonth[11] = "December"
RETURN asMonth[iMonth]
END
PRIVATE FUNCTION GetDayName(iDay AS Integer) AS String
DIM asDay[7] AS String
' dutch abrev.
asDay[0] = "Zo"
asDay[1] = "Ma"
asDay[2] = "Di"
asDay[3] = "Wo"
asDay[4] = "Do"
asDay[5] = "Vr"
asDay[6] = "Za"
RETURN asDay[iDay]
END
PUBLIC SUB Button1_Click()
ME.close
END
PRIVATE SUB DisplayMonthYear()
lblMonth.Text = GetMonthName(iMonth) & " " & iYear
END
PRIVATE SUB ShowDays()
DIM lblDay AS Label
DIM i AS Integer
FOR i = 0 TO 6
lblDay = NEW Label(pnlCalendar)
lblDay.X = i * 40 + 60
lblDay.Y = 20
lblDay.Width = 41
lblDay.Height = 28
lblDay.Font.Italic = TRUE
lblDay.Font.Size = 12
lblDay.BackColor = &Hccccff&
lblDay.Border = 1
lblDay.Alignment = 4
lblDay.Text = GetDayName(i)
NEXT
END
PRIVATE SUB ClearCalendar()
DIM hControl AS Control
FOR EACH hControl IN pnlCalendar.Children
Object.Call(hControl, "Delete")
NEXT
END
PRIVATE SUB BuildCalendar()
DIM i AS Integer
DIM iStart AS Integer
DIM iEnd AS Integer
DIM lblDay AS label
DIM btnDay AS button
DIM iY AS Integer
DIM iPos AS Integer
DIM iPrevMonth AS Integer
DIM iNextMonth AS Integer
ClearCalendar()
ShowDays()
DisplayMonthYear()
Button2.Text = "<< " & (iYear - 1)
iPrevMonth = iMonth - 1
IF iMonth = 0 THEN iPrevMonth = 11
Button3.Text = "< " & Left(GetMonthName(iPrevMonth),3) & "."
iNextMonth = iMonth + 1
IF iMonth = 11 THEN iNextMonth = 0
Button4.Text = Left(GetMonthName(iNextMonth),3) & ". >"
Button5.Text = (iYear + 1) & " >>"
iStart = WeekDay(Date(iYear,iMonth+1,1))
iEnd = GetMonthDays(iMonth)
' days of prev month
FOR i = 0 TO iStart - 1
lblDay = NEW Label(pnlCalendar)
lblDay.X = i * 40 + 60
lblDay.Y = 47
lblDay.Width = 41
lblDay.Height = 28
lblDay.BackColor = &Hcccccc&
lblDay.Border = 1
lblDay.Alignment = 4
lblDay.Text = ""
NEXT
' show the days of this month
iY = 47
iPos = iStart - 1
FOR i = 0 TO iEnd
iPos = iPos + 1
IF iPos = 7 THEN
iPos = 0
iY = iY + 27
ENDIF
btnDay = NEW Button(pnlCalendar) AS "btnDay"
btnDay.X = iPos * 40 + 60
btnDay.Y = iY
btnDay.Width = 41
btnDay.Height = 28
btnDay.Font.Bold = TRUE
btnDay.Font.Size = 12
IF iDay = i AND iMonth = iThisMonth AND iYear = iThisYear THEN
btnDay.BackColor = &H00ff00&
ELSE
btnDay.BackColor = &Hffffff&
ENDIF
' btnDay.Alignment = 4
btnDay.Text = Str(i+1)
NEXT
' days of next month
IF iPos > -1 THEN
FOR i = iPos TO 6
lblDay = NEW Label(pnlCalendar)
lblDay.X = i * 40 + 60
lblDay.Y = iY
lblDay.Width = 41
lblDay.Height = 28
lblDay.BackColor = &Hcccccc&
lblDay.Border = 1
lblDay.Alignment = 4
lblDay.Text = ""
NEXT
ENDIF
END
PUBLIC SUB Form_Open()
dToday = Now()
iYear =Year(dToday)
iMonth = Month(dToday) - 1
iDay = Day(dToday) - 1
iThisMonth = iMonth
iThisYear = iYear
BuildCalendar()
END
' next year
PUBLIC SUB Button5_Click()
iYear = iYear + 1
BuildCalendar()
END
' prev year
PUBLIC SUB Button2_Click()
iYear = iYear - 1
BuildCalendar()
END
' next month
PUBLIC SUB Button4_Click()
iMonth = iMonth + 1
IF iMonth = 12 THEN iMonth = 0
BuildCalendar()
END
' prev month
PUBLIC SUB Button3_Click()
iMonth = iMonth - 1
IF iMonth = -1 THEN iMonth = 11
BuildCalendar()
END
More information about the User
mailing list