From ea71df6e761658eb61d2358f19ef380120c397b5 Mon Sep 17 00:00:00 2001 From: Flavio Calva Date: Mon, 4 Jul 2022 19:50:50 +0100 Subject: [PATCH] fixes for building --- pmachines/gui/menu.py | 36 ++++++++++++++++++++++++++++++------ pmachines/posmgr.py | 5 +++++ setup.py | 4 ++-- tests/test_functional.py | 4 ++-- ya2/build/build.py | 4 ++-- 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/pmachines/gui/menu.py b/pmachines/gui/menu.py index ab2248f..f9017db 100644 --- a/pmachines/gui/menu.py +++ b/pmachines/gui/menu.py @@ -14,6 +14,18 @@ from ya2.utils.cursor import MouseCursor from ya2.p3d.p3d import LibP3d +class DirectOptionMenuTest(DirectOptionMenu): + + def __init__(self, parent=None, **kw): + DirectOptionMenu.__init__(self, parent, **kw) + self.initialiseoptions(DirectOptionMenuTest) + + def showPopupMenu(self, event=None): + super().showPopupMenu(event) + self._show_cb([self.component(cmp) for cmp in self.components()]) + + + class Menu(DirectObject): def __init__(self, fsm, lang_mgr, opt_file, music, pipeline, scenes, @@ -112,18 +124,21 @@ class Menu(DirectObject): 'en': _('English'), 'it': _('Italian') }[self._opt_file['settings']['language']] - btn = DirectOptionMenu( + + def lang_cb(comps): + self._pos_mgr.remove(['english', 'italian']) + for lng, btn in zip(['english', 'italian'], comps): + pos = LibP3d.wdg_pos(btn) + self._pos_mgr.register(lng, (pos[0] + 5, pos[1])) + btn = DirectOptionMenuTest( text=_('Language'), items=items, initialitem=inititem, pos=(0, 1, .8), command=self.on_language, **self._common_opt) + btn._show_cb = lang_cb btn.popupMenu['frameColor'] = self._common_btn['frameColor'] btn.popupMenu['relief'] = self._common_btn['relief'] self._widgets += [btn] pos_lang = LibP3d.wdg_pos(self._widgets[-1]) self._pos_mgr.register('languages', pos_lang) - pos_eng = pos_lang[0] + 300, pos_lang[1] - 57 - pos_it = pos_lang[0] + 300, pos_lang[1] + 33 - self._pos_mgr.register('english', pos_eng) - self._pos_mgr.register('italian', pos_it) self._widgets += [OnscreenText( _('Volume'), pos=(-.1, .55), font=self._common['text_font'], scale=self._common['scale'], fg=self._common['text_fg'], @@ -157,9 +172,18 @@ class Menu(DirectObject): resolutions = ['x'.join(_res) for _res in resolutions] if not res: res = resolutions[-1] - btn = DirectOptionMenu( + + def res_cb(comps): + self._pos_mgr.remove(['res_1440x900', 'res_1360x768']) + for tgt_res in ['1440x900', '1360x768']: + for btn in comps: + if btn['text'] == tgt_res: + pos = LibP3d.wdg_pos(btn) + self._pos_mgr.register('res_' + tgt_res, (pos[0] + 5, pos[1])) + btn = DirectOptionMenuTest( text=_('Resolution'), items=resolutions, initialitem=res, pos=(0, 1, .05), command=self.on_resolution, **self._common_opt) + btn._show_cb = res_cb btn.popupMenu['frameColor'] = self._common_btn['frameColor'] btn.popupMenu['relief'] = self._common_btn['relief'] self._widgets += [btn] diff --git a/pmachines/posmgr.py b/pmachines/posmgr.py index 980d43c..0ec5340 100644 --- a/pmachines/posmgr.py +++ b/pmachines/posmgr.py @@ -12,3 +12,8 @@ class PositionMgr: def get(self, tgt): return self._pos[tgt] + + def remove(self, elements): + for element in elements: + if element in self._pos: + del self._pos[element] diff --git a/setup.py b/setup.py index 11c8fbe..6133f04 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ from setuptools import setup, Command from setuptools.command.develop import develop from multiprocessing import cpu_count from direct.dist.commands import bdist_apps -from ya2.build.build import _branch, files, _ver, files +from ya2.build.build import _branch, files, _version #from ya2.build.docs import bld_docs from ya2.build.models import ModelsBuilder from ya2.build.images import bld_images @@ -155,7 +155,7 @@ if __name__ == '__main__': package_data_dirs = {'simplepbr': [('simplepbr/shaders*', '', {})]} setup( name=appname, - version=ver, + version=_version(), cmdclass={ 'develop': DevelopPyCmd, # 'docs': DocsCmd, diff --git a/tests/test_functional.py b/tests/test_functional.py index fa8ce9a..994f557 100644 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -12,7 +12,7 @@ from os import system, remove, environ from os.path import exists, basename, join from glob import glob from panda3d.core import Filename -from ya2.build.build import exec_cmd, _branch, _ver +from ya2.build.build import exec_cmd, _branch, _version class FunctionalTests(TestCase): @@ -171,7 +171,7 @@ class FunctionalTests(TestCase): for line in lines: if line.strip().split()[0] == _branch(): commit = line.strip().split()[1][:7] - __ver = _ver() + __ver = _version() if _branch() == 'stable': with open('/home/flavio/builders/pmachines_builder/pmachines/assets/version.txt') as fver: __ver = fver.read().strip() + '-' diff --git a/ya2/build/build.py b/ya2/build/build.py index d9b77a4..f67345d 100644 --- a/ya2/build/build.py +++ b/ya2/build/build.py @@ -10,11 +10,11 @@ from hashlib import md5 # TODO refactor: make class BuilderTools -def exec_cmd(cmd): +def exec_cmd(cmd, check=True): '''Synchronously executes a command and returns its output.''' # ret = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True).communicate() # return ret[0].decode('utf-8').strip() - proc = run(cmd, shell=True, stdout=PIPE, stderr=PIPE, universal_newlines=True, check=True) + proc = run(cmd, shell=True, stdout=PIPE, stderr=PIPE, universal_newlines=True, check=check) return proc.stdout.strip() + proc.stderr.strip() -- 2.30.2