Text scroll and time graph

Post Reply
JoséQuintas
Posts: 60
Joined: Tue Feb 09, 2021 4:20 pm

Text scroll and time graph

Post by JoséQuintas »

Image

Image is my MySQL backup from harbour.
I do not think how to do this on fivewin.

Graph routine is simple, I update each second, to do not slow proccess.

Code: Select all | Expand

/*
ZE_GRAFTEMPO - GRAFICOS DE PROCESSAMENTO
1990.05 - José Quintas
*/

#include "inkey.ch"
#include "set.ch"

#define GRAFMODE 1
#define GRAFTIME 2
#define GRAF_SEC_OLD  1
#define GRAF_SEC_INI  2
#define GRAF_TXT_BAR  3
#define GRAF_TXT_TEXT 4

FUNCTION GrafProc( nRow, nCol )

   THREAD STATIC GrafInfo := { 1, "X" }
   LOCAL mSetDevice

   hb_Default( @nRow, MaxRow() - 1 )
   hb_Default( @nCol, MaxCol() - 2 )
   IF GrafInfo[ GRAFTIME ] != Time()
      mSetDevice := Set( _SET_DEVICE, "SCREEN" )
      @ nRow, nCol SAY "(" + Substr( "|/-\", GrafInfo[ GRAFMODE ], 1 ) + ")" COLOR SetColorMensagem()
      GrafInfo[ GRAFMODE ] = iif( GrafInfo[ GRAFMODE ] == 4, 1, GrafInfo[ GRAFMODE ] + 1 )
      Set( _SET_DEVICE, mSetDevice )
      GrafInfo[ GRAFTIME ] := Time()
   ENDIF

   RETURN .T.

FUNCTION GrafTempo( xContNow, xContTotal )

   THREAD STATIC aStatic := { 0, 0, "", "" }
   LOCAL nSecondsNow, nSecondsRemaining, nSecondsElapsed, nCont, nPos, cTxt, cCorAnt
   LOCAL nPercent, cTexto, mSetDevice

   xContNow := iif( xContNow == NIL, "", xContNow )
   IF Empty( aStatic[ GRAF_TXT_BAR ] )
      aStatic[ GRAF_TXT_BAR ] := Replicate( ".", MaxCol() )
      FOR nCont = 1 to 10
         nPos := Int( Len( aStatic[ GRAF_TXT_BAR ] ) / 10 * nCont )
         cTxt := lTrim( Str( nCont, 3 ) ) + "0%" + Chr(30)
         aStatic[ GRAF_TXT_BAR ] := Stuff( aStatic[ GRAF_TXT_BAR ], ( nPos - Len( cTxt ) ) + 1, Len( cTxt ), cTxt )
      NEXT
      aStatic[ GRAF_TXT_BAR ] := Chr(30) + aStatic[ GRAF_TXT_BAR ]
   ENDIF
   mSetDevice := Set( _SET_DEVICE, "SCREEN" )
   DO CASE
   CASE ValType( xContNow ) == "C"
      cTexto                  := xContNow
      aStatic[ GRAF_SEC_INI ] := Int( Seconds() )
   CASE xContTotal == NIL
      nPercent := xContNow
   CASE xContNow >= xContTotal
      nPercent := 100
   CASE xContTotal == 0
      nPercent := 0
   OTHERWISE
      nPercent := xContNow / xContTotal * 100
   ENDCASE
   xContNow   := iif( ValType( xContNow ) != "N", 0, xContNow )
   xContTotal := iif( ValType( xContTotal ) != "N", 0, xContTotal )

   cCorAnt := SetColor()
   SetColor( SetColorMensagem() )
   nSecondsNow := Int( Seconds() )
   IF nPercent == NIL
      aStatic[ GRAF_SEC_OLD ] := nSecondsNow
      Mensagem()
      @ MaxRow(), 0 SAY aStatic[ GRAF_TXT_BAR ]
      aStatic[ GRAF_TXT_TEXT ] := cTexto

   ELSEIF nPercent == 100 .OR. ( nSecondsNow != aStatic[ GRAF_SEC_OLD ] .AND. nPercent != 0 )
      aStatic[ GRAF_SEC_OLD ] := nSecondsNow
      nSecondsElapsed   := nSecondsNow - aStatic[ GRAF_SEC_INI ]
      DO WHILE nSecondsElapsed < 0
         nSecondsElapsed += ( 24 * 3600 ) // Acima de 24 horas
      ENDDO
      nSecondsRemaining := nSecondsElapsed / nPercent * ( 100 - nPercent )
      @ MaxRow()-1, 0 SAY aStatic[ GRAF_TXT_TEXT ] + " " + Ltrim( Transform( xContNow, PicVal(14,0) ) ) + "/" + Ltrim( Transform( xContTotal, PicVal(14,0) ) )
      cTxt := "Gasto:"
      cTxt += " " + Ltrim( Str( Int( nSecondsElapsed / 3600 ), 10 ) ) + "h"
      cTxt += " " + Ltrim( Str( Mod( Int( nSecondsElapsed / 60 ), 60 ), 10, 0 ) ) + "m"
      cTxt += " " + Ltrim( Str( Mod( nSecondsElapsed, 60 ), 10, 0 ) ) + "s"
      cTxt += Space(3)
      cTxt += "Falta:"
      cTxt += " " + Ltrim( Str( Int( nSecondsRemaining / 3600 ), 10 ) ) + "h"
      cTxt += " " + Ltrim( Str( Mod( Int( nSecondsRemaining / 60 ), 60 ), 10, 0 ) ) + "m"
      cTxt += " " + Ltrim( Str( Mod( nSecondsRemaining, 60 ), 10, 0 ) ) + "s"
      @ Row(), Col() SAY Padl( cTxt, MaxCol() - Col() - 4 )
      GrafProc()
      @ MaxRow(), 0 SAY Left( aStatic[ GRAF_TXT_BAR ], Len( aStatic[ GRAF_TXT_BAR ] ) * nPercent / 100 ) COLOR SetColorFocus()
   ENDIF
   SetColor( cCorAnt )
   SET( _SET_DEVICE, mSetDevice )

   RETURN .T.
