jupyter lab script to set up view layout - jupyter-lab

I have some python functions to create graphical interface components in jupyter (lab) using ipywidgets. For my specific application, it's very useful to create different views for different cell outputs containing different widgets. I do this manually with "right click / create new view for output". However, sometimes this process gets annoying when I close everything and come back to work on it later, because I have to redo this layout manually every time and I was wondering if there's a way to write a single script (that I can run from some command line interface) that basically sets this up automatically, i.e. run commands in a jupyter lab session, get specific output cells and send them to different views, etc. Is there a way to do this?

Related

Reprint a table in js terminal without a waterfall print or clearing console

JS has this great feature called console.table. It allows a list of objects to be displayed as a table.
Now I could like to create a simple little program that continously displays the same table just with updated values (individual values change very fast, so a re render only on change isn't an option)
So far I got the best results simply rendering one table after the other, which leaves the most recent table always at the bottom. The problem with this is that it fills the entire terminal extremely fast and as such makes scrolling back up difficult.
Another option would be to clear the terminal and the print the table again. But this leads to excessive "blinking" which makes the table unreadable.
So basically I would need a way to print the console.table, somehow get the terminal cursor back to the start of a table and the overwrite it, similar to how it works in a lot of terminal programms like htop. Is there a way to do this in node js?

How to open multiple files in PyCharm with one click?

I have a directory with multiple files. There is one main file and other ones in subdirectories (including in a virtual environment directory) all of which I want to open with one click in the same instance of PyCharm. Is there a way to do this? Is there a native PyCharm way? Is there a way to do it using a Bash script. For the latter I have managed using pycharm.sh (see Open files from the command line). However, the different files are opened in different PyCharm instances which is not what I want.
I just tried this on Windows running from CMD. Simply listing the paths to the files separated by a space opens them in a single editor instance. (Although the documentation doesn't clearly mention this possibility, suggesting only 1 single file/project as argument).
For example executing the following:
pycharm64.exe C:\test_file1.txt C:\test_file2.txt
Opens like this:
This means PyCharm does accept a list of individual files as command line arguments to open them in a single instance.
all of which I want to open with one click in the same instance of PyCharm.
If the above example works on your shell you should be able to create a shell script that can be clicked.
However, the different files are opened in different PyCharm instances which is not what I want.
I don't know if depending on the shell any special rule applies that might cause each file to be opened in a different PyCharm instance/window, but if that's the case there's also likely to be a shell specific syntax rule to launch a single instance of the application passing multiple arguments.
Is there a native PyCharm way?
It seems PyCharm is naturally geared to working with projects. Looking closely at some functionalities like open/close/search in the PyCharm IDE their logic is entirely "project oriented" not like the usual concept of opening a set of unrelated files as in some other editors. (This is actually really smart, it doesn't clutter the UI with marginal functionalities and it forces users to set up a project - see this thread for a similar example about using search with individual unrelated files in PyCharm).
If you look at the screenshot, it's noteworthy that only 1 file is listed in the Project Tool Window although several files are opened in the editor.

Script to paste a specific string into a text field with a hotkey

I am trying to find a way to paste a predefined string upon entering a specific keyboard sequence, on any app.
For example if I have to paste an url or a password into a field, I can have said password in a hidden script and when I press, say, [ctrl] + [5], it would write "example123" on the text field where my cursor is.
Ideally without copying to the clipboard (I'd prefer keeping what I have on my clipboard and also avoiding to paste a password or such by mistake elsewhere).
I have tried every solution I've found so far that include xclip, xdotool and xvkdb. All of them either do not work or are really inconsistent: They only paste the string sometimes, and when they do, it's usually only part of the string ("ample123" instead of "example123").
I thought of using compose key, which I heavily use anyway to write in french on an us keyboard, but it seems it only supports 1 character sequences, as nothing is printed when I modify my .XCompose to include custom output sequences of len > 1.
I am using Ubuntu 18.04 with Gnome as a DE. Ideally something that also works when logging back (like compose keys).
You need to walk the Document Object Model for either Gnome or your web-page. My concern is that with a desktop script you wont be able to access the web page because you will need to be able to establish a target to send string to. I see in your question that you tried using using "x{tool-name}" to grab the text field element. Delivering the sting really isn't the problem. The problem is getting the GUI element of text box pragmatically. The easiest way to get access to this in a user loaded web-page is with WebExtensions API which is how to make extensions for most modern browsers. Otherwise, if you can get away with only having access to Gnome's GUI I would try LDTP, it's a library used for testing, but it looks like it can be used for automation too.
For keyboard shortcuts:
It really shouldn't matter what the script is doing to how you want to activate it. I would just go to Gnome/Settings/Keyboard and set the path to where I saved the script to be the Command. If you go the WebExtension route, you will want to build the shortcut into your extension.

How to change the Sublime Text 3 StatusBar message in a command or macro (no plugin)?

addressing Sublime Text 3 users here.
I wrote a couple of macros to enable spell-check and load a specific dictionary, as I constantly swap between French and English and I wanted a simple shortcut for this (instead of browsing the menu or two successive commands in the command pallet).
My macros work as expected (french-spellcheck.sublime-macro, english-spellcheck.sublime-macro).
But I would like to display a message in the Status Bar, for instance "Switched to French" or "Switched to English" (for some time, let say 5 sec).
I looked everywhere I know and I tried for some time, but apparently there is no way to do this in a command (that could be added at the end of the macro), as the set_status internal ST3's Python API command (from Window package) is only available for plugins...
Does any one has an idea of how to display a message to the SublimeText3 StatusBar in a command/macro and not with a plugin? Thanks!
There is no built in command that invokes the API methods for doing this (at least not a documented one), so there's no way to go about this without a plugin of some sort.
That said, in order to do what you want, the following is all you would need to save into a file named e.g. set_status.py in your Packages/User folder (alongside your macros). This provides a set_status command that takes a value named value for the text to display, as mentioned in the commented out portion of your macro file.
import sublime, sublime_plugin
class SetStatusCommand(sublime_plugin.TextCommand):
def run(self, edit, value="set_status: use arg 'value' to set text"):
self.view.window ().status_message (value)
This uses a different API than the one you mention in your macro file comments; status_message does the work of displaying a message in the status bar, waiting a few seconds, and then removing it, which makes the command simple to implement.
If you wanted more control (i.e. to change the duration) you would need to modify this to invoke the API commands your macro files already mention: view.set_status() and sublime.set_timeout().

Is it possible to keep a variable active with Revit Python Shell, using canned commands?

I'm currently using Revit Python Shell 2017 and I'd like let's say to make "communicate" different canned commands.
For instance, let's say I load a house model, and I create some additional walls on it, via a canned command that I would have previously created. While creating these walls, I could store all these new walls IDs in a variable, as a list.
Now, if I want to delete exactly these walls afterwards, I'd like to identify them using their IDs that I stored in the list, then delete them.
If I was in an interactive Python Shell session, well the "IDs list" variable would still be accessible (as long as I don't close the shell), and I could just retrieve the IDs from it, then delete the walls.
But what if I'm using canned commands? The first command would be "create the walls", and the 2nd would be "erase these walls". But that "IDs list" variable doesn't exists in the second canned command environment, so that I can't use it to erase the walls.
So, what would be the approach? Of course in this example I could identify the walls in the second command using a different methodology, such as asking the user to select them etc etc.. But the idea I'm going for would be the store that list from the first command "somewhere in Revit", and retrieve it when calling the second command.
I could write the list to an external text file, and read the file in the second command... but is there a cleaner way?
I'm sorry for the beginner's language used here, and hope that my question is clear enough! And that somebody can help ;)
Best,
Arnaud.
This is a great question Arnaud, in the past Ive done the following:
Create a text project parameter, and populate it with XML (yes you can have line breaks in a text parameter). This is similar to what Ideate BIM Link does (check the project parameters of any project that has used BIM Link). This is a long-winded method for keeping data persistent between commands.
The second part (saving a walls IDs) is more difficult I think, as I understand it every time you open a project the IDs are reassigned. You could test this to see if its the case?
Another method could involve using an External command that lingers after you have finished selecting walls. Could you go into a little more info about what youre wanting to achieve?
So,
Just for leaving a trace, I solved this using pyRevit and its ability to store data in temporary files (here, look for "Using Temporary Files").

Resources