Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Py36 PySide2 #159

Merged
merged 7 commits into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/a2ui.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ a2_python := _init_get_var("a2_python")
a2_ui_call := _init_get_var("a2_ui_call")
a2_startup_tool_tips := _init_get_var("a2_startup_tool_tips")

PY_VERSION_SHORT := "3.4"
PY_VERSION_SHORT := "3.6"

StringLower, a2_startup_tool_tips, a2_startup_tool_tips
if (a2_startup_tool_tips == "true")
Expand Down Expand Up @@ -34,7 +34,7 @@ else
check_pypath := found_list[1]
}

; check if a2_python is version 3.4.x ==============================================
; check if a2_python is correct version ============================================
check_version(check_pypath)

; check if a2_call contains more than the a2app-string =============================
Expand Down Expand Up @@ -91,7 +91,7 @@ check_version(check_pypath) {
FileGetVersion, py_version, %check_pypath%
if (py_version == "")
{
; no version string received. might be 3.4!
; no version string received. check the readme file for a hint
SplitPath, check_pypath,, py_dir
readme_path := py_dir "\README.txt"
IfExist, %readme_path%
Expand All @@ -110,10 +110,10 @@ check_version(check_pypath) {
}
else
{
if vshort != PY_VERSION_SHORT
if (SubStr(py_version, 1, 3) != PY_VERSION_SHORT)
{
MsgBox, 16, Wrong Python Version?, The found Python executable (%check_pypath%)(%py_version%) does not match version "%PY_VERSION_SHORT%"`n`nPlease make sure that a fitting version is found for a2 ui to run on!`nThanks!
MsgBox, 16, Wrong Python Version?, The found Python executable (%check_pypath%) (%py_version%) does not match version "%PY_VERSION_SHORT%"`n`nPlease make sure that a fitting version is found for a2 ui to run on!`nThanks!
ExitApp
}
}
}
}
199 changes: 103 additions & 96 deletions lib/batches/check_pyside2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,105 +7,112 @@

IMPORT_STR = ' import '
FROM_IMPORT = 'from PySide2 import '
PYPAKS = pyside_package.__all__
PAK_MEMBERS = {}
MEMBER_PAKS = {}


def main():
pypaks = pyside_package.__all__
print('pypaks:', pypaks)
pak_members = {}
member_paks = {}
for pakname in pypaks:
print('pypaks:', PYPAKS)
global PAK_MEMBERS, MEMBER_PAKS
for pakname in PYPAKS:
qmod = importlib.import_module(f'{pyside_package.__name__}.{pakname}')
members = [m for m in dir(qmod) if not m.startswith('_')]
pak_members[pakname] = members
PAK_MEMBERS[pakname] = members
for m in members:
member_paks[m] = pakname

uipath = os.path.abspath(os.path.join(__file__, '..', '..', '..', 'ui'))
numpys, pydirs, qlines, numqfiles, changed_files, change_count = 0, 0, 0, 0, 0, 0
for dirpath, folders, files in os.walk(uipath):
pyfiles = [f for f in files if os.path.splitext(f)[1] == '.py']
if pyfiles:
pydirs += 1
numpys += len(pyfiles)
for pyfile in pyfiles:
this_q_lines = []
import_lines = []
qpacks = []
try:
this_path = os.path.join(dirpath, pyfile)
needs_unicode = False
try:
with open(this_path) as fob:
lines = fob.read().split('\n')
except UnicodeDecodeError:
needs_unicode = True
with codecs.open(this_path, encoding='utf-8-sig') as fob:
lines = fob.read().split('\n')

print(f'checking {len(lines)} lines in file {this_path} ...')

change_file = False
for i, line in enumerate(lines):
line = line.rstrip()
# skip empty lines
if not line:
continue
# skip comments
if line.lstrip().startswith('#'):
continue

try:
changed, newline, this_qpacks = check_line(line, pypaks, pak_members, member_paks)
if changed:
change_file = True
lines[i] = newline
change_count += 1
qpacks.extend(this_qpacks)
except Exception as error:
print(f'problems with File: "{this_path}", line {i}')
raise error

if line.strip().startswith(FROM_IMPORT):
import_lines.append(i)

