GtkScrolledWindow + WebkitWebView Scrolling - c

Hey I am trying to make a GTK IRC client that uses webkit to display its messages.
The webview is within a ScrolledWindow, and I want the scrolledwindow to scroll to the bottom everytime it gets too big.
I've tried changing the vadjustment value of the scrolledwindow when a message is added but this doesn't seem to work at all. It keeps reseting it to 0 for some reason.
Does anyone know how I might solve this?
Cheers!

I had this same problem. I believe the issue is caused because the adjustment-changed and adjustment-value-changed signals not always sent after the window has completely finished redrawing. This causes the adjustment value to be zero because the page has no content at that point. The solution is to connect to the size-allocate signal instead. This is only called when the window has completely finished resizing, and has the extra advantage of not being called when the user scrolls the window manually.
Here is a sample using python bindings:
def autoscroll_view(view, allocation):
#parent is the gtk.ScrolledWindow that needs updating
parent = view.get_parent()
adj = parent.get_vadjustment()
adj.value = adj.upper - adj.page_size
parent.set_vadjustment(adj)
view = webkit.WebView()
window = gtk.ScrolledWindow()
window.add(view)
view.connect('size-allocate', autoscroll_view)

Related

Move specific application to a specific screen

I have read over here how to move an application to a specific screen.
In my case I have a variation of this. In this case I want to open for example Todoist on a specific screen. This code below opens Todoist but on my wrong screen.
How can I solve this?
local screens = hs.screen.allScreens()
hs.application.open("Todoist")
local win = hs.application:findWindow("Todoist")
win.moveToScreen(screens[1])
findWindow() is an instance method, so it cannot be called directly as hs.application:findWindow(). To properly call this method, you must create an instance of the hs.application class and then call findWindow() on that instance.
The following snippet should work, although you may need to adjust the wait time (and the screens index). It is generally recommended to use hs.application.watcher to watch for when an app has been launched, rather than using a timer.
local notes = hs.application.open("Notes")
hs.timer.doAfter(1, function()
-- `notes:mainWindow()` will return `nil` if called immediately after opening the app,
-- so we wait for a second to allow the window to be launched.
local notesMainWindow = notes:mainWindow()
local screens = hs.screen.allScreens()
notesMainWindow:moveToScreen(screens[1])
end)

CodedUI WPF Test: Cannot perform 'Click' on the hidden control

