How to control size of GenericDialog

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to control size of GenericDialog

Alex-2
I'm building a simple generic dialog with following code:
from ij import gui

if __name__ == '__main__':

    gd = gui.GenericDialog('Test')
    gd.addStringField('Test1', 'MyTest')
    gd.addToSameRow()
    gd.addChoice('Test1', ['MyTest1','MyTest2'],'MyTest1')
    gd.showDialog()

I am having a few issues. 

1) The dialog box doesn't size correctly to show all the elements2) If manually resized the String Field and Choice elements seem to be right justified
Is there a way to control the size of the GenericDialog manually?Is there a way to force the StringField and Choice elements to stick to the left of the GenericDialog?
ThanksAlex






--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

Screen Shot 2018-07-02 at 12.18.33 AM.png (107K) Download Attachment
Screen Shot 2018-07-02 at 12.18.28 AM.png (78K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to control size of GenericDialog

Philippe CARL
Dear Alex,
I tried the following IJ macro code:
  Dialog.create("Test");
  Dialog.addString('Test1', 'MyTest');
  Dialog.addToSameRow();
  Dialog.addChoice('Test1', newArray('MyTest1','MyTest2'),'MyTest1');
  Dialog.show();
and didn't have any issue.
But did you read the details about the Dialog.addToSameRow()method?:
Makes the next item added appear on the same row as the previous item. May be used for addNumericField, addSlider, addChoice, addCheckbox, addStringField, addMessage, addPanel, and before the showDialog() method.
"In the latter case, the buttons appear to the right of the previous item. Note that addMessage (and addString if a width of more than 8 is specified) use the remaining width, so it must be the last item of a row."
Requires 1.51r.

Also did you try the following method:
Dialog.setInsets(top, left, bottom)?

My best regards,
Philippe

Philippe CARL
Laboratoire de Bioimagerie et Pathologies
UMR 7021 CNRS - Université de Strasbourg
Faculté de Pharmacie
74 route du Rhin
67401 ILLKIRCH
Tel : +33(0)3 68 85 41 84

-----Message d'origine-----
De : ImageJ Interest Group [mailto:[hidden email]] De la part de Alex
Envoyé : lundi 2 juillet 2018 09:23
À : [hidden email]
Objet : How to control size of GenericDialog

I'm building a simple generic dialog with following code:
from ij import gui

if __name__ == '__main__':

    gd = gui.GenericDialog('Test')
    gd.addStringField('Test1', 'MyTest')
    gd.addToSameRow()
    gd.addChoice('Test1', ['MyTest1','MyTest2'],'MyTest1')
    gd.showDialog()

I am having a few issues.  

1) The dialog box doesn't size correctly to show all the elements2) If manually resized the String Field and Choice elements seem to be right justified Is there a way to control the size of the GenericDialog manually?Is there a way to force the StringField and Choice elements to stick to the left of the GenericDialog?
ThanksAlex






--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How to control size of GenericDialog

Alex-2
 
 Philippe,
The macro code you provided exhibits the same behavior on my system as the Python. Did you see my attached screenshots?I just tried placing the Choice before the String and that workaround seems to fix the problem.   Given the Strings aren't 8 characters, I didn't think the condition applied but apparently it does.

Regardless, is it possible in imageJ using Python to control the size of the GenericDialog?
Alex


    On Monday, July 2, 2018, 2:14:03 AM PDT, Philippe CARL <[hidden email]> wrote:  
 
 Dear Alex,
I tried the following IJ macro code:
  Dialog.create("Test");
  Dialog.addString('Test1', 'MyTest');
  Dialog.addToSameRow();
  Dialog.addChoice('Test1', newArray('MyTest1','MyTest2'),'MyTest1');
  Dialog.show();
and didn't have any issue.
But did you read the details about the Dialog.addToSameRow()method?:
Makes the next item added appear on the same row as the previous item. May be used for addNumericField, addSlider, addChoice, addCheckbox, addStringField, addMessage, addPanel, and before the showDialog() method.
"In the latter case, the buttons appear to the right of the previous item. Note that addMessage (and addString if a width of more than 8 is specified) use the remaining width, so it must be the last item of a row."
Requires 1.51r.

Also did you try the following method:
Dialog.setInsets(top, left, bottom)?

My best regards,
Philippe

Philippe CARL
Laboratoire de Bioimagerie et Pathologies
UMR 7021 CNRS - Université de Strasbourg
Faculté de Pharmacie
74 route du Rhin
67401 ILLKIRCH
Tel : +33(0)3 68 85 41 84

-----Message d'origine-----
De : ImageJ Interest Group [mailto:[hidden email]] De la part de Alex
Envoyé : lundi 2 juillet 2018 09:23
À : [hidden email]
Objet : How to control size of GenericDialog

