Using FileChooserButton in GTK+ - gtk

I'm trying hard to find out how to use the file chooser button properly. Reading the reference manual on GtkFileChooserButton, GtkFileChooserDialog and GtkFileChooser didn't help so far. I've tried connecting to the undocumented signal file-set of GtkFileChooserButton and calling get\_filename() from here, but it seems to behave quite unreliably. When the user clicks the button and selects a file, it works fine so far.
But, if after clicking on the same button (which already has a filename set), the user changes his mind and closes the "open file" dialog, get\_filename() returns None (a Python type, i write it using pygtk) while the file remains set. Even more weird, if i call get_filename() on that button later from within another signal handler, the filename returns to what it previously had been set by the user. By the way, only closing the dialog box seems to cause the problem, pressing "cancel" works just fine.

Unclear question:
if you mean how to distinct between a valid chosen file:
if you call Run you will get a reponse:
Gtk::RESPONSE_ACCEPT if the user selected a file and accepted this file (clicked ok)
So only get the filename when the file is accepted.
if you mean how to reset filepath:
see gtk FileChooser -> set_ current_folder(filename) (without the space)

Related

Autohotkey only replace text in URL field

I'm trying to set up AHK only when I'm typing it in to the URL portion of a browser. That way I can continue to use my keyword other places.
Is this possible? I've been trying to mess around some with `ifWinActive("ahk_exe chrome.exe") which almost works, however when I try to type it not in the URL it simply deletes the text (and also will still make the replacement even if I'm typing in to a separate text box in the browser, not the URL box.)
You are on the right track. Once the command is limited to chrome, you have to do a conditional test to see if you are in the address bar or not. If not, simply "return" without doing anything.
For chrome, window spy however does not indicate the "focused Control" that you could use with "ControlGet" and its related commands:
https://www.autohotkey.com/docs/commands/ControlGet.htm
Oh well, so in your hotkey result, you may have to first do a quick copy all from your current caret position to clipboard and then see if the clipboard result is text only and starts with "http" and has a "://" and at least one "." and is otherwise a fully formed url address, and if so, then go ahead and run your hotkey result because now you can be pretty sure you actually are in the address bar.
Klugey, but certainly possible.

What is hotkey to manually check a C function api in vscode?

Sometimes when I write the function name, the api is shown above its name automatically, but sometimes it doesn't work and I have to rewrite the function name to get that, so is there a shortcut key for it?
(I know man function_name but I used to CTRL+Q in NetBeans to get the same thing quickly but I can't find one for vscode.)
ALT+F12 seems to do the job. It's called "peek definition" which is available in the right click options too.
Also note that the opened window doesn't go away by clicking somewhere else outside of it, however, instead you can still use the ESC from keyboard.

Why does a right click sent from pywinauto not change the state of the grayed out connect button in informatica, but a real mouse button click does?

I am trying to write a script using pywinauto to open a repository in Informatica powercenter workflow manager (v9.6.1)
After the below lines are executed, I get the context menu with the connect option as in the screenshot. Also notice the 'connect' button on the toolbar stays grayed out. If I use the actual mouse and click on the treeview item for the repository I want to connect to, the connect button turns green and enabled. But not when pywinauto sends the right click.
from pywinauto.application import Application
from pywinauto.keyboard import SendKeys
import time
app = Application().Start(cmd_line=r'C:\PowerCenterClient\client\bin\pmwflmgr.exe')
informaticaworkflowmanager = app[u'Informatica::WorkflowManager']
informaticaworkflowmanager.Wait('ready')
time.sleep(2)
systreeview = informaticaworkflowmanager[u'TreeView']
tree_item = systreeview.GetItem([u'Repositories', u'REP'])
tree_item.Select()
tree_item.Click(button='right',double=True,where='icon')
I tried using SendKeys to send 'c' followed by {ENTER} and it just returns without doing anything. Also if I use the actual keyboard on the right click context menu generated after the above pywinauto steps run- it selects the connect menu when i press c , but it just doesn't do anything when I press Enter. I think somehow the connect function is not enabled.
I am clueless if any other input is required by the application to enable it. I also tried using the informaticaworkflowmanager.MenuItem(u'&Repository->&Connect...') option but to no avail- it says it is disabled.
Any pointers to help get pywinauto to open a repository are welcome!
Just summarizing the comments...
First try running the script as Administrator. If it doesn't help, use method click_input(). It runs real click like a user does. Method click() sends WM_CLICK or BM_CLICK which is probably not handled by the app in grayed button state.
If you run the script as Administrator, it should inherit privileges for child process by default. There is no special flag in method start() because some functions may not work if target app process has higher privileges. Anyway elevation usually requires confirmation from user and this Security Confirmation dialog can't be automated by OS design (even click_input() with hard coded coordinates won't work while this dialog was shown, I checked it a while ago).

VSCode: I want to remove annoying info message bar

