1. Time And Status Bar
- Posted by Andy Nov 22, 2008
- 1042 views
Hey Guys,
I posted something like this on the old Euforum. However since this is the new one, I kinda have the same problem and forgot how to do it. What I want to do is show the date and time in a status bar on a window. I'm using the win32lib. Also, I'd like the status bar to be split. Can someone give me the code on how to do this? Thanks.
2. Re: Time And Status Bar
- Posted by DerekParnell (admin) Nov 22, 2008
- 1101 views
What I want to do is show the date and time in a status bar on a window. I'm using the win32lib. Also, I'd like the status bar to be split.
Look up the documentation on setSubFields() and setText(). I assume you know how to format the date and time into a string already.
3. Re: Time And Status Bar
- Posted by Andy Nov 23, 2008
- 1006 views
Well I kinda remember, but not much. Could you please give me an example, so I can go from there?
4. Re: Time And Status Bar
- Posted by DerekParnell (admin) Nov 23, 2008
- 1004 views
Well I kinda remember, but not much. Could you please give me an example, so I can go from there?
What is there about the examples in the documentation that you don't understand?
5. Re: Time And Status Bar
- Posted by Andy Nov 23, 2008
- 1030 views
Oh I'm sorry, I forgot there was an example in the win32lib library.
6. Re: Time And Status Bar
- Posted by otterdad Nov 24, 2008
- 1002 views
Oh I'm sorry, I forgot there was an example in the win32lib library.
here's an include file i made to handle auto time bars. hope it helps. call it by using
global procedure Status_Bar_initialize(atom Status_Bar)
-- code based on following: -- Date: Mon 28 19:34 -- From: Greg Haberek <ghaberek at gm?il?com> -- Subject: Re: Display Time & Date In Status Bar include win32lib.ew -- ==================================================================== constant Status_Bar_TimerId = 1 constant DAYS = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"} constant date_year = 1, date_month = 2, date_day = 3, date_hour = 4, date_minute = 5, date_second = 6, date_weekday = 7, date_jul = 8 object status_junk -- ==================================================================== procedure Status_Bar_pause() doEvents(0) end procedure -- ==================================================================== sequence rect procedure Status_Bar_set_sub_fields( integer pSelf, integer pEvent, sequence pParams ) Status_Bar_pause() status_junk = pSelf + pEvent + pParams rect = getClientRect( getMainWindow() ) -- setSubFields ( integer pID, sequence pPartInfo ) -- Defines the sub-fields in a status bar. -- Category: Attributes -- pID must refer to a status bar control. -- pPartInfo is a list of panel size specifiers for each subfield (a.k.a. panel) in the statusbar. -- Each value in this list can be expressed in one of four ways: -- A positive integer refers to the panels absolute right-hand side pixel position -- A negitive integer less than -1. This refers to a right-hand side position relative to the -- window's right-hand edge. -- An atom > 0 and < 1 refers to the panel's width as a fraction of the window's width -- (0.25 means 25% of the window width) -- A sequence (containing one integer) refers to the panel's width in pixels. If the any specification -- has the value -1, it means that this is the last panel and it extends to the right hand edge of the window. -- You can use setText() and getText() to write and read these panels. -- Example: -- setSubFields(SB, {55, {100}, 0.10, {20},-10,-1}) -- This specifies 6 panels. -- The first one's rightedge is at pixel 55. -- The second is 100 pixels wide. -- The third is 10% of the window width. -- The 4th is 20 pixels wide. -- The 5th is 10 pixels in from the window's RHS. -- The last one extends to the window's edge. setSubFields( pSelf, {rect[3]-170, -80, -1} ) end procedure -- ==================================================================== sequence dt, ampm, the_date, the_time procedure setDateTime(atom Status_Bar) Status_Bar_pause() dt = date() ampm = "AM" if dt[date_hour] > 12 then dt[date_hour] -= 12 ampm = "PM" elsif dt[date_hour] = 0 then dt[date_hour] = 12 end if the_date = sprintf( "%s %02d/%02d/%04d", { DAYS[dt[date_weekday]], dt[date_month], dt[date_day], dt[date_year] + 1900 }) the_time = sprintf( "%02d:%02d:%02d %s", { dt[date_hour], dt[date_minute], dt[date_second], ampm } ) setText({Status_Bar, 2}, the_date) setText({Status_Bar, 3}, the_time) end procedure -- ==================================================================== procedure Status_Bar_onTimer( integer pSelf, integer pEvent, sequence pParams ) status_junk = pSelf + pEvent + pParams if pParams[1] = Status_Bar_TimerId then setDateTime(pSelf) end if end procedure -- ==================================================================== procedure Status_Bar_onDestroy (integer self, integer event, sequence params)--params is () status_junk = self + event + params killTimer(self, Status_Bar_TimerId) end procedure -- ==================================================================== global procedure Status_Bar_initialize(atom Status_Bar) -- passes in id to status bar to use Status_Bar_pause() Status_Bar_set_sub_fields(Status_Bar, 0, {}) -- split up status bar and add time and date fields setHandler(Status_Bar, w32HResize, routine_id("Status_Bar_set_sub_fields")) -- set handler for resize setDateTime(Status_Bar) -- set the initial display setTimer(Status_Bar, Status_Bar_TimerId, 1000) -- set auto update timer setHandler(Status_Bar, w32HTimer, routine_id("Status_Bar_onTimer")) -- set timer handler setHandler(Status_Bar, w32HDestroy, routine_id("Status_Bar_onDestroy")) -- set handler to kill timer on exit end procedure -- ====================================================================
7. Re: Time And Status Bar
- Posted by otterdad Nov 24, 2008
- 971 views
one more time
-- code based on following: -- Date: Mon 28 19:34 -- From: Greg Haberek <ghaberek at gm?il?com> -- Subject: Re: Display Time & Date In Status Bar include win32lib.ew -- ==================================================================== constant Status_Bar_TimerId = 1 constant DAYS = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"} constant date_year = 1, date_month = 2, date_day = 3, date_hour = 4, date_minute = 5, date_second = 6, date_weekday = 7, date_jul = 8 object status_junk -- ==================================================================== procedure Status_Bar_pause() doEvents(0) end procedure -- ==================================================================== sequence rect procedure Status_Bar_set_sub_fields( integer pSelf, integer pEvent, sequence pParams ) Status_Bar_pause() status_junk = pSelf + pEvent + pParams rect = getClientRect( getMainWindow() ) -- setSubFields ( integer pID, sequence pPartInfo ) -- Defines the sub-fields in a status bar. -- Category: Attributes -- pID must refer to a status bar control. -- pPartInfo is a list of panel size specifiers for each subfield (a.k.a. panel) in the statusbar. -- Each value in this list can be expressed in one of four ways: -- A positive integer refers to the panels absolute right-hand side pixel position -- A negitive integer less than -1. This refers to a right-hand side position relative to the -- window's right-hand edge. -- An atom > 0 and < 1 refers to the panel's width as a fraction of the window's width -- (0.25 means 25% of the window width) -- A sequence (containing one integer) refers to the panel's width in pixels. If the any specification -- has the value -1, it means that this is the last panel and it extends to the right hand edge of the window. -- You can use setText() and getText() to write and read these panels. -- Example: -- setSubFields(SB, {55, {100}, 0.10, {20},-10,-1}) -- This specifies 6 panels. -- The first one's rightedge is at pixel 55. -- The second is 100 pixels wide. -- The third is 10% of the window width. -- The 4th is 20 pixels wide. -- The 5th is 10 pixels in from the window's RHS. -- The last one extends to the window's edge. setSubFields( pSelf, {rect[3]-170, -80, -1} ) end procedure -- ==================================================================== sequence dt, ampm, the_date, the_time procedure setDateTime(atom Status_Bar) Status_Bar_pause() dt = date() ampm = "AM" if dt[date_hour] > 12 then dt[date_hour] -= 12 ampm = "PM" elsif dt[date_hour] = 0 then dt[date_hour] = 12 end if the_date = sprintf( "%s %02d/%02d/%04d", { DAYS[dt[date_weekday]], dt[date_month], dt[date_day], dt[date_year] + 1900 }) the_time = sprintf( "%02d:%02d:%02d %s", { dt[date_hour], dt[date_minute], dt[date_second], ampm } ) setText({Status_Bar, 2}, the_date) setText({Status_Bar, 3}, the_time) end procedure -- ==================================================================== procedure Status_Bar_onTimer( integer pSelf, integer pEvent, sequence pParams ) status_junk = pSelf + pEvent + pParams if pParams[1] = Status_Bar_TimerId then setDateTime(pSelf) end if end procedure -- ==================================================================== procedure Status_Bar_onDestroy (integer self, integer event, sequence params)--params is () status_junk = self + event + params killTimer(self, Status_Bar_TimerId) end procedure -- ==================================================================== global procedure Status_Bar_initialize(atom Status_Bar) -- passes in id to status bar to use Status_Bar_pause() Status_Bar_set_sub_fields(Status_Bar, 0, {}) -- split up status bar and add time and date fields setHandler(Status_Bar, w32HResize, routine_id("Status_Bar_set_sub_fields")) -- set handler for resize setDateTime(Status_Bar) -- set the initial display setTimer(Status_Bar, Status_Bar_TimerId, 1000) -- set auto update timer setHandler(Status_Bar, w32HTimer, routine_id("Status_Bar_onTimer")) -- set timer handler setHandler(Status_Bar, w32HDestroy, routine_id("Status_Bar_onDestroy")) -- set handler to kill timer on exit end procedure -- ====================================================================
8. Re: Time And Status Bar
- Posted by otterdad Nov 24, 2008
- 988 views
in case the web doesn't cooperate, the file is temporarily located here