[Solved] Non-Blocking MsgBox without a button

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
paulhr
Posts: 40
Joined: Fri Jun 27, 2014 4:42 pm
Location: Raleigh, NC

[Solved] Non-Blocking MsgBox without a button

Post by paulhr »

I would like to pop up a message saying the macro is running. I was hopping there was a way to have a second msgbox that would replace the first saying "Macro is done running press 'ok' to continue" Is this possible with OO. I looked at https://wiki.openoffice.org/wiki/Docume ... Library%29 and only found option with at least one button. I don't want the execution of the macro to get blocked when the first message is rendered/shown. But I do want MsgBox to block for the second message about "Macro is done."
Last edited by RoryOF on Wed Jan 14, 2015 6:36 pm, edited 2 times in total.
Reason: Added green tick. [RoryOF, Moderator]
OpenOffice 4.1.1 on Windows 7 Pro
User avatar
MTP
Volunteer
Posts: 1620
Joined: Mon Sep 10, 2012 7:31 pm
Location: Midwest USA

Re: Non-Blocking MsgBox without a button

Post by MTP »

I think what you want is called a non-modal dialog. Non-modal means it doesn't stop the execution of a macro. Dialogs have a lot more options than the "MsgBox" preconfigured with StarBasic.

Maybe check out:
Making of a non-modal dialog?
Working With Dialogs

For me the pictures in the wiki are broken - I think the only critical bit that is missing is that, to create a dialog, open your module like you're going to write a macro. Right-click on a module tab at the bottom of the window and choose Insert->BASIC Dialog
OpenOffice 4.1.1 on Windows 10, HSQLDB 1.8 split database
mcmurchy1917
Posts: 23
Joined: Fri Feb 22, 2013 2:15 pm

Re: Non-Blocking MsgBox without a button

Post by mcmurchy1917 »

What I've done in the past is use the Status Bar to provide details of progress whilst the macro is running. Then a Modal Message Box when the macro completes. I've found this less intrusive than a non-modal message box.
Slackware user
paulhr
Posts: 40
Joined: Fri Jun 27, 2014 4:42 pm
Location: Raleigh, NC

Re: Non-Blocking MsgBox without a button

Post by paulhr »

I like the idea. But a search on "status bar" is not doing me any good. Got a link to get me started? Or better yet a sample?
OpenOffice 4.1.1 on Windows 7 Pro
User avatar
RoryOF
Moderator
Posts: 35103
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Non-Blocking MsgBox without a button

Post by RoryOF »

Discussion on how to put info in Calc status bar in this thread
viewtopic.php?f=21&t=10104

Presumably it could be adapted for Writer and other OpenOffice applications.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.5 LTS
paulhr
Posts: 40
Joined: Fri Jun 27, 2014 4:42 pm
Location: Raleigh, NC

[Solved] Re: Non-Blocking MsgBox without a button

Post by paulhr »

This worked great, thanks. Only had to comment out the following line. I was getting errors about not finding "VisibleArea" Since the functionality I needed was not dependent on this line commenting out out had no effect for me.

Code: Select all

vStatusBarText=right(vStatusBarText,int(ThisComponent.CurrentController.VisibleArea.Width/150)) 'Select last part that could be displayed.
OpenOffice 4.1.1 on Windows 7 Pro
User avatar
RoryOF
Moderator
Posts: 35103
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: [Solved] Non-Blocking MsgBox without a button

Post by RoryOF »

It might be helpful to other users if you would post the core section of your status bar code to this thread.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.5 LTS
paulhr
Posts: 40
Joined: Fri Jun 27, 2014 4:42 pm
Location: Raleigh, NC

Re: [Solved] Non-Blocking MsgBox without a button

Post by paulhr »

The main part of the below code snippet can be found at viewtopic.php?f=21&t=10104 as RoryOF said. As per RoryOF's request I am posting the code again, with my few uses, here for easy reference.

Code: Select all

global vStatusBarText as string '=text that is been displayed on the statusbar

sub main()
   sStatusBar "Running Macro subroutine AssignConstants()"
   AssignConstants ' function source code not included in this code snippet for brevity 
   sStatusBar  'This will clear and restore the StatusBar

   sStatusBar "Running Macro subroutine Total_Disk_Needed()"
   sMessageBoxString = sMessageBoxString & Total_Disk_Needed ' function source code not included in this code snippet for brevity 
   sStatusBar  'This will clear and restore the StatusBar

   sStatusBar "Running Macro subroutine Field_Value_Propagation()"
   sMessageBoxString = sMessageBoxString & CHR(10) & Field_Value_Propagation ' function source code not included in this code snippet for brevity 
   sStatusBar  'This will clear and restore the StatusBar

   sStatusBar "Running Macro subroutine LargePageSpace_calculations()"
   sMessageBoxString = sMessageBoxString & CHR(10) & LargePageSpace_calculations ' function source code not included in this code snippet for brevity 
   sStatusBar  'This will clear and restore the StatusBar

   sStatusBar "Running Macro subroutine JVM_calculations()"
   sMessageBoxString = sMessageBoxString & CHR(10) & JVM_calculations ' function source code not included in this code snippet for brevity 
   sStatusBar  'This will clear and restore the StatusBar

   sStatusBar "Running Macro subroutine Performance_Tuning_calculations()"
   sMessageBoxString = sMessageBoxString & CHR(10) & Performance_Tuning_calculations ' function source code not included in this code snippet for brevity 
   sStatusBar  'This will clear and restore the StatusBar

   msgbox sMessageBoxString
   sStatusBar  'This will clear and restore the StatusBar
