Minimal code example, run on OSX and Python 3:
#! /usr/bin/env python3
from dialog import Dialog
d = Dialog(dialog="dialog")
sel = d.menu("Test",
choices=[ ("FooTag", "Foo", False, "FooHelp"),
("BarTag", "Bar", True, "BarHelp")]
)
I get the error message:
Traceback (most recent call last):
File "./test.py", line 5, in <module>
d = Dialog(dialog="dialog")
File "/usr/local/lib/python3.3/site-packages/dialog.py", line 1371, in __init__
self.backend_version())
File "/usr/local/lib/python3.3/site-packages/dialog.py", line 2012, in backend_version
"{1!r}".format(self._dialog_prg, output))
dialog.UnableToRetrieveBackendVersion: Unable to retrieve the version of the dialog-like backend: unable to parse the output of '/usr/local/bin/dialog --print-version': ''
However, dialog reports correctly:
> dialog --print-version
Version: 1.1-20100428
>
Nothing changes, if I use the absolut path /usr/local/bin/dialog. I guess, it is an install problem, but I've no clue.
As you have found yourself, the problem is caused by the fact that your dialog program prints its version on stdout whereas more recent versions print it on stderr. So, the string pythondialog tries to parse as a version number is empty in such a case.
pythondialog 3.2.2rc1 (latest release at the time of this writing) detects this situation and automatically reruns dialog --stdout --print-version, making sure this time to read from dialog's stdout stream. Since this is only done once at Dialog instance creation (the backend version being cached), the impact of this workaround is minimal.
It is better than your solution (passing use_stdout=True to the Dialog constructor), because it allows the rest of pythondialog to use dialog's stderr stream normally: the use of --stdout is only limited to retrieving the version of dialog. On the contrary, the solution you found will pass --stdout to all dialog calls which, according to the dialog(1) manual page, may fail "depending on the platform and your environment".
Had you reported this problem on the pythondialog issue tracker or mailing list, the workaround I mentioned here would certainly have been implemented earlier...
Your example with little fixes for on my computer (i changed False to 'False'). Your issue is that version is not matched against regex. This is code from pythondialog:
mo = self._print_version_cre.match(output)
if mo:
return mo.group("version")
else:
raise UnableToRetrieveBackendVersion(
"unable to parse the output of '{0} --print-version': "
"{1!r}".format(self._dialog_prg, output))
#this is located upper
_print_version_cre = re.compile(r"^Version:[ \t]+(?P<version>.+?)[ \t]*$", re.MULTILINE)
I've tested your version with this regexp and it matched on my computer, but I guess you have other version of pythondialog. So check _print_version_cre in your dialog.py and try to much with dialog version.
I found the solution myself:
dialog in OSX reports to stdout, not stderr.
By using
d = Dialog(dialog="dialog", use_stdout=True)
I get the expected result.
Related
I have a Python subprocess to call R:
cmd = ['Rscript', 'Rcode.R', 'file_to_process.txt']
out = subprocess.run(cmd, universal_newlines = True, stdout = subprocess.PIPE)
lines = out.stdout.splitlines() #split stdout
My R code first checks if the 'ape' package is installed before proceeding:
if (!require("ape")) install.packages("ape")
library(ape)
do_R_stuff.......
return_output_to_Python
Previously, the whole process from Python to R worked perfectly - R was called and processed output was returned to Python - until I added the first line (if (!require("ape")) install.packages("ape")). Now Python reports: "there is no package called 'ape'" (i.e. when I uninstall ape in R). I have tried wait instructions in both the R and Python scripts but I can't get it working. When checking, the R code works in isolation.
The full error output from Python is:
Traceback (most recent call last):
File ~\Documents\GitHub\wolPredictor\wolPredictor_MANUAL_parallel.py:347 in <module>
if __name__ == '__main__': main()
File ~\Documents\GitHub\wolPredictor\wolPredictor_MANUAL_parallel.py:127 in main
cophen, purge, pge_incr, z, _ = R_cophen('{}/{}'.format(dat_dir, tree), path2script) #get Dist Mat from phylogeny in R
File ~\Documents\GitHub\wolPredictor\wolPredictor_MANUAL_parallel.py:214 in R_cophen
purge = int(np.max(cophen) * 100) + 1 #max tree pw distance
File <__array_function__ internals>:5 in amax
File ~\anaconda3\lib\site-packages\numpy\core\fromnumeric.py:2754 in amax
return _wrapreduction(a, np.maximum, 'max', axis, None, out,
File ~\anaconda3\lib\site-packages\numpy\core\fromnumeric.py:86 in _wrapreduction
return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
ValueError: zero-size array to reduction operation maximum which has no identity
Loading required package: ape
Installing package into 'C:/Users/Windows/Documents/R/win-library/4.1'
(as 'lib' is unspecified)
Error in contrib.url(repos, "source") :
trying to use CRAN without setting a mirror
Calls: install.packages -> contrib.url
In addition: Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called 'ape'
Execution halted
Point 1: The path to R libraries when using R in a standalone mode may not be the same when using Rscript.
Point 2: The error says there was difficulty in finding the CRAN repository, so perhaps the options that set the repos were not set for the Rscript environment. They can be set in the call to install packages or with a Sys.setenv() call.
Ther OP wrote: "Thanks #IRTFM I had to set a new sub process in a new .R file specifically for the install, but the CRAN mirror was key, I never realised it would be an issue as it's not a requirement on my local machine (not sure why it becomes an issue thru subprocess)."
The places to find more information are the ?Startup help page and the ?Rscript page. Rscript has many fewer defaults. Even the usual set of recommended packages may not get loaded by default. The Rscript help page includes these flags which could be used for debugging and setting a proper path to the libraries desired.:
--verbose
gives details of what Rscript is doing.
--default-packages=list
where list is a comma-separated list of package names or NULL. Sets the environment variable R_DEFAULT_PACKAGES which determines the packages loaded on startup.
Here is a previous similar SO question with an answer that includes some options for construction of a proper working environment: Rscript: There is no package called ...?
There are a few R packages on CRAN that aid in overcoming some of the differences between programming for standalone R and Rsript.
getopt: https://cran.r-project.org/web/packages/getopt/index.html
optparse: https://cran.r-project.org/web/packages/optparse/index.html (styled after a similar Python package.)
argparse: https://cran.r-project.org/web/packages/argparse/index.html
I solved the issue (thanks to #IRTFM) by placing the if-then-install.packages code in a separate Rscript (including the CRAN mirror):
if (!require("ape")) install.packages("ape", repos='http://cran.us.r-project.org')
which I then called using a separate Python subprocess in my Python routine
Swi-prolog provides an in-built "shell" predicate to interact with operating system but the documentation is poor.
For a Windows platform, I want to execute something like this:
shell('cmd.exe python file_name.py')
This hangs the terminal!
But if I use: shell('cmd.exe ipconfig')
This gives a true and hence I suppose it is working.
You can use process_create/3 inside a setup_call_cleanup/3
I have not tried this in windows just linux but I think it would be similar:
(I also show how to call jars)
run_jar(Jar,Option,Lines):-
setup_call_cleanup(
process_create(path(java),['-jar',Jar,Option],[stdout(pipe(Out))]),
read_lines(Out,Lines),
close(Out)).
run_python(Script,Option,Lines):-
setup_call_cleanup(
process_create(path(python),[Script,Option],[stdout(pipe(Out))]),
read_lines(Out,Lines),
close(Out)).
read_lines(Out, Lines) :-
read_line_to_codes(Out, Line1),
read_lines(Line1, Out, Lines).
read_lines(end_of_file, _, []) :- !.
read_lines(Codes, Out, [Line|Lines]) :-
atom_codes(Line, Codes),
read_line_to_codes(Out, Line2),
read_lines(Line2, Out, Lines).
Currently I'm working with 3D objects rendering. In that while dealing with framebuffer part I'm getting some error.
self.fbo = glGenFramebuffers(1)
whenever interpreter hits this line its showing following error
**File "C:\Python27\lib\site-packages\OpenGL\latebind.py", line 44, in __call__
self._finalCall = self.finalise()
File "C:\Python27\lib\site-packages\OpenGL\extensions.py", line 189, in finalise
self.__name__,
NullFunctionError: Attempt to call an undefined alternate function (glGenFramebuffers, glGenFramebuffersEXT), check for bool(glGenFramebuffers) before calling**
I'm using python 2.7.3 and pyOpenGL 3.0.2.I couldn't find any answer for this error.
If bool(glGenFramebuffers) returns False, the error probably means that your computer does not have access to OpenGL >= 2.1 so Framebufffer objects won't work. Check your OpenGL supported version with GPU Caps Viewer for Windows. For Linux see here: https://askubuntu.com/questions/47062/what-is-terminal-command-that-can-show-opengl-version
If you have at least 2.1, then maybe the library you are using to create the context (pySDL, glut, pySFML, etc.) is not creating a compatible one. Fixing that depends on the library and probably already has an answer.
If bool(glGenFramebuffers) returns True, the problem might be somewhere else early in the code.
Also, remember that the context must be created and current before trying to create or use shaders, framebuffers, etc.
I'm trying to create an automated GUI test framework for a desktop application and I am using pywinauto for this.
My problem is that even using SWAPY and Winspector I still have problems detecting the tray area and finding my app there.
I have tried everything from the current documentation and also tried the Volume example from the web to no success.
from pywinauto import taskbar
sti = taskbar.SystemTrayIcons.WrapperObject()
print 'Clicking ', sti.Button(0).info.text
sti.Button(0).Click()
Technically the only thing i need is finding the exact position of the tray icon and executing a click on it to bring up a menu.
pywinauto has some functions related to the taskbar but i wasn't able to get them to work.
Could anybody give me any ideas on how to do this?
EDIT
I tried your idea Vasily but I am getting this error:
import pywinauto
from pywinauto import taskbar
app = pywinauto.application.Application()
app.start_('C:\Program Files (x86)\MyApp.exe')
w_handle = pywinauto.findwindows.find_windows(title=u'MyApp')[0]
window = app.window_(handle=w_handle)
texts = taskbar.SystemTrayIcons.Texts()
print texts
and the traceback:
Traceback (most recent call last):
File "C:/Users/nicolae.farcas/Desktop/pywinauto_c1.py", line 9, in <module>
texts = taskbar.SystemTrayIcons.Texts()
File "C:\Python27\lib\site-packages\pywinauto\controls\common_controls.py", line 1932, in Texts
btn_text = self.GetButton(i).text
File "C:\Python27\lib\site-packages\pywinauto\controls\common_controls.py", line 1914, in GetButton
button.idCommand)
RuntimeError: GetButtonInfo failed for button with command id 0
I'm using Windows 7 Pro x64 right now but I need this to also run on 8, 8.1 and 10 (I can drop 10 since I imagine support for it is still behind)
If you use pywinauto 0.5.1, please call taskbar.SystemTrayIcons.Texts() and then copy corresponding text to the following call:
taskbar.ClickSystemTrayIcon('button text', exact=True, double=True)
For hidden area use ClickHiddenSystemTrayIcon(...).
Also please note that popup menu belongs to your application process. So you need to connect to the application and call app.PopupMenu.MenuItem('item name').Click() or ClickInput().
If it doesn't work, please provide error output and OS version.
EDIT:
(comment about Python 32/64 bit problem)
Ideal way is running taskbar specific code in 64-bit Python and then launching 32-bit Python for separate app specific script. It's not so convenient but should work.
I have a widget where the mac shortcut Command+C works well interactively, and the content is correctly stored in the clipboard.
I am trying to implement the same behavior in the unittests. It works on other platforms, but not on Mac.
expected_clipboard = "whatever"
self._widget.show()
Test.processEvents()
QtTest.QTest.keyClick(self._widget, QtCore.Qt.Key_C, QtCore.Qt.ControlModifier)
Test.processEvents()
current_clipboard= QtGui.qApp.clipboard().text()
self.assertEqual(current_clipboard, expected_clipboard) # Fails.
According to the Qt documentation, ControlModifier is the proper corresponding entity for Command on Mac. I also tried MetaModifier just out of curiosity, but it doesn't work.
The action is correctly attached with the following code
self._action = QtGui.QAction('text', self)
action.connect(self._action, QtCore.SIGNAL('triggered()'), self.copyAction)
self._action.setShortcut(QtGui.QKeySequence.Copy)
self.addAction(self._action)
Qt 4.8 latest, osx 10.8.
Ok, the problem is that the window must be visible, raised and activated, otherwise OSX does not deliver events. Just call widget.raise_() and widget.activateWindow()