Page 1 of 4

ScreenShot

Posted: Saturday 16th May 2020 3:33pm
by cogier
Hi guys, here is another of my efforts. Comments welcome.

Image
ScreenShot-1.0.tar.gz
(10.5 KiB) Downloaded 69 times

Re: ScreenShot

Posted: Saturday 16th May 2020 4:05pm
by johnaaronrose
I've just downloaded the attached tar.gz, extracted its files and opened the resultant project.
You've got some things that I didn't have:
As I wasn't able to find the Mode command (in the Gambas documentation), could you tell me what it (& its argument does)?
A Mouse_Drag event (rather than Mouse_Move) event with code of

Code: Select all

DrawingArea1.Clear
Paint.Begin(DrawingArea1)
Paint.LineWidth = 5
Paint.Rectangle(iStartX, iStartY, Mouse..ScreenX - iStartX, Mouse.ScreenY - iStartY)
Paint.Stroke
Paint.End
I'm unclear about the meaning of Mouse_Drag. Could you clarify?
I looked at Mouse.X & Mouse.ScreenX and didn't understand the difference between the 2: Relative is relative to what? Presumably Absolute is looking at the screen as a whole (i.e. including docks etc).

BTW In the Capture code, you have 2 dots between Mouse & ScreenX:

Code: Select all

