1. Cesar Lirato
  2. PowerBuilder
  3. Monday, 20 July 2020 01:50 AM UTC

Good night from Peru, dear appeon community.
I want to develop a program, that it able show a clock and get hour,minute and second; when user press a button.
The clock able be of two types: circle clock and digital clock.
I'am using PB 17.
Thanks.

Daryl Foster Accepted Answer Pending Moderation
  1. Monday, 27 July 2020 05:26 AM UTC
  2. PowerBuilder
  3. # 1

There is an example of an analog clock in the PB Examples project that comes with Powerbuilder.  It's under the User Objects treeview item in the running project.  The userobject is called u_analog_clock in the pbexamuo.pbl

Comment
There are no comments made yet.
Johann Lessmann Accepted Answer Pending Moderation
  1. Friday, 24 July 2020 14:09 PM UTC
  2. PowerBuilder
  3. # 2
Hi Cesar,
 
here comes my quick approach for an analog clock. It is an port from an C# snippet into the PB-World and it is not tested :-)
 
I used an UO inherited from datawindow.
 
What you need to do is:
 -use the source below for the UO
 -create a Datawindow "d_clock" with 3 line objects l_hr, l_min, l_sec and set
 -insert in your window timer event "uo_clock.of_show(now())"
 
 
 
Hope this helps,
Johann
 
/////Source of the UO /////
forward
global type u_dw_clock from datawindow
end type
end forward
global type u_dw_clock from datawindow
integer width = 1143
integer height = 840
string title = "none"
string dataobject = "d_clock"
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type
global u_dw_clock u_dw_clock
type variables
string is_centerX, is_centerY
string is_pointSecX[60], is_pointSecY[60]
string is_pointMinX[60], is_pointMinY[60]
string is_pointHrX[60], is_pointHrY[60]
long il_secLen
long il_minLen
long il_hrLen
end variables
forward prototypes
public function integer of_show (time at_time)
end prototypes
public function integer of_show (time at_time);long ll_sec, ll_min, ll_hr
string ls_ret
ll_sec = second(at_time)
if ll_sec = 0 then ll_sec = 60
ll_min = minute(at_time)
if ll_min = 0 then ll_min = 60
ll_hr = hour(at_time)
if ll_hr > 11 then
 ll_hr = ll_hr -12
end if
ll_hr = ll_hr * 5
if ll_hr = 0 then ll_hr = 60
ll_hr += long(ll_min / 12)
ls_ret = this.modify( "l_hr.x2='" + is_pointHrX[ll_hr] +"'")
ls_ret = this.modify( "l_hr.y2='" + is_pointHrY[ll_hr] +"'")
ls_ret = this.modify( "l_min.x2='" + is_pointMinX[ll_min] +"'")
ls_ret = this.modify( "l_min.y2='" + is_pointMinY[ll_min] +"'")
ls_ret = this.modify( "l_sec.x2='" + is_pointSecX[ll_sec] +"'")
ls_ret = this.modify( "l_sec.y2='" + is_pointSecY[ll_sec] +"'")
return 1
end function
on u_dw_clock.create
end on
on u_dw_clock.destroy
end on
event constructor;long ll_i, ll_deg, ll_deg_h
long ll_centerX,ll_centerY
long ll_maxlen
string ls_syntax, ls_ret
//Center
ll_centerX = this.width/ 2
ll_centerY = this.height/2
is_centerX = string(ll_centerX)
is_centerY = string(ll_centerY)
ll_maxlen = min(ll_centerX,ll_centerY)
il_SecLen = ll_maxlen * 0.9
il_MinLen = ll_maxlen * 0.85
il_HrLen = ll_maxlen * 0.75
//Fill Arrays
for ll_i = 1 to 60
 ll_deg = ll_i * 6
 if (ll_deg >= 0 and ll_deg <= 180) then
  is_pointSecX[ll_i] = string(ll_centerX + long(il_SecLen * Sin(Pi(1) * ll_deg /180)))
  is_pointSecY[ll_i] = string(ll_centerY - long(il_SecLen * Cos(Pi(1) * ll_deg /180)))
  is_pointMinX[ll_i] = string(ll_centerX + long(il_MinLen * Sin(Pi(1) * ll_deg /180)))
  is_pointMinY[ll_i] = string(ll_centerY - long(il_MinLen * Cos(Pi(1) * ll_deg /180)))
  is_pointHrX[ll_i] = string(ll_centerX + long(il_HrLen * Sin(Pi(1) * ll_deg /180)))
  is_pointHrY[ll_i] = string(ll_centerY - long(il_HrLen * Cos(Pi(1) * ll_deg /180)))
 else
  is_pointSecX[ll_i] =  string(ll_centerX - long(il_SecLen * -Sin(Pi(1) * ll_deg /180)))
  is_pointSecY[ll_i] =  string(ll_centerY - long(il_SecLen * Cos(Pi(1) * ll_deg /180)))
  is_pointMinX[ll_i] =  string(ll_centerX - long(il_MinLen * -Sin(Pi(1) * ll_deg /180)))
  is_pointMinY[ll_i] =  string(ll_centerY - long(il_MinLen * Cos(Pi(1) * ll_deg /180)))
  is_pointHrX[ll_i] =  string(ll_centerX - long(il_HrLen * -Sin(Pi(1) * ll_deg /180)))
  is_pointHrY[ll_i] =  string(ll_centerY - long(il_HrLen * Cos(Pi(1) * ll_deg /180)))
 end if
