AutoUpdate gadget 4 each new char in search $ threaded exmpl

Share your advanced PureBasic knowledge/code with the community.
User avatar
Zebuddi123
Enthusiast
Enthusiast
Posts: 796
Joined: Wed Feb 01, 2012 3:30 pm
Location: Nottinghamshire UK
Contact:

AutoUpdate gadget 4 each new char in search $ threaded exmpl

Post by Zebuddi123 »

Hi to all

Thought this might be useful to some. Small example of auto updating a gadget (Listview used) whist adding new characters to the search string gadget via a threaded procedure. nothing fancy. commented.

I have created this (has been altered for the example) for a music mp3 collection 3500+ tracks, to check if i have the track on disk or is in a known track list (Northern Soul) part of a larger project.

Will require the the names & meaning text (for the example) to be place in a name.txt file in the same dir as the example.

Hope its useful.

Zebuddi. :D

ProcedureDLL Formatnumber() windows specific, all rest of code should be pure, so FormatNumber(, can be replaced directly with Str( to work of the peg with linux & osx

code:

Code: Select all

;{- Enumerations / DataSections
;{ Windows
Enumeration
	#Window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
	#Editor_0
	#Button_1
	#String_2
	#StatusBar_Window_0
	#ListIcon_0
EndEnumeration
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;}
Structure nslist
	name.s
	meaning.s
EndStructure

Global NewList  nslist.nslist() ; track from  file on disk NSList.txt

ProcedureDLL.s _FormatNumber(Number.q) ;1000000===>1,000,000
	Buffer.s=Space(255)
	GetNumberFormat_(0,0,Str(Number),0,@Buffer,Len(Buffer)) ;API
	Buffer=Mid(Buffer,1,Len(Buffer)-3)
	ProcedureReturn Buffer
EndProcedure

Procedure  do_list() ;  parse file names.txt and fill nslist structured linkedlist
	If ReadFile(0,"name.txt")
		With nslist()
			While Eof(0)=0
				a$=ReadString(0,ReadStringFormat(0))
				p=FindString(a$," - ")
				AddElement(nslist())
				\name=Left(a$,p-1)
				\meaning=Right(a$,(Len(a$)-(p+2)))
			Wend
		EndWith
		CloseFile(0)
	EndIf
EndProcedure

Procedure OpenWindow_Window_0()
	If OpenWindow(#Window_0, 450, 32, 497, 573, "Names & Meanings", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
		If CreateStatusBar(#StatusBar_Window_0, WindowID(#Window_0))
			AddStatusBarField(350)
			AddStatusBarField(147)
		EndIf
		ListIconGadget(#ListIcon_0, 0, 0, 497, 525, "Nb", 30, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
		AddGadgetColumn(#ListIcon_0,2,"Name",150)
		AddGadgetColumn(#ListIcon_0,3,"Meaning",317)
		StringGadget(#String_2, 0, 525, 497, 25, "")
		SetGadgetColor(#ListIcon_0,#PB_Gadget_BackColor,$80FFFF)
		SetGadgetColor(#String_2,#PB_Gadget_BackColor, $1FF6F5)
	EndIf
EndProcedure

Procedure check(aaa) ; threaded auto update routine 
	Protected NbItems, check$, match_counter,ag, initgadget=0
	Repeat
		oldcheck$=GetGadgetText(#String_2)
		Delay(200)
		If oldcheck$<>GetGadgetText(#String_2)  ;If changed
			NbItems=CountGadgetItems(#ListIcon_0)
			ClearGadgetItems(#ListIcon_0)
			check$=GetGadgetText(#String_2)
			If check$>""
				ForEach nslist()
					If FindString(LCase(nslist()\name),LCase(check$)) Or FindString(LCase(nslist()\meaning),LCase(check$)) ; match in either name or meaning definition in the linkedlist
						match_counter+1 
						AddGadgetItem(#ListIcon_0,-1, Str(match_counter) + ".  "+Chr(10) + nslist()\name +Chr(10)+nslist()\meaning)
					EndIf
					If GetGadgetText(#String_2)<>check$ ; check if user altered search term if true abandon current search
						Break
					EndIf
				Next
				StatusBarText(#StatusBar_Window_0,0,"Found "+_FormatNumber(match_counter)+" Matches")
				If match_counter=0
					AddGadgetItem(#ListIcon_0,-1,Chr(10)+"No Match`s Found")
				EndIf
				StatusBarText(#StatusBar_Window_0,0,"Found "+_FormatNumber(match_counter)+" Matches")
			EndIf
			
			If GetGadgetText(#String_2)="" ; search term is empty clear listview
				match_counter=0
				ClearGadgetItems(#ListIcon_0)
				StatusBarText(#StatusBar_Window_0,0,"No Search Term")
			EndIf
		EndIf
		st=0
		match_counter=0
	ForEver
EndProcedure

do_list()

OpenWindow_Window_0()

SetWindowTitle(#Window_0,"Names --- "+_FormatNumber(ListSize(nslist()))+" Name & Meanings Found ")

mythread=CreateThread(@check(),0)
;{- Event loop
Repeat
	Event = WaitWindowEvent()
	Select Event
			; ///////////////////
		Case #PB_Event_Gadget
			EventGadget = EventGadget()
			EventType = EventType()
			; ////////////////////////
		Case #PB_Event_CloseWindow
			EventWindow = EventWindow()
			If EventWindow = #Window_0
				If mythread
					KillThread(mythread)
				EndIf
				FreeList(nslist())
				CloseWindow(#Window_0)
				Break
			EndIf
	EndSelect
ForEver
;
;}
name.txt:

Aaron - Enlightened
Abbott - Father
Abel - Breath
Abner - Father of Light
Abraham - Exalted Father
Adam - Man of Earth
Addison - Son of Adam
Adler - Eagle
Adley - The Just
Adrian Adrien - The Dark One
Aedan Aiden - Born of Fire
Aiken - The Oaken
Alan Allan - Handsome One
Alastair - Defender of Men
Albern - Of Noble Valor
Albert - Noble Bright
Albion - White or Fair
Alden - Wise Guardian
Aldis - From the Old House
Aldrich - Old Wise Leader
Alexander - Great Protector
Alfie - Form of Alfred
Alfred - Supernaturally Wise
Algernon - Bearded
Alston - From the Old Manor
Alton - From the Old Town
Alvin - Noble Friend
Ambrose - Immortal
Amery - Industrious
Amos - A Burden
Andrew - Manly Valiant
Angus - Strong and Unique
Ansel - Nobel
Anthony - Priceless
Archer - Bowman
Archibald - Bold Prince
Arlen - Pledge
Arnold - Strong as an Eagle
Arthur Art - Champion Follower of Thor
Arvel - Wept Over
Atwater - From the Waterside
Atwood - Forest Dweller
Aubrey - Ruler of the Elves
Austin - Helpful
Avery - Elfin Ruler
Axel - Man of Peace
Baird - Bard or Minstrel
Baldwin - Princely Friend
Barclay - Meadow of Birch Trees
Barnaby - Prophet
Baron - Nobleman
Barrett - Bear-Like
Barry - Marksman
Bartholomew - Warlike
Basil - King-like
Benedict - Blessed
Benjamin - Son of Right Hand
Benton - Moor Dweller
Bernard - Stern Bear
Bert - Bright
Bevis - Bowman
Blaine - Lean or Thin
Blair - Man of Flatlands
Blake - Fair Complexioned
Bond - Farmer
Boris - Warrior
Bowen - Son of Owen
Braden - From the Broad Valley
Bradley - from the Broad Meadow
Brandan Brendan Brendon - Traveller
Brent - From the Steep Hill
Bret Brett - Native of Brittany
Brian - High Noble Strong
Brice - Great Ambition
Brigham - Dweller by the Bridge
Brock - The Badger
Broderick - Form of Roderick
Brooke - A stream
Bruce - Brushwood
Bruno - Dark Complexioned
Bryant - Strong
Buck - The Deer
Bud - Messenger
Burgess - Citizen of a Town
Burton - Fortress
Byron - Bear
Cadman - Warrior
Calvert - Shepherd
Caldwell - Near a Cold Well
Caleb - Faithful
Calvin - Bald
Carrick - Rock
Carl - Farmer
Carlton - From Carl's Farm
Carney - Warrior
Carroll - Champion
Carter - Cart Driver
Carver - Wood Carver
Cary - Fort
Casey - Brave
Casper - Treasure
Cecil - Blind
Cedric - Chieftain
Chad Chadwick - Warrior
Chalmers - Lord of the Household
Chandler - Candlemaker
Channing - A Canon
Chapman - Merchant
Charles - Manly
Chatwin - Warlike Friend
Chester - Castle Dweller
Christian - A Christian
Christopher - Christ-Bearer
Clarence - Famous
Claude - Lame
Clayton Clay - The Clay Farm
Clifford Cliff - Near the Cliff
Clive - Cliff Dweller
Clyde - Heard from Afar
Coleman - Dove
Colin - People's Victory
Collier - Miner
Conan - Wise
Connell - Friendship
Connor - Lover of Hounds
Conrad - Able in Counsel
Conroy - Wise Man
Conway - Hound in the Plain
Corwin - The Raven
Crispin - Curly Haired
Crosby - Dweller by Town Cross
Culbert - Cool and Brilliant
Culver - Dove
Curt - Short or Little
Curtis - Courteous
Cuthbert - Famous and Brilliant
Craig - Rocky Hill
Cyril - Lord-like
Dale Daley - Frequenter of Gatherings
Dalton - Valley Estate
Damon - Day of the Week
Daniel - Ruler of the World
Darcy - Dark
Darian - Wealthy
Darell Darrel - Beloved
David - Swift Nimble Beloved
Davin - Little Deer
Dean - Great Leader
Declan - Full of Goodness
Delmar - Mariner
Denley - From the Valley Meadow
Dennis - Wild or Crazy
Derek - Great Ruler
Dermot - Without Enemy
Derwin - Friend of Wild Animals
Des Desmond - Like an Oak
Dexter - Dexterous
Dillon - Faithful
Dion - Short for Dionysus
Dirk - Ruler of People
Dixon - Powerful Ruler
Dominic - Belonging to the Lord
Donald - Ruler
Dorian - A Dorian
Douglas - Dark
Doyle - Stranger
Drake - Dragon
Drew - Trustworthy
Driscoll - Interpreter
Dudley - Residence Name
Duncan - Dark Skinned Warrior
Durwin - Beloved Friend
Dwayne - Field or Meadow
Dwight - White or Fair
Dylan - Faithful Loyal
Earl - Nobleman
Eaton - From the Riverside
Ebenezer - Rock of Help
Edan - Fiery Flame
Edgar - Fortunate Spear
Edric - Prosperous Ruler
Edmond Edmund - Guardian of the Riches
Edward Eddie - Happy Protector
Edwin - Valuable Friend
Efrain - Guardian of the Mists
Egan - Ardent
Egbert - Formidably Brilliant
Egerton - The Edge
Egil - A Sting
Elbert - Nobly Brilliant
Eldon - Respected
Eldwin - Sage Friend
Eli Ely Elijah - The Highest
Elias - Jehovah is God
Eliot Elliott - Close to God
Ellery - Cheerful
Elmer - Awe-Inspiring
Elroy - Royal
Elton - Residence Name
Elvis - A Wise and Noble Friend
Emerson Emery - Industrious
Emmanuel - God-like
Emmett - Hard Working
Emrick - Immortal
Enoch - Dedicated or Consecrated
Eric Erik - Honourable and Powerful
Ernest - Iron Man Vigour
Errol - Wanderering Noble
Erskine - Hill Dweller
Erwin - Friend of the Sea
Esmond - Protective Grace
Ethan Ethanael - Constant Firm Strong
Ethen - Endurance
Eugene - Born of the Yew Tree
Evan - Young Warrior
Everett - Wild Boar
Ezra - The Helper
Fabian - Bean Farmer
Fairfax - Fair Haired
Falkner - Falcon Trainer
Farley - Distant Meadow
Farrell - Man of Valor
Felix - Prosperous
Fenton - From the Flat Lands
Ferdinand - Adventurous in Life
Fergal - Brave and Couragous
Fergus Ferguson - Strong and Virile
Ferris - Iron Worker
Finbar - The Fair
Fitzgerald - Son of Gerald
Fleming - Originating from Flanders
Fletcher - Arrow Maker
Floyd - The Hollow
Forbes - Prosperous
Forrest - Woodsman
Foster - Bird Catcher
Fox - Cunning
Francis - Free
Frank - Free Man
Frasier - Strawberry
Frederick - Peaceful Ruler
Freeman - A Freeman
Jack - Godly
Jacob - Conqueror
James Jimmy - Supplanter
Jarvis - Accurate Arrow
Jason - God is my Saviour
Jasper - Bearer of Treasure
Jed - Beloved of the Lord
Jeffrey - Peace Bringer
Jeremiah Jeremy - Exalted
Jerome - Of Sacred Name
Jesse - Gift Giver
John - God is Gracious
Jonathan - A Gift
Joseph Joey Joe - God Multiplies
Joshua - God is my Salvation
Justin - Just
Kane - Honor
Keene - Sharp
Keegan - Fiery
Keaton - Where Hawks Go
Keith - Forest
Kelsey - Island of Ships
Kelvin - Friend of the Sea
Kendall - Narrow River
Kendrick - Ruler
Kenneth Ken - Handsome
Kent - Bright White
Kenway - Courageous in Battle
Kenyon - Blonde Haired
Kerry - The Dark
Kerwin - Dark Skinned
Kevin - Handsome
Kiefer - Barrel Maker
Kilby - Residence Name
Kilian - Blind
Kim - Chief
Kimball - Royally Brave
Kingsley - Residence Name
Kirby - Residence Name
Kirk - Church
Kit - The Christ-Bearer
Kody - Helpful
Konrad - Bold Speaker
Kurt - Able in Counsel
Kyle - Handsome
Lambert - Land Bright
Lamont - Lawyer
Lancelot - Land
Landon - Owner
Landry - Ruler of the Place
Lane - Narrow Road
Lars - Variant of Lawrence
Laurence - Bay or Laurel Tree
Lee - Meadow
Leith - Wide
Leonard Leo Leon - Bold Lion
Leroy - Powerful King
Leslie - Residence Name
Lester - Camp of the Legion
Lincoln - Residence Name
Lionel - Lion-like
Lloyd - Grey
Logan - Trench or Forest
Lombard - Long-Beard
Louis Lewis - Warrior
Lowell - Beloved
Lucas Luke - Luminous
Luther - Warrior
Lyndon - Linden Tree
Maddox - Beneficient
Magnus - Great
Malcolm - Royal Blood
Melvin - Servant
Marcus - Warlike
Mark Marc - Variant of Marcus
Marlon - Falcon
Martin - Warlike
Marvin - Sea
Matthew - Gift of the Lord
Maurice - Dark Skin
Max Maxwell - Great
Medwin - Powerful Friend
Melville - Form of Malvin
Merlin - Bird
Michael - Like God
Milburn - Residence Name
Miles - Soldier
Monroe - A Wheeler
Montague - Residence Name
Montgomery - Mountain
Morgan - From the Sea's Edge
Morris - Moorish
Morton - From the Farm or Moor
Murray - Seaman
Nathaniel Nathan - Gift of God
Neal - Champion
Neville - New Town
Nicholas - People Triumph
Nigel - Black
Noel - To be Born
Norman - Norseman
Norris - Caretaker
Olaf - Relic
Olin - Holly
Oliver - Olive Tree
Orson - Like the Bear
Oscar - Spear of God
Oswald - Of God-Like Power
Otis - Hears Well
Owen - Well-Born
Paul - Small
Paxton - Travelling Trader
Percival Percy - The Gorge Piercer
Perry - Pear Tree
Peter - Rock or Stone
Peyton - Form of Patrick
Philbert - Illustriously Brilliant
Philip - Horse Lover
Phineas - Brazen Mouth
Pierce - Rock or Stone
Quade - Fourth
Quenby - Form of Quimby
Quillan - Cub
Quimby - Woman's Estate
Quentin - Fifth Child
Quinby - Residence Name
Quincy - Residence Name
Quinlan - Strong
Quinn - The Wise
Ralph - Variant of Randolph
Ramsey - Island of Ravens
Randolph - Strong Shield
Raymond - Wise Guardian
Reginald - Power
Renfred - Peacemaker
Rex - King
Rhett - Stream
Richard - Powerful Ruler
Ridley - Residence Name
Riley - Valiant
Robert Robin - Bright Fame
Roderick - Famous Ruler
Rodney - Famous
Roger - Famous Warrior
Roland - Fame of the Land
Rolf - Wolf
Ronald - Of Mighty Power
Rory - Red King
Ross - Wood
Roswell - Mighty Steed
Roy - King
Royce - Son of Roy Kingly
Rufus - Red-Haired
Rupert - Of Shining Fame
Russell - Red
Ryan - Variant of Bryan
Samson - Bright as the Sun
Samuel - Answer to Prayers
Scott - From Scotland
Sean - Heavenly Generosity
Sebastian - Majestic
Seth - Appointed One
Seymour - Moorish Saint
Shamus - Supplanter
Shawn - God's Gracious Gift
Shelley - Articulate
Sherard - Of Splendid Valour
Sheridan - The Wild Man
Sherlock - Fair-Haired
Sherman - Occupation Name
Sherwin - A Friend
Sidney - Earthy
Sigmund - Victorious Protection
Silas - Sound Forester
Simon - A Visionary and Listener
Sinclair - The Illustrious
Sloane - Warrior
Solomon - Peaceful
Spencer - Steward
Stanley Stan - Stony Field
Stephen Stefan - Crown
Sterling - High Quality
Stewart Stuart - A Steward
Theobold - Patriotic
Theodore - Gift of God
Thomas - Dependable
Timothy - Honour God
Titus - The Safe
Tobias - Goodness of the Lord
Toby - God is Good
Todd - Fox
Tony - Beyond Praise
Travis Travers - At the Crossing
Trent - Torrent
Trevor - Great House
Tristan - Sorrowful
Troy - After the City
Truman - A Faithful Loyal Man
Tyler - Occupation Name
Udolf - Prosperous Wolf
Unwin - Nonfriend
Uriah - God is my Light
Vance - Thresher
Vaughan - Small
Vernon - Flourishing
Victor - Conqueror
Vincent - Victorious
Wallace - Stranger
Walter - Powerful Ruler
Walton - Residence Name
Ward - Guardian
Warren - Protective Friend
Washington - Residence Name
Wayne - Wagon Maker
Wesley - Man from the West
Wilbur - Beloved Stronghold
Willard - Great Bravery
William Will - Determined Guardian
Willis - Variant of Will
Winston - Town of Victory
Winthrop - Residence Name
Wyatt - Guide
Wylie - Beguiling
Wyman - Warrior
Zachariah - Remembered by the Lord
Zachary - Remember the Lord
Zebadiah - Gift of the Lord
Zane - Form of John
Zebediah - God's Gift
Last edited by Zebuddi123 on Mon Jun 17, 2013 10:25 pm, edited 1 time in total.
malleo, caput, bang. Ego, comprehendunt in tempore
User avatar
em_uk
Enthusiast
Enthusiast
Posts: 366
Joined: Sun Aug 08, 2010 3:32 pm
Location: Manchester UK

Re: AutoUpdate gadget 4 each new char in search $ threaded e

Post by em_uk »

Nice, good code.

Pretty swift :)

Thanks
----

R Tape loading error, 0:1
Post Reply