I can use automatic as example:

Code: Select all | Expand

USE ( file )
GrafTempo( "processing" )
DO WHILE ! Eof()
   GrafTempo( RecNo(), LastRec() )
   SKIP
ENDDO
or

Code: Select all | Expand

USE ( file )
INDEX ON field->x FOR GrafTempo( RecNo(), LastRec() )
or manual

Code: Select all | Expand

USE ( File ) INDEX ( file )
nAtual := 0
nTotal := LastRec()
DO WHILE ! Eof()
   GrafTempo( nAtual++, nTotal )
   SKIP
ENDDO
Image

On minigui I use windows type panel, to me it is like an user control.
It is simple too.

main dialog

Code: Select all | Expand


#include "hmg.ch"
#include "i_altsyntax.ch"

REQUEST HB_CODEPAGE_PTISO

PROCEDURE Main

   LOCAL oControl, aControlList := Array(6), nColor, nRow
   LOCAL nCurrent := 0, nTotal := 100, xDlg := "A"

   DEFINE WINDOW (xDlg) ;
      ROW 0 COL 0 ;
      WIDTH 1024 HEIGHT 768 ;
      TITLE "test" ;
      WINDOWTYPE MAIN ;
      ON INIT SetBackImage( xDlg )

      FOR EACH oControl, nRow, nColor IN aControlList, ;
         { 80, 160, 240, 320, 400, 480 }, ;
         { COLOR_SKYBLUE, COLOR_PERU, COLOR_GOLD, COLOR_VIOLET, COLOR_PEACHPUFF, COLOR_YELLOWGREEN }
         oControl := GraphTime():New( "A", nRow, 10, 500, 50, "working", nColor )
      NEXT

      DEFINE BUTTON BUTTON_1
         ROW      40
         COL      10
         CAPTION      'Click Me!'
         ACTION      AEval( aControlList, { | e | e:SetValues( nCurrent += 2, nTotal ) } )
         DEFAULT      .T.
      END BUTTON

   END WINDOW

   ACTIVATE WINDOW A

   RETURN

FUNCTION SetBackImage( xDlg )

   LOCAL hBrush

   DoMethod( xDlg, "DISABLEUPDATE" )
   DEFINE BKGBRUSH hBrush PATTERN IMAGE "imw10.png" IN ( xDlg )
   DoMethod( xDlg, "ENABLEUPDATE" )
   (hBrush)

   RETURN Nil
