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

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
hika
Posts: 39
Joined: Tue Apr 17, 2018 12:53 am

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

Post 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
Last edited by hika on Thu May 10, 2018 11:26 pm, edited 1 time in total.
openoffice 4.1.2/4.1.4 and libreoffice 5.4.4.2/5.4.5.1 both on Gentoo and on Windows
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Post 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.
Last edited by Zizi64 on Tue May 08, 2018 9:57 pm, edited 1 time in total.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
hika
Posts: 39
Joined: Tue Apr 17, 2018 12:53 am

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Post 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
openoffice 4.1.2/4.1.4 and libreoffice 5.4.4.2/5.4.5.1 both on Gentoo and on Windows
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Post 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?
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Post 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. 
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
hika
Posts: 39
Joined: Tue Apr 17, 2018 12:53 am

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Post 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
openoffice 4.1.2/4.1.4 and libreoffice 5.4.4.2/5.4.5.1 both on Gentoo and on Windows
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Post 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?
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
hika
Posts: 39
Joined: Tue Apr 17, 2018 12:53 am

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Post 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.
openoffice 4.1.2/4.1.4 and libreoffice 5.4.4.2/5.4.5.1 both on Gentoo and on Windows
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Post by Villeroy »

use a formatted field or a numeric field with spin buttons.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
hika
Posts: 39
Joined: Tue Apr 17, 2018 12:53 am

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Post 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.
openoffice 4.1.2/4.1.4 and libreoffice 5.4.4.2/5.4.5.1 both on Gentoo and on Windows
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Post 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.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
hika
Posts: 39
Joined: Tue Apr 17, 2018 12:53 am

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Post 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?
openoffice 4.1.2/4.1.4 and libreoffice 5.4.4.2/5.4.5.1 both on Gentoo and on Windows
hika
Posts: 39
Joined: Tue Apr 17, 2018 12:53 am

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Post 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
openoffice 4.1.2/4.1.4 and libreoffice 5.4.4.2/5.4.5.1 both on Gentoo and on Windows
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Post by JeJe »

Yeah, the embedded dialog thing got solved here:

viewtopic.php?f=21&t=92867
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
hika
Posts: 39
Joined: Tue Apr 17, 2018 12:53 am

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Post 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 ...
openoffice 4.1.2/4.1.4 and libreoffice 5.4.4.2/5.4.5.1 both on Gentoo and on Windows
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Post 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.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
hika
Posts: 39
Joined: Tue Apr 17, 2018 12:53 am

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Post 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?
openoffice 4.1.2/4.1.4 and libreoffice 5.4.4.2/5.4.5.1 both on Gentoo and on Windows
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Post by JeJe »

No, its a setting for each instance of the control.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Post by JeJe »

Its the "PrependCurrencySymbol" value

https://www.openoffice.org/api/docs/com ... Model.html
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
hika
Posts: 39
Joined: Tue Apr 17, 2018 12:53 am

Re: "UnoControlSpinButtonModel" and "MouseWheelBehavior"

Post by hika »

Thanks! I overlooked that one. And it's not in my IDE. But it works as I want it to work.
openoffice 4.1.2/4.1.4 and libreoffice 5.4.4.2/5.4.5.1 both on Gentoo and on Windows
hika
Posts: 39
Joined: Tue Apr 17, 2018 12:53 am

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

Post 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.
openoffice 4.1.2/4.1.4 and libreoffice 5.4.4.2/5.4.5.1 both on Gentoo and on Windows
Post Reply