basically,
the same application when a selection button is clicked should perform
again all the imports from a specific repository. This specific repository
is not known beforehand, it is only known at the specific moment when the
artist chooses and hits that button.
Some of the dependencies are duplicated in both folders, so what im doing
is deleting the modules loaded in the "pre-button hit", modifiying the sys
path and then importing them manually again to the sys.modules dictionary
For example, we are using the Qt.py module. This module is duplicated and
appears in the "static" repo and also in every other "dynamic" repo,
although the PySide modules are the same.
uhmm, maybe  i could treat PySide modules as a special case and choose not
to reimport them...... will give it a try.

Apparently im not having any other problems with importing the 'dynamic'
repo modules but when it comes to PySide it does.... is this a general
behaviour of compiled libraries?


2018-07-27 3:35 GMT+02:00 Alok Gandhi <alok.gandhi2...@gmail.com>:

> Try using importlib  <https://docs.python.org/2/library/importlib.html>or
> imp <https://docs.python.org/2.7/library/imp.html>
>
> Although, as Justin has already pointed out, it is not recommended to use
> reload in production code or to dynamically append/insert paths in sys.path.
>
> Give more thought to the design and architecture of your app. A good
> design should handle dependencies in a more elegant and efficient manner. A
> possible design idea would be this - If you are already aware of all the
> path that the app might need during runtime, load them up at boot time and
> use them later. Do note the fact that python modules are first class object
> i.e they can be used as a variable, can be dynamically created, passed and
> returned from a function. Use this for your design.
>
> - Alok
>
> On Fri, Jul 27, 2018 at 7:00 AM Justin Israel <justinisr...@gmail.com>
> wrote:
>
>> Would you be able to explain a bit more about the goal you are trying to
>> solve, with dynamically loading a second widget into your main application?
>> Does this second widget have drastically different dependencies? I'm
>> interested specifically in the part where you need to reload modules. This
>> is where things are going to go wrong. It is one thing to modify the
>> sys.path (which you should still try to avoid at runtime), but reloading is
>> usually something only reserved for debug situations. It definitely does
>> not work correct with compiled extensions like the PySide modules.
>>
>>
>>
>> On Fri, Jul 27, 2018 at 1:52 AM Juan Cristóbal Quesada <
>> juan.cristobal...@gmail.com> wrote:
>>
>>> Hi,
>>> this is more of a pure python question i want to throw here.
>>> Im developing a PySide Application that is used as the
>>> context/task/app/openfile launcher by the artists.
>>>
>>> The artist makes some choices that drive him towards different dialogs
>>> and widgets. The thing is, due to a request, im facing the need to
>>> dynamically change the sys path and reload all the modules from a different
>>> location inside the same main QApplication.
>>>
>>> The reason for this is that, once an artist makes a specific choice, all
>>> the following widgets... and code that is executed should be loaded from
>>> another location different than the current app. But, should look as if it
>>> were still part of the same app, the widgets need to appear embedded.
>>>
>>> Ive managed to change the sys.path of the original folder to the folder
>>> i want and successfully loaded all the modules from the new path, but then
>>> im starting to get some strange behavior:
>>>
>>> QtCore.QObject.__init__(self)
>>> AttributeError: 'NoneType' object has no attribute 'QObject'
>>>
>>> (Even if performed the from PySide2 import QtCore)
>>>
>>> I understand what im trying to achieve is not very orthodox, i was
>>> wondering if its even possible!
>>>
>>> I would like to avoid obvious ways of separating it in two QApplications
>>> and closing one when the other is opened for example.
>>>
>>> Has any of you ever tried to do something like this?
>>> What concerns should i be aware of when doing it?
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Python Programming for Autodesk Maya" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to python_inside_maya+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/python_inside_maya/CANOg8wWN-Gwzz-drk79z3C_
>>> CMxvLqC_iyCRzRbcH%2BZoAsXMJRw%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/python_inside_maya/CANOg8wWN-Gwzz-drk79z3C_CMxvLqC_iyCRzRbcH%2BZoAsXMJRw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Python Programming for Autodesk Maya" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to python_inside_maya+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/
>> msgid/python_inside_maya/CAPGFgA07W7eyZktdSOEgVuAGkO0TF
>> O-bRHkh28fAaQDOB849JQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA07W7eyZktdSOEgVuAGkO0TFO-bRHkh28fAaQDOB849JQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> --
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/python_inside_maya/CAPaTLMRzu_d9%2BtP-b1fJawQ8DGYVHDmcW3FeXmb4%
> 3DEEMU72D5g%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAPaTLMRzu_d9%2BtP-b1fJawQ8DGYVHDmcW3FeXmb4%3DEEMU72D5g%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CANOg8wUTtSzaZMSTzUG9QcBCa5wGu6x%3DQPHzqAwzo%2Bm5%3DRe7%3DA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to