I'm building a simple generic dialog with following code:
from ij import gui

if __name__ == '__main__':

    gd = gui.GenericDialog('Test')
    gd.addStringField('Test1', 'MyTest')
    gd.addToSameRow()
    gd.addChoice('Test1', ['MyTest1','MyTest2'],'MyTest1')
    gd.showDialog()

I am having a few issues. 

1) The dialog box doesn't size correctly to show all the elements2) If manually resized the String Field and Choice elements seem to be right justified Is there a way to control the size of the GenericDialog manually?Is there a way to force the StringField and Choice elements to stick to the left of the GenericDialog?
ThanksAlex






--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html 

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How to control size of GenericDialog

Michael Schmid-3
In reply to this post by Alex-2
Hi Alex,

please make sure you have the latest ImageJ version (1.52d; Help>Update
ImageJ).
In ImageJ versions prior to 1.52a, one could not add items to the same
row after addStringField with the default field width.
(By the way, also in new versions, you cannot add anything to the same
row after "addStringField" with a custom width above 8. Such large
fields span all remaining columns).

I have tried the JavaScript equivalent of your code with the latest
ImageJ and the dialog looks correct (at least under Linux).


Michael
________________________________________________________________
On 02/07/2018 09:23, Alex wrote:

> I'm building a simple generic dialog with following code:
> from ij import gui
>
> if __name__ == '__main__':
>
>      gd = gui.GenericDialog('Test')
>      gd.addStringField('Test1', 'MyTest')
>      gd.addToSameRow()
>      gd.addChoice('Test1', ['MyTest1','MyTest2'],'MyTest1')
>      gd.showDialog()
>
> I am having a few issues.
>
> 1) The dialog box doesn't size correctly to show all the elements2) If manually resized the String Field and Choice elements seem to be right justified
> Is there a way to control the size of the GenericDialog manually?Is there a way to force the StringField and Choice elements to stick to the left of the GenericDialog?
> ThanksAlex

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How to control size of GenericDialog

Alex-2
 Michael,

Attached is code showing the problem and screenshots.  It appears that the alignment of UI elements is affected by other elements in the dialog.I'm currently using ImageJ 1.52d.  Is the behavior illustrated below expected?
ThanksAlex

from ij import gui

def dialog1():
    # Choice and String Field in same row
    gd = gui.GenericDialog('Test')
    gd.addChoice('Color ', ['Red','Green','Blue'], 'Red')
    gd.addToSameRow()
    gd.addStringField('Name', '')

    # Show the Dialog
    gd.showDialog()

def dialog2():
    # Choice and String Field in same row
    gd = gui.GenericDialog('Test')
    gd.addChoice('Color ', ['Red','Green','Blue'], 'Red')
    gd.addToSameRow()
    gd.addStringField('Name', '')

    # Followed by a checkbox
    msg = 'My checkbox for some option'
    gd.addCheckbox(msg, False)

    # Show the Dialog
    gd.showDialog()

def dialog3():
    # Choice and String Field in same row
    gd = gui.GenericDialog('Test')
    gd.addChoice('Color ', ['Red','Green','Blue'], 'Red')
    gd.addToSameRow()
    gd.addStringField('Name', '')

    # Followed by a numeric field
    msg = 'My number field'
    gd.addNumericField(msg, 0.5, 2)

    # Show the Dialog
    gd.showDialog()

if __name__ in ['__builtin__','__main__']:

    # Produces expected behavior
    dialog1()

    # Checkbox shifts the String Field to right
    dialog2()

    # Adding a numeric field shifts the choice to the right
    dialog3()



    On Monday, July 2, 2018, 2:41:26 AM PDT, Michael Schmid <[hidden email]> wrote:  
 
 Hi Alex,

please make sure you have the latest ImageJ version (1.52d; Help>Update
ImageJ).
In ImageJ versions prior to 1.52a, one could not add items to the same
row after addStringField with the default field width.
(By the way, also in new versions, you cannot add anything to the same
row after "addStringField" with a custom width above 8. Such large
fields span all remaining columns).

I have tried the JavaScript equivalent of your code with the latest
ImageJ and the dialog looks correct (at least under Linux).


Michael
________________________________________________________________
On 02/07/2018 09:23, Alex wrote:

> I'm building a simple generic dialog with following code:
> from ij import gui
>
> if __name__ == '__main__':
>
>      gd = gui.GenericDialog('Test')
>      gd.addStringField('Test1', 'MyTest')
>      gd.addToSameRow()
>      gd.addChoice('Test1', ['MyTest1','MyTest2'],'MyTest1')
>      gd.showDialog()
>
> I am having a few issues.
>
> 1) The dialog box doesn't size correctly to show all the elements2) If manually resized the String Field and Choice elements seem to be right justified
> Is there a way to control the size of the GenericDialog manually?Is there a way to force the StringField and Choice elements to stick to the left of the GenericDialog?
> ThanksAlex
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
 

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

