It is currently Thu Mar 21, 2019 10:42 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Module ThreadToGUI-Update windows,gadgets,... from threa
PostPosted: Fri Feb 17, 2017 1:59 am 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5780
Location: Wales, UK
This is very fine work. It would be good to see these functions incorporated into PB. What do you think Fred?

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: Module ThreadToGUI-Update windows,gadgets,... from threa
PostPosted: Wed Jun 28, 2017 10:52 am 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1617
Location: Germany
Update v1.14
- Added Clipboard functions. On Linux crashed clipboard functions over threads
- Added Requester
- Added check AllocateStructure() and CreateSemaphore()

The functions without return values give a success (1) if the event is successfully entered. Not that the event was processed in the Mainscope.
Do not want the thread blocked ...

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


Last edited by mk-soft on Sat Jul 08, 2017 7:08 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Module ThreadToGUI-Update windows,gadgets,... from threa
PostPosted: Sat Jul 08, 2017 7:07 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1617
Location: Germany
Update v1.15
- Added more Requester
- Update OpenFileRequester
- Optimize code

Added Input, Color and Font Requester.

Example Requester
Code:
;-TOP

; Example ThreadToGUI Requester

IncludeFile "Modul_ThreadToGUI.pb"

Enumeration
  #Window
EndEnumeration

Enumeration
  #List
EndEnumeration

;- Constants
Enumeration #PB_Event_FirstCustomValue
  #My_DoEvent
EndEnumeration