if import_lines:
if len(import_lines) > 1:
raise RuntimeError('Multiple import lines?!?!', import_lines, this_path)
current_paks = [p.strip() for p in lines[import_lines[0]][len(FROM_IMPORT):].split(',')]
new_paks = set(qpacks)
if new_paks != set(current_paks):
lines[import_lines[0]] = FROM_IMPORT + ', '.join(new_paks)
change_file = True
change_count += 1

if change_file:
if needs_unicode:
with codecs.open(this_path, 'w', encoding='utf-8-sig') as fob:
fob.write('\n'.join(lines))
else:
with open(this_path, 'w') as fob:
fob.write('\n'.join(lines))
print(f'changed file: {this_path}')
changed_files += 1
MEMBER_PAKS[m] = pakname

stats = {
'py_dirs': 0,
'num_py_files': 0,
'changed_files': 0,
'change_count': 0}

ui_path = os.path.abspath(os.path.join(__file__, '..', '..', '..', 'ui'))
check_files(ui_path, stats)

pprint(stats)


def check_files(path, stats):
pyfiles = []
for item in os.listdir(path):
item_path = os.path.join(path, item)
if os.path.isdir(item_path) and not item.startswith('_'):
check_files(item_path, stats)
elif os.path.isfile(item_path) and os.path.splitext(item)[1] == '.py':
pyfiles.append(item_path)

if not pyfiles:
return
stats['py_dirs'] += 1
stats['num_py_files'] += len(pyfiles)

for this_path in pyfiles:
import_lines = []
qpacks = []
try:
needs_unicode = False
try:
with open(this_path) as fob:
lines = fob.read().split('\n')
except UnicodeDecodeError:
needs_unicode = True
with codecs.open(this_path, encoding='utf-8-sig') as fob:
lines = fob.read().split('\n')

print(f'checking {len(lines)} lines in file {this_path} ...')

change_file = False
for i, line in enumerate(lines):
line = line.rstrip()
# skip empty lines
if not line:
continue
# skip comments
if line.lstrip().startswith('#'):
continue

try:
changed, newline, this_qpacks = check_line(line)
if changed:
change_file = True
lines[i] = newline
stats['change_count'] += 1
qpacks.extend(this_qpacks)
except Exception as error:
print(f'problems with file: {this_path}')
print(f'problems with File: "{this_path}", line {i}')
raise error

if this_q_lines:
numqfiles += 1
print('Qt lines in file: %s\n %s' % (pyfile, ' \n'.join(this_q_lines)))

print('numpys:', numpys)
print('pydirs:', pydirs)
print('numqfiles:', numqfiles)
print('qlines:', qlines)
print('changed_files', changed_files)
print('change_count', change_count)


def check_line(line, pypaks, pak_members, member_paks):
if line.strip().startswith(FROM_IMPORT):
import_lines.append(i)

if import_lines:
if len(import_lines) > 1:
raise RuntimeError('Multiple import lines?!?!', import_lines, this_path)
current_paks = [p.strip() for p in lines[import_lines[0]][len(FROM_IMPORT):].split(',')]
new_paks = set(qpacks)
if new_paks != set(current_paks):
lines[import_lines[0]] = FROM_IMPORT + ', '.join(new_paks)
change_file = True
stats['change_count'] += 1

if change_file:
if needs_unicode:
with codecs.open(this_path, 'w', encoding='utf-8-sig') as fob:
fob.write('\n'.join(lines))
else:
with open(this_path, 'w') as fob:
fob.write('\n'.join(lines))
print(f'changed file: {this_path}')
stats['changed_files'] += 1

except Exception as error:
print(f'problems with File: {this_path}')
raise error


def check_line(line):
any_changed = False

if 'PySide' in line:
Expand All @@ -117,7 +124,7 @@ def check_line(line, pypaks, pak_members, member_paks):
any_changed = True

qpacks = []
for pak in pypaks:
for pak in PYPAKS:
if pak not in line:
continue
if '\n' in line:
Expand All @@ -131,7 +138,7 @@ def check_line(line, pypaks, pak_members, member_paks):
while changed:
if num_tries > 23:
break
changed, line, pos0, changed_packs = fix_moved_members(pak, line, pos0, pak_members, member_paks)
changed, line, pos0, changed_packs = fix_moved_members(pak, line, pos0)
if changed:
qpacks.extend(changed_packs)
num_tries += 1
Expand All @@ -157,7 +164,7 @@ def fix_pyside1(line, pos0):
return changed, line, pos0