Is there any way to completely remove this message popup or move it to somewhere?
I already know why this message comes, but I do not want to disturb my activity with annoying info popup.
When it pops up it hides the document tab, so I have to close it every single time. (I do not want to know how to fix this particular error message, this screenshot is just an example.)
It's very annoying and I've searched around for a way to remove it, but the answers keep saying how to fix that particular error and not how to hide the popup itself.
Press ESC.
I agree that this is really annoying. VS Code is all about high-speed workflow and not having to interact with anything except your code via keyboard. Everything has key chords, e.g. CTRL-P and CTRL-SHIFT-P. So having to stop what I'm doing, go to the mouse, and dismiss this popup, whenever a background task feels like completing (and not even really then, because the popup actually appears some short time later) just so I can get visual confirmation of which file I'm currently coding in, to refocus my work after being distracted by the same popup, is really awkward. They are in a stupid location and don't even fade away after time like well-behaved toasts.
That said, I think that's really two parts; the distraction, and relatively high workflow cost to dismiss.
It helped me a lot to learn that it can be dismissed quickly and easily with the ESC key. The other half the problem I still haven't solved, but hope that helps you.
In the screenshot it shows trying to validate PHP.
In a VS Code window select File > Preferences > User Settings
An editor will open on the left called Default Settings and on the right with a file called settings.json
In the right side editor you can add settings that will override those found in the left-hand-side one.
Between the braces type:
// Whether php validation is enabled or not.
"php.validate.enable": false,
Then save the document.
VS Code will no longer attempt to validate PHP files.
You can override any of the defaults using this method.
You can use the same technique for each Workspace (or project folder) using File > Preferences > Workspace Settings
You can't disable the alert bar in general as VS Code needs to tell you things and doesn't (thankfully) use modal dialogs to communicate.
Go to File > preferences > settings
Then add this to your user settings
"editor.parameterHints": false
You may want to try adding the line
"extensions.ignoreRecommendations": true
to your VS Code settings file (which you can easily reach with the keystroke (CMD + ,) on a Mac OS X or macOS system.)
Solution: User Preferences > change "editor.parameterHints": true to "editor.parameterHints": false
This will at least remove the obstructive boxes that appear above the cursor.

Applescript drag and drop doesn't work

I am new to Applescript, and wrote a script to securely wipe files, which brings up a file-selection dialog and confirmation, then wipes the file. However, when I tried to add drag and drop functionality, it doesn't work like everyone says it should. The icon never highlights (indicating drag and drop is working), and Finder just copies the file to the app's folder instead of dragging onto the app!
Here is the original script, which works fine (saved as "Wipe File.app"):
on run
set the_file to choose file with prompt "Select the file to wipe:"
wipe_file(the_file)
end run
to wipe_file(file_to_wipe)
set file_to_wipe to POSIX path of file_to_wipe
set ok_to_wipe to display dialog "Are you sure you want to wipe \"" & file_to_wipe & "\"?" buttons {"Cancel", "OK"} default button "Cancel"
set ok_to_wipe to button returned of ok_to_wipe
if (ok_to_wipe = "OK") then
tell application "Terminal"
activate
do script "set prompt='';cls;srm -v \"" & file_to_wipe & "\""
delay 3
close front window
set still_active to count windows
if still_active = 0 then
quit
end if
end tell
end if
end wipe_file
Then I added the following to the top. Running the script still works with the file-selection dialog, but the system never allows drag and drop!
on open the_files
repeat with the_file in the_files
wipe_file(the_file)
end repeat
end open
Everywhere I looked (Google, stack overflow) all say this approach should work, but it doesn't. I even tried removing the on run... block, leaving just on open..., but then the script does nothing at all.
EDIT
If I create a new script with the content above, and save it as an app, then copy it to the Applications folder, and paste a custom icon onto it, drag and drop works. However, the old script, which originally didn't have "on open" support, still doesn't work even after "on open" support was added to the script. So now I'm thinking that Apple must set some special attribute to indicate a script supports drag and drop, and for some reason (because it didn't have it when I first saved?) Apple didn't set that attribute for my file. Looking at Get Info and Show Package Contents for both apps, there are some strange differences:
The newly-created (working) app is only 693 KB, but the old (supposedly identical, but broken) one is 9.4 MB!
Inside the Contents/MacOS folder, the new (working) app has a file called "droplet", whereas the old one (broken) one has a file called "applet".
The first one is bizarre, and made me think of some sort of file corruption, but the second one is clearly the magic setting Apple uses for drag and drop. I verified that if I remove the "on open" block from the working script, and save it, Apple does not update the script icon to remove the "drop" arrow, and you can still drag and drop files onto it, but nothing happens.
So it seems that Apple decides whether a script supports drag and drop or not the first time it saves the script, and after that you get the wrong results unless save a brand new script!
You do not need to call Terminal and open window. The ‘do shell script’ opens already a shell session, in background, not visible in Terminal. You must just use it inside a 'try/end try' block to avoid script stops in case of error (like no authorization for the files !)
Also you are using ‘srm’ with option v (verbose). This option is used to display what is being done, but you do not see it because you are closing the window.
The possible issue of your script could also be when your file path contains special characters which must be escaped in shell. To avoid this, use ‘quoted form of ‘.
Script bellow is tested OK :
on run
set the_file to choose file with prompt "Select the file to wipe:"
wipe_file(the_file)
end run
on open the_files
repeat with the_file in the_files
wipe_file(the_file)
end repeat
end open
to wipe_file(file_to_wipe)
set file_to_wipe to POSIX path of file_to_wipe
set ok_to_wipe to display dialog "Are you sure you want to wipe \"" & file_to_wipe & "\"?" buttons {"Cancel", "OK"} default button "Cancel"
if (button returned of ok_to_wipe = "OK") then
try
do shell script "srm " & quoted form of (file_to_wipe)
end try
end if
end wipe_file