Can't catch InvalidFileException - python

I'm trying to get a path of a file via filedialog from tkinter but instead of choosing a file I'm closing the window to browse for that file which makes my GUI go a bit crazy.
When I close the browsing window I see the following log:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Shtlrs\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1702, in __call__
return self.func(*args)
File "D:\Invoice handling\GUITest.py", line 76, in browseXLL
self.man = xManip.XManip(file)
File "D:\Invoice handling\xManip.py", line 13, in __init__
self.sheet = openpyxl.load_workbook(path)
File "D:\Invoice handling\venv\lib\site-packages\openpyxl\reader\excel.py", line 313, in load_workbook
data_only, keep_links)
File "D:\Invoice handling\venv\lib\site-packages\openpyxl\reader\excel.py", line 124, in __init__
self.archive = _validate_archive(fn)
File "D:\Invoice handling\venv\lib\site-packages\openpyxl\reader\excel.py", line 94, in _validate_archive
raise InvalidFileException(msg)
openpyxl.utils.exceptions.InvalidFileException: openpyxl does not support file format, please check you can open it with Excel first. Supported formats are: .xlsx,.xlsm,.xltx,.xltm
What I want to do is restart the GUI ( or maybe eventually another action) when I close the browsing window
here's the bit of code that's supposed to handle the situation:
from tkinter import messagebox
from tkinter import filedialog
from openpyxl.utils.exceptions import InvalidFileException
...
def browseXLL(self,event):
try:
file = filedialog.askopenfilename()
except InvalidFileException:
self.window.destroy()
self.__init__()
but the error is n

Related

Your Config.prc file must name at least one valid panda display library via load-display or aux-display. error

