JavaFX app become unusable after print dialog - javafx

I'm displaying a ControlsFX PopOver for invoice, naturally its content must be printable. I have successfully print it using this code:
val printer = Printer.getDefaultPrinter()
val layout = printer.createPageLayout(PAPER_INVOICE, PORTRAIT, 0.0, 0.0, 0.0, 0.0)
printer.printerAttributes
val job = PrinterJob.createPrinterJob()
invoiceBox.run {
border = null
transforms += Scale(
layout.printableWidth / invoiceBox.boundsInParent.width,
layout.printableHeight / invoiceBox.boundsInParent.height
)
}
if (job != null && job.showPrintDialog(invoiceBox.scene.window)) {
val success = job.printPage(layout, invoiceBox)
if (success) {
job.endJob()
}
}
However, the whole application becomes unusable after the printing process (even after canceling the print dialog). The main window is still there, it just can't be focused while clicking on it (or the app in the Windows taskbar) just produces error sound. Is this a known bug?
I have only tested this on Windows since I don't believe the printer I'm working with (Epson LX-310) are compatible with Mac/Linux.

Related

ImageCapture cameraX orientation detect when is locked

I want to capture an Image and a Video using the CameraX library. By following the documentation i have no problem implementing the preview and the capture use cases. The code i use is the following.
private fun startCamera() {
cameraProviderFuture = ProcessCameraProvider.getInstance(this)
cameraProviderFuture.addListener({ setUpCamera() }, cameraExecutor)
}
private fun setUpCamera() {
cameraProvider = cameraProviderFuture.get()
bindPreview()
}
private fun bindPreview() {
preview = Preview.Builder().build().also {
it.setSurfaceProvider(binding.cameraPreview.surfaceProvider)
}
imageCapture = ImageCapture.Builder()
.setFlashMode(flashMode)
.setCaptureMode(CAPTURE_MODE_MAXIMIZE_QUALITY)
.build()
videoCapture = ...
bindCamera()
}
private fun bindCamera() {
cameraSelector = selectExternalOrBestCamera()
cameraProvider.unbindAll()
camera = cameraProvider.bindToLifecycle(this, cameraSelector, preview, imageCapture, videoCapture)
Now, let's say that i have locked my device orientation from the menu panel. So if i rotate de device, the applications do not rotate at all. In that case, if a capture an Image, the captured image which i save and i want to send to a Server is rotated by 90 degrees,, which is reasonable since i rotated the device and capture a photo.
As i can see, in other applications (like Whatsapp) the same senario does not happen since they show the preview image correctly rotated after the capture. How can i solve that issue?
So finally i found the solution.
val rotation = display?.rotation ?: Surface.ROTATION_0
val isLandscape = rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270
imageCapture = ImageCapture.Builder()
.setFlashMode(flashMode)
.setCaptureMode(CAPTURE_MODE_MAXIMIZE_QUALITY)
.setTargetRotation(rotation)
.setTargetResolution(
if (isLandscape)
Size(1920, 1080)
else
Size(1080, 1920)
)
.build()
That gives me the preview image that i capture in the desired orientation

how to keep shadow in borderless window

I'm trying to drop a shadow on a borderless window using Qt in windows.
I succeeded in dropping the shadow when launching the application, referring to the following article.
Borderless Window Using Areo Snap, Shadow, Minimize Animation, and Shake
Borderless Window with Drop Shadow
But I encountered the problem that the shadow will disappear if the application is deactivated and reactivated (
In other words, click the other applications, and click my application again.)
Perhaps my implementation is not good enough.
I'm glad if you have some ideas for this issue.
I'm trying to imprement Qt with Go bindings
Here is the code snippet:
package qframelesswindow
import (
"unsafe"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/widgets"
win "github.com/akiyosi/w32"
)
func (f *QFramelessWindow) SetNativeEvent(app *widgets.QApplication) {
filterObj := core.NewQAbstractNativeEventFilter()
filterObj.ConnectNativeEventFilter(func(eventType *core.QByteArray, message unsafe.Pointer, result int) bool {
msg := (*win.MSG)(message)
lparam := msg.LParam
hwnd := msg.Hwnd
var uflag uint
uflag = win.SWP_NOZORDER | win.SWP_NOOWNERZORDER | win.SWP_NOMOVE | win.SWP_NOSIZE | win.SWP_FRAMECHANGED
var nullptr win.HWND
shadow := &win.MARGINS{0, 0, 0, 1}
switch msg.Message {
case win.WM_CREATE:
style := win.WS_POPUP | win.WS_THICKFRAME | win.WS_MINIMIZEBOX | win.WS_MAXIMIZEBOX | win.WS_CAPTION
win.SetWindowLong(hwnd, win.GWL_STYLE, uint32(style))
win.DwmExtendFrameIntoClientArea(hwnd, shadow)
win.SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, uflag)
return true
case win.WM_NCCALCSIZE:
if msg.WParam == 1 {
// this kills the window frame and title bar we added with WS_THICKFRAME and WS_CAPTION
result = 0
return true
}
return false
case win.WM_GETMINMAXINFO:
mm := (*win.MINMAXINFO)((unsafe.Pointer)(lparam))
mm.PtMinTrackSize.X = int32(f.minimumWidth)
mm.PtMinTrackSize.Y = int32(f.minimumHeight)
return true
default:
}
return false
})
app.InstallNativeEventFilter(filterObj)
}
All source code is in my repository;
akiyosi/goqtframelesswindow
WM_NCCALCSIZE:
If wParam is TRUE, the application should return zero or a combination
of the following values.(In document)
And also:
When wParam is TRUE, simply returning 0 without processing the
NCCALCSIZE_PARAMS rectangles will cause the client area to resize to
the size of the window, including the window frame. This will remove
the window frame and caption items from your window, leaving only the
client area displayed.
Starting with Windows Vista, simply returning 0 does not affect extended frames, only the standard frame will be removed.
EDIT:
Set the return value with the DWL_MSGRESULT instead of result = 0.

