I'm trying to use the save_file() from traitsui.file_dialog, and I'm having a problem...the really odd thing is that if I run my code in Visual Studio (using PTVS), it works just fine!
Here's the problem as I see it...
When I use the dialog created by save_file() to pick an already existing file, I get NotImplemented errors in the iPython window of the Canopy editor, and I think it indicates that I don't have a FileExistsHandler in my code (I'm still in the early phases of learning Python/Canopy/Traits, so I may be all wet here :)). I never get a 'File Already Exists' popup either.
However, when I run the same code from inside Visual Studio using PTVS, I do get the 'File Already Exists' popup with the option to accept it or cancel.
Why does the PTVS version work, and (more importantly) how can I get my Canopy Editor version to work???
Thanks for any hand-holding anyone can supply :)
Steve
Steve, one simple thing to try in the Canopy preferences dialog's Python tab would be changing the GUI backend from Qt to WX.
Updating:
A somewhat more attractive and performant solution would be to continue using Qt but to use the file dialogs from pyface (pyface.api.FileDialog (Qt-specific; for the API, see https://github.com/enthought/pyface/blob/master/pyface/i_file_dialog.py).
Further Update...
Here's a simple block of code that works fine when using WX as the Python backend, but it has problems running using Qt:
from traitsui.file_dialog import save_file, TextInfo
import os
def SaveFile ( filename ):
""" Handles the user clicking the 'SaveAs...' button.
"""
if not os.path.isfile(filename): # if the file doesn't exist, just put the path into the file_name so I start in the same directory
(filename, dummyname) = os.path.split(filename)
filename = save_file( extensions = TextInfo(),
file_name = filename,
title = 'Save File As...',
)
return filename
newfile = SaveFile('C:\\temp\\already_there.txt')
If you run this using WX, you get the pop-up 'File already exists...' dialog with OK/Cancel buttons...running using Qt on the backend produces no pop-up, and NotImplemented errors in the iPython window :( (If I type in a new, non-existing filename, the save_file works correctly)
I really like the look of Qt screens, and someone told me that WX is for Windows only (I'm not sure of that, I haven't checked)
Is there a way I can get the save_file() to work correctly and error-free under Qt?
Related
I see this is a problem, but the program still runs. Where is the problem?
I can't solve this on my own even if I search it online. I need a pointer to where I can solve this problem.
For me, modules who have a yellow line under them are ones that your program doesn't need. If I import a module that my program doesn't need functions from, a yellow line will show under it.
To fix this issue, hover over the statement with the yellow line under it, then click on Fix Issue. A list will appear, with the first item probably being Remove unused import statements.
If, however, the list item says something like Select Python interpreter, then this answer would fix your problem.
Those yellow lines means that the imported modules cannot be located.
This probably means that you downloaded the modules into a virtual environment and the modules are not installed globally. You are probably running the script with the correct virtual environment. Open your Command Palette with Ctrl + Shift + P and choose the correct Python interpreter.
Long-time Arduino IDE user, one-day VS Code + Arduino extension user:
When I first load a sketch and do "Arduino:Initialize", the name of the sketch is stored in the arduino.json settings file, e.g. "sketch": "esp32_test/esp32_test.ino". It then compiles ok when I press the "Verify" button.
But if I close that sketch and open a different one, and then do "Arduino:Initialize", the first file is NOT replaced in the arduino.json file. The first one remains there. I get a message that says, "Arduinio.json is already generated." So when I try to compile the new file, the old one is compiled instead.
The only way I've been able to compile a different file is to manually edit the arduino.json settings file to remove the "sketch": "esp32_test/esp32_test.ino" entry. Then AND ONLY THEN will the .json file update to allow me to compile the new file.
Shouldn't this happen automatically when I select/edit a file and hit the Verify button? Maybe there's an issue with my installation...?
(forgot to mention: VS Code + Arduino on OSX 10.14.6)
Down at the bottom, on the right you'll see the Arduino status bar. There you'll find your board, your programmer, your port... and the .ino file that you're compiling. Click there, change the name to the sketch you want to compile and done!
It's no intuitive.
You should select the sketch in the status bar:
and then you can change the sketch in the upper screen text box:
I know exactly the issue you are having - because it happens to me quite often.
In the status bar, often the sketch file name will not be displayed for some reason - I think this is an issue with the Arduino extension. You'll see everything else you need - board, port, etc, but not the "target sketch"
Here is how you can change the "target sketch":
Open the command pallete (Ctrl + Shift + P for PC - CMD + Shift + P for mac)
Type in "sketch"
Select the option "Arduino: Select Sketch"
Select the sketch you want to upload/verify -> this will now become the active sketch
Like other respondents mentioned, it "should" be shown in the task bar, but for some reason it does not sometimes.
I use the plugin SimpleSession with Sublime Text 3 (but any plugin could be considered). If I save a session with multiple windows, this creates a .simplesession file. How can I open that session file just by clicking on the file? The goal is to avoid having to launch ST3 and use the Command Palette to run the "Load Session" command. Currently, clicking on the .simplesession file causes ST3 to open it as a regular file.
Sublime doesn't know that a simplesession file is important in any way, so double clicking on one is going to open it the same as Sublime would open any other file.
Since it's a plugin that created the file, that plugin is the only thing that knows that it's special and what to do with it. So what you really need is the way to tell the plugin to take the action for you.
All actions in Sublime (including things as simple as inserting text) are taken by executing a command. Here that would be a command in the plugin that created the file in question, which would tell it that you want to carry out the action you would normally take manually, such as loading a session.
To do that from within Sublime you'd do something like bind a keyboard key to the appropriate command, add it to a menu, the command palette, etc. If you want to take the action from outside of Sublime, then you need to communicate that command to Sublime in order to get it to execute.
In core Sublime you can do this by executing the subl program that ships with Sublime and tell it a plugin command that you would like to execute.
Although it's possible to do this, the solution provided here has the requirement that Sublime already be running due to technical limitations within Sublime itself, but more on that in a moment.
This answer will give you the information that you need to formulate the command line that you need to execute in order to get the plugin command to run and carry out the action that you desire.
If you want to run this command in response to double clicking a file of a particular type (here a simplesession file), how you do that is specific to the operating system and file browser that you're using, and is best asked as a separate question.
Assuming you instead want a level of integration where you just have a desktop shortcut, start menu entry, etc that does this, this is more straight forward because such a shortcut is really just a visual wrapper that executes a command of your choosing.
Again, how you would do that is different depending on your OS, but the important part is knowing what full command line you need to give to the shortcut to be able to run it, which is what this answer tells you how to construct.
Important Note: The specific package in your question implements a load_session command, which prompts you for the session to load from a list of sessions you've previously created.
This command doesn't take any argument that would tell it what session to load without asking you to pick one first. As a result, what you want isn't technically possible without more work because there's no way to directly tell the load_session command the file that you want to open.
In order to more fully automate things in this particular case, the underlying package needs to be modified. In particular either the load_session command would need an optional argument which, when given, would cause it to load that session without prompting first, or
a new command would need to be created to do the same thing.
If you're not comfortable or knowledgeable enough to make such modifications to the package directly, you need to either find someone that will do that for you or (even better) discuss it with the package author, since that is a feature that others would probably enjoy as well.
The first thing you need to know is, "What command in the plugin is the one that I need to execute to do what I want?". In some cases you may already know exactly what command you need to use because it's documented, or you have already made a custom key binding for it, and so on.
If you don't know the command you need to use, check the documentation on the package (if any) to see if it mentions them. In your particular case, the README on the package page specifically mentions a list of commands, of which load_session seems like the most appropriate fit.
Lacking any documentation, the next easiest thing to do would be to ask Sublime directly. To do this, select View > Show Console from the menu or press the keyboard shortcut associated with it, Ctrl+`. In the console that appears, enter the following command and press enter.
sublime.log_commands(True)
Now whenever you do anything, this console is going to show you exactly what command Sublime is executing, along with any arguments that it may be passing to the command. This remains in effect until you use the same command with False or restart Sublime.
With logging turned on, select the appropriate command from the command palette and see what the Console says.
For example, with this package installed, I get output like the following:
>>> sublime.log_commands(True)
command: show_overlay {"overlay": "command_palette"}
command: load_session
This is showing two commands; first I opened the command palette which uses the show_overlay command, and then I selected the SimpleSession: Load command, which is the load_session command with no arguments.
In order to get Sublime to execute the command from the command line, you use the --command command line argument to subl. So in order to get Sublime to run the load_session command, you can enter the following command in a command prompt/terminal in your OS. This is also the command you would set in your desktop shortcut.
subl --command "load_session"
This presumes that you've set up Sublime so that it's in the path (how you do that is OS specific). If running subl in a terminal gives you an error about a missing command, either add the Sublime install directory to the path or use a fully qualified file name in place of subl (e,g. "C:\Program Files\Sublime Text 3\subl" if you're on Windows); either requires you to know what location Sublime is installed in.
If you want to use a command that takes arguments you need to include the arguments in the command as well, in the same way as they were displayed in the console above.
It's important that the command name and the arguments all be considered one command line argument, which requires you to wrap the whole thing in quote characters, since otherwise the spaces will make it appear as multiple arguments.
If you forget this, Sublime will respond by opening files named after the different parts of the command and arguments that you tried to open under the mistaken belief that you're giving it files to open.
As a concrete example, to get Sublime to open the command palette from outside of Sublime, the command to do this would look like the following if you were on Linux/MacOS:
subl --command 'show_overlay {"overlay": "command_palette"}'
Note again that we are passing exactly what the console showed above, but the whole thing, command and arguments, are wrapped in single quotes so that the terminal knows that the entire value is one argument.
This makes things a little tricky on Windows, which doesn't allow single quotes. On that platform you need to use double quotes instead. This requires you to "quote" the internal double quotes with a leading \ character so that the command processor knows that they're part of the argument and not the double quote that ends the argument.
For the case of opening the command palette on Windows, the command thus looks like this:
subl --command "show_overlay {\"overlay\": \"command_palette\"}"
With this information in hand, you can set up something like a desktop shortcut to run the appropriate command, or potentially set up the file explorer that you're using to execute a command specifically when you double click on a file of your choosing.
Again, how you would do that is specific to the operating system that you're using, and so I'm not really covering that in depth here in this answer. Just keep in mind that regardless of the OS in question, the part that remains the same is that you need to use subl command like the above.
Now, in your particular case, if the package that you're using provided a command that would let it load the session directly without prompting you first, the command that you use would need to also include the name of the session file as one of the command arguments.
However, as I mentioned above, this package doesn't currently allow that at the moment.
Now, here is the GIANT CAVEAT with this whole thing; this only works if Sublime is already running.
The subl command talks to an existing running copy of Sublime and gives it commands to open a file, directory, run a command as we're doing here, and so on. If Sublime isn't already running, then subl will start Sublime first and then communicate these details to it.
Sublime starts and makes it's interface available to you to work right away, and then starts to load packages and plugins in the background. This is to get you in and working on your files without having to wait for all packages to load first.
An issue with this is that as soon as Sublime starts, subl passes off the appropriate commands and then quits, and since packages aren't loaded yet, the command that you want to execute doesn't exist yet (hasn't been loaded), so nothing actually happens.
Unfortunately there's not really a satisfactory way around this particular issue if you want to start Sublime and also execute commands.
A potential workaround would be use something like a script or batch file that would check to see if Sublime is already running, and if not Start it and delay a little bit to allow plugins to finish loading, then use subl to run the command.
However this would require you to basically guess how long it takes Sublime to finish loading, which is less than ideal.
I'm running Matlab 2013a, under Linux, using Xmonad (using the XMonad.Config.Xfce package).
This problem occurs whether the command window is docked or not.
The command window prompt does not get the keyboard focus unless the pointer is located
over the command window.
Is there a way to get the Matlab command window to have focus behaviour just like other normal windows, like a terminal?
Most important: I'd like to have the keyboard focus follow the window focus,
and not require any special positioning of the pointer, so that I can just "Alt-Tab" around my windows and have the command window get the keyboard focus. All of the resources I've found so far relate to programmatic control of focus; I'm just trying to improve my user experience in an interactive session.
To get keyboard focus on the Command Window, include the following in your xmonad.hs
import XMonad.Hooks.SetWMName
import XMonad.Hooks.ManageHelpers
and configure your ManageHook as follows
myManageHook = composeAll . concat $
[ [appName =? a --> doCenterFloat | a <- myFloatAS ]
, (your other hooks)
] where
myFloatAS = ["MATLAB"]
Finally, include setWMName "LG3D" in your startupHook. See here for a full xmonad.hs configuration which uses this (this is where I found the solution). If you have other Java apps that don't get focus as they should you can add them to the myFloatAS list.
It's a problem in the built-in java.
If i run:
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk/jre
matlab -desktop
Matlab works as expected.
I ran into this problem, running MATLAB2014a. I set up setWMName "LG3D" but still i couldn't get focus on my window. I had to click on the focused window to get the cursor, and sometimes the situation was even worse and I had to click on random places till i get my cursor back. This wouldn't happen on MATLAB2010. What worked for me was to use the native version of java as describe above.
In the end, i used the following bash script to start matlab8:
#!/bin/bash
export MATLAB_JAVA=/usr/lib/jvm/java-7-openjdk-amd64/jre/
/usr/local/bin/matlab8 -desktop -nosplash
I have an exam and I would like to print my Java (in NetBeans project) files as fast as possible. I was wondering is there a way to print an entire project/project in NetBeans with one click? or do you have a better suggestion? (I will be using Windows XP and there is no nice editor like Gedit or Kate installed)
Give that the identical question on the netbeans forum from last year is not answered yet, I would say no.
When I needed to print off my final year Comp Sc project (needed to hand in a full print out + polished install CD, oh the poor trees that died for that one...), I opened every file then went through and did a print & close on each one. :(
It can be done. Switch to file mode, select all files, open all, then print. From http://dgreen.github.io/blog/2010/11/02/printing-multiple-files-in-netbeans/
I had the same problem. I am in a Computer Science class with Java Programming. My homework asignment involves creating a project with many class files (7 at the moment) so I searched google for how to print out the project and found nothing. However, I have come up with a bit of a kludgy way to do this, after reading it you can be the judge of how much time it will actually save. The more classes you have in a single project, the more time it will save. The methodology is kludgy because it involves as little system access as possible, because as you said you are on a school computer so I will assume only the most basic access. It DOES require command prompt access, so this may not be helpful for you. However, it is possible that if you cannot open the command prompt you may be able to execute a .bat file. So here goes.
Point command prompt to your source directory and type:
dir /b > projectDir.txt
or save that 1 line in a text editor as dir.bat
this will give you a text file listing all of the java files in your source directory
open notepad and type this 1 line
/*PAGEBREAK*/
save that file as pagebreak.txt
now, open the projectDir.txt file you created with Notepad.
do a global replace of ".java" with ".java+pagebreak.txt+"
get rid of the line that has projectDir.txt listed
save the file as projectDir.html
open this file in a web browser. the point of this is to get rid of the line breaks created by using dir /b.
now, copy this line of text and paste it into a new notepad window. at the beginning of the line, add "copy /b " and at the end of the line, replace the final "+" with " wholeProject.java"
run your bat file. if everything has been successful, you will have a single java file containing all of your classes. add this file to your project tree in netBeans IDE.
Export that file as an HTML file. one problem is that if you use line numbers, the numbers will be continuous; each new class will not start with 1, so I would advise against that.
Open up the html file in notepad. Do a global replace of "/*PAGEBREAK*/" with "<p style='page-break-before: always'>". Save your file, open it in a browser.
When you print it, it should print each class on its own page.
hope this helps! netBeans should really implement this though, my method is pretty goofy and contrived.
I found a new way (I hope it is a new way...)
You first want to copy the html , you can do that by choosing "Print to HTML ... " option from the Netbeans settings and choose the " Print to Clipboard " option .
Open the any text app and paste it , save with .html extension .
Now you can use from any browser to print the way you want it .