Page 1 of 1

[Solved sort of] "SpinButtonModel" and "MouseWheelBehavior"

Posted: Tue May 08, 2018 6:15 pm
by hika
I needed a spin control having a value between 25% and 400% with a exponential increment. Not possible by default, but I created it by combining a SpinButton and a read-only textbox. If still have to create a model to manage any textual input in the box and then you can edit it there too.
I later realised I could also have used an embedded spinbutton creating the exponential increment by changing the step value to 10% of the actual value on any change. But I have now this one.

The problem I have is that I can not get the SpinButton (like with the integrated spinbuttons) to react to any mousewheel scrolling. The documentation mentions for both the optional "MouseWheelBehavior" property, which works nicely with any box with an integrated spinbutton. And for those the default setting seems to be: SCROLL_FOCUS_ONLY, but SCROLL_ALWAYS also works.
If I try to set it on a standalone SpinButton (com.sun.star.awt.UnoControlSpinButtonModel) I get an error. The model does not seem to know the property. Has this to do with its optional status?
I want it to be on SCROLL_ALWAYS or better I would want to be able to catch this event when the textbox has focus, but there does not seem to be a listener for the mousescrollwheel. Although it must be there somewhere under the hood.

Has anybody any suggestion?

Hika

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Posted: Tue May 08, 2018 8:20 pm
by Zizi64
Please upload a sample file here with the embedded macro code.

My tip:
Use an oject inspection tool like the MRI or the XrayTool. Then you will able to examine all of the properties, methods, interfaces, ... etc. of the programming objects.

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Posted: Tue May 08, 2018 8:48 pm
by hika
Uploading the code will be complicated as it is a complex set of classes and routines. But using introspection and a query on the actual properties these are the reported properties for the Model:
  • "BackgroundColor" = None
    "Border" = 1
    "BorderColor" = None
    "ContextWritingMode" = 4
    "DefaultControl" = com.sun.star.awt.UnoControlSpinButton
    "EnableVisible" = True
    "Enabled" = True
    "Height" = 0
    "HelpText" =
    "HelpURL" =
    "Name" =
    "Orientation" = 1
    "PositionX" = 0
    "PositionY" = 0
    "Printable" = True
    "Repeat" = True
    "RepeatDelay" = 100
    "ResourceResolver" = None
    "SpinIncrement" = 1
    "SpinValue" = 0
    "SpinValueMax" = 15
    "SpinValueMin" = -15
    "Step" = 0
    "SymbolColor" = None
    "TabIndex" = -1
    "Tabstop" = None
    "Tag" =
    "Width" = 0
    "WritingMode" = 4
    "PropertyToDefault" property does not exist
    "Delegator" property does not exist

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Posted: Tue May 08, 2018 10:03 pm
by Zizi64
It will be too hard to help you without detailed informations, and samples. We even do not know it: what is the application what you want to control: Calc? Writer? Base? Or other?

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Posted: Tue May 08, 2018 10:15 pm
by Villeroy
Zizi64 wrote:It will be too hard to help you without detailed informations, and samples. We even do not know it: what is the application what you want to control: Calc? Writer? Base? Or other?
Form contols belong to forms.
Forms are attached to draw pages.
All four major types of documents have draw pages.
Why someone wants to design form control models programmatically is beyond my understanding.
 Edit: A spin button has no mouse wheel behaviour as you could see if you would draw one off the toolbar. 

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Posted: Tue May 08, 2018 10:56 pm
by hika
Zizi64 wrote:It will be too hard to help you without detailed informations, and samples. We even do not know it: what is the application what you want to control: Calc? Writer? Base? Or other?
I am building a dialog, so completely independent of the application.
Villeroy wrote:
 Edit: A spin button has no mouse wheel behaviour as you could see if you would draw one from the toolbar. 
My mystery is then why the documentation contains the "MouseWheelBehavior" property, implying it does.
http://www.openoffice.org/api/docs/comm ... Model.html
Also this does not say anything. I have on several models seen that not all supported properties are present in the UI
Villeroy wrote: Why someone wants to design form control models programmatically is beyond my understanding.
Because management is programmatically far and far easier. It only takes initially some more time. actually I am working on easy to create dialogs. This is the whole macrocode for my test form.

Code: Select all

from unofunctions import UnoFunctions
from unoform import UnoForm

