Posts: 795
Threads: 136
Joined: Feb 2009
Hi Gintaras, hi all
I need to be steered to the right way.
I want to implement a toolbar, containing changing text based on browser titlebar.
I don't know how to dynamicaly change toolbar text item.
TY
Posts: 12,074
Threads: 141
Joined: Dec 2002
Download
Collected QM apps, functions, samples
Look for
ChangeQmToolbarButtonText
ReplaceToolbarButtonText
Posts: 795
Threads: 136
Joined: Feb 2009
Yes, good way to begin with...
Is there a function to monitor a specific Acc object change, like the url bar of firefox or chrome (where the url is set)??
Posts: 12,074
Threads: 141
Joined: Dec 2002
Trigger 'window name changed' or an accessible object trigger.
Posts: 795
Threads: 136
Joined: Feb 2009
Tried accessible object trigger with no joy sooo many times..if any example, would be happy
Posts: 12,074
Threads: 141
Joined: Dec 2002
Function firefox_address_text_changed
Trigger $a 142 -4 "" "MozillaWindowClass" "" "*- Mozilla Firefox" "" "" 42 "" "Search or enter address" "" "" 0x20
;\
function hwnd idObject idChild
Acc a.FromEvent(hwnd idObject idChild)
out a.Value
Posts: 795
Threads: 136
Joined: Feb 2009
hmm, nearly there...works perfectly in firefox after tweaking language Acc name...
but i don't want to use firefox anymore, and when adapted for chrome does not work, any hint???
trigger for chrome:
$a 142 -4 "" "Chrome_WidgetWin_1" "" "*- Google Chrome" "" "" 42 "" "Barre d'adresse et de recherche" "" "" 0x20
TY
Posts: 12,074
Threads: 141
Joined: Dec 2002
Function chrome_address_text_changed
Trigger $a 140 -4 "" "Chrome_WidgetWin_1" "" "*- Google Chrome" "" "" 42 "" "Address and search bar" "" "" 0x20
;\
function hwnd idObject idChild
Acc a.FromEvent(hwnd idObject idChild)
out a.Value
Posts: 795
Threads: 136
Joined: Feb 2009
Seems to work in chrome when triggers is based on NAMECHANGE and not VALUECHANGE as in firefox, although the url is in the value property of the Acc object..
do you know why????
EDIT : crossed replies...
Posts: 795
Threads: 136
Joined: Feb 2009
ok, last piece of the puzzle.
The framework of the project is to mimic this:
on tab change, QM changes a toolbar linked to chrome button name (as the first question of the thread).
What is the best implemetation for the storage of the datas?
Should a couple like
URL CUSTOMTEXT
Do I use a CVS, a stringmap or something else? The goal is the speed in this case
TAB Change -> Read data -> matching text for given URL
The procedure must be able to change text associated to URL on the fly, and be loaded/saved when chrome starts/ends (to preserve the informations)
Posts: 12,074
Threads: 141
Joined: Dec 2002
IStringMap or ICsv.
Use IStringMap if expected large number of items, else both are good. If very very large number, use Sqlite.
Posts: 795
Threads: 136
Joined: Feb 2009
Posts: 795
Threads: 136
Joined: Feb 2009
i forgot to ask, how create a file from a stringmap object????
I can get items from a string variable (AddList function) but what is the opposite procedure?
Posts: 795
Threads: 136
Joined: Feb 2009
yes, but it's the stringmap -> string procedure i miss
must use an intermediate array, or can i do it directly?
Posts: 12,074
Threads: 141
Joined: Dec 2002
str.getfile; IStringMap.AddList ... IStringMap.GetList; str.setfile
Posts: 795
Threads: 136
Joined: Feb 2009
ok, missed the GetList function, sorry
Posts: 795
Threads: 136
Joined: Feb 2009
ok, some letters in the file text are messed, and the string when read is not the good one
I suspect an encoding problem
M굩o
is météo in the file.
How fix that??
Posts: 12,074
Threads: 141
Joined: Dec 2002
Open the file in notepad and save as UTF-8.
Or use str.ConvertEncoding.
Posts: 795
Threads: 136
Joined: Feb 2009
ok, fixed...
is it possible to create from code a UTF8 text file, convertencoding asks for a encoding code prior to do it, and not sure which one my system uses
Posts: 12,074
Threads: 141
Joined: Dec 2002
setfile creates utf8 file if checked Unicode in Options.
Posts: 795
Threads: 136
Joined: Feb 2009
yes, it is..problem solved..
Posts: 795
Threads: 136
Joined: Feb 2009
as it can be very fast used code, and text file is read/written each time the function is called, i want to ensure there is no corruption and/or bad write/reading of datas.
The triggered QM code is in a function, and i ticked the "only single thread" option of this function.
Must I too use lock in the function???
function hwnd idObject idChild
Acc a.FromEvent(hwnd idObject idChild)
lock
str url=a.Value
...
some code
....
_s.getfile("q:\test.txt" 0 -1)
IStringMap m._create
....
some code
....
m.GetList(f....)
f.setfile("q:\test.txt"0 -1)
lock-
Posts: 12,074
Threads: 141
Joined: Dec 2002
I think 'lock' should be used, as it is in your code, and don't need "only single thread".
Posts: 795
Threads: 136
Joined: Feb 2009
Posts: 12,074
Threads: 141
Joined: Dec 2002
But frequent getfile/setfile is not good, especially when the file is big.
Other options:
Use a global IStringMap variable and save it to file less frequently.
Maybe use registry functions instead.
Or a global Sqlite variable.
Posts: 795
Threads: 136
Joined: Feb 2009
in fact, the file will be opened at chrome launch, and writed at chrome closure, so less used
the global istringmap initialized at chrome launch, and closed with chrome...
just need to find the right code, as chrome launches several processes (up to 12!!!!!) and not one, if you have ideas to
code some functions to launch *only* once (the first time i click the icon) and close when nom more chrome processes ...
I tried with EnumProcessesEx which work quite good, but is fooled when some the many chrome processes closes, but
some remain....
EDIT:
ended up with this code
Triggered by process "chrome" ended
wait 1
event: 1 started, 2 ended, 4 running
out F"{event} {pid} {name}"
ARRAY(int) allPids
str u="chrome"
_i=ProcessNameToId(u &allPids)
if(allPids.len=0) osd "chrome closed"
if you have more accurate/better coded idea.........
Posts: 12,074
Threads: 141
Joined: Dec 2002
Macro chrome address etc
Trigger !cv"* - Google Chrome" "Chrome_WidgetWin_1" "" "" "" 0x2
if(getopt(nthreads)>1) ret ;;allow single instance, assuming this is a function or a 'run simultaneously' macro
int hwnd=TriggerWindow ;;if trigger
if(!hwnd) hwnd=win("* - Google Chrome" "Chrome_WidgetWin_1" "" 1) ;;if Run button
if(!hwnd) ret ;;no Chrome
int pid; if(!GetWindowThreadProcessId(hwnd &pid)) end ERR_FAILED 16 ;;hook only this Chrome process
int hh=SetWinEventHook(EVENT_OBJECT_NAMECHANGE EVENT_OBJECT_NAMECHANGE 0 &sub.Hook pid 0 WINEVENT_OUTOFCONTEXT)
if(!hh) end ERR_FAILED 16
opt waitmsg 1 ;;don't block Windows messages, else sub.Hook cannot be called
wait 0 WP hwnd ;;wait until Chrome process exits
UnhookWinEvent hh
#sub Hook
function hHook event hwnd idObject idChild dwEventThread dwmsEventTime
if(!hwnd) ret
;outw hwnd ;;debug
Acc a.FromEvent(hwnd idObject idChild)
;out a.Name
sel a.Name
,case ["Address and search bar","Barre d'adresse et de recherche"]
,case else ret
str url=a.Value
err+ ;;Acc functions throw error when closing Chrome
out url
Then don't need lock and global variables.
Posts: 795
Threads: 136
Joined: Feb 2009
Function triggerd by chrome launched
IStringMap+ m._create
Function triggered when chrome closed
IStringMap+ m
str f
m.GetList(f)
f.setfile...
no destructor for IStringMap object????
Posts: 795
Threads: 136
Joined: Feb 2009
wonderful, will need some tweaks...
Posts: 12,074
Threads: 141
Joined: Dec 2002
Quote:no destructor for IStringMap object????
IStringMap is a COM interface, QM calls its hidden method Release, and the COM object destroys itself when need.
|