ya2 · news · projects · code · about

fixes for building
authorFlavio Calva <f.calva@gmail.com>
Mon, 4 Jul 2022 18:50:50 +0000 (19:50 +0100)
committerFlavio Calva <f.calva@gmail.com>
Mon, 4 Jul 2022 18:50:50 +0000 (19:50 +0100)
pmachines/gui/menu.py
pmachines/posmgr.py
setup.py
tests/test_functional.py
ya2/build/build.py

index ab2248f8bb81b4ee6034a579578219de0bd4fabb..f9017db714d0f0608bce2b2636163ee308457e36 100644 (file)
@@ -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]
index 980d43cb9a39f409da639f827d1012f4ede85a2f..0ec5340390d577855fc4efb1d618aace1925251b 100644 (file)
@@ -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]
index 11c8fbed6a9aa8eef351f22a980ff71f7445d6f4..6133f04189f8c0ce105272241506af7ebe12e4b1 100644 (file)
--- 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,
index fa8ce9af6a334d335af3c871b4a41db232a054ed..994f557cacf1c35f79a0867b4d7381bb81104704 100644 (file)
@@ -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() + '-'
index d9b77a402eb8bda7adc96b0a8a04c5e67484dd43..f67345d4c2bb4bcfd7835507a937347c37074c0a 100644 (file)
@@ -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()