Blender Panel Visible (Python)

For panels with settings for HTML5 and Android, I made separate panels, I specified the Armory Explorer panel as parents.
I wanted one or another panel to become visible when choosing a target platform, and the other, respectively, not visible. Used the poll() function. Code in the respective panels:

@classmethod
def poll(cls, context):
    wrd = bpy.data.worlds['Arm']
    if len(wrd.arm_exporterlist) > 0:
        item = wrd.arm_exporterlist[wrd.arm_exporterlist_index]
        return item.arm_project_target == 'android-hl'
    else:
        return False

@classmethod
def poll(cls, context):
    wrd = bpy.data.worlds['Arm']
    if len(wrd.arm_exporterlist) > 0:
        item = wrd.arm_exporterlist[wrd.arm_exporterlist_index]
        return item.arm_project_target == 'html5'
    else:
        return False

As a result, for some reason, the Android panel does not appear now.
Unfortunately, I noticed only now and a question arose about solving this problem.
You can simply show both panels, but only allow the values ​​to be changed when the required platform is selected.
The option to display only those panels that were also worked out in the list of target platforms, here is the code:

@classmethod
def poll(cls, context):
    wrd = bpy.data.worlds['Arm']
    is_check = False
    for item in wrd.arm_exporterlist:
        is_check = item.arm_project_target == 'android-hl'
        if is_check:
            break
    return is_check

But the Android settings panel doesn’t appear until the HTML5 panel appears.
Description of the classes:

class ARM_PT_ArmoryExporterAndroidSettingsPanel(bpy.types.Panel):
    bl_label = "Android Settings"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "render"
    bl_options = { 'DEFAULT_CLOSED' }
    bl_parent_id = "ARM_PT_ArmoryExporterPanel"

class ARM_PT_ArmoryExporterHTML5SettingsPanel(bpy.types.Panel):
    bl_label = "HTML5 Settings"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "render"
    bl_options = { 'DEFAULT_CLOSED' }
    bl_parent_id = "ARM_PT_ArmoryExporterPanel"
2 Likes

That’s weird. I get this problem only in files that don’t already have a export configuration. Maybe using some of Blenders debug flags can help?

Also, the polling seems kind of doubled (there are checks in both the poll and in the draw function) but that’s not the issue here.

1 Like

Thanks, I’ll try

This option remained from the way all panels are displayed (i.e. when they are displayed depending on the list) and accordingly enable and disable access to them. I forgot to remove, but now it may come in handy :sweat_smile:

:rofl:
And the problem turned out to be precisely this, if you remove the verification code from Draw, then everything works correctly. Some kind of magic, I do not understand why this happens.
But this is a lesson for me: clean up the extra code. :thinking:

Update: In general, it’s strange… At first it worked, now it doesn’t.

Update 2:
And it also happens like this:

2 Likes

I tried the same. It worked once and then it didn’t :laughing:, but I thought this was because of the file used. I have no idea what’s going on here. Are there some layout attributes in some weird combination that could lead to this?

Found something, steps:
1.add platform (will be html5 by default);
The html5 panel has appeared.
2. add android;
As a result, the android panel is not displayed.
3. remove html5;
The android panel appeared.
4. Add the platform (will be html5).
We get a bug with the display as in the picture above.
5. Expand the html5 panel (the android panel cannot be opened due to the wrong location).
Everything falls into place and works fine.

If you delete and add html5 again, then without expanding the panel it displays crooked.

Feel like a shaman with drums :drum: :smiley:

I also got it displaying when randomly clicking on the empty space where the panel should show up. Maybe the screen needs some custom redraw call?

Also, there seems to be some issue with the emulator field, at least after clicking on the refresh button when no emulator is found:

WARN (bpy.rna): C:\b\buildbot-worker-windows\windows_lts_283\blender.git\source\blender\python\intern\bpy_rna.c:1479 pyrna_enum_to_py: current value '0' matches no enum in 'World', 'Arm', 'arm_project_android_list_avd'

This happens when hovering over the UI, so it’s probably drawing related.

Found the region.tag_redraw() function, but I don’t know if it is correct and how to apply it.

I’ll see. Thanks

As an option for correct operation, remove the deployment (options - HIDE_HEADER) and add Label. Get it like this:
android_v1 html5_v1

You can wrap all this in Box, but then for Android Settings, all nested panels must also be pulled out. (*android - not final)

html5_v2

This could work:

bpy.ops.wm.redraw_timer(type="DRAW_WIN", iterations=1)
bpy.context.area.tag_redraw()

