Merge pull request #2683 from PySimpleGUI/Dev-latest
Check for image is bytes in Image.Update. Was crashing trying to get …
This commit is contained in:
commit
d7c9cd52b6
135
PySimpleGUI.py
135
PySimpleGUI.py
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
version = __version__ = "4.16.13 Unreleased\n update_animation_no_buffering, popup_notify, removed TRANSPARENT_BUTTON, TabGroup now autonumbers keys, Table col width better size based on font, Table measure row height, Upgrade from GitHub utility (experimental), Multiline.print, fix padding lost with visibility, new upgrade utility, upgrade parameter"
|
version = __version__ = "4.16.14 Unreleased\n update_animation_no_buffering, popup_notify, removed TRANSPARENT_BUTTON, TabGroup now autonumbers keys, Table col width better size based on font, Table measure row height, Upgrade from GitHub utility (experimental), Multiline.print, fix padding lost with visibility, new upgrade utility, upgrade parameter, switched to urllib"
|
||||||
|
|
||||||
port = 'PySimpleGUI'
|
port = 'PySimpleGUI'
|
||||||
|
|
||||||
|
@ -3376,7 +3376,10 @@ class Image(Element):
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
if image is not None:
|
if image is not None:
|
||||||
|
if type(image) is not bytes:
|
||||||
width, height = size[0] or image.width(), size[1] or image.height()
|
width, height = size[0] or image.width(), size[1] or image.height()
|
||||||
|
else:
|
||||||
|
width, height = size
|
||||||
try: # sometimes crashes if user closed with X
|
try: # sometimes crashes if user closed with X
|
||||||
self.tktext_label.configure(image=image, width=width, height=height)
|
self.tktext_label.configure(image=image, width=width, height=height)
|
||||||
except:
|
except:
|
||||||
|
@ -14482,11 +14485,13 @@ def _refresh_debugger():
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import site
|
import site
|
||||||
import requests
|
|
||||||
import shutil
|
import shutil
|
||||||
import hashlib
|
import hashlib
|
||||||
import base64
|
import base64
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import configparser
|
||||||
|
import urllib.request
|
||||||
|
import urllib.error
|
||||||
|
|
||||||
|
|
||||||
def _install(files, url=None):
|
def _install(files, url=None):
|
||||||
|
@ -14524,7 +14529,15 @@ def _install(files, url=None):
|
||||||
Otherwise, an __init__/py file will be generated. In thet case, if a __version__ = statement
|
Otherwise, an __init__/py file will be generated. In thet case, if a __version__ = statement
|
||||||
is found in the source file, the __version__ will be included in that __init__.py file.
|
is found in the source file, the __version__ will be included in that __init__.py file.
|
||||||
|
|
||||||
version 1.0.0
|
Version history
|
||||||
|
---------------
|
||||||
|
version 1.0.1 2020-03-04
|
||||||
|
now uses urllib instead of requests to avoid non standard libraries
|
||||||
|
installation for Pythonista improved
|
||||||
|
|
||||||
|
version 1.0.0 2020-03-04
|
||||||
|
initial version
|
||||||
|
|
||||||
(c)2020 Ruud van der Ham - www.salabim.org
|
(c)2020 Ruud van der Ham - www.salabim.org
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -14533,56 +14546,41 @@ def _install(files, url=None):
|
||||||
package = "?"
|
package = "?"
|
||||||
path = "?"
|
path = "?"
|
||||||
files_copied = []
|
files_copied = []
|
||||||
log = ''
|
|
||||||
|
|
||||||
info = Info()
|
info = Info()
|
||||||
Pythonista = sys.platform == "ios"
|
Pythonista = sys.platform == "ios"
|
||||||
|
if not files:
|
||||||
|
raise ValueError('no files specified')
|
||||||
|
if files[0][0] == '!':
|
||||||
|
raise ValueError('first item in files (sourcefile) may not be optional')
|
||||||
package = Path(files[0]).stem
|
package = Path(files[0]).stem
|
||||||
sourcefile = files[0]
|
sourcefile = files[0]
|
||||||
|
|
||||||
if Pythonista:
|
|
||||||
cwd = Path.cwd()
|
|
||||||
parts1 = []
|
|
||||||
for part in cwd.parts:
|
|
||||||
parts1.append(part)
|
|
||||||
if part == "Documents":
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
raise EnvironmentError("unable to install")
|
|
||||||
|
|
||||||
sitepackages_path = Path(*parts1) / "site-packages"
|
|
||||||
else:
|
|
||||||
sitepackages_path = Path(site.getsitepackages()[-1])
|
|
||||||
|
|
||||||
path = sitepackages_path / package
|
|
||||||
|
|
||||||
file_contents = {}
|
file_contents = {}
|
||||||
if url is None:
|
|
||||||
for file in files:
|
for file in files:
|
||||||
optional = file[0] == "!"
|
optional = file[0] == "!"
|
||||||
if optional:
|
if optional:
|
||||||
file = file[1:]
|
file = file[1:]
|
||||||
if Path(file).is_file():
|
|
||||||
|
if url:
|
||||||
|
try:
|
||||||
|
with urllib.request.urlopen(url + file) as response:
|
||||||
|
page = response.read()
|
||||||
|
# page = requests.get(url + file)
|
||||||
|
file_contents[file] = page
|
||||||
|
exists = True
|
||||||
|
except urllib.error.URLError:
|
||||||
|
exists = False
|
||||||
|
|
||||||
|
else:
|
||||||
|
exists = Path(file).is_file()
|
||||||
|
if exists:
|
||||||
with open(file, "rb") as f:
|
with open(file, "rb") as f:
|
||||||
file_contents[file] = f.read()
|
file_contents[file] = f.read()
|
||||||
else:
|
|
||||||
if not optional:
|
if (not exists) and (not optional):
|
||||||
raise FileNotFoundError(file + " not found. Nothing installed.")
|
raise FileNotFoundError(file + " not found. Nothing installed.")
|
||||||
|
|
||||||
else:
|
|
||||||
for file in files:
|
|
||||||
optional = file[0] == "!"
|
|
||||||
if optional:
|
|
||||||
file = file[1:]
|
|
||||||
|
|
||||||
page = requests.get(url + file)
|
|
||||||
|
|
||||||
if page.status_code == 200:
|
|
||||||
file_contents[file] = page.content
|
|
||||||
else:
|
|
||||||
if not optional:
|
|
||||||
raise FileNotFoundError(file + " not found on github. Nothing installed.")
|
|
||||||
|
|
||||||
version = "unknown"
|
version = "unknown"
|
||||||
for line in file_contents[sourcefile].decode("utf-8").split("\n"):
|
for line in file_contents[sourcefile].decode("utf-8").split("\n"):
|
||||||
line_split = line.split("__version__ =")
|
line_split = line.split("__version__ =")
|
||||||
|
@ -14596,21 +14594,56 @@ def _install(files, url=None):
|
||||||
break
|
break
|
||||||
break
|
break
|
||||||
|
|
||||||
|
info.files_copied = list(file_contents.keys())
|
||||||
|
info.package = package
|
||||||
|
info.version = version
|
||||||
|
paths = []
|
||||||
|
|
||||||
|
file = '__init__.py'
|
||||||
|
if file not in file_contents:
|
||||||
|
file_contents[file] = ("from ." + package + " import *\n").encode()
|
||||||
|
if version != 'unknown':
|
||||||
|
file_contents[file] += ("from ." + package + " import __version__\n").encode()
|
||||||
|
|
||||||
|
if Pythonista:
|
||||||
|
cwd = Path.cwd()
|
||||||
|
parts1 = []
|
||||||
|
for part in cwd.parts:
|
||||||
|
parts1.append(part)
|
||||||
|
if part == "Documents":
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
raise EnvironmentError("unable to install")
|
||||||
|
|
||||||
|
sitepackages_paths = [Path(*parts1) / ("site-packages" + ver) for ver in ("", "-2", "-3")]
|
||||||
|
else:
|
||||||
|
sitepackages_paths = [Path(site.getsitepackages()[-1])]
|
||||||
|
|
||||||
|
for sitepackages_path in sitepackages_paths:
|
||||||
|
|
||||||
|
path = sitepackages_path / package
|
||||||
|
paths.append(str(path))
|
||||||
|
|
||||||
if not path.is_dir():
|
if not path.is_dir():
|
||||||
path.mkdir()
|
path.mkdir()
|
||||||
|
|
||||||
for file, contents in file_contents.items():
|
for file, contents in file_contents.items():
|
||||||
with open(path / file, "wb") as f:
|
with open(path / file, "wb") as f:
|
||||||
f.write(contents)
|
f.write(contents)
|
||||||
info.files_copied.append(file)
|
|
||||||
|
|
||||||
if "__init__.py" not in file_contents:
|
if Pythonista:
|
||||||
with open(path / "__init__.py", "w") as f:
|
pypi_packages = sitepackages_path / '.pypi_packages'
|
||||||
f.write("from ." + package + " import *\n")
|
config = configparser.ConfigParser()
|
||||||
if version != "unknown":
|
config.read(pypi_packages)
|
||||||
f.write("from ." + package + " import __version__\n")
|
config[package] = {}
|
||||||
|
config[package]['url'] = 'github'
|
||||||
if not Pythonista:
|
config[package]['version'] = version
|
||||||
|
config[package]['summary'] = ''
|
||||||
|
config[package]['files'] = path.as_posix()
|
||||||
|
config[package]['dependency'] = ''
|
||||||
|
with pypi_packages.open('w') as f:
|
||||||
|
config.write(f)
|
||||||
|
else:
|
||||||
for entry in sitepackages_path.glob("*"):
|
for entry in sitepackages_path.glob("*"):
|
||||||
if entry.is_dir():
|
if entry.is_dir():
|
||||||
if entry.stem.startswith(package) and entry.suffix == ".dist-info":
|
if entry.stem.startswith(package) and entry.suffix == ".dist-info":
|
||||||
|
@ -14631,9 +14664,9 @@ def _install(files, url=None):
|
||||||
|
|
||||||
for p in (path, path_distinfo):
|
for p in (path, path_distinfo):
|
||||||
for file in p.glob("**/*"):
|
for file in p.glob("**/*"):
|
||||||
info.log += "{} {} {}".format(file, file.is_file(), file.is_dir())
|
|
||||||
if file.is_file():
|
if file.is_file():
|
||||||
name = str(file.relative_to(sitepackages_path)).replace("\\", "/")
|
name = file.relative_to(sitepackages_path).as_posix() # make sure we have slashes
|
||||||
record_file.write(name + ",")
|
record_file.write(name + ",")
|
||||||
|
|
||||||
if (file.stem == "RECORD" and p == path_distinfo) or ("__pycache__" in name.lower()):
|
if (file.stem == "RECORD" and p == path_distinfo) or ("__pycache__" in name.lower()):
|
||||||
|
@ -14651,13 +14684,9 @@ def _install(files, url=None):
|
||||||
|
|
||||||
record_file.write("\n")
|
record_file.write("\n")
|
||||||
|
|
||||||
info.package = package
|
info.path = ','.join(paths)
|
||||||
info.version = version
|
|
||||||
info.path = str(path)
|
|
||||||
return info
|
return info
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _upgrade_from_github():
|
def _upgrade_from_github():
|
||||||
info = _install(
|
info = _install(
|
||||||
files="PySimpleGUI.py !init.py".split(), url="https://raw.githubusercontent.com/PySimpleGUI/PySimpleGUI/master/"
|
files="PySimpleGUI.py !init.py".split(), url="https://raw.githubusercontent.com/PySimpleGUI/PySimpleGUI/master/"
|
||||||
|
|
Loading…
Reference in New Issue