It is currently Sat Oct 19, 2019 7:33 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: The progress bar hangs around 5%
PostPosted: Fri Aug 23, 2019 10:35 pm 
Offline
User
User
User avatar

Joined: Tue Jan 04, 2011 6:21 pm
Posts: 73
Good,
there is a problem we need to talk about. A bug I would say.
Run this code and choose a 700MB file (a movie for example).
At home, the progress bar hangs around 5%
WHY ?
It does not make sense ... :evil:

Code:
Declare Lis()

OpenWindow(0, 0, 0, 749, 596+27+20, "MutanteKey 2", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)

Global Repertoire$

ExplorerTreeGadget(1, 11, 73, 230, 280, Repertoire$, #PB_Explorer_NoFiles)
ExplorerListGadget(2, 247,73,490,280, "*.*", #PB_Explorer_NoFolders|#PB_Explorer_NoParentFolder)

Procedure Afficher_fichiers()
  SetGadgetText(2, "")                    ; Vider la liste des fichiers
  Repertoire$ = GetGadgetText(1)          ; Voir quel est le répertoire sélectionné
  SetGadgetText(2, Repertoire$)           ; Remplir la liste avec le répertoire
  SetGadgetText(100, Repertoire$)         ; Remplir la liste avec le répertoire
EndProcedure

BindGadgetEvent(1, @Afficher_fichiers(), #PB_EventType_Change) ; #PB_EventType_LeftClick)
StringGadget(100,50,360,642,20,"")                             ; contient le chemin+fichier complet

ButtonGadget(16, 200, 450,342,20,"Lire le fichier + barre de progression")




Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      End
     
    Case #PB_Event_Gadget
     
      Select EventGadget()
        Case 2 ; Démarrer un d&d           
               ;           If EventType() = #PB_EventType_DragStart
               ;             DragFiles(GetGadgetItemText(2, GetGadgetState(2)), #PB_Drag_Copy)
               ;           EndIf
          Select type
            Case #PB_EventType_LeftClick
              If GetGadgetItemText(2, GetGadgetState(2))<>"Nom"
                Repertoire$=GetGadgetText(2)+GetGadgetItemText(2, GetGadgetState(2))
              EndIf
              SetGadgetText(100, Repertoire$)
          EndSelect
         
        Case 16
         
           Lis()
         
          Select type
            Case #PB_EventType_LeftClick
             
          EndSelect
         
      EndSelect     
     
  EndSelect

Until Evenement = #PB_Event_CloseWindow
End


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



Procedure Lis()

If ReadFile(0, GetGadgetText(100))
longueur_q=Lof(0) : Debug "longueur_q " + longueur_q
ProgressBarGadget(200,  13, 400, 722,  15, 0, longueur_q)
z=0

  For a = 0 To longueur_q       
 
    z+1
    If z>100000
      SetGadgetState   (200, a)
      z=0
    EndIf
   
  Next
  q.q=ReadQuad(0)
  CloseFile(0)

  Beep_(500,500)
  SetGadgetState   (200, 0)
ProcedureReturn 1
Else
  ProcedureReturn 0
EndIf
EndProcedure

_________________
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 5.70LTS - 32 bits


Top
 Profile  
Reply with quote  
 Post subject: Re: The progress bar hangs around 5%
PostPosted: Fri Aug 23, 2019 11:44 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 4:34 pm
Posts: 911
Location: Canada
In your loop that reads the file you are trying to update the ProgressBar but are not allowing Windows to have a slice of time to do it.
You can add a WindowEvent or put your file reading in a Thread.

Code:
    z+1
    If z>100000
      SetGadgetState   (200, a)
      While WindowEvent():Wend  ;<<-----------------------------
      z=0
    EndIf



(This is a quick fix but looking at how you have structured your program so far, you will certainly run into more problems)

_________________
Image Image


Top
 Profile  
Reply with quote  
 Post subject: Re: The progress bar hangs around 5%
PostPosted: Sat Aug 24, 2019 12:02 am 
Offline
Addict
Addict
User avatar

Joined: Thu Feb 09, 2006 11:27 pm
Posts: 2443
You need to call WindowEvent from time to time, so what about using a thread to keep the main event loop alive?
Additionally you may reduce the value of steps within the loop (and so the progress bar maximum) to a fixed value like 1024 or so.

Code:
Declare Lis(dummy)

OpenWindow(0, 0, 0, 749, 596+27+20, "MutanteKey 2", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)

Global Repertoire$

ExplorerTreeGadget(1, 11, 73, 230, 280, Repertoire$, #PB_Explorer_NoFiles)
ExplorerListGadget(2, 247,73,490,280, "*.*", #PB_Explorer_NoFolders|#PB_Explorer_NoParentFolder)

Procedure Afficher_fichiers()
   SetGadgetText(2, "")                    ; Vider la liste des fichiers
   Repertoire$ = GetGadgetText(1)          ; Voir quel est le répertoire sélectionné
   SetGadgetText(2, Repertoire$)           ; Remplir la liste avec le répertoire
   SetGadgetText(100, Repertoire$)         ; Remplir la liste avec le répertoire
EndProcedure

BindGadgetEvent(1, @Afficher_fichiers(), #PB_EventType_Change) ; #PB_EventType_LeftClick)
StringGadget(100,50,360,642,20,"")                             ; contient le chemin+fichier complet

ButtonGadget(16, 200, 450,342,20,"Lire le fichier + barre de progression")
ProgressBarGadget(200,  13, 400, 722,  15, 0, 0)




Repeat
   Select WaitWindowEvent()
   Case #PB_Event_CloseWindow
      End

   Case #PB_Event_Gadget

      Select EventGadget()
      Case 2 ; Démarrer un d&d
         ;           If EventType() = #PB_EventType_DragStart
         ;             DragFiles(GetGadgetItemText(2, GetGadgetState(2)), #PB_Drag_Copy)
         ;           EndIf
         Select type
         Case #PB_EventType_LeftClick
            If GetGadgetItemText(2, GetGadgetState(2))<>"Nom"
               Repertoire$=GetGadgetText(2)+GetGadgetItemText(2, GetGadgetState(2))
            EndIf
            SetGadgetText(100, Repertoire$)
         EndSelect

      Case 16

         CreateThread(@Lis(),#Null)

         Select type
         Case #PB_EventType_LeftClick

         EndSelect

      EndSelect

   EndSelect

Until Evenement = #PB_Event_CloseWindow
End


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



Procedure Lis(dummy)
   
   #Ticks=100
   Protected update
   
   ;If ReadFile(0, GetGadgetText(100))
   ;longueur_q=Lof(0)
   longueur_q=700000000

   SetGadgetAttribute(200,#PB_ProgressBar_Maximum ,longueur_q)
   update=ElapsedMilliseconds()+#Ticks
   
   For a = 0 To longueur_q
      If ElapsedMilliseconds()>update
         SetGadgetState(200, a)
         update=ElapsedMilliseconds()+#Ticks
      EndIf
   Next
   ;q.q=ReadQuad(0)
   ;CloseFile(0)

   Beep_(500,500)
   SetGadgetState   (200, 0)
   ProcedureReturn 1
   ;   Else
   ;      ProcedureReturn 0
   ;   EndIf
EndProcedure


Top
 Profile  
Reply with quote  
 Post subject: Re: The progress bar hangs around 5%
PostPosted: Sat Aug 24, 2019 5:57 am 
Offline
User
User
User avatar

Joined: Tue Jan 04, 2011 6:21 pm
Posts: 73
Thx a lot 8)

_________________
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 5.70LTS - 32 bits


Top
 Profile  
Reply with quote  
 Post subject: Re: The progress bar hangs around 5%
PostPosted: Sat Aug 24, 2019 11:24 am 
Online
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1968
Location: Germany
Don´t update gadget from threads. With Windows work perhaps. With Linux and macOS not work.
Use PostEvent...

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: The progress bar hangs around 5%
PostPosted: Sat Aug 24, 2019 11:33 am 
Offline
User
User
User avatar

Joined: Tue Jan 04, 2011 6:21 pm
Posts: 73
mk-soft wrote:
Don´t update gadget from threads. With Windows work perhaps. With Linux and macOS not work.
Use PostEvent...

I did not understand what you meant and what it would be like in the code ... :!: :?: :?:

_________________
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 5.70LTS - 32 bits


Top
 Profile  
Reply with quote  
 Post subject: Re: The progress bar hangs around 5%
PostPosted: Sat Aug 24, 2019 11:44 am 
Online
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1968
Location: Germany
Windows is doing fine most of the time,
but under Linux and macOS it crashes the program.
Only Windows and Gadgets may be created and changed only in the Main-Scope.

If it is only for windows most functions also go from a thread. The option Threadsafe should be enabled in any case.
But if you want the program to run under Linux, it won't work anymore.

See Signature "ThreadToGUI"

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: mk-soft, VB6_to_PBx and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye