Mathematica "export" function creates irritating pop-up window when generating graphics - graphics

Is there a way to prevent Mathematica(7)'s Export function from creating annoying pop-up windows when it is used to created graphics? I understand that it has to call the front end and use the system's window manager to create the graphics, but when I am running automated generation of a lot of graphics in the background it is extremely disruptive to have these blank windows popping up and disappearing constantly. It occurs when using Mathematica through the front-end and through the kernel for batch jobs.
I can find no discussion on this anywhere, surely I am not the only one who finds this really annoying. My OS is Ubuntu 9.10, perhaps this doesn't happen on other OS's?

I'm running Ubuntu 11.04 and I couldn't get any popup windows when generating graphics in Mathematica 7 or 8.
For example, create a file "makegraphs.m" containing the following
num = 10;
g = Graphics[];
Do[g = Show[g, Plot[Sin[i x], {x, 0, 2 Pi}, PlotStyle -> ColorData[2][i]]];
(*Print[g];*)
Export[FileNameJoin[{$HomeDirectory, "g"<>ToString[i]<>".eps"}], g],
{i, 1, num}];
Exit[]
which you call from the shell using math -noprompt -initfile "makegraphs.m" or math -noprompt -run "<<makegraphs.m",
for command-line switches, see the version 7 documentation: math.
This does not create any frontend windows even when the print statement is uncommented.
Note that graphics never do not normally display when using the Mathematica command prompt: e.g.
:~$ math7
Mathematica 7.0 for Linux x86 (64-bit)
Copyright 1988-2009 Wolfram Research, Inc.
In[1]:= Plot[x,{x,0,1}]
Out[1]= -Graphics-
However, if you are (automatically) loading a package like <<JavaGraphics`, then the command prompt will produce graphics windows - but they won't be blank, nor Mathematica notebook windows.
Maybe you can post some of the code you're using?
Also, have you tried SetOptions[Plot,DisplayFunction->Identity]?
Note that in Mathematica version 8, a script mode has been added (see also math).

Related

Changing a default color in curses

In playing with the curses library, I discovered that if a default color is changed (say COLOR_BLUE, for example) using init_color, that changed color will continue to be used across stopping and restarting my program if I don't reset it back to its original definition. Even creating a new terminal window in which to run the program, the color of blue shows up as defined in the original windows. It even survives running a completely different program.
How is this happening? I would have thought the original definition would be used upon starting a new instance. I can only surmise that these default colors are cached somewhere at the OS level. Can someone explain what is happening here that allows this to happen?
I'm running this on a Centos 7.6 distro.
The colors are maintained/cached/whatever by a given terminal.
If the terminal description has this feature:
orig_colors oc oc Set all color pairs
to the original ones
that would be sent by the ncurses library as part of exiting curses mode.
It also might be sent by reset (or tput reset) command as part of the rs1 string. That's not automatic (and those commands do nothing special with color other than as a side-effect of the initialization and reset strings).
xterm supports a control sequence for resetting palettes back to their default, which was added to the terminal description in
2016-04-23
# + add 'oc' capability to xterm+256color, allowing palette reset for
# xterm -TD
referring to this:
oc=\E]104\007,
That uses OSC 104, which was developed for xterm in patch #252 (2009/12/7):
add OSC 104, for resetting ANSI/16/88/256 colors to default.
However, in discussing CentOS (RHEL), you have to keep in mind that it doesn't get updates for things like that:
The package information says that it has a development snapshot of ncurses from just a couple of days past 8 years ago.
Your terminal may/may not support the control sequence. If you are using xterm, no problem. For anything else (with that version of CentOS), you are out of luck. VTE developers (e.g., gnome-terminal) copied the feature in January 2014, but that version of VTE was released as 0.35.2, while CentOS 7 has 0.28.2

Inconsistent Imagesnap behavior taking pictures on MacOS X, depending on calling environment

EDITED POST
When I first wrote this, I was mystified by the varied behaviors of the "imagesnap" USB cam image capture program on MacOS. Sometimes it took pictures and sometimes it didn't, and this seemed to vary with the environment where it was called: such as directly in a Terminal window, in a shell program, in a Python program running in the Terminal, in a Python program running in the Pycharm IDE, called with os.popen(), subprocess.run(), subprocess.call(), subprocess.popen(), etc.
Sometimes imagesnap would work just fine and take images, and sometimes it would fail silently. I was really having a hard time figuring out why the behaviors were varied, and how to get picture taking using imagesnap on my mac to work reliably when called from a Python program.
I searched on keywords like MacOS, Catalina, imagesnap, USB camera, webcam, Python, PyCharm IDE, shell command, os.popen(), subprocess.run(), subprocess.call(), subprocess.Popen(), and more. I did not find the solution anywhere, and I didn't get an answer here.
I've finally understood the problem better, and that's why I've rewritten this question.
What's behind the inconsistent behavior of imagesnap when called from different environments, and how can I call it from a Linux program and get it to reliably take pictures?
I now understand that MacOS X's privacy settings in System Preferences control which environments are allowed or silently denied to access USB cameras.
For more detail, and a workaround, see my own answer below. I hope that others who understand the issues even more will add improved answers.
ORIGINAL POST:
Below is a simple Python test program. It uses os.popen() and
captures an image from a selected USB webcam using imagesnap -d and
saves an image in image.jpg.
But the imagesnap -d command behaves differently when running in the
PyCharm environment, returning a blank response (' ') and failing to save the requested image.
Submitting this same code WITHIN PyCharm's terminal window fails in
exactly the same way.
But when the same python commands are submitted to the terminal
outside Pycharm, the program takes the image successfully and reports back as shown in the output below.
I'm running Mac OS X Catalina, and using PyCharm 2019.2.3
Community Edition for development. Python version is 3.7.4
Sample code:
import os
return_string = os.popen("imagesnap -d 'DEVICE_NAME' 'image.jpg'").read()
print("'",return_string,"'")
Within the PyCharm development environment this program returns the following and does not create the jpg file:
/Users/mcgregor94086/PycharmProjects/SonaScannerGUI/venv/bin/python
/Users/mcgregor94086/Library/Preferences/PyCharmCE2019.2/scratches/scratch_5.py
' '
Process finished with exit code 0
Outside PyCharm this same code returns:
$ python3
Python 3.7.4 (v3.7.4:e09359112e, Jul 8 2019, 14:54:52)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> return_string = os.popen("imagesnap -d 'DEVICE_NAME' 'image.jpg'").read()
>>> print("'",return_string,"'")
' Capturing image from device "<AVCaptureDALDevice: 0x7fa9bc203330 [DEVICE_NAME][0x141717501bcf0b09]>"... '
>>>
After digging into this problem a great deal, and without any responses, I started to search the web more broadly for answers. And although I found almost no information on the web to guide me what was happening, I now believe that I know what is preventing me from taking pictures programmatically within a python program. I also believe that I now have a reasonable hypothesis as to why I am seeing the results I was seeing.
I have a work around that is currently working, but which I fear may not in the future.
The believe the problem has to do with MacOS and I believe it may vary with the specific release of MacOS. I am currently using MacOS X 10.15.1 Catalina. earlier MacOS X releases might not be as strict.
In the Catalina release at a minimum, ANY connected USB Camera is considered a special device governed by special security, and management of access to the camera device is controlled in the Systems Preferences -> Security & Privacy panel.
When you click the Camera row in the menu on the left of the panel you will see a checkbox list of apps which are allowed to programmatically access you camera. If you unlock the page (lower left), you can change which apps are allowed to access the camera by checking or unchecking them in the list.
On the machines I have available, there is a list of 4 apps in this panel: Terminal, UberConference, Google Chrome, Skype.
The list of available apps varies for other resources, such as Contacts, Calendars, Accessibility, Full Disk Access, etc.
Some of these resources (such as Accessibility and Full Disk Access) selection lists have a pair of "+|-" buttons below the app list that allow you to add, or permanently remove, apps from accessing that resource.
But Camera. Microphone and some other resource do not have such a pair of buttons, and for these devices, the list appear unchangeable by the user.
The panel suggests that the apps get on the list by "requesting access" to the camera, but I have not found an explanation anywhere on line about how to add an app to this access list.
One of the predefined apps in the list is "Terminal". That was checked, so when I ran imagesnap from within a terminal window the program had the necessary privacy privileges and the camera took pictures just fine.
In contrast, when I tried to run a python program within the PyCharm IDE, the PyCharm IDE did not identify itself as a terminal and the request silently failed.
Python has a number of different ways to launch an independent program such as imagesnap. These methods include os.popen(), subprocess.run() and subprocess.Popen(). Some of these methods are deprecated, so we can't rely on them working in the future. Other methods() have additional options which control whether a new "shell" is created or not, and these may complicate determining what environment the app will see.
I found it confusing to try to predict which of these python methods
would succeed in opening the camera and which would not, as well as
their behavior when run inside the IDE vs. in a terminal window.
Perhaps someone else can compile such a table.
Work around: For the present, I was able to work around this problem by using os.popen, by having it open a new terminal with an initial string. This seems to ensure that Apple security sees the parent as the "Terminal" app which we specifically authorized in the control panel.
I then found
os.popen("open -a Terminal.app imagesnap.sh")
worked.
While this work around is working for me at present, I was not happy about using os.popen() instead of one of the subprocess methods, as I worry it may be deprecated. Second, this worked with a shell script ("imagesnap.sh") but I have not figured out how to pass parameters or run executables.
Perhaps a knowledgable reader can help with better suggestions.

Gnuplot - Windows terminal and save in png/pdf ... (not only .EMF)

I'm using gnuplot to draw graphics by piping the data from my C++ program to gnuplot.exe trough shell. I'm using the windows terminal and it is used exclusively with Windows OS.
However, I can only save the graphic as a .EMF file. How can I extend the windows GUI terminal to support more formats ?
I think that the windows GUI terminal can not be extended.
I have finally switched to the QT interactive terminal as recommended by #gboffi. This terminal permits to export the graph to :
pdf
svg
bmp (via image)
png (via image)
See bellow :
Note that this answer entails that the generated gnuplot.exe will be dependent to some external dlls ( QT5Core.dll ...)

GTK+, GLADE, PYTHON 3.6 Windows

I am an Electrical engineer. I am completely new for programming and coding..
Actually i am working as estimation engineer, where i am doing the same estimation again and again with excel.
As same in design stage also i am doing the same again and again.
I thought i will create a application which will automatically do the estimation based on my input. and the same time at the time of design stage it will input from my estimation sheet it will generate the drawing automatically.
(i am doing estimation in excel, preparing drawing in auto cad)
from google, i found the following..
To write a program I need to know a language. so i selected python version 3.6.1
To create a stand alone or micro soft windows installer i selected cx freeze which is converting my code to .exe filex
To create a user interface i selected glade.
But i dont know how to install gtk builder to link pythin code and glade files.
Hopefully you got the point what i am looking..
I am using windiws 10 with 64 bit version
Advance thanks for all
All the information you need on how to install GTK+ and Glade on Windows is on the GTK+ Website.
However, If you're a total beginner, then I suggest you start small, as the kind of work you're describing seems a lot of work for someone who has never written a single line of code.
As suggested by #liberforce, install GTK+ and Glade on Windows from their GTK+ Website. This way you will have an environment (MINGW64) inside which you can practice.
Install python from their download site.
Check also these instructions for how to use it.
The key points (at least for me) are:
Copy the hello.py script you created to C:\msys64\home\<username>
In the mingw32 terminal execute python3 hello.py - a window should appear.
After that, if you want to make an executable, follow these instructions. Try their example for gedit to get some ideas on how to create and how PKGBUILD works (a.k.a. follow the instructions for gedit to see what's happening).

Visual Studio Code transparent window?

A have a small resolution on my PC so it's not very convenient to work in several tabs at the same time like: open console window, browser, code editor and some other stuff.
Console has a very cool feature: a transparent background, so it's very very comfortabe to type something in console while looking to some learning material in browser through the trasparent background.
So I guessed if there any way to make VS Code transparent so i can write code and research in browser at the same time not Alt-Tabing any time I have to switch, so I dont have to interrupt my workflow such often.
Use VS Code extension
GlassIt-VSC
search in extension search bar
just install and enjoy
it works great !
Don't know about other OS but Windows can make any window transparent.
I've tried several 3rd party apps and stopped on AutoHotkey (free, Open-source, easy to learn, can be used for much more).
Install AutoHotkey
Create file transparency.ahk
Place inside this file:
^!RButton::
WinGet, currentTransparency, Transparent, A
if (currentTransparency = OFF)
{
WinSet, Transparent, 150, A
}
else
{
WinSet, Transparent, OFF, A
}
return
Run the script
This script will toggle active window transparency(0-255, 0 - transparent, 255 - opaque)
on Ctrl+Alt+Right mouse button
^ - Ctrl
! - Alt
RButton - Right mouse button
Add this script to startup folder (Win+R shell:common startup)
Based on: https://superuser.com/questions/272812/simple-transparency-toggle-with-autohotkey
As far as I know - this isn't possible in e.g. Visual Studio Express or VS Code.
It seems not to be on the feature request list at Microsoft.
One solution I see for you is Notepad++. Install the TopMost add-in. It works like you can see in following screenshot:
All the possible solutions are in:
"How to be cool and make Visual Studio Code (VSCode) transparent " from Emmanuel N Kyeyune
Mainly:
Windows 10
Install the GlassIt-VSC extension
In the VSCode settings (File > Preferences > Settings OR Ctrl + ,):
glassit.alpha (integer): Transparency level [1-255]
glassit.step (integer): Increment of alpha OR:
ctrl+alt+z to increase transparency and
ctrl+alt+c to decrease it as set by the extension
(take care it doesn't override some other shortcuts assigned these hotkeys)
Linux (tested on Ubuntu 18.04)
Based on devilspie
sudo apt-get install devilspie
with instruction like:
( if
( contains ( window_class ) "Code" )
( begin
( spawn_async (str "xprop -id " (window_xid) " -f _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY 0xdfffffff") )
)
)
PR 52707 "Windows, macOS and Linux transparency" from Charles Milette (sylveon).
The PR has been closed in August 2019:
We currently do not accept more features that are Electron specific. We have seen to many issues lately when updating to newer Electron versions and playing the catch-up game is very painful.
But said PR still includes a ton of options, like the Vibrancy extension.
Update Dec. 2021:
Chaim Eliyah mentions in the comments:
Vibrancy "works" for Mac OS X; it modifies the base CSS files so Microsoft will forever complain about your VSCode installation
(they tell you how to ignore the warning in the README)
If your in Linux(Debian), Install this: Glassit Linux
Don't remember Install requirements:
sudo apt install -y wmctrl x11-utils bash

Resources