next
ls_ret = this.modify("l_hr.X1 = '"+ is_centerX +"'"  )
ls_ret = this.modify("l_hr.Y1 = '"+ is_centerY +"'"  )
ls_ret = this.modify("l_hr.X2 = '"+ is_pointHrX[1] +"'"  )
ls_ret = this.modify("l_hr.Y2 = '"+ is_pointHrY[1]  +"'"  )
ls_ret = this.modify("l_min.X1 = '"+ is_centerX +"'"  )
ls_ret = this.modify("l_min.Y1 = '"+ is_centerY +"'"  )
ls_ret = this.modify("l_min.X2 = '"+ is_pointMinX[1] +"'"  )
ls_ret = this.modify("l_min.Y2 = '"+ is_pointMinY[1]  +"'"  )
ls_ret = this.modify("l_sec.X1 = '"+ is_centerX +"'"  )
ls_ret = this.modify("l_sec.Y1 = '"+ is_centerY +"'"  )
ls_ret = this.modify("l_sec.X2 = '"+ is_pointSecX[1] +"'"  )
ls_ret = this.modify("l_sec.Y2 = '"+ is_pointSecY[1]  +"'"  )
return 1
end event

//// END////////

 

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Monday, 20 July 2020 15:02 PM UTC
  2. PowerBuilder
  3. # 3

Greetings, Cesar -

For a digital clock, you might consider obtaining a "digital display segment" TrueType font (.ttf). A web search shows there several you can download. Some are free for personal use and some are not. Some are free for commercial use and some are not. It appears there are many different styles to choose from.

For an analog clock, consider drawing your own. A filled-in circle, lines for the hour, minute and second hands, text labels for the hour numbers. The challenge is performing the math to calculate the X,Y coordinates of the line endpoints. It's not impossible, but it's not trivial, either. The complexity depends on the size, appearance and sophistication of what you are trying to render, whether you want to use this in a DataWindow or in a Window, does it "run" (tick second-by-second) or not, how would you indicate A.M. or P.M., etc., none of which you described in your post.

Regards, John

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 20 July 2020 14:50 PM UTC
  2. PowerBuilder
  3. # 4

Hi Ceasar;

  My framework has the ability to add a User Object to any Menu's toolbar. The UO can contain as many child UO or Control's within it. Below is an example of a UO that has a DataWindow, CB and DDLB within it. The DWO is displaying as a digital clock, as follows:

Is this something that you could use for the digital clock?

Regards ... Chris

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.