Paint.Rectangle(iStartX, iStartY, Mouse..ScreenX - iStartX, Mouse.ScreenY - iStartY)
I last looked at this app 2+ years ago and never got it working. So it's giving me problems! It's quite difficult to work out how to move from the SelectArea form (equivalent of your Capture form) at the form's opening to displaying of the original desktop which has a video (equivalent of your photos display) as part of the available desktop: typically the app's user would have their internet browser open with its window maximised (i.e. covering the available desktop, which doesn't include the launch panel etc), the user would then see a popup requesting press mouse button down when the cursor is at the top left of the video's display, release mouse button when the cursor is at the bottom right of the video's display. So the user would click on the internet browser icon in the launch panel and then do the mouse down, mouse move & mouse up (with the app's code ensuring has the resultant rectangle has its outline redrawn as the mouse moves (but ignoring any mouse position where the right would be to the left of the mouse's down left position or the bottom would be above the mouse's down bottom position).

Re: ScreenShot

Posted: Sunday 17th May 2020 10:11am
by cogier
As I wasn't able to find the Mode command (in the Gambas documentation), could you tell me what it (& its argument does)?
It is in the Gambas help as I spent some time updating the help on this topic. Have a look here, I wrote a small program to explain its workings which is also available on the Gambas Farm and here.

Forum tip
Don't use the code (</>) button to add code try the gb button.

Code: Select all

Paint.Rectangle(iStartX, iStartY, Mouse..ScreenX - iStartX, Mouse.ScreenY - iStartY)
Paint.Rectangle(iStartX, iStartY, Mouse..ScreenX - iStartX, Mouse.ScreenY - iStartY)
I looked at my code and there was only one dot, not sure what happened there :?
I last looked at this app 2+ years ago and never got it working. So it's giving me problems! It's quite difficult to work out how to move from the SelectArea form (equivalent of your Capture form) at the form's opening to displaying of the original desktop which has a video (equivalent of your photos display) as part of the available desktop: typically the app's user would have their internet browser open with its window maximised (i.e. covering the available desktop, which doesn't include the launch panel etc), the user would then see a popup requesting press mouse button down when the cursor is at the top left of the video's display, release mouse button when the cursor is at the bottom right of the video's display. So the user would click on the internet browser icon in the launch panel and then do the mouse down, mouse move & mouse up (with the app's code ensuring has the resultant rectangle has its outline redrawn as the mouse moves (but ignoring any mouse position where the right would be to the left of the mouse's down left position or the bottom would be above the mouse's down bottom position).
I created a new Form (Capture) with the Form's Opacity set to 35, Maximized with no Border. This allows the user to draw the rectangle on any part of the screen. When finished (MouseUp) the values are passed back to the FMain Form and the Capture window closed. Then Hide the FMain Form and take the Desktop.Snapshot. Does that help?

Re: ScreenShot

Posted: Sunday 17th May 2020 11:06am
by johnaaronrose
Thanks for informative replies.

I didn't notice that the Mode command (first line of Capture Sub) was actually a Public Sub written by you! I understood its use after I looked at the Mode Public Sub. I often don't realise that a command calls a Public Sub when the name of it superficially appears to be a Method. I tend to use Sub names with at least 2 words (e.g. ModeSet) to avoid this confusion. Similarly for Controls.

Thanks for tip about gb icon.

I didn't see an answer to these 2 questions:
I'm unclear about the meaning of Mouse_Drag. Could you clarify?
I looked at Mouse.X & Mouse.ScreenX and didn't understand the difference between the two: Relative is relative to what? Presumably Absolute is looking at the screen as a whole (i.e. including docks etc)
new Form (Capture) with the Form's Opacity set to 35, Maximized with no Border. This allows the user to draw the rectangle on any part of the screen. When finished (MouseUp) the values are passed back to the FMain Form and the Capture window closed. Then Hide the FMain Form and take the Desktop.Snapshot. ]
Could you attach the changed app's tar.gz as I didn't see it in your reply?

Re: ScreenShot

Posted: Sunday 17th May 2020 2:20pm
by cogier
I didn't notice that the Mode command (first line of Capture Sub) was actually a Public Sub written by you!
Sorry I was not trying to confuse anybody!
I'm unclear about the meaning of Mouse_Drag. Could you clarify?
Have a look at the attached example.
MouseDrag.tar.gz
(11.98 KiB) Downloaded 45 times
Could you attach the changed app's tar.gz as I didn't see it in your reply?
I only explained the code provided I have not changed it. Does it not work on your system?
I looked at Mouse.X & Mouse.ScreenX and didn't understand the difference between the two: Relative is relative to what? Presumably Absolute is looking at the screen as a whole (i.e. including docks etc)
I am looking into this.....

Re: ScreenShot

Posted: Sunday 17th May 2020 2:52pm
by cogier
I looked at Mouse.X & Mouse.ScreenX and didn't understand the difference between the two: Relative is relative to what? Presumably Absolute is looking at the screen as a whole (i.e. including docks etc)
Have a look at the attached program, hopefully that will help.
MousePosition-0.0.1.tar.gz
(12.04 KiB) Downloaded 83 times

Re: ScreenShot

Posted: Thursday 21st May 2020 11:29am
by johnaaronrose
Charlie,
Thanks for your useful MousePosition app. I still think that the help within Gambas3 when coding a class could be explained better. For example:
1. Screen object: Property X - it uses the term 'Virtual Desktop' without explanation of what means.
2. Drawing Area object: Property Left & X have the exact same description - are they really the same? Does one of them include a border? Same for Top & Y properties.

Notes on the code shown below:
The idea is take a screenshot of the available desktop (i.e. the whole of my monitor's screen excluding the top panel (containing the Systray etc, whcih is used by the FSelectArea form's title and the Launch side panel) and copy it into the DrawingAreaDesktop control. This would then allow the user to select an area on the available desktop before the form is hidden and control is returned back to the Fmain form.
The FSelectArea form contains the DesktopAreaDesktop (Drawing Area object) control

Code: Select all

  Private hPicture As Picture
  Public Sub Form_Open()               
  Print "SB"
  Inc Application.Busy
  hPicture = Desktop.Screenshot(Screen.AvailableX, Screen.AvailableY, Screen.AvailableWidth, Screen.AvailableHeight)
  Print "SB1"
  Print "Screen X=" & Screen.X & ", Screen Y = " & Screen.Y
  Print "Screen AvailableX = " & Screen.AvailableX & ", AvailableY = " & Screen.AvailableY
  Print "Screen Width = " & Screen.Width & ", Screen Height = " & Screen.Height
  Print "Screen AvailableWidth = " & Screen.AvailableWidth & ", Screen AvailableHeight = " & Screen.AvailableHeight
  Print "hPicture Width = " & hPicture.Width & ", hPicture Height = " & hPicture.Height
  Last.X = Screen.AvailableX
  Last.Y = Screen.AvailableY
  Last.Resize(Screen.AvailableWidth, Screen.AvailableHeight)
  Print "FSelectArea X = " & FSelectArea.X & ", FSelectArea Y = " & FSelectArea.Y
  Print "FSelectArea Left = " & FSelectArea.Left & ", FSelectArea Top = " & FSelectArea.Top
  Print "FSelectArea Width = " & FSelectArea.Width & ", FSelectArea Height = " & FSelectArea.Height
  DrawingAreaDesktop.Left = Screen.AvailableX
  DrawingAreaDesktop.Top = Screen.AvailableY
  DrawingAreaDesktop.Width = Screen.AvailableWidth
  DrawingAreaDesktop.Height = Screen.AvailableHeight
  Print "DrawingAreaDesktop X = " & DrawingAreaDesktop.X & ", DrawingAreaDesktop Y = " & DrawingAreaDesktop.Y
  Print "DrawingAreaDesktop Left = " & DrawingAreaDesktop.Left & ", DrawingAreaDesktop Top = " & DrawingAreaDesktop.Top
  Print "DrawingAreaDesktop Width = " & DrawingAreaDesktop.Width & ", DrawingAreaDesktop Height = " & DrawingAreaDesktop.Height
  Print "SB2"
  Paint.Begin(DrawingAreaDesktop)
  Print "SB3"
  Paint.DrawPicture(hPicture, DrawingAreaDesktop.Left, DrawingAreaDesktop.Top, DrawingAreaDesktop.Width, DrawingAreaDesktop.Height)
  Print "SB4"
  Paint.End
When I run the app (using Debug) I get a popup stating 'Cannot Paint outside of Draw event handler'. I'm baffled as the Console output (shown below) shows that the variable hPicture (used to paint the DrawingAreaDesktop control) & that control & the FSelectArea form all have the same size. This size is actually my monitor's screen size (1920 x 1080) excluding the top panel (containing Systray and the FSelectArea's title) & the side Launcher panel: this is the Available Desktop size, namely width = 1920-67 = 1853 & height = 1080-1053 = 27/ The FSelectArea form & the DrawingAreaDesktop control both have no border specified in their properties. Any ideas concerning the popup message's cause and how to stop it?

Console output:

Code: Select all

SB
SB1
Screen X=0, Screen Y = 0
Screen AvailableX = 67, AvailableY = 27
Screen Width = 1920, Screen Height = 1080
Screen AvailableWidth = 1853, Screen AvailableHeight = 1053
hPicture Width = 1853, hPicture Height = 1053
FSelectArea X = 67, FSelectArea Y = 27
FSelectArea Left = 67, FSelectArea Top = 27
FSelectArea Width = 1853, FSelectArea Height = 1053
DrawingAreaDesktop X = 67, DrawingAreaDesktop Y = 27
DrawingAreaDesktop Left = 67, DrawingAreaDesktop Top = 27
DrawingAreaDesktop Width = 1853, DrawingAreaDesktop Height = 1053
SB2
NB It doesn't show SB3 which is coded before the Paint.Draw command.

I've also attached the app's source just in case.

Re: ScreenShot

Posted: Thursday 21st May 2020 4:44pm
by cogier
Hi John,
still think that the help within Gambas3 when coding a class could be explained better
This is and has been an issue. When you understand something you can create an account and then edit the help pages yourself.
The idea is take a screenshot of the available desktop (i.e. the whole of my monitor's screen excluding the top panel (containing the Systray etc,...
You need to be careful here as I use the Cinnamon Desktop and my toolbar and System Tray is on the bottom of the screen.
When I run the app (using Debug) I get a popup stating 'Cannot Paint outside of Draw event handler'.
This is a nasty one and I don't pretend to fully understand it but if you change the DrawingArea Cached property to True I think you will find that it is OK.

I have messed about with your code. There is a lot of code that you could get rid of if you understood the way Gambas works with Forms.
For the Form that the user is going to 'draw' the rectangle, set the Form properties:-

Arrangement = Vertical
Border = False
Maximized = True
Opacity = 35

Put your DrawingArea on the Form and set the Expand property to True

With these settings the form and DrawingArea will expand to fill the whole screen (whatever the size). The opacity at 35 allows you to see the Desktop behind.
Have a look at the FMain form settings and layout in the attached then resize the form and you will see that you don't need to write any code to get these results.
I wrote a program to help people understand these concepts. The program is called 'ExpandingForms' and is on the Farm or is available here.
SelectArea-CO-0.0.16.tar.gz
(22.66 KiB) Downloaded 56 times

Re: ScreenShot

Posted: Friday 22nd May 2020 8:10am
by johnaaronrose
Charlie,
Thanks for your invaluable help. I'm not a professional developer: I left programming behind (except for Oracle database coding, and dabbling in Visual Basic when I was a Uni Lecturer, when I became a Business/Systems Analyst decades ago). SelectArea app now works fine. Now moving onto SelectWindow app which I suspect will have its own difficulties: is it possible to identify Windows in the desktop screenshot?
This is and has been an issue. When you understand something you can create an account and then edit the help pages yourself.
I don't know how to create an account: how do I do it? I'm also a little worried that I might get an explanation wrong! How did you find out about Opacity=35?
You need to be careful here as I use the Cinnamon Desktop and my toolbar and System Tray is on the bottom of the screen.
I had vaguely thought about that before. I use standard Ubuntu Xenial, with systray panel & launcher panel left in standard positions. Your methods obviously cope with any Ubuntu flavour & I guess even standard Debian etc. ( I might check that out on my Raspberry Pi 3 using Raspbian, which I use for controlling cameras using Motion (much better for me than ZoneMinder), File Server (for all computers on home network), VPN (when I get it working!)).
This is a nasty one and I don't pretend to fully understand it but if you change the DrawingArea Cached property to True I think you will find that it is OK.
I changed the DrawingArea Cached property to True on my app (before incorporating your ideas) and it was OK (i.e. the popup stating 'Cannot Paint outside of Draw event handler' didn't happen).
For the Form that the user is going to 'draw' the rectangle, set the Form properties:-

Arrangement = Vertical
Border = False
Maximized = True
Opacity = 35

Put your DrawingArea on the Form and set the Expand property to True

With these settings the form and DrawingArea will expand to fill the whole screen (whatever the size). The opacity at 35 allows you to see the Desktop behind.
Have a look at the FMain form settings and layout in the attached then resize the form and you will see that you don't need to write any code to get these results.
Why is the 'Arrangement = Vertical' property setting necessary? It's interesting that the Expand property set to True results in filling the (available) desktop rather than the whole screen (i.e. excluding the Systray panel & the Launcher panel): the help is ambiguous about this.

I have previously looked at the book Introduction to Gambas. But it's rather out of date and the examples are so so IMO. In fact I bought the book a few years ago but recycled it as I find found it of little use to me. Gambas really needs a reference manual i.e. incorporating all the online & internet help but with more detail.

Re: ScreenShot

Posted: Friday 22nd May 2020 3:03pm
by cogier
I'm not a professional developer:
Nor me!!
..is it possible to identify Windows in the desktop screenshot?
I have taken this from the Gambas Mailing List 20/05/20 by vuott: -
Public Sub Form_Open()

  Dim i As Integer
  Dim dw As DesktopWindow

' Gets the ID of all the "windows" open on the desktop:
  For Each i In Desktop.FindWindow(Null, Null, Null)

    With dw = New DesktopWindow(i)
' Shows the visible name and ID of the Window:
      Print .VisibleName, Hex(i)
    End With

  Next

End
Note I used the 'gb' button to get the formatted code above not the '</>' button.
How did you find out about Opacity=35?
Experimentation....
Why is the 'Arrangement = Vertical' property setting necessary?
I could have used Horizonal or Fill in this case. Vertical will force all the objects to the top of the form and lay the next item underneath and the next..
Try this:-
On a new Form set the Arrangement to vertical then add 10 Labels with borders and some text. Scatter them all over the Form then run the program. (No code required). Now resize the Form. Then change the Arrangement to Horizontal and run the program again. It takes sometime to understand it all but its very powerful. For a complex version have a look here.
Gambas really needs a reference manual
Have you seen this book here and here?