def fix_moved_members(pak, line, pos0, pak_members, member_paks):
def fix_moved_members(pak, line, pos0):
pos1 = line.find(pak, pos0)
changed = False
if pos1 == -1:
Expand All @@ -172,9 +179,9 @@ def fix_moved_members(pak, line, pos0, pak_members, member_paks):
if line[pos2] == '.':
rest_of_line = line[pos2 + 1:]
member_name = get_member(rest_of_line)
if member_name not in pak_members[pak]:
if member_name not in PAK_MEMBERS[pak]:
try:
new_pak = member_paks[member_name]
new_pak = MEMBER_PAKS[member_name]
except KeyError:
raise RuntimeError(f'Name "{member_name}" not under any of the paks!')

Expand All @@ -189,11 +196,11 @@ def fix_moved_members(pak, line, pos0, pak_members, member_paks):
pos3 = pos2 + len(IMPORT_STR)
if line[pos2:pos3] == IMPORT_STR:
import_members = [m.strip() for m in line[pos3:].split(',')]
not_in_pak = [m not in pak_members[pak] for m in import_members]
not_in_pak = [m not in PAK_MEMBERS[pak] for m in import_members]
if any(not_in_pak):
lines = {}
for m in import_members:
lines.setdefault(member_paks[m], []).append(m)
lines.setdefault(MEMBER_PAKS[m], []).append(m)
new_lines = []
for new_pak, members in lines.items():
new_lines.append(line[:pos1] + new_pak + IMPORT_STR + ', '.join(members))
Expand Down
8 changes: 4 additions & 4 deletions ui/a2app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from ctypes import windll

from siding import QSingleApplication
from PySide import QtGui
from PySide2 import QtWidgets

# first basicConfic. No need for more.
logging.basicConfig()
Expand All @@ -38,8 +38,8 @@ def main():
app.ensure_single()

# adding PySide plugin paths. e.g. to make all the imageformats available
pyside_plugin_path = os.path.join(sys.modules['PySide'].__path__[0], 'plugins')
QtGui.QApplication.addLibraryPath(pyside_plugin_path)
pyside_plugin_path = os.path.join(sys.modules['PySide2'].__path__[0], 'plugins')
QtWidgets.QApplication.addLibraryPath(pyside_plugin_path)

winfo = platform.uname()
log.info('initialised!\n python: %s\n windows: %s' % (sys.version, str(winfo)[31:-1]))
Expand Down Expand Up @@ -73,7 +73,7 @@ def init_a2_win(app):
msg = ('Could not call A2Window! Error:\n%s\n'
'Traceback:%s\n\nPress Ctrl+C to copy this message.'
% (error, traceback.format_exc().strip()))
QtGui.QMessageBox.critical(None, title, msg)
QtWidgets.QMessageBox.critical(None, title, msg)
raise RuntimeError(msg)
return a2win

Expand Down
4 changes: 2 additions & 2 deletions ui/a2core.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ def set_loglevel(debug=False):
if name.startswith('a2'):
try:
logger.setLevel(level)
log.debug('Log level DEBUG: active')
log.info('Log level INFO: active')
log.debug(f'"{name}" Log level DEBUG: active')
log.info(f'"{name}" Log level INFO: active')
except AttributeError as error:
if not isinstance(logger, logging.PlaceHolder):
log.info('Could not set log level on logger object "%s": %s' % (name, str(logger)))
Expand Down
7 changes: 3 additions & 4 deletions ui/a2ctrl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import sys
import traceback
from pysideuic import compileUi
from pyside2uic import compileUi
from importlib import reload, import_module

import a2core
Expand Down Expand Up @@ -151,16 +151,15 @@ def get_local_element(itempath):
with open(itempath) as fobj:
element_content = fobj.read()

element_objects = {}
try:
element_objects = {}
exec(element_content, element_objects)

# element_objects.pop('__builtins__')
return element_objects

except Exception:
log.error(traceback.format_exc().strip())
log.error('Could not exec code from "%s"' % itempath)
return element_objects
else:
raise RuntimeError('Cannot load local element! File does not exist! (%s)' % itempath)

Expand Down
Loading