But I have to guess every time again how this works, for me it’s just trial and error. Actually, nevermind. I don’t know how I got it to suddenly display earlier, but just clicking on the empty space doesn’t work anymore. Edit: redrawing might help. It appears when you open and close another panel.

Using labels instead of panels is a good idea, if this looks like a Blender bug it might be a good idea to use labels for now and maybe report it (also, are there any open bug reports about this? Maybe there are known workarounds).

EDIT: Removing the {'DEFAULT_CLOSED'} flag solves this for me although the panel is opened then by default of course. Still might be better than using labels instead.

2 Likes

I tried. As a result, it works in the beginning, but if we collapse the panels and remove/add platforms we get back to display issues.

After various attempts, I came to the conclusion that this is a Blender error. The fact is that the poll() function works correctly and the collapsed panel is drawn, but it is not in its place (see the picture above, and under different conditions, it is in different places, even drives into the panel below). It turns out that the position of the interface elements (position, size) is not updated. And when any panel opens, it works and everything is fine. It is necessary to somehow force the update (hide or show another panel quickly, etc.), but I don’t know how to do it.

At the moment I can offer the following options for the location of the panels:

  1. Always show the open panel of the selected platform:

  2. Show settings for the selected platform:

  3. Show settings for everyone in the list:

    all_v5_2

I corrected this error. Thanks

3 Likes

All options look good to me. I spend one or two hours this morning trying to find the issue but I give up. The draw() function doesn’t even get called and the draw_header() function gets called but isn’t drawn (visibly). Something very weird is going on here and I suspect it has something to do with combining panel drawing with list items.

Opening a Blender bug report would be a good idea but it is difficult without enough information and the developers will probably not answer in the next 10 years because this is some addon related code^^

Btw, is there some documentation about how to use the Android emulator functionality in Armory? How do you get an emulator showing up in that dropdown? Just install it in Android Studio?

2 Likes

I also tried these functions and thought to make a PanelContainer that contained a panel with settings. The PanelContainer would always be exposed and handle poll(). And the settings panel was just as it is. I thought that due to this, the necessary functions would be called, but it did not help. I think that if you just add the same functionality to the switches, there will be the same problems. Here it is possible because of two hiding panels, because one is always displayed correctly.
Therefore, I propose such solutions.

You just have to make a clean example of the problem and send it as a problem. But there is no need to wait for an answer. I will probably do it later.

When installing Android Studio, also install the AVD Manager tool (Android Virtual Device). It is included in the Android SDK. This is where virtual machines are created.
When you click on the Update button, the console utility is called in the -list-avds parameter (about the list of existing emulators):
emulator -list-avds
Next, we call the same utility to start the emulator:
emulator -avd [selected name from list]

And everything else is done by the user.
In fact, I made a wrapper in the Armory interface for executing console commands for the utility.

P.S. When I was developing this functionality, then in the list I had 4 emulators that I did not create in Android Studio. It turned out that when I installed Visual Studio with functionality for Android development, it installed these emulators by default (at least 3 of them). And when I uninstalled Visual Studio, they did not disappear and lay in the system folders, these 20 GB.

Regarding the panels:
Which option is better all the same?
1.all settings related to export in the Armory Exporter panel;
2. display the settings for a specific platform in a separate panel from the export panel.
Here it can be considered from the point of view of convenience and functionality, if there are such problems with the interface.

1 Like

Thanks! I got some huge error messages when auto-building the project but I think that’s my local configuration. Also somehow I’m no longer able to uncheck “Building APK after Publishing”, the layout is disabled altough it shouldn’t.

Which option is better all the same?
1.all settings related to export in the Armory Exporter panel;
2. display the settings for a specific platform in a separate panel from the export panel.

I would go with option 1, the labels approach looks pretty good.

Thanks. Strange, I’ll check.

1 Like

If I understand correctly (and was able to reproduce it myself), then the following happened:
for the Building APK After Publishing option, processing is necessary, if the ANDROID_SDK_ROOT system variable or Android SDK Path is specified in the settings, then this option is available to enable / disable. But if at first it was available, you turned it on, then the conditions changed (you removed Android Studio, for example), then the option became unavailable and you can no longer turn it off. Fixed this so, if the option is not available, then it automatically turns off.

My Android SDK settings:

If I remember correctly, then you need to install a certain version of the Android NDK. If the android compiler gives errors, then the solution is easily searched on the Internet.

2 Likes

Thanks! Yes, I think it was indeed the NDK and maybe also some gradle configuration. Both were installed for a different emulator that I used a while ago, and the one that I installed yesterday required some other NDK and gradle versions.

2 Likes