end sub

sub sStatusBar(optional vNewText, optional vAddText) 'set or add text to the statusbar, nothing = clear&reset it.
   if isError(vNewText) then
      if isError(vAddText) then 'clear statusbar
         vStatusBarText=""
      else 'add text to the previous statusbar
         vStatusBarText=vStatusBarText & vAddText
      endif
   else
      if isError(vAddText) then 'use new text
         vStatusBarText=vNewText
      else 'use new text and add the other text as well
         vStatusBarText=vNewText & vAddText
      endif
   endif
   rem vStatusBarText=right(vStatusBarText,int(ThisComponent.CurrentController.VisibleArea.Width/150)) 'Select last part that could be displayed.
   if isNull(ThisComponent.CurrentController) then exit sub 'Because the last XEventListener-event can't be written to the statusbar, because it's no longer there!
   if vStatusBarText="" then 'reset statusbar
      ThisComponent.CurrentController.StatusIndicator.Reset
   else 'change the text in the statusbar
      ThisComponent.CurrentController.StatusIndicator.Start(vStatusBarText,0)
   endif
end sub
OpenOffice 4.1.1 on Windows 7 Pro
mcmurchy1917
Posts: 23
Joined: Fri Feb 22, 2013 2:15 pm

Re: [Solved] Non-Blocking MsgBox without a button

Post by mcmurchy1917 »

Beat me to it. This is an cut down version of what I do -

Code: Select all

Sub demonstrate_status_bar

	dim document   as object
	
	document   = ThisComponent.CurrentController.Frame
	oBar = document.createStatusIndicator()
	oBar.start("Started...",100)
	oBar.Value = 33 ' show  progress bar
	wait 2000
	oBar.Text = "Initialising Mail Merge ..."
	oBar.Value = 66
	wait 2000
	oBar.Text ="Converting to PDF file ...."
	oBar.Value = ProgressValue
	oBar.Text = "Finished !"
	oBar.Value = 100
	wait 2000
	oBar.end()

End Sub
Slackware user
User avatar
RoryOF
Moderator
Posts: 35103
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: [Solved] Non-Blocking MsgBox without a button

Post by RoryOF »

Thank you both. I've been programming an OpenOffice extension all afternoon and am realising how important working code examples are. I doubt I'll have use for these snippets, but I'm sure someone will.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.5 LTS
paulhr
Posts: 40
Joined: Fri Jun 27, 2014 4:42 pm
Location: Raleigh, NC

Re: [Solved] Non-Blocking MsgBox without a button

Post by paulhr »

mcmurchy1917: I am using your example and I like it more the mine. But one thing I can not get right is returning the status bar back to its original format and content when done. .reset() and .end() don't make a difference. I looked at the API docs and found nothing. What am I missing?
OpenOffice 4.1.1 on Windows 7 Pro
mcmurchy1917
Posts: 23
Joined: Fri Feb 22, 2013 2:15 pm

Re: [Solved] Non-Blocking MsgBox without a button

Post by mcmurchy1917 »

My Status Bar looks the same before and after. I'm using LibreOffice 4.3.2. See attachment. I've not studied the API - I always have trouble finding where to start.

How does the other code perform?

The worked example in Andrew Pitonyak's document has this example which is probably what I copied from

Code: Select all

Sub SetStatus
  Dim oBar    ' Generated status bar
  Dim oFrame  ' Current frame

  REM Obtain the current frame from the current controller
  oFrame = ThisComponent.getCurrentController().getFrame()

  REM Create a NEW status indicator
  oBar = oFrame.createStatusIndicator()

  REM Start using the new status bar in the lower left corner.
  REM The original status bar will no longer be visible.
  REM The value of 100 is an arbitrary value for use as a 
  REM progress bar if I choose to do so.
  oBar.start("Hello You", 100)

  REM Pause the macro so that I can see the text in the lower
  REM left corner.
  Print "Waiting"

  REM Terminate this status bar, causing the original status
  REM bar to be used instead.
  oBar.end()
End Sub 
Attachments
Demonstrates Status Bar before and after.
Demonstrates Status Bar before and after.
statusbar.png (6.49 KiB) Viewed 10095 times
Slackware user
paulhr
Posts: 40
Joined: Fri Jun 27, 2014 4:42 pm
Location: Raleigh, NC

Re: [Solved] Non-Blocking MsgBox without a button

Post by paulhr »

Not sure why, but adding the "wait 500" after the .end() and .reset() got the status bar back to normal.

Code: Select all

   
oBar.reset()
oBar.end()
wait 500
OpenOffice 4.1.1 on Windows 7 Pro
Robitron
Posts: 107
Joined: Thu Nov 15, 2012 5:27 pm

Re: [Solved] Non-Blocking MsgBox without a button

Post by Robitron »

I had no idea that we could use the status bar like this!

I did a macro once that was very time intensive. It took more than a minute, possibly more than 2 minutes, so I was a afraid it had locked up.

So, I used a previously unused cell to display data that was being updated during the process and was amazed at how much was being done in a millisecond! LOL

If I'd known about this, I could have used the status bar instead!!!

Thanks a lot!!!
Libre Office 7.3.3.2

If I had to, I'd put Tabasco on everything!
Post Reply