Python QTextBrowser - scrolling issue - pythonqt

I'm using a read-only QTextBrowser that is used to show me diagnostic message. Even though I have attempted to move the cursor to the end as well as automatically scroll to the end I keep having really annoying issues with the text outout.
I really don't want to the bottom cut off, but I don't know what else to do with it.
The code I am using to write to the box is this:
text_cursor = main_app.all_messages.textCursor()
text_cursor.movePosition(QtGui.QTextCursor.End)
main_app.all_messages.setTextCursor(text_cursor)
main_app.all_messages.insertPlainText(message + "\n")
main_app.all_messages.reload()
# always scroll to the end
scrollBar = main_app.all_messages.verticalScrollBar()
scrollBar.setValue(scrollBar.maximum())
Anything else I can try to keep this from happening?

Related

Automatic Scroll SAP GUI

I'm trying to scroll until the end of the page and I recorded a script and did some changes. I thought of something like that
For i = 1 To END_PAGE
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").setCurrentCell i, "AUFNR"
Next
Where "AUFNR" is the name of the column I'm analyzing. But how do I know the END_PAGE if the code stops working when it checks a line it doesn't exist?
Here is a screenshot of the table I'm analyzing in SAP GUI
For example I could verify if EACH element has a text but unfortunely I don't know how to do that. Any ideas?

VB.NET MENUSTRIP doesnt honor ImageScaling at runtime

I am trying to implement a 'Flag' w/ a menustrip.
I have an image list w/ a red flag and a black flag.
When I click the menu item, i want to toggle the image.
The problem I have is that once I change the image, it wants to do SizeToFit which makes the Icon roughly the height of text. I dont want that. I want the Image to be its actual size.
I have tried putting the statements in different orders, nothing i have tried seems to work.
Currently, I have the button set to the black flag at design time.
This code shows me trying to change to a Red flag.
tsbFlagPatient.Image = ilFlags.Images(1)
tsbFlagPatient.ImageScaling = ToolStripItemImageScaling.None
tsbFlagPatient.DisplayStyle = ToolStripItemDisplayStyle.Image
[If there is some better way to approach toggling the image, im open to that. That seems like a separate question. ]
I was unable to make ImageScrolling work.
Since I dont need text here, I used BackGround Image and set
BackgroundImageLayout = Stretch
This allows the images to be the right size.
You can turn AutoSize = false and then manually set Height, Width to fine tune your menu's size.
I did reconsider the ImageList and changed the images to being stored in the project Resources. This is the code to toggle the image
Public Sub SetFlagImage(flagSet As Boolean)
If flagSet = False Then
btnFlag.BackgroundImage = My.Resources.appbar_flag_wavy_black
btnFlag.BackgroundImage.Tag = "black"
Else
btnFlag.BackgroundImage = My.Resources.appbar_flag_wavy_red
btnFlag.BackgroundImage.Tag = "red"
End If
End Sub
This had no effect on the question posed here. In general, probably better than having an image list because all forms can access it.

MS Access 2007 Continuous Form Alternate Back Colour Screen Corruption

There should be a simple solution to this but I can't find one:
I have a continuous form with all of the controls Enabled and Locked with transparent background and frames. the Form:Detail section has an Alternate Back Colour set.
The form displays transactions for a bank account selected via a combo box in the form header. When the bank account is changed the new account's transactions are displayed.
However, if the first on-screen row displayed for the new account isn't the same colour as that for the previous account then all of the controls retain the background colour of the previously displayed row. The same screen corruption occurs on Requery or if control goes to a particular row.
Hopefully the picture below will clarify:
Example of Alternate Back Colour problem
I've tried all sorts of things but nothing seems to solve this. The last resort is removing the alternate back colour but I really don't want to do that. Any help in resolving this would be greatly appreciated.
Despite having tried to put this out of my mind and get on with functional stuff, it has been niggling away constantly. After a great deal of searching and generally getting distracted, I've found a really simple solution ( at https://access-programmers.co.uk/forums/showthread.php?t=268390):
When I change accounts or go to a record, it is simply a matter of bracketing the record operation in an 'Echo False', 'Echo True' pair. So, for example:
If RecordsetClone.RecordCount > 0 Then
Me.RecordsetClone.MoveLast
If Me.RecordsetClone.RecordCount > wRowNum Then
wRecordNo = Me.RecordsetClone.RecordCount - wRowNum
Else
wRecordNo = Me.RecordsetClone.RecordCount
End If
Echo False
DoCmd.GoToRecord , , acGoTo, wRecordNo
Echo True
End If
or:
Set rs = Me.Recordset.Clone
rs.FindFirst "WkACT_ID = " & Nz(wCurrentRecord, 0)
If Not rs.EOF Then
Echo False
Me.Bookmark = rs.Bookmark
Echo True
End If
Hoorah! Hopefully that will be helpful to somebody stuck with the same cosmetic, though infuriating, problem.

Wait for 1 second before starting code again - VB.NET

I desperately need help with a game I am making. For a bit of context, i am making a memory game and i have the following piece of code that is being troublesome. I have a bunch of labels on the form, 16 to be exact, with 1 randomly generated symbol placed in each. Each symbol appears in the labels twice.
------------------------------Continued----------------------------------------
'MsgBox("hello") 'used to check if the second inccorect press shows up - it does show but instantly changes colour
'''''''''''''''''NEED SOME CODE THAT PAUSES IT HERE'''''''''''''''
labels(0).ForeColor = Color.DarkRed
sender.ForeColor = Color.DarkRed
End If
flips = 1
End If
End If
tmrmemory.Enabled = True ' starts the timer after the user clicks the first label
End Sub
What's supposed to happen is that when the labels clicked don't match, it should show both the clicked labels for a short period before changing them both back to "DarkRed" which is the colour of the form's background.
I have tried using a timer but then i can't use sender.forecolor=color.darkred because it is not declared globally.
I have also tried using the command Threading.Thread.Sleep(500) but it still doesn't show the second incorrect click. I know that the code i have used works because when i use the message box, i can see both symbols and when the two clicks are correct, it stays.
Threading.Thread.Sleep(500) will actually pause your code for half a second. However during this time it won't do anything, not even refresh your controls. To get the effect you want, you need to call the YourControl.Refresh method before calling Threading.Thread.Sleep to force the control to redraw immediately.
On a side note, I would advise you not to call Threading.Thread.Sleep on UI thread. It will give a feeling of program hang. Instead do your work on a separate thread. You can either do all the work yourself right from creating a separate thread to destroying it, or use the BackgroundWorker control which has all the functionality built in.
Here is the link to an article I wrote a long time ago regarding BackgroundWorker that might be useful for you:
http://www.vbforums.com/showthread.php?680130-Correct-way-to-use-the-BackgroundWorker
Declare a variable outside the sub that stores what label should be flipped when the timer ends.
Label click sets
storedLabel = sender
Timer tick sets storedLabel.ForeColor = Color.DarkRed

Showing the updates being performed by macro

So I have seen all the ways to hide the screen updating in excel, what I'm looking for is a data problem, so I WANT to see the screen update. Is there a way to code the screen to update during the macro slowly? I tried the following:
'//////adding screen updating to watch what's happening
Application.ScreenUpdating = True
Application.Wait Now + TimeValue("00:00:01")
'/////
and all I got was screen flicker.
Thanks for being excellent unto me.
What you're after is a better method of debugging your errors. ScreenUpdating property of the Application is not what you want :)
Instead, set a breakpoint in your code using F9, at or before where you suspect the error is happening. If necessary, you can put this on your first line of code (if you literally have no idea where the error happens).
Here is a breakpoint, it's the red/maroon highlighted line:
Then, using the F8 key, you can step through the code line by line.
You can add as many breakpoints as you want. Pressing F5 will execute the code only up to the next breakpoint, then you would have to F8 or F5 to resume execution.
Some additional things to help you debug
Use the Locals window.
This shows you the vairables in scope, and you can click on them to view their properties/etc. As you can see, I have a shitload of variables in a fairly complicated application. I've found the immeidates window is very helpful for Object variables and arrays. Here is what it looks like when I expand an array variable, so that I can see all its contents:
Use the Immediate window to query variables or execute statements outside of your code, this is equivalent to Debug.Print statements. For example, let's check to see if the value of some variable is "9", you can:
?someVar = 9 and then press enter. It will show you True or False. You could query the value directly by ?someVar and it would print the value.
In this screenshot, I am checking the value of a boolean, and it shows me that the value is False. I could also verify this in the Locals window.
The screen updating must be set only once, at the start of the code.
But the Wait you will need to put inside your loop, or spread between your code lines.