The "user control", using window type panel, and textbox over textbox

Code: Select all | Expand

/*
graphtime - graphic with time calculate
*/

#include "hmg.ch"
#include "i_altsyntax.ch"
#include "i_wincolor.ch"
#include "hbclass.ch"

STATIC nWindow := 1

CREATE CLASS GraphTime

   VAR xDlg
   VAR Parent
   VAR cTimeShow   INIT Time()
   VAR nSecondsInit
   VAR nSecondsOld
   VAR cText
   METHOD New( Parent, nRow, nCol, nWidth, nHeight, cTitle, xColor )
   METHOD SetValues( nCurrent, nTotal )

   ENDCLASS

METHOD SetValues( nCurrent, nTotal ) CLASS GraphTime

   LOCAL nSecNow, nSecElapsed, nSecRemaining, nPercent, nNewWidth, cCaption

   nCurrent := Min( nCurrent, nTotal )
   nSecNow := Int( Seconds() )
   IF nSecNow != ::nSecondsOld .AND. nCurrent != 0
      nNewWidth := Int( GetProperty( ::xDlg, "label1", "WIDTH" ) * nCurrent / nTotal )
      SetProperty( ::xDlg, "label3", "WIDTH", nNewWidth )
      ::nSecondsOld := nSecNow

      nSecElapsed   := nSecNow - ::nSecondsInit
      nSecRemaining := nSecElapsed / nCurrent * ( nTotal - nCurrent )
      nPercent := nCurrent * 100 / nTotal
      SetProperty( ::xDlg, "label1", "VALUE", ;
         Ltrim( Str( nCurrent ) ) + "/" + Ltrim( Str( nTotal ) ) + " " + ;
         "Elapsed " + SecToTime( nSecElapsed ) + ;
         " Remain " + SecToTime( nSecRemaining ) )
      cCaption := ::cText + " " + Ltrim( Str( nPercent ) ) + "%"
      SetProperty( ::xDlg, "label2", "VALUE", cCaption )
      SetProperty( ::xDlg, "label3", "VALUE", cCaption )
   ENDIF

   RETURN Nil

METHOD New( Parent, nRow, nCol, nWidth, nHeight, cTitle, xColor ) CLASS GraphTime

   ::cText := cTitle
   ::Parent := Parent
   ::nSecondsInit := Int( Seconds() )
   ::nSecondsOld  := Int( Seconds() )
   ::xDlg := "GTIME" + StrZero( nWindow++, 3 )

   DEFINE WINDOW ( ::xDlg ) ;
      ROW nRow ;
      COL nCol ;
      WIDTH nWidth ;
      HEIGHT nHeight ;
      WINDOWTYPE PANEL

      DEFINE LABEL ( "label1" )
         PARENT ( ::xDlg )
         ROW 10
         COL 10
         VALUE ""
         BORDER .T.
         WIDTH nWidth - 30
         HEIGHT 20
         BORDER .T.
      END LABEL

      DEFINE LABEL ( "label2" )
         PARENT ( ::xDlg )
         ROW 30
         COL 10
         VALUE ::cText
         BORDER .T.
         WIDTH nWidth - 30
         HEIGHT 20
         BORDER .T.
      END LABEL

      DEFINE LABEL ( "label3" )
         PARENT ( ::xDlg )
         ROW 30
         COL 10
         VALUE ::cText
         WIDTH 1
         HEIGHT 20
         BACKCOLOR xColor
         BORDER .T.
      END LABEL
   END WINDOW

   RETURN Self
At momment I do not know what can be used to anything like this on fivewin.
For Graph and for scroll text.

Note: post routines because they can be a reference to new ones.

For MySQL backup I get quantity and record count.