class Forms():
    def __init__(self):
        self.uno = UnoFunctions()
        fname = '/home/hika/Files//Ubuntu/KasOverzicht/formtest.log'
        self.uno.set_logfile(fname)
        self.form = None
        self.step = False

    def make_form(self):
        fargs = {
            'log_settings': False,
            'log_object_tree': False,
            'log_size_tree': False,
            'log_listeners': False,
            'form_defaults': {
                'size_factor': 1,
                'use_os_style': False},
            'title': 'Test Formulier',
            'x': 100,
            'y': 100,
            'cmode': self.uno.uc_contmode.HBOX,
            'listener': self,
            'mode': self.uno.uc_objmode.MODELESSDIALOG,
            'padding': 0,
            'children': [
                {'name': 'maingrid',
                    'ctype': 'container',
                    'cmode': self.uno.uc_contmode.VBOX,
                    'v_baseline': self.uno.uc_alignment.CENTER,
                    'v_cellalign': self.uno.uc_alignment.TOP,
                    'v_resizable': False,
                    'padding': 10,
                    'children': [
                        {'name': 'txtInput',
                            'ctype': 'text',
                            'x': 2,
                            'y': 2,
                            'label_side': self.uno.uc_side.LEFT,
                            'label_line': True,
                            'label': {'caption': 'TextLabel:'},
                            'listener': self},
                        {'name': 'Hspin',
                            'ctype': 'numeric',
                            'x': 2,
                            'y': 3,
                            'spin': True,
                            'formatstring': '0%',
                            'max_value': 4.0,
                            'min_value': 0.25,
                            'label_side': self.uno.uc_side.LEFT,
                            'label_line': True,
                            'label': {'caption': 'TextLabel2:'},
                            'listener': self}]},
                {'name': 'line1',
                    'ctype': 'vline'},
                {'name': 'sidebox',
                    'ctype': 'container',
                    'cmode': self.uno.uc_contmode.VBOX,
                    'h_resizable': False,
                    'padding': 0,
                    'children': [
                        {'name': 'Sizer',
                            'ctype': 'sizer',
                            'padding': 0,
                            'h_cellalign': self.uno.uc_alignment.RIGHT},
                        {'name': 'buttonbox',
                            'ctype': 'container',
                            'caption': 'buttons',
                            'cmode': self.uno.uc_contmode.VBOX,
                            'h_resizable': False,
                            'padding': 10,
                            'children': [
                                 {'name': 'btnPrint',
                                    'ctype': 'button',
                                    'caption': 'Print',
                                    'listener': self},
                                {'name': 'btnClose',
                                    'ctype': 'button',
                                    'backcolor': self.uno.uc_colors.RED3,
                                    'caption': 'Close',
                                    'font': {'bold': True, 'underline': self.uno.uc_underline.NONE},
                                    'insert': self.uno.uc_insertpos.END,
                                    'listener': self}]}]}]}

        self.form = UnoForm(self.uno, 'testform', **fargs)

    def clicked(self, ev, **kwargs):
        #~ for k, v in kwargs.items():
            #~ self.uno.log('"%s": %s' % (k, v))
        try:
            if kwargs['name'] == 'btnClose':
                self.form.hide()

            if kwargs['name'] == 'btnPrint':
                self.step = not self.step
                if self.step:
                    self.form.set_size_factor(2)

                else:
                    self.form.set_size_factor(1)

        except:
            self.uno.log('%s' % (traceback.format_exc(), ))

__F__ = Forms()

def make_form(x = None):
    __F__.make_form()

def show_form(x = None):
    if __F__.form == None:
        __F__.make_form()

    __F__.form.show()
    __F__.uno.log('show_form executed')
Resulting in:
https://drive.google.com/open?id=1Fq9sp ... L8yDRcJlqS
https://drive.google.com/open?id=1fYEg5 ... LrpW47eWoy
The control in question is the one to the top right. Spinning it will resize the form in its entirety, including the fontsize.
The second image shows what happens when you resize it.
The rest is default code in pythonpath

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Posted: Tue May 08, 2018 11:51 pm
by JeJe
Can't answer your question... and haven't tried this to see if this would work... but why not have a resizeable dialog with a window listener and on the windowResized event use SetPosSize to size the dialog to the nearest one of your sizes?

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Posted: Wed May 09, 2018 12:32 am
by hika
An elegant idea.
But there are in my model two different sizing mechanisms involved.

First there is the one triggered by someone resizing the window and that also is used when first building the dialog. It involves relative positions and sizes not unlike the one used in GTK.

Second there is an overall parameter the "size_factor" that can be used to enlarge or reduce the entire dialog. For instance for someone not so well sighted or on a small high resolution or big low resolution screen. For this I need a control. It could be a combobox with predefined factors or a toggle between two or more sizes or as I choose a spinbox. However in this case you don't want a linear change but an exponential one. Enlarge or reduce by say 10%. Only unlike what the documentation suggests the mousewheel support does not seem to be implemented in the general SpinButton model. Reducing the functionality significantly. Possibly, as the property is marked optional, there is some property or methode to enable it, but I have not been able to find that.
Maybe I must go for my alternate idea and use a box type with built-in spinbutton support, changing the "ValueStep" on any value change to 10% of the value.

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Posted: Wed May 09, 2018 1:02 am
by Villeroy
use a formatted field or a numeric field with spin buttons.

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Posted: Wed May 09, 2018 1:08 am
by hika
That's my alternate idea, but at first I had not thought out how I could make in/decrement exponentially. As I recently found the solution there I might go that way.

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Posted: Wed May 09, 2018 5:08 am
by JeJe
You might be able to invent your own control here. I rehashed an old idea of mine for a window sizing widget when I couldn't get the resizable borders to work in OOBasic:

