Python Eel - Close windows from js when connection to eel is lost - javascript

During dev it's a pain to close all the eel windows when you need to restart eel for python code changes.
For development purposes, and since we don't yet have live-reload for python using eel, it would be helpful to close all the windows when the python program is quit.
I have the limitation that I am unable to call js from python in case that is part of your solution.
I thought of using a ping to eel and closing each window using this little script, but eel doesn't seem to throw the error while the function is being called.
setInterval(pingEel, 250);
function pingEel(a, b) {
try {
eel.ping_eel();
} catch (error) {
console.log("Ping to eel failed, python must be closed. Closing windows.")
window.close()
}
}

Related

Internal Server error using Bash Terminal, any idea why is it throwing this error and how to fix it?

I have just recently started learning about APIs as party of Full stack developer course. Everything has been working fine until I have activated system storage sense in Windows to clear some space in the disk /c, the curl command stopped working and is giving internal server error.
curl calling request error using bash terminal
I have realized there is an issue when I have run my code and it stopped pulling information from the API link.
Since you made a windows change my guess would be - try addding the curl folder path to your Windows PATH environment variable so that the curl command is available from any location at the command prompt.

Cypress TestRunner via "cypress.open" works locally but does not work on Windows Server 2008

I am using Cypress testing framework JS API and trying to host it on Windows Server 2008. When I execute a Javascript command "cypress.open" locally on Windows 10 laptop, the TestRunner window opens up and I can run manually run tests.
But the same does not work on Windows Server 2008. No error is being reported. Has this something to do with any kind of security aspect related to Windows Server 2008? Can anyone please shed any light on what might be happening here.
I have installed cypress using npm on the server.
npm install cypress
Installing it at C:\Users\xyz\AppData\Local
Here is the Javascript code to open the cypress test runner.
Var cypress = require(‘cypress’);
module.exports = function(callback)
{
cypress.open({
project: ‘./node_modules/.bin’
});
callback(null,”Opening cypress”);
};
I am using ASP.NET Core to run the node module. The C# code is here:
public asynchronous Task<IActionResult> OpenTests()
{
Var data = await _nodeservices.InvokeAsync<string>(“Scripts/OpenTests.js”);
return ok(data);
}
Any help is appreciated. Thank you.
I would verify you meet the System requirements

Writing to terminal in node.js / electron

I'm new to Electron. Just trying it out today, to port a simple single-page app I have in CoffeeScript to it.
To debug something I tried console.log but nothing appears in the terminal that I launch the app. from. Is there a way to write to the terminal from inside node.js / electron?
I'm running the program with
npm start
which I guess is a wrapper for
./node_modules/.bin/electron .
But I'm guessing both suppress writing to stdout. (In node itself console.log seems to write to stdout)

Can programs be written with JavaScript that run Windows 8 terminal commands when a gui button is clicked?

I know Windows 8 'apps' can be developed using web technologies but I haven't been able to find out if terminal commands can be run in the background using web technologies as an interface. I basically have mongoDB on my computer and it takes two terminal windows open to run it. I thought it might be a neat project to see if I could write a little app that is nothing more than a button that launches both commands behind the scenes saving me the hassle of going to the directories and running the commands manually for both terminal windows.
If you plan to launch apps via server-side JavaScript (e.g. node.js), use the child_process module..
The workflow would be that in the windows 8 gui side, it will just issue a request to your own local server in node.js, then it would execute those commands.
Example:
var exec = require('child_process').exec;
var child = exec("insert command here", function(err, stdout, stderr) { });
See examples exec and spawn for more examples.
======
Another thing you can do is create a batch (.bat) file that contains those two commands needed for your mongodb instance and put that as a shortcut in the Windows 8 Start Screen.
It depends on what kinds of commands you need to execute, and when and where. If you plan to execute commands remotely, I'd assume server-side JS would be appropriate, but if you plan to execute commands locally, I think all you need is just batch scripting.

Writing a pseudo terminal in python for a web based ubuntu terminal

I am interested in writing a web based terminal which can execute and autocomplete the commands in ubuntu terminal.
I have fiddled with Anyterm http://www.anyterm.org which uses ROTE: "a simple C library for VT102 terminal emulation" at the backend server and javascript/html for the terminal ui. The problem was that I couldn't have it open two terminals in the same window.
After doing some research I've decided to write a terminal server/pseudo terminal (whichever is the right terminology) in python which can:
execute commands in ubuntu terminal (such as ls, grep etc...)
autocomplete the commands (like $gedi (pressed tab) $gedit)
and have multiple instances of terminal open at the same time (when typed ls in one, the other terminal won't recognize ls as the last command since its another terminal session)
I have found that with pty python module I can write a pseudo terminal
however I'm new to python and I couldn't even get the example on that page to work.
I'm planning to have the python script serve a http server with the javascript/html terminal ui I would write (this was the main reason I wanted to choose python for this project). Then I want to let the web ui talk to the backend terminal "server" and get the results back to the web ui.
If you could point me in the right direction, maybe tell me which module I should use -if not pty- and give me some ideas on how to write the python pseudo terminal server I would appreciate it.
I know javascript/php and familiar with bash scripting- At this point I could go for a C based or python based backend server, is python right for this project?
Note: I'm planning to write a ui that uses ajax post or get methods to retrieve the terminal output from backend server.
You need to learn the basic terminology first. The shell is the program that interprets your input command lines, such as grep "foo" abc.txt. A terminal emulator is a program that mimics a terminal. Terminal is a device with display and keyboard that one
used in 1970s to access a UNIX mainframe. A pseudoterminal, pty is the device node supporting terminal emulators, as opposed to "real terminal devices" (tty1) for example.
Now, you could either build a shell, that would work in terminal instead of bash or dash; or you could build a terminal emulator that is usable over the internet; you could run any existing shell in it. Both are challenging tasks by themselves.
Python documentation is not of much use, I recommend you should start by googling more of these concepts first - and not only python references, but C, C++ too.
And lastly, if you want to run Emacs or nano or some other advanced program in your shell, you want to use the pty module.
I had a friends who did something similar but he did it over Google chat, I don't know how much help it will be but take a look at xmpp (python modual) maybe it could help you, or even here is a link to his source code:
chatIO
I didn't work with him on it but it was really easy for him to use
Good Luck

Categories