Code: Select all | Expand

   Mensagem( "Fazendo backup da base SQL" )

   WITH OBJECT cnSQL
      :Execute( "SHOW PROCEDURE STATUS WHERE db = DATABASE()" )
      nTotal += :RecordCount()
      :CloseRecordset()
      :Execute( "SHOW FUNCTION STATUS WHERE db = DATABASE()" )
      nTotal += :RecordCount()
      :CloseRecordset()
      :Execute( "SELECT table_name FROM information_schema.TABLES" + ;
         " WHERE table_schema = " + StringSQL( Lower( AppEmpresaApelido() ) ) + ;
         " AND  TABLE_TYPE = 'BASE TABLE'" )
      DO WHILE ! :Eof()
         nTotal += 1
         oTableRec := cnSQL:ExecuteReturnRS( "SELECT COUNT(*) AS QTD FROM " + cnSQL:String( "table_name" ) )
         nTotal += oTableRec:Fields( "QTD" ):Value
         oTableRec:Close()
         :MoveNext()
      ENDDO
      :CloseRecordset()
   ENDWITH

   GrafTempo( "Backup SQL" )
   nAtual := 0

   hFileOutput := fCreate( "backup" + Str( nBackupFileNum, 1 ) + ".sql", FC_NORMAL )
...
GrafTempo( nAtual, nTotal )
...
Note2: at momment I use table, procedure and function, I will add more types when use them.
José M. C. Quintas Brazil
gtwvg, fivewin 24.10 mt, hwgui, mingw 15.0 rc (32 bits)
User avatar
Antonio Linares
Site Admin
Posts: 42551
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 79 times
Contact:

Re: Text scroll and time graph

Post by Antonio Linares »

Dear Jose,

You may use a Meter to show the progress.

For the text scroll you may use a TScrollPanel or a TXBrowse.

Do you allow the user to move up and down on the scrolled text ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
wilsongamboa
Posts: 614
Joined: Wed Oct 19, 2005 6:41 pm
Location: Quito - Ecuador
Been thanked: 5 times

Re: Text scroll and time graph

Post by wilsongamboa »

Dear Jose thnks for your code, I Try your sample and obtain

hbmk2: Error: Función(es) referenciada, no encontrada, pero desconocida:
SETCOLORMENSAGEM(), MENSAGEM(), PICVAL(), SETCOLORFOCUS()
Wilson 'W' Gamboa A
Wilson.josenet@gmail.com
JoséQuintas
Posts: 60
Joined: Tue Feb 09, 2021 4:20 pm

Re: Text scroll and time graph

Post by JoséQuintas »

Function is from my application.
A workaround:

Code: Select all | Expand

FUNCTION Mensagem( cTexto )
   LOCAL cColorOld
   cColorOld := SetColor()
   hb_Default( @cTexto, "" )
   SetColor( SetColorMensagem() )
   Scroll( MaxRow() - 1, 0, MaxRow(), MaxCol(), 0 )
   @ MaxRow() - 1, 0 SAY cTexto
   SetColor( cColorOld )
   RETURN Nil

FUNCTION SetColorMensagem()
   RETURN "W/N"

FUNCTION SetColorFocus()
   RETURN "W/GR+"

FUNCTION PicVal( nLen, nDec )
   LOCAL cPicture
   hb_Default( @nDec, 0 )
   cPicture := Replicate( "9", nLen )
   cPicture := Ltrim( Transform( Val( cPicture ), "999,999,999,999,999" ) )
   IF nDec != 0
      cPicture += "." + Replicate( "9", nDec )
   ENDIF
   cPicture := "@E " + cPicture
   RETURN cPicture
   
Last edited by JoséQuintas on Mon Feb 17, 2025 2:41 pm, edited 1 time in total.
José M. C. Quintas Brazil
gtwvg, fivewin 24.10 mt, hwgui, mingw 15.0 rc (32 bits)
JoséQuintas
Posts: 60
Joined: Tue Feb 09, 2021 4:20 pm

Re: Text scroll and time graph

Post by JoséQuintas »

Antonio Linares wrote: Tue Feb 11, 2025 10:24 pm Do you allow the user to move up and down on the scrolled text ?
On most cases no.
- my server send eletronic factura mail, check new post codes, and others
- application update structures (dbf or mySQL)
- applicatin makes backup/zip of DBF and MySQL
- On application using dbf, I show each file pack/index
- application Import from XMLs - here is interesting up/down, because I inform about changed codes and others
At momment I remember about these ones.
José M. C. Quintas Brazil
gtwvg, fivewin 24.10 mt, hwgui, mingw 15.0 rc (32 bits)
Post Reply