Procedure Test(Null)
 
  Protected result, path.s
 
  UseModule ThreadToGUI
 
  DoAddGadgetItem(#List, -1, "Start Thread")
  Delay(500)
  result = DoMessageRequester("MessageRequester", "Question", #PB_MessageRequester_YesNoCancel | #PB_MessageRequester_Info)
  Select result
    Case #PB_MessageRequester_Yes
      DoAddGadgetItem(#List, -1, "Message result yes")
    Case #PB_MessageRequester_No
      DoAddGadgetItem(#List, -1, "Message result no")
    Case #PB_MessageRequester_Cancel
      DoAddGadgetItem(#List, -1, "Message result cancel")
  EndSelect
  path = DoOpenFileRequester("OpenFileRequester", "/", "", 0, #PB_Requester_MultiSelection)
  DoAddGadgetItem(#List, -1, "OpenFile: " + path)
  While path
    path = DoNextSelectedFileName()
    If path
      DoAddGadgetItem(#List, -1, "OpenFile: " + path)
    EndIf
  Wend
  path = DoSaveFileRequester("SaveFileRequester", "Test.txt", "", 0)
  DoAddGadgetItem(#List, -1, "SaveFile: " + path)
  path = DoPathRequester("PathRequester", "/")
  DoAddGadgetItem(#List, -1, "Path: " + path)
  path = DoInputRequester("InputRequester", "Password", "******", #PB_InputRequester_Password)
  DoAddGadgetItem(#List, -1, "Input: " + path)
  result = DoColorRequester()
  DoAddGadgetItem(#List, -1, "Color: " + Hex(Result))
  DoAddGadgetItem(#List, -1, "Exit Thread")
 
EndProcedure

If OpenWindow(#Window, 0, 0, 600, 400, "Example Requester", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
  ListViewGadget(#List, 0, 0, 600, 400)
 
  UseModule ThreadToGUI
 
  BindEventGUI(#My_DoEvent)
  hThread = CreateThread(@Test(), #Null)
 
  Repeat
   
    Select WaitWindowEvent()
       
      Case #PB_Event_CloseWindow
        exit = 1
       
    EndSelect
   
  Until exit
  If IsThread(hThread)
    Debug "Thread läuft"
    KillThread(hThread)
  EndIf
 
EndIf

FontRequester
Code:
;-TOP

; Example ThreadToGUI Requester

IncludeFile "Modul_ThreadToGUI.pb"

Enumeration
  #Window
EndEnumeration

Enumeration
  #List
EndEnumeration

;- Constants
Enumeration #PB_Event_FirstCustomValue
  #My_DoEvent
EndEnumeration

Procedure Test(Null)
 
  Protected result, path.s, message$
 
  UseModule ThreadToGUI
 
  DoAddGadgetItem(#List, -1, "Start Thread")
  Delay(500)
  path = DoOpenFileRequester("OpenFileRequester", "/", "", 0, #PB_Requester_MultiSelection)
  DoAddGadgetItem(#List, -1, "OpenFile: " + path)
  While path
    path = DoNextSelectedFileName()
    If path
      DoAddGadgetItem(#List, -1, "OpenFile: " + path)
    EndIf
  Wend
  result = DoFontRequester("Arial", 12, 0, #Red, #PB_Font_Bold)
  If Result
    Message$ = "Selected Font:"
    DoAddGadgetItem(#List, -1, message$)
    Message$ = "Name:  " + DoSelectedFontName()
    DoAddGadgetItem(#List, -1, message$)
    Message$ = "Size: " + Str(DoSelectedFontSize())
    DoAddGadgetItem(#List, -1, message$)
    Message$ = "Color: " + Str(DoSelectedFontColor())
    DoAddGadgetItem(#List, -1, message$)
    message$ = "Style "
    If DoSelectedFontStyle() & #PB_Font_Italic
      Message$ + "/ Italic"
    EndIf
    If DoSelectedFontStyle() & #PB_Font_Bold
      Message$ + " / Bold"
    EndIf
    If DoSelectedFontStyle() & #PB_Font_StrikeOut
      Message$ + " / StrikeOut"
    EndIf
    If DoSelectedFontStyle() & #PB_Font_Underline
      Message$ + " / Underline"
    EndIf
    DoAddGadgetItem(#List, -1, message$)
  Else
    Message$ = "Cancel."
    DoAddGadgetItem(#List, -1, message$)
  EndIf
  DoAddGadgetItem(#List, -1, "Exit Thread")
 
EndProcedure

If OpenWindow(#Window, 0, 0, 600, 400, "Example Requester", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
  ListViewGadget(#List, 0, 0, 600, 400)
 
  UseModule ThreadToGUI
 
  BindEventGUI(#My_DoEvent)
  hThread = CreateThread(@Test(), #Null)
 
  Repeat
   
    Select WaitWindowEvent()
       
      Case #PB_Event_CloseWindow
        exit = 1
       
    EndSelect
   
  Until exit
  If IsThread(hThread)
    Debug "Thread läuft"
    KillThread(hThread)
  EndIf
 
EndIf

:wink:

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / Event-Designer
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: Module ThreadToGUI-Update windows,gadgets,... from threa
PostPosted: Sat Jul 15, 2017 9:49 am 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1617
Location: Germany
Update v1.16
- Added second module 'ThreadedGUI' with macro to activate threaded gadget commands

Code:
;-TOP

; Comment: Thread To GUI Help Macro
; Author : mk-soft
; Version: v1.17
; Created: 16.07.2016
; Updated: 14.03.2018
; Link En: http://www.purebasic.fr/english/viewtopic.php?f=12&t=66180
; Link De: http://www.purebasic.fr/german/viewtopic.php?f=8&t=29728

; ***************************************************************************************

;- Begin Module Macros

DeclareModule ThreadedGUI
 
  ; Macros switch to ThreadToGUI
 
  ; Window
  Macro DisableWindow(Window, State)
    ThreadToGUI::DoDisableWindow(Window, State)
  EndMacro
  Macro HideWindow(Window, State, Flags)
    ThreadToGUI::DoHideWindow(Window, State, Flags)
  EndMacro
  Macro SetActiveWindow(Window)
    ThreadToGUI::DoSetActiveWindow(Window)
  EndMacro
  Macro SetWindowColor(Window, Color)
    ThreadToGUI::DoSetWindowColor(Window, Color)
  EndMacro
  Macro SetWindowData(Window, Value)
    ThreadToGUI::DoSetWindowData(Window, Value)
  EndMacro
  Macro SetWindowState(Window, State)
    ThreadToGUI::DoSetWindowState(Window, State)
  EndMacro
  Macro SetWindowTitle(Window, Text)
    ThreadToGUI::DoSetWindowTitle(Window, Text)
  EndMacro
  ; Menus
  Macro DisableMenuItem(Menu, MenuItem, State)
    ThreadToGUI::DoDisableMenuItem(Menu, MenuItem, State)
  EndMacro
  Macro SetMenuItemState(Menu, MenuItem, State)
    ThreadToGUI::DoSetMenuItemState(Menu, MenuItem, State)
  EndMacro
  Macro SetMenuItemText(Menu, MenuItem, Text)
    ThreadToGUI::DoSetMenuItemText(Menu, MenuItem, Text)
  EndMacro
  Macro SetMenuTitleText(Menu, Index, Text)
    ThreadToGUI::DoSetMenuTitleText(Menu, Index, Text)
  EndMacro
  ; Gadgets
  Macro AddGadgetColumn(Gadget, Postion, Text, Width)
    ThreadToGUI::DoAddGadgetColumn(Gadget, Postion, Text, Width)
  EndMacro
  Macro AddGadgetItem(Gadget, Position, Text, ImageID = 0, Flags = #PB_Ignore)
    ThreadToGUI::DoAddGadgetItem(Gadget, Position, Text, ImageID, Flags)
  EndMacro
  Macro ClearGadgetItems(Gadget)
    ThreadToGUI::DoClearGadgetItems(Gadget)
  EndMacro
  Macro ClearGadgetColumns(Gadget) ; Owner Gadget Function
    ThreadToGUI::DoClearGadgetColumns(Gadget) ; Owner Gadget Function
  EndMacro
  Macro DisableGadget(Gadget, State)
    ThreadToGUI::DoDisableGadget(Gadget, State)
  EndMacro
  Macro HideGadget(Gadget, State)
    ThreadToGUI::DoHideGadget(Gadget, State)
  EndMacro
  Macro SetActiveGadget(Gadget)
    ThreadToGUI::DoSetActiveGadget(Gadget)
  EndMacro
  Macro SetGadgetAttribute(Gadget, Attribute, Value)
    ThreadToGUI::DoSetGadgetAttribute(Gadget, Attribute, Value)
  EndMacro
  Macro SetGadgetColor(Gadget, ColorType, Color)
    ThreadToGUI::DoSetGadgetColor(Gadget, ColorType, Color)
  EndMacro
  Macro SetGadgetData(Gadget, Value)
    ThreadToGUI::DoSetGadgetData(Gadget, Value)
  EndMacro
  Macro SetGadgetFont(Gadget, FontID)
    ThreadToGUI::DoSetGadgetFont(Gadget, FontID)
  EndMacro
  Macro SetGadgetItemAttribute(Gadget, Item, Attribute, Value, Column = 0)
    ThreadToGUI::DoSetGadgetItemAttribute(Gadget, Item, Attribute, Value, Column)
  EndMacro
  Macro SetGadgetItemColor(Gadget, Item, ColorType, Color, Column = 0)
    ThreadToGUI::DoSetGadgetItemColor(Gadget, Item, ColorType, Color, Column)
  EndMacro
  Macro SetGadgetItemData(Gadget, Item, Value)
    ThreadToGUI::DoSetGadgetItemData(Gadget, Item, Value)
  EndMacro
  Macro SetGadgetItemImage(Gadget, Item, ImageID)
    ThreadToGUI::DoSetGadgetItemImage(Gadget, Item, ImageID)
  EndMacro
  Macro SetGadgetItemState(Gadget, Postion, State)
    ThreadToGUI::DoSetGadgetItemState(Gadget, Postion, State)
  EndMacro
  Macro SetGadgetItemText(Gadget, Postion, Text, Column = 0)
    ThreadToGUI::DoSetGadgetItemText(Gadget, Postion, Text, Column)
  EndMacro
  Macro SetGadgetState(Gadget, State)
    ThreadToGUI::DoSetGadgetState(Gadget, State)
  EndMacro
  Macro SetGadgetText(Gadget, Text)
    ThreadToGUI::DoSetGadgetText(Gadget, Text)
  EndMacro
  Macro ResizeGadget(Gadget, x, y, Width, Height)
    ThreadToGUI::DoResizeGadget(Gadget, x, y, Width, Height)
  EndMacro
  Macro RemoveGadgetColumn(Gadget, Column)
    ThreadToGUI::DoRemoveGadgetColumn(Gadget, Column)
  EndMacro
  Macro RemoveGadgetItem(Gadget, Position)
    ThreadToGUI::DoRemoveGadgetItem(Gadget, Position)
  EndMacro
  Macro GadgetToolTip(Gadget, Text)
    ThreadToGUI::DoGadgetToolTip(Gadget, Text)
  EndMacro
  ; Statusbar
  Macro StatusBarImage(StatusBar, Field, ImageID, Appearance = 0)
    ThreadToGUI::DoStatusBarImage(StatusBar, Field, ImageID, Appearance)
  EndMacro
  Macro StatusBarProgress(StatusBar, Field, Value, Appearance = 0, Min = #PB_Ignore, Max = #PB_Ignore)
    ThreadToGUI::DoStatusBarProgress(StatusBar, Field, Value, Appearance, Min, Max)
  EndMacro
  Macro StatusBarText(StatusBar, Field, Text, Appearance = 0)
    ThreadToGUI::DoStatusBarText(StatusBar, Field, Text, Appearance)
  EndMacro
  ; Toolbar
  Macro DisableToolBarButton(ToolBar, ButtonID, State)
    ThreadToGUI::DoDisableToolBarButton(ToolBar, ButtonID, State)
  EndMacro
  Macro SetToolBarButtonState(ToolBar, ButtonID, State)
    ThreadToGUI::DoSetToolBarButtonState(ToolBar, ButtonID, State)
  EndMacro
  ; Systray
  Macro ChangeSysTrayIcon(SysTrayIcon, ImageID)
    ThreadToGUI::DoChangeSysTrayIcon(SysTrayIcon, ImageID)
  EndMacro
  Macro SysTrayIconToolTip(SysTrayIcon, Text)
    ThreadToGUI::DoSysTrayIconToolTip(SysTrayIcon, Text)
  EndMacro
  ; Clipboard
  Macro GetClipboardImage(Image, Depth=24)
    ThreadToGUI::DoGetClipboardImage(Image, Depth)
  EndMacro
  Macro GetClipboardText()
    ThreadToGUI::DoGetClipboardText()
  EndMacro
  Macro SetClipboardImage(Image)
    ThreadToGUI::DoSetClipboardImage(Image)
  EndMacro
  Macro SetClipboardText(Texte)
    ThreadToGUI::DoSetClipboardText(Texte)
  EndMacro
  Macro ClearClipboard()
    ThreadToGUI::DoClearClipboard()
  EndMacro
  ; Requester
  Macro MessageRequester(Titel, Text, Flags=0)
    ThreadToGUI::DoMessageRequester(Titel, Text, Flags)
  EndMacro
  Macro OpenFileRequester(Titel, DefaultFile, Pattern, PatterPosition, Flags=0)
    ThreadToGUI::DoOpenFileRequester(Titel, DefaultFile, Pattern, PatterPosition, Flags)
  EndMacro
  Macro NextSelectedFileName()
    ThreadToGUI::DoNextSelectedFileName()
  EndMacro
  Macro SelectedFilePattern()
    ThreadToGUI::DoSelectedFilePattern()
  EndMacro
  Macro SaveFileRequester(Titel, DefaultFile, Pattern, PatterPosition)
    ThreadToGUI::DoSaveFileRequester(Titel, DefaultFile, Pattern, PatterPosition)
  EndMacro
  Macro PathRequester(Titel, InitialPath)
    ThreadToGUI::DoPathRequester(Titel, InitialPath)
  EndMacro
  Macro InputRequester(Titel, Message, DefaultString, Flags=0)
    ThreadToGUI::DoInputRequester(Titel, Message, DefaultString, Flags)
  EndMacro
  Macro ColorRequester(Color = $FFFFFF)
    ThreadToGUI::DoColorRequester(Color)
  EndMacro
  Macro FontRequester(FontName, FontSize, Flags, Color = 0, Style = 0)
    ThreadToGUI::DoFontRequester(FontName, FontSize, Flags, Color, Style)
  EndMacro
  Macro SelectedFontName()
    ThreadToGUI::DoSelectedFontName()
  EndMacro
  Macro SelectedFontSize()
    ThreadToGUI::DoSelectedFontSize()
  EndMacro
  Macro SelectedFontColor()
    ThreadToGUI::DoSelectedFontColor()
  EndMacro
  Macro SelectedFontStyle()
    ThreadToGUI::DoSelectedFontStyle()
  EndMacro
EndDeclareModule

Module ThreadedGUI
  ; Do nothing
EndModule

;- End Module Macros


Example
Code:
...
Procedure thFlash(id)
  Protected count, col
 
  UseModule ThreadedGUI ; Enable macros to switch all gadget commands to ThreadToGUI
 
  DisableGadget(2, #True)
  For count = 0 To 4
    For col = 0 To 3
      StatusBarProgress(0, 1, count * 20 + col * 5)
      Select col
        Case 0 : SetGadgetColor(3, #PB_Gadget_BackColor, RGB(255,0,0))
        Case 1 : SetGadgetColor(3, #PB_Gadget_BackColor, RGB(255,255,0))
        Case 2 : SetGadgetColor(3, #PB_Gadget_BackColor, RGB(0,255,0))
        Case 3 : SetGadgetColor(3, #PB_Gadget_BackColor, RGB(255,255,255))
      EndSelect
      Delay(1000)
    Next
  Next
  StatusBarProgress(0, 1, 100)
  DisableGadget(2, #False)
 
  UnuseModule ThreadedGUI ; Don´t forget to disable the macros
 
EndProcedure
...


P.S. Updated Example 1

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / Event-Designer
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: Module ThreadToGUI-Update windows,gadgets,... from threa
PostPosted: Mon May 21, 2018 12:03 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1617
Location: Germany
Update v1.19
- Added DoDisplayPopupMenu

:wink:

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / Event-Designer
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: Module ThreadToGUI-Update windows,gadgets,... from threa
PostPosted: Sat Dec 08, 2018 11:23 am 
Offline
Addict
Addict

Joined: Fri Nov 09, 2012 11:04 pm
Posts: 1634
Location: Uttoxeter, UK
@mk-soft
I found this very helpful.
Thank you for sharing. :D

_________________
DE AA EB


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 9 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