I am using panda3d and have come across a bug in my code. I can't seem to find whats wrong.
Here it is:
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/panda3d/etc/Confauto.prc
:util: Reading /Users/Munish/Desktop/python/pygame_games/Config.prc
Known pipe types:
(all display modules loaded.)
Traceback (most recent call last):
File "3d.py", line 12, in <module>
game = MyGame()
File "3d.py", line 10, in __init__
super().__init__()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/direct/showbase/ShowBase.py", line 338, in __init__
self.openDefaultWindow(startDirect = False, props=props)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/direct/showbase/ShowBase.py", line 1020, in openDefaultWindow
self.openMainWindow(*args, **kw)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/direct/showbase/ShowBase.py", line 1055, in openMainWindow
self.openWindow(*args, **kw)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/direct/showbase/ShowBase.py", line 765, in openWindow
win = func()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/direct/showbase/ShowBase.py", line 745, in <lambda>
func = lambda : self._doOpenWindow(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/direct/showbase/ShowBase.py", line 817, in _doOpenWindow
self.makeDefaultPipe()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/direct/showbase/ShowBase.py", line 646, in makeDefaultPipe
self.notify.error(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/direct/directnotify/Notifier.py", line 130, in error
raise exception(errorString)
Exception: No graphics pipe is available!
Your Config.prc file must name at least one valid panda display
library via load-display or aux-display.
Here is my coding script:
from panda3d.core import loadPrcFile
from panda3d.core import ConfigPageManager
print( ConfigPageManager.getGlobalPtr())
loadPrcFile('Config.prc')
from direct.showbase.ShowBase import ShowBase
class MyGame(ShowBase):
def __init__(self):
super().__init__()
game = MyGame()
print(base)
ShowBase().run()
Here is my Config.prc:
window-width 1280 720
What am I doing wrong? Thank you in advance.
this should hopefully work:
3d.py:
from panda3d.core import loadPrcFile
from panda3d.core import ConfigPageManager
from direct.showbase.ShowBase import ShowBase
print(ConfigPageManager.getGlobalPtr())
# capitalization is important.
loadPrcFile('config.prc')
class MyGame(ShowBase):
def __init__(self):
super().__init__(self)
game = MyGame()
print(base)
game.run()
config.prc:
win-size 1280 720
Rename your Config.prc file to something else. Otherwise, you are overriding Panda3D's default configuration file, which is also called Config.prc.

pygame game crashes when I edit tilesheets in tiled

I am trying to make a game with pygame using tiled. When I edit tilesheets (to for example add collision) I get a bunch of error messages when I run my code.
When I use the same tilesheet without editing I get no errors and all the files work.
Traceback (most recent call last):
File "C:/Users/47988/PycharmProjects/Terrible/Main.py", line 94, in
<module>
g = Game()
File "C:/Users/47988/PycharmProjects/Terrible/Main.py", line 16, in init
self.load_data()
File "C:/Users/47988/PycharmProjects/Terrible/Main.py", line 22, in load_data
self.map = TiledMap(path.join(map_folder, "map6.tmx"))
File "C:\Users\47988\PycharmProjects\Terrible\Tilemap.py", line 21, in init
tm = pytmx.load_pygame(filename, pixelalpha=True)
File "C:\Users\47988\PycharmProjects\Terrible\venv\lib\site- packages\pytmx\util_pygame.py", line 141, in load_pygame
return pytmx.TiledMap(filename, *args, **kwargs)
File "C:\Users\47988\PycharmProjects\Terrible\venv\lib\site-packages\pytmx\pytmx.py", line 360, in init
self.parse_xml(ElementTree.parse(self.filename).getroot())
File "C:\Users\47988\PycharmProjects\Terrible\venv\lib\site- packages\pytmx\pytmx.py", line 400, in parse_xml
self.add_tileset(TiledTileset(self, subnode))
File "C:\Users\47988\PycharmProjects\Terrible\venv\lib\site-packages\pytmx\pytmx.py", line 845, in init
self.parse_xml(node)
File "C:\Users\47988\PycharmProjects\Terrible\venv\lib\site-packages\pytmx\pytmx.py", line 874, in parse_xml
raise Exception
Exception
Is there any way of solving this?

Python 3.x multiprocessing tkinter mainloop

How do you use multiprocessing on root.mainloop? I am using Python 3.6. I need to do lines of code after it, some requiring the object.
I do not want to create a second object, like some of the other answers for my question suggest.
Here is a little code snippet (set being a JSON object):
from multiprocessing import Process
def check():
try: sett['setup']
except KeyError:
sett['troubleshoot_file']=None
check()
else:
if sett['setup'] is True: return
elif type(sett['setup']) is not bool: raise TypeError('sett[\'setup\'] is not a type of boolian (\'bool\')')
root.=Tk()
root['bg']='blue'
mainloop=Process(target=root.mainloop)
mainloop.start()
mainloop.join()
check()
However, I get this traceback:
Traceback (most recent call last):
File "(directory)/main.py", line 41, in <module>
check()
File "(directory)/main.py", line 39, in check
mainloop.start()
File "C:\Program Files (x86)\Python36-32\lib\multiprocessing\process.py", line 105, in start
self._popen = self._Popen(self)
File "C:\Program Files (x86)\Python36-32\lib\multiprocessing\context.py", line 223, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "C:\Program Files (x86)\Python36-32\lib\multiprocessing\context.py", line 322, in _Popen
return Popen(process_obj)
File "C:\Program Files (x86)\Python36-32\lib\multiprocessing\popen_spawn_win32.py", line 65, in __init__
reduction.dump(process_obj, to_child)
File "C:\Program Files (x86)\Python36-32\lib\multiprocessing\reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
TypeError: can't pickle _tkinter.tkapp objects
I have tried running:
from queue import Queue
from tkinter import Tk
from multiprocessing import Process
p=Process(target=q.get())
The interpreter then completely crashes.
You cannot use any tkinter objects across multiple processes or threads. If you need to share data between the gui and other processes you will need to set up a queue, and poll the queue from the GUI.
The reason for this is that tkinter is a wrapper around a tcl interpreter that knows nothing about python threads or processes.
You will find a link on how to do this at:
docs.python.org/3.6/library/queue.html

Error for Next button in pywinauto using python

I have to currently install windows application, create a new database etc almost everyday when testing the Windows desktop software builds that I get.
To make this job easier, I've decided to use python with pywinauto to automate this process.
Currently I was just trying to write a sample script to automate just another application. Following is my code:
from pywinauto.application import Application
app = Application().start(r"E:\New\any-video-converter.exe -a -n -y -- arguments")
dlg=app['Setup - Any Video Converter Professional']
Now I wanted to click on the 'Next >' button on the setup so I added the following to my code:
app.dlg.Next.Click()
But I get the following error message:
Traceback (most recent call last): File
"C:\Python34\lib\site-packages\pywinauto\application.py", line 243, in
__resolve_control
criteria)
File "C:\Python34\lib\site-packages\pywinauto\timings.py", line 424, in
wait_until_passes
raise err pywinauto.timings.TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in
<module>
app.dlg.NextButton.ClickInput()
File "C:\Python34\lib\site-packages\pywinauto\application.py", line 349, in
__getattribute__
ctrls = self.__resolve_control(self.criteria)
File "C:\Python34\lib\site-packages\pywinauto\application.py", line 246, in
__resolve_control
raise e.original_exception
File "C:\Python34\lib\site-packages\pywinauto\timings.py", line 402, in
wait_until_passes
func_val = func(*args)
File "C:\Python34\lib\site-packages\pywinauto\application.py", line 188, in
__get_ctrl
dialog = self.backend.generic_wrapper_class(findwindows.find_element(**criteria[0]))
File "C:\Python34\lib\site-packages\pywinauto\findwindows.py", line
84, in find_element
elements = find_elements(**kwargs)
File "C:\Python34\lib\site-packages\pywinauto\findwindows.py", line 294, in
find_elements
elements = findbestmatch.find_best_control_matches(best_match, wrapped_elems)
File "C:\Python34\lib\site-packages\pywinauto\findbestmatch.py", line 534, in
find_best_control_matches
raise MatchError(items = name_control_map.keys(), tofind = search_text)
pywinauto.findbestmatch.MatchError: Could not find 'dlg' in 'dict_keys([])'
Here is the snippet of the UI of the installer: Sample installer UI
I can't understand what's going wrong here. Any help would be appreciated.

pandasDataFrame.to_clipboard() error

I have this code to enable CTRL+C copy on the selected contents of a tkinter.ttk treeview:
def Copy(event):
'''
Copies the selected treeview items to the
clipboard. Includes Column numbers.
'''
selectedRows = []
selectedRows.append(self.maindata.columns)
for i in self.tree.selection():
selectedRows.append(self.tree.item(i)['values'])
d = pd.DataFrame(selectedRows)
d.to_clipboard(index=False)
self.tree.bind("<Control-Key-c>", Copy)
This was working fine in plan text.py files executed in IDLE but I'm using the Liclipse IDE for a more confortable debugging experience now and I get the error:
Exception in Tkinter callback
Traceback (most recent call last):
File "E:\Programming\Anaconda3_4.2.0\lib\tkinter\__init__.py", line 1550, in __call__
return self.func(*args)
File "E:\Programming\EclipseWorkspace\AssetManager\workingTreeview.py", line 90, in Copy
d.to_clipboard(index=False)
File "E:\Programming\Anaconda3_4.2.0\lib\site-packages\pandas\core\generic.py", line 1202, in to_clipboard
clipboard.to_clipboard(self, excel=excel, sep=sep, **kwargs)
File "E:\Programming\Anaconda3_4.2.0\lib\site-packages\pandas\io\clipboard.py", line 98, in to_clipboard
clipboard_set(objstr)
File "E:\Programming\Anaconda3_4.2.0\lib\site-packages\pandas\util\clipboard.py", line 85, in _copyWindows
ctypes.cdll.msvcrt.wcscpy(ctypes.c_wchar_p(pchData), text)
OSError: exception: access violation writing 0x0000000000000000
Can anyone explain why this is happening and what I need to do to fix it?

Categories

Resources