viewtopic.php?f=21&t=86032&p=401690#p401690

For your problem you could have a button or a menu item that pops up a dialog and have a series of frames or labels drawn on that dialog to represent the sizes as boxes. These could be small boxes that represent larger dialog sizes, or it could be a full screen dialog with the actual new dialog sizes drawn with frames for the user to click on.

With frames and labels can create your own controls - for example it won't handle the mousewheel but you can make your own spin button with two buttons, the button captions set to the appropriate triangles, and repeat set to true.

Edit: another idea just occurs is a small popup dialog with scrollbars which the user uses to set the proportions of the new dialog against the screen size.

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Posted: Thu May 10, 2018 1:30 am
by hika
Making a spinbutton in say a UnoControlNumericField behave different (non linear) is even simpler then I at first though. The increment is applied before you get a spin event. But by setting `model.ValueStep = 0` you can apply your own action. In my case I first set a constant class:

Code: Select all

class _ConstSpinType:
    NONE = 0
    LINEAR = 1
    EXPONENTIAL = 2
    VALUES = (0, 1, 2)
    DEFAULT = 0
And then when on creation this constant has a value of EXPONENTIAL, model.ValueStep = 0 and in reaction to the event:

Code: Select all

   def up(self, ev):
        if self.properties['spin'] == self.uc_spintype.EXPONENTIAL:
            self.set_value(self.get_value() * (1 + self.properties['spin_step']))

   def down(self, ev):
        if self.properties['spin'] == self.uc_spintype.EXPONENTIAL:
            self.uno.log(self.get_value() / (1 + self.properties['spin_step']))
Oh and JeJe, I will have a look at your example, but at present I don't want to mix languages as that will drastically increase the number of typos. You since found out how to embed a dialog in a window/frame set?

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Posted: Thu May 10, 2018 1:36 am
by hika
Oh and if the presence of the "MouseWheelBehavior" property in the UnoControlSpinButtonModel documentation is indeed faulty, how to go about to get this under the attention of the maintainer(s) of that documentation?

Hika

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Posted: Thu May 10, 2018 8:02 am
by JeJe
Yeah, the embedded dialog thing got solved here:

viewtopic.php?f=21&t=92867

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Posted: Thu May 10, 2018 10:15 pm
by hika
This gets annoying. With the "UnoControlNumericFieldModel" it worked like a charm, but I want to display percentages.
So I looked at the "UnoControlFormattedFieldModel" , but that does not have a settable step value, so I can not make it behave exponential. The "UnoControlCurrencyFieldModel" has ValueStep so I could set the CurrencySymbol to "%" if it would have had an option to put it behind the value.
So now I must choose between:
- no mousescroll support
- a linear solution
- no formatting to percentage
- building a complete new model, but I think I need to know C++ for that, which I don't

Annoying

Hika

Maybe I could build something with the "UnoControlComboBoxModel" The documentation mentions the "MouseWheelBehavior" property and by disabling the dropdown ...

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Posted: Thu May 10, 2018 10:58 pm
by JeJe
You can put the % behind the value in the currency field - in the Basic IDE setting the "prefix symbol" to yes or no decides whether its in front or behind.

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Posted: Thu May 10, 2018 11:05 pm
by hika
JeJe wrote:You can put the % behind the value in the currency field - in the Basic IDE setting the "prefix symbol" to yes or no decides whether its in front or behind.
You mean a generic setting, that will effect every currency display?

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Posted: Thu May 10, 2018 11:11 pm
by JeJe
No, its a setting for each instance of the control.

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Posted: Thu May 10, 2018 11:13 pm
by JeJe
Its the "PrependCurrencySymbol" value

https://www.openoffice.org/api/docs/com ... Model.html

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Posted: Thu May 10, 2018 11:16 pm
by hika
Thanks! I overlooked that one. And it's not in my IDE. But it works as I want it to work.

Re: [Solved sort of] "SpinButtonModel" and "MouseWheelBehavi

Posted: Thu May 10, 2018 11:36 pm
by hika
When my project reaches alfa stage I'll publish it on git. But still a lot of work to do. Interegrating all the model and on the datamodel underneath it.