Screen Shot 2018-07-03 at 3.27.53 PM.png (100K) Download Attachment
Screen Shot 2018-07-03 at 3.27.47 PM.png (105K) Download Attachment
Screen Shot 2018-07-03 at 3.27.41 PM.png (84K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to control size of GenericDialog

Michael Schmid-3
Hi Alex,

the ImageJ GeneriDialog uses the Java GridBag layout, so all items are
arranged in a grid.
If one item in a column is wider than the others, the whole column will
become wider.

For many dialogs, this gives a nicer layout than adjusting the width for
each item individually. Here is a macro example:

   Dialog.create("Test Dialog");
   Dialog.addString("Title:", "Untitled Image", 20);
   Dialog.addNumber("Size: X", 512);
   Dialog.addToSameRow();
   Dialog.addNumber("Y", 512, 0, 6, "Pixels");
   Dialog.addNumber("Scale: X", 1, 2, 6, "");
   Dialog.addToSameRow();
   Dialog.addNumber("Y", 1, 2, 6, "Unit per Pixel");
   Dialog.addString("Unit: X", "um", 6);
   Dialog.addToSameRow();
   Dialog.addString("Y", "um", 6);
   Dialog.show();

Michael
________________________________________________________________
On 04/07/2018 00:29, Alex wrote:

>   Michael,
>
> Attached is code showing the problem and screenshots.  It appears that the alignment of UI elements is affected by other elements in the dialog.I'm currently using ImageJ 1.52d.  Is the behavior illustrated below expected?
> ThanksAlex
>
> from ij import gui
>
> def dialog1():
>      # Choice and String Field in same row
>      gd = gui.GenericDialog('Test')
>      gd.addChoice('Color ', ['Red','Green','Blue'], 'Red')
>      gd.addToSameRow()
>      gd.addStringField('Name', '')
>
>      # Show the Dialog
>      gd.showDialog()
>
> def dialog2():
>      # Choice and String Field in same row
>      gd = gui.GenericDialog('Test')
>      gd.addChoice('Color ', ['Red','Green','Blue'], 'Red')
>      gd.addToSameRow()
>      gd.addStringField('Name', '')
>
>      # Followed by a checkbox
>      msg = 'My checkbox for some option'
>      gd.addCheckbox(msg, False)
>
>      # Show the Dialog
>      gd.showDialog()
>
> def dialog3():
>      # Choice and String Field in same row
>      gd = gui.GenericDialog('Test')
>      gd.addChoice('Color ', ['Red','Green','Blue'], 'Red')
>      gd.addToSameRow()
>      gd.addStringField('Name', '')
>
>      # Followed by a numeric field
>      msg = 'My number field'
>      gd.addNumericField(msg, 0.5, 2)
>
>      # Show the Dialog
>      gd.showDialog()
>
> if __name__ in ['__builtin__','__main__']:
>
>      # Produces expected behavior
>      dialog1()
>
>      # Checkbox shifts the String Field to right
>      dialog2()
>
>      # Adding a numeric field shifts the choice to the right
>      dialog3()
>
>
>
>      On Monday, July 2, 2018, 2:41:26 AM PDT, Michael Schmid <[hidden email]> wrote:
>  
>   Hi Alex,
>
> please make sure you have the latest ImageJ version (1.52d; Help>Update
> ImageJ).
> In ImageJ versions prior to 1.52a, one could not add items to the same
> row after addStringField with the default field width.
> (By the way, also in new versions, you cannot add anything to the same
> row after "addStringField" with a custom width above 8. Such large
> fields span all remaining columns).
>
> I have tried the JavaScript equivalent of your code with the latest
> ImageJ and the dialog looks correct (at least under Linux).
>
>
> Michael
> ________________________________________________________________
> On 02/07/2018 09:23, Alex wrote:
>> I'm building a simple generic dialog with following code:
>> from ij import gui
>>
>> if __name__ == '__main__':
>>
>>        gd = gui.GenericDialog('Test')
>>        gd.addStringField('Test1', 'MyTest')
>>        gd.addToSameRow()
>>        gd.addChoice('Test1', ['MyTest1','MyTest2'],'MyTest1')
>>        gd.showDialog()
>>
>> I am having a few issues.
>>
>> 1) The dialog box doesn't size correctly to show all the elements2) If manually resized the String Field and Choice elements seem to be right justified
>> Is there a way to control the size of the GenericDialog manually?Is there a way to force the StringField and Choice elements to stick to the left of the GenericDialog?
>> ThanksAlex
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>    
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html