Robot Framework: Timed out waiting for page load

We have run our Robot Framework environment nearly one year without any problems, but now we get the error message:
TimeoutException: Message: Timed out waiting for page load.
Stacktrace:
at Utils.initWebLoadingListener/< (file:///tmp/tmp77bOby/webdriver-py-profilecopy/extensions/fxdriver#googlecode.com/components/driver-component.js:9089)
at WebLoadingListener/e (file:///tmp/tmp77bOby/webdriver-py-profilecopy/extensions/fxdriver#googlecode.com/components/driver-component.js:5145)
at WebLoadingListener/< (file:///tmp/tmp77bOby/webdriver-py-profilecopy/extensions/fxdriver#googlecode.com/components/driver-component.js:5153)
at fxdriver.Timer.prototype.setTimeout/<.notify (file:///tmp/tmp77bOby/webdriver-py-profilecopy/extensions/fxdriver#googlecode.com/components/driver-component.js:625)
What could be problem? I checked the disk space and there are disk space left.
A timeout error can have a laundry list of possible issues. Loading a page after a year of smooth operation narrows it down a little, but there are still many possibilities. Connection speeds sometimes change, sometimes the page you're loading up has added features that cause it to take longer to load or was just written poorly so it loads slowly... you get the idea. Without the code of the page or your code to look at, I can only suggest two fixes.
First, in the code of Selenium2Library, there is a timeout variable somewhere that can be set with Set Selenium Timeout. The default is 5 seconds, but if your page is taking longer to load, then increasing it might solve your problem. This assumes that your page loads at a reasonable rate in manual testing and that opening it is the least of your concerns.
Second, it's possible that you're testing an AngularJS application, not a normal website. If that's true, then you're going to want to use ExtendedSelenium2Library, not Selenium2Library. ExtendedSelenium2Library is better-equipped to deal with AngularJS applications and includes code to wait for Angular applications to load.
The old webdriver.xpi is buggy about page load handling. Timers are not correctly canceled, resulting in random windows switches and memory leaks. I copy here some replacement code that may be useful to anybody.
var WebLoadingListener = function(a, b, c, d) {
if ("none" == Utils.getPageLoadStrategy()) {
b(!1, !0);
} else {
this.logger = fxdriver.logging.getLogger("fxdriver.WebLoadingListener");
this.loadingListenerTimer = new fxdriver.Timer;
this.browser = a;
var self = this;
var e = function(a, c) {
self.destroy ();
b(a, c);
};
this.handler = buildHandler(a, e, d);
a.addProgressListener(this.handler);
-1 == c && (c = 18E5);
this.loadingListenerTimer.setTimeout(function() {
e(!0);
}, c);
WebLoadingListener.listeners [this.handler] = this;
goog.log.warning(this.logger, "WebLoadingListener created [" + Object.keys (WebLoadingListener.listeners).length + "] " + d.document.location);
}
};
WebLoadingListener.listeners = {};
WebLoadingListener.removeListener = function(a, b) {
if (b.constructor !== WebLoadingListener) {
b = WebLoadingListener.listeners [b];
}
b.destroy ();
};
WebLoadingListener.prototype.destroy = function() {
if (this.browser) {
this.loadingListenerTimer.cancel();
this.browser.removeProgressListener && this.handler && this.browser.removeProgressListener(this.handler);
delete WebLoadingListener.listeners [this.handler]
this.loadingListenerTimer = undefined;
this.browser = undefined;
goog.log.warning(this.logger, "WebLoadingListener destroyed [" + Object.keys (WebLoadingListener.listeners).length + "]");
}
};
enter code here

Awesome WM - Application's fullscreen mode without taking whole screen

i'm looking for a way to let applications using their own fullscreen mode but without resizing their own windows.
For example, i want to watch a video on a web browser in fullscreen mode to hide all other bars/content of the browser/website except the video but i want to keep my display layout to see other apps at the same time.
Any ideas?
Thanks !
I did not test the following, but it might work. The idea of the rule is that it is used to detect which windows should not be fullscreend. It is a normal awful.rules-rule. All clients which do not match the rule are handled normally by awful.ewmh.geometry.
local rule = { class = "Firefox" }
client.disconnect_signal("request::geometry", awful.ewmh.geometry)
client.connect_signal("request::geometry", function(c, context, ...)
if context ~= "fullscreen" or not awful.rules.match(c, rule) then
awful.ewmh.geometry(c, context, ...)
end
end)
Edit: To toggle this behaviour I suggest the following:
local no_fullscreen = true
local rule = { class = "Firefox" }
client.disconnect_signal("request::geometry", awful.ewmh.geometry)
client.connect_signal("request::geometry", function(c, context, ...)
if not no_fullscreen or context ~= "fullscreen" or not awful.rules.match(c, rule) then
awful.ewmh.geometry(c, context, ...)
end
end)
Then add a key binding with callback function function() no_fullscreen = not no_fullscreen end.

how to set margin for PrintLayout in javafx?

i have a javaFx application and am working on the Printer module , in the software am done with other things, like installed printer list , taking print from the specific printer but getting issue in the layout , now am having 80mm printer and when i get print from this printer then there are lots of margin in left side and right side, please help me to get correct print.
am using following code for print:-
PageLayout pageLayout = prnterForJob.createPageLayout(Paper.MONARCH_ENVELOPE,
PageOrientation.PORTRAIT, 0, 0, 0, 0);
PrinterJob job = PrinterJob.createPrinterJob(prnterForJob);
job.getJobSettings().setCopies(nmbrOfCopies1);
if (job != null) {
//boolean success = job.printPage(node);
weOrderPrint.print(job);
job.endJob();
}
Aren't you just forgetting to set the page layout you created?
job.getJobSettings().setPageLayout(pageLayout);

Resources