I've set-up a relatively basic Coded UI test for a WPF application. The test opens an application, presses a few buttons and then closes it. Here's the test code:
[TestMethod]
public void CodedUITestMethod1()
{
ApplicationUnderTest.Launch(#"c:\myapp\bin\Debug\myapp.exe");
this.UIMap.LoginAndClickDoAction1();
for (int i = 1; i <= 10; i++)
{
this.UIMap.DoAction1();
}
this.UIMap.ExitMyApp();
}
The application launches fine, logs in and clicks the buttons the first time. It subsequently throws the exception:
Cannot perform 'Click' on the hidden control
When it throws this seems to vary, but the button that it gives is never hidden. After seeing this question, I tried inserting:
uIMyButton1.Find();
uIMyButton2.Find();
Into the UIMap at the top of the test, but it made no difference.
What could be causing this error and how would I go about debugging it?
Quick disclaimer: this question relates to VS2015, so I suppose it could be a legitimate MS bug.
Details of uIMyButton1 and uIMyButton2 are not shown in the question. They may be used in code of this style (once intervening declarations are combined):
UIControl aControl = this.UIMap.uione.uitwo.uithree.uIMyButton1.Click();
Any of the parent properties of the buttons may be for the item that has been redisplayed. So I think the question linked in this question shows the answer, just that the Find() should be applied at a higher level.
You would try calling:
uithree.Find();
if that is not successful then call
uitwo.Find();
and so on.
For performance reasons Find is called as deep into the hierarchy as possible.

Selenium: why is sleep apparently needed before clicking?

Selenium 2.25, Firefox, OSX ML.
I have Selenium click a button that has an Ajax impact.
Then I want to interact with the results. Without the sleep below, I get an error that the click fails because it cannot scroll the click target into view. I don't get it. What's going on?
WebElement sampleComboInput = driver.findElement(By.id("sampleCombo-inputEl"));
sampleComboInput.click();
sampleComboInput.sendKeys("English-03.txt");
sampleComboInput.sendKeys(Keys.TAB, Keys.TAB);
WebElement goButton = driver.findElement(By.id("inputDialogGoButton-btnInnerEl"));
goButton.click();
WebElement resultsSpan = driver.findElement(By.cssSelector("span.ne-type-node.PERSON"));
assertTrue(resultsSpan.isDisplayed());
assertEquals("PERSON (3)", resultsSpan.getText());
WebElement parent = resultsSpan.findElement(By.xpath(".."));
Thread.sleep(5000); // without sleep, get error unable to scroll
Actions action = new Actions(driver);
action.doubleClick(parent);
action.perform();
it needs to wait for the element to load, have you tried waitForVisible instead? It might be more efficent also using Sleep may cause your code to not function on other machines where the wait time can be longer
You should try to avoid using Thread.Sleep as it will work inconsistently. Space ranger is right that it needs to wait for the element to load.
The c# version has the "WebDriverWait" class and the "Until" method. Using these two you can wait for elements to load.
Look at the answer by Loudenvier to this post:
Selenium c# Webdriver: Wait Until Element is Present
This is the way I prefer. Simple to use, easily reusable, and avoids issues related to Thread.Sleep.

What WPF threading approach should I go with?

I'm writing a WPF application (new technique, mostly I've been writing in WinForms). My goal is to make UI responsive whole time, and I've read that it can be achived using Threading/BackgroundWorker. I think that I should use background worker to put there time consuming methods. But I plan to use method *m_AddLog(string logText)* which should append text to textbox. This method I want to call from main UI thread aswell as from background worker, so messages would be sent immediatelly while processing in backround instead of waiting for background task to end. Could you please kindly advise how to write properly write these methods for UI being fully responsive as I don't know much about delegates, invoking, background workers, etc?
If you want to run some background process then update the UI on completion the following pattern works well (if ran from the UI thread).
Task.Factory.StartNew(() =>
{
// Background work
}).ContinueWith((t) => {
// Update UI thread
}, TaskScheduler.FromCurrentSynchronizationContext());
Put the background work in the first task and the UI work in the following his is task. The TaskScheduler option ensures the second task runs on the UI thread.
Most of the items in wpf application using task and dispatcher will give better results.
have a Look at the following code hope this may helps you..
In the below code i have considered a scenario like fetching images from remote server and i created a task for doing that... in the task in side for loop i am using dispatched thread to update UI to notify the progress... and after fetching all the images execution will be moved to continue block....
You can have a look at the following link that may helps you to understand it better
ObservableCollection items= new ObservableCollection();
TaskFactory tFactory = new TaskFactory();
tFactory.StartNew(() =>
{
for (int i = 0; i < 50; i++)
{
//Request to server
System.Windows.Application.Current.Dispatcher.BeginInvoke((Action)delegate()
{
// UPDATE PROGRESS BAR IN UI
});
items.Add(("");
}
}).ContinueWith(t =>
{
if (t.IsFaulted)
{
// EXCEPTION IF THREAD IS FAULT
throw t.Exception;
}
System.Windows.Application.Current.Dispatcher.BeginInvoke((Action)delegate()
{
//PROCESS DATA AND DISPLAY
});
});
As People Said there are tons of question that will show you how to do that But if you want to compare it you can find it here with detailed comparison

"The calling thread must be STA, because many UI components require this." Error in WPF?

I am creating a xps document as below.
Assembly assembly = Assembly.GetExecutingAssembly();
//read embedded xpsDocument file
Stream helpStream = assembly.GetManifestResourceStream(resourceNameOfContext);
if (helpStream != null)
{
Package package = Package.Open(helpStream);
string inMemoryPackageName = "memorystream://" + topicName + ".xps";
Uri packageUri = new Uri(inMemoryPackageName);
//Add package to PackageStore
PackageStore.AddPackage(packageUri, package);
docXps = new XpsDocument(package, CompressionOption.Maximum, inMemoryPackageName);
}
return docXps;
When i am trying to get docXps.GetFixedDocumentSequence();
I am getting the above error. Can anyone help?
Thanks,
Your problem has nothing to do with the code surrounding the creation or use of the XPS document. It has everything to do with what thread you are running under.
You will receive the The calling thread must be STA, because many UI components require this error whenever any of the following are attempted on a MTA thread:
You construct any object derived from FrameworkElement (including Controls and Panels)
You construct any object derived from BitmapEffect
You construct any object derived from TextComposition
You construct any object derived from HwndSource
You access the current InputManager
You access the primary KeyboardDevice, StylusDevice, or TabletDevice
You attempt to change the focus on a FrameworkContentElement
You provide mouse, keyboard or IME input to any control that accepts text input
You make WPF content visible or update its layout
You manipulate the visual tree in such a way as to cause a re-evaluation for rendering
Several other changes, mostly having to do with display and input
For example, I received this error last year when I tried to deserialize some XAML that contained <Button> and other WPF objects from within a WCF service. The problem was simple to solve: I just switch to a STA thread to do the processing.
Obviously most work with XPS documents will trigger one or more of the above conditions. In your case I suspect that GetFixedDocumentSequence ends up using TextComposition or one of its subclasses.
No doubt the my solution of switching to a STA thread will also work for you, but first you need to figure out how your code that works with XpsDocuments is getting executed run from a MTA thread. Normally any code from from the GUI (eg a button press) is automatically run in a STA thread.
Is it possible that your code that manipulates XPS Documents may be being executed without a GUI? From a user-created thread? From a WCF service or a web service? From an ASPX page? Track that down and you'll probably find your solution.
If that doesn't work, let us know the details of the path through which GetFixedDocumentSequence is called, so we can diagnose it. The directly surrounding code isn't nearly as important as the call stack and how it is originally being invoked. If it is hard to explain you probably should add a call stack to prevent misunderstandings and help us diagnose the problem further, or tell you how to start a STA thread in your particular situation.
Is your code trying to access the xps doc from a background thread? If this is the case, you'll want to use the dispatcher. Info on that here.
If this doesn't help, could you post the code where you're actually calling GetFixedDocumentSequence()?

Resources