Hello,
I am facing a problem with a UI that randomly changes the component width on subsequent dialog displays.
Sequence of images here:
Correct rendering:
https://pasteboard.co/HUkI7D1.png
Wrong ones:
https://pasteboard.co/HUkIBwG.png
https://pasteboard.co/HUkISMC.png
https://pasteboard.co/HUkJ2HS.png
https://pasteboard.co/HUkJcHy.png
Top image is as it should render. Notice the random left aligns with all other images.
What's wrong here?
Here's the code that creates the UI:
from mforms import *
from abc import ABCMeta
@ModuleInfo.plugin(...)
@ModuleInfo.export(grt.INT, grt.classes.db_Catalog)
def export_jpa_annotated_classes(catalog):
do_export = Builder.ask_for_options()
class Builder:
__metaclass__ = ABCMeta
supported_java_versions = ['5', '6', '7', '8', '9', '10', '11']
supported_jpa_versions = ['1.0', '2.0', '2.1', '2.2']
@staticmethod
def ask_for_options():
"""Ask the user for the options on the current MWB model file and returns True if the user pressed OK and False if the user pressed cancel."""
# Java version
java_version_rds = GuiUtils.create_radiobuttons_for(Builder.supported_java_versions)
# JPA version
jpa_version_rds = GuiUtils.create_radiobuttons_for(Builder.supported_jpa_versions)
# Java version box
java_version_bx = Box(True)
java_version_bx.set_spacing(1)
java_version_lb = Label('Java version:')
java_version_lb.set_wrap_text(False)
java_version_bx.add(java_version_lb, False, True)
java_version_rds[4].set_active(True)
for rd in java_version_rds:
java_version_bx.add(rd, False, True)
# JPA version box
jpa_version_bx = Box(True)
jpa_version_bx.set_spacing(1)
jpa_version_lb = Label('JPA version:')
jpa_version_lb.set_wrap_text(False)
jpa_version_bx.add(jpa_version_lb, False, True)
jpa_version_rds[1].set_active(True)
for rd in jpa_version_rds:
jpa_version_bx.add(rd, False, True)
# set same label width
GuiUtils.set_common_view_widths([java_version_lb, jpa_version_lb])
# need wrapped box for TitledGroupPanel
target_platform_bx = Box(False)
target_platform_bx.set_spacing(5)
target_platform_bx.set_padding(3)
target_platform_bx.add(java_version_bx, False, True)
target_platform_bx.add(jpa_version_bx, False, True)
target_platform_pn = Panel(TitledGroupPanel)
target_platform_pn.set_title('Target Platform')
target_platform_pn.add(target_platform_bx)
# box for tab
main1_bx = Box(False)
main1_bx.set_spacing(5)
main1_bx.set_padding(3)
# main1_bx.add(common_table_prefix_pn, False, True)
# main1_bx.add(language_pn, False, True)
main1_bx.add(target_platform_pn, False, True)
# main1_bx.add(cpk_classes_pn, False, True)
# main1_bx.add(enum_naming_pn, False, True)
# main1_bx.add(annotation_fallback_package_name_pn, False, True)
main_tv = TabView(False)
main_tv.set_size(565, 450)
main_tv.add_page(main1_bx, 'General')
# DISPLAY MAIN FORM
# buttons
export_btn = Button()
export_btn.set_text('Export')
cancel_btn = Button()
cancel_btn.set_text('Cancel')
# button box
buttons_bx = Box(True)
buttons_bx.set_spacing(5)
buttons_bx.set_padding(3)
# uses OS-specific positioning
Utilities.add_end_ok_cancel_buttons(buttons_bx, export_btn, cancel_btn)
# main + button boxes
content_bx = Box(False)
content_bx.set_spacing(5)
content_bx.set_padding(5)
# content_bx.add(path_pn, False, True)
content_bx.add(main_tv, True, True)
content_bx.add(buttons_bx, False, True)
# create centered options dialog
form = Form(None, FormDialogFrame)
form.set_title('JPA Export Options')
form.set_content(content_bx)
form.set_size(500, 500) # must set this to any equaling x,y sizes or the window is not centered
form.center()
form.run_modal(export_btn, cancel_btn)
class GuiUtils:
"""
Some convenience methods for constructing the UI.
"""
def __init__(self):
pass
@staticmethod
def set_common_view_widths(views):
"""Set common width for UI view components by calculating the max width and setting it for every component.
:param views:
:return:
"""
# method for faking column layouts
max_width = max([view.get_width() for view in views])
# map(lambda v: v.set_size(max_width, v.get_height()), views)
for view in views:
view.set_size(max_width, view.get_height())
@staticmethod
def create_radiobuttons_for(texts):
"""Create a list of radio buttons for a given list of text labels.
:param texts: list[str]
:rtype: list[RadioButton]
"""
width = 57
gid = RadioButton.new_id()
rds = []
for text in texts:
rd = RadioButton(gid)
rd.set_text(text)
rd.set_name(text)
rd.set_back_color('orange')
rd.set_size(width, rd.get_height())
rd.set_min_size(width, rd.get_height())
print 'Radio "' + rd.get_name() + '" preferred width = ' + str(rd.get_preferred_width())
rds.append(rd)
return rds
Maybe it's something for the WB team to look at, as it is absolutely not understandable why this is happening...
I'd very much appreciate if you could have a look at this.
Thanks and happy new year.
Karsten
I am facing a problem with a UI that randomly changes the component width on subsequent dialog displays.
Sequence of images here:
Correct rendering:
https://pasteboard.co/HUkI7D1.png
Wrong ones:
https://pasteboard.co/HUkIBwG.png
https://pasteboard.co/HUkISMC.png
https://pasteboard.co/HUkJ2HS.png
https://pasteboard.co/HUkJcHy.png
Top image is as it should render. Notice the random left aligns with all other images.
What's wrong here?
Here's the code that creates the UI:
from mforms import *
from abc import ABCMeta
@ModuleInfo.plugin(...)
@ModuleInfo.export(grt.INT, grt.classes.db_Catalog)
def export_jpa_annotated_classes(catalog):
do_export = Builder.ask_for_options()
class Builder:
__metaclass__ = ABCMeta
supported_java_versions = ['5', '6', '7', '8', '9', '10', '11']
supported_jpa_versions = ['1.0', '2.0', '2.1', '2.2']
@staticmethod
def ask_for_options():
"""Ask the user for the options on the current MWB model file and returns True if the user pressed OK and False if the user pressed cancel."""
# Java version
java_version_rds = GuiUtils.create_radiobuttons_for(Builder.supported_java_versions)
# JPA version
jpa_version_rds = GuiUtils.create_radiobuttons_for(Builder.supported_jpa_versions)
# Java version box
java_version_bx = Box(True)
java_version_bx.set_spacing(1)
java_version_lb = Label('Java version:')
java_version_lb.set_wrap_text(False)
java_version_bx.add(java_version_lb, False, True)
java_version_rds[4].set_active(True)
for rd in java_version_rds:
java_version_bx.add(rd, False, True)
# JPA version box
jpa_version_bx = Box(True)
jpa_version_bx.set_spacing(1)
jpa_version_lb = Label('JPA version:')
jpa_version_lb.set_wrap_text(False)
jpa_version_bx.add(jpa_version_lb, False, True)
jpa_version_rds[1].set_active(True)
for rd in jpa_version_rds:
jpa_version_bx.add(rd, False, True)
# set same label width
GuiUtils.set_common_view_widths([java_version_lb, jpa_version_lb])
# need wrapped box for TitledGroupPanel
target_platform_bx = Box(False)
target_platform_bx.set_spacing(5)
target_platform_bx.set_padding(3)
target_platform_bx.add(java_version_bx, False, True)
target_platform_bx.add(jpa_version_bx, False, True)
target_platform_pn = Panel(TitledGroupPanel)
target_platform_pn.set_title('Target Platform')
target_platform_pn.add(target_platform_bx)
# box for tab
main1_bx = Box(False)
main1_bx.set_spacing(5)
main1_bx.set_padding(3)
# main1_bx.add(common_table_prefix_pn, False, True)
# main1_bx.add(language_pn, False, True)
main1_bx.add(target_platform_pn, False, True)
# main1_bx.add(cpk_classes_pn, False, True)
# main1_bx.add(enum_naming_pn, False, True)
# main1_bx.add(annotation_fallback_package_name_pn, False, True)
main_tv = TabView(False)
main_tv.set_size(565, 450)
main_tv.add_page(main1_bx, 'General')
# DISPLAY MAIN FORM
# buttons
export_btn = Button()
export_btn.set_text('Export')
cancel_btn = Button()
cancel_btn.set_text('Cancel')
# button box
buttons_bx = Box(True)
buttons_bx.set_spacing(5)
buttons_bx.set_padding(3)
# uses OS-specific positioning
Utilities.add_end_ok_cancel_buttons(buttons_bx, export_btn, cancel_btn)
# main + button boxes
content_bx = Box(False)
content_bx.set_spacing(5)
content_bx.set_padding(5)
# content_bx.add(path_pn, False, True)
content_bx.add(main_tv, True, True)
content_bx.add(buttons_bx, False, True)
# create centered options dialog
form = Form(None, FormDialogFrame)
form.set_title('JPA Export Options')
form.set_content(content_bx)
form.set_size(500, 500) # must set this to any equaling x,y sizes or the window is not centered
form.center()
form.run_modal(export_btn, cancel_btn)
class GuiUtils:
"""
Some convenience methods for constructing the UI.
"""
def __init__(self):
pass
@staticmethod
def set_common_view_widths(views):
"""Set common width for UI view components by calculating the max width and setting it for every component.
:param views:
:return:
"""
# method for faking column layouts
max_width = max([view.get_width() for view in views])
# map(lambda v: v.set_size(max_width, v.get_height()), views)
for view in views:
view.set_size(max_width, view.get_height())
@staticmethod
def create_radiobuttons_for(texts):
"""Create a list of radio buttons for a given list of text labels.
:param texts: list[str]
:rtype: list[RadioButton]
"""
width = 57
gid = RadioButton.new_id()
rds = []
for text in texts:
rd = RadioButton(gid)
rd.set_text(text)
rd.set_name(text)
rd.set_back_color('orange')
rd.set_size(width, rd.get_height())
rd.set_min_size(width, rd.get_height())
print 'Radio "' + rd.get_name() + '" preferred width = ' + str(rd.get_preferred_width())
rds.append(rd)
return rds
Maybe it's something for the WB team to look at, as it is absolutely not understandable why this is happening...
I'd very much appreciate if you could have a look at this.
Thanks and happy new year.
Karsten