Why does such a simple animation consume high cpu? - javafx

This example simple, consume high cpu , is bug or design technology failure ?
Detail: let the program run and note that the CPU consumption is increasing...
Many programmers, like me, like javafx, and when that kind of approach pops up, the post staff should put setCache(true);
But apparently it is not solving.
I also think that Platform.runLater, when there are many it goes to the queue and ends up harming the use too much of the cpu.
Where does the problem come from, I would like colleagues in the area to check if the javafx of you is experiencing the same error !!?
Here in Ubuntu I opened the teminal and called the "top", and also opened the graphical display of cpu usage statistics, and there really is something wrong.
Ubuntu 14.04.1
Prism pipeline init order: es2 sw Using java-based Pisces
rasterizer Using dirty region optimizations Not using texture mask
for primitives Not forcing power of 2 sizes for textures Using
hardware CLAMP_TO_ZERO mode Opting in for HiDPI pixel scaling Prism
pipeline name = com.sun.prism.es2.ES2Pipeline Loading ES2 native
library ... prism_es2 succeeded. GLFactory using
com.sun.prism.es2.X11GLFactory (X) Got class = class
com.sun.prism.es2.ES2Pipeline Initialized prism pipeline:
com.sun.prism.es2.ES2Pipeline Maximum supported texture size: 16384
Maximum texture size clamped to 4096 Non power of two texture support
= true Maximum number of vertex attributes = 16 Maximum number of uniform vertex components = 16384 Maximum number of uniform fragment
components = 16384 Maximum number of varying components = 128 Maximum
number of texture units usable in a vertex shader = 16 Maximum number
of texture units usable in a fragment shader = 16 Graphics Vendor:
X.Org
Renderer: Gallium 0.4 on AMD ARUBA (DRM 2.43.0, LLVM 3.8.0)
Version: 3.0 Mesa 11.2.0 vsync: true vpipe: true new alphas ES2ResourceFactory: Prism - createStockShader:
Texture_LinearGradient_PAD.frag new alphas ES2ResourceFactory: Prism -
createStockShader: Solid_TextureRGB.frag
PPSRenderer: scenario.effect
- createShader: Blend_HARD_LIGHT PPSRenderer: scenario.effect - createShader: LinearConvolveShadow_24
java version "1.8.0_112" Java(TM) SE Runtime Environment (build
1.8.0_112-b15) Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.CacheHint;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.util.Duration;
public class AnimatedTeste extends Application {
#Override
public void start(Stage primaryStage) {
ImageView imv = new ImageView("http://icons.iconarchive.com/icons/icons-land/sport/16/Tennis-Ball-icon.png");
Label label = new Label("");
label.setGraphic(imv);
Timeline tl = new Timeline(new KeyFrame(
Duration.millis(500),
new KeyValue(label.layoutYProperty(), label.getLayoutY()+15 ),
new KeyValue(label.rotateProperty(), 360)
));
tl.setAutoReverse(true);
tl.setCycleCount(Timeline.INDEFINITE);
tl.play();
Group root = new Group();
root.getChildren().add(label);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Thanks

Related

How to import external library in QT Python?

I have an issue when importing external python library in QT app.
The program is crashing when I'm trying to import the canlib.
However, no import error is caught, only application communicate appear like this:
program finished with code -1
When I comment out the canlib import, program runs fine.
import os
from pathlib import Path
import sys
import random
from Connection import Connection
from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine
from PySide6.QtCore import QTimer
from canlib import kvadblib #here is an error source
if __name__ == "__main__":
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
# Connection QT <---> Python
connection = Connection()
engine.rootContext().setContextProperty("connection", connection)
# End
# Hardware Init
db = kvadblib.Dbc(filename='battery_monitoring_app.dbc')
ch = communication.open_virtual_channel(1)
# End
engine.load(os.fspath(Path(__file__).resolve().parent / "qml/main.qml"))
if not engine.rootObjects():
sys.exit(-1)
### DO WHILE TRUE STUFF
def doStuff():
connection.testSignalVariable.emit(random.uniform(0.00, 2.00))
### END
timer = QTimer()
timer.timeout.connect(doStuff)
timer.start(100)
sys.exit(app.exec_())

importing avro data using java api in sqoop

The problem is how to run java program for sqoop import ?
I am using sqoop version 1.4.7 and hadoop version 2.7.2 and I
am trying to run on net beans ide 8.1
here is the code:
package sqoop5;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
import com.cloudera.sqoop.SqoopOptions;
import com.cloudera.sqoop.tool.BaseSqoopTool;
import com.cloudera.sqoop.tool.ImportTool;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Sqoop5 {
public static void main(String[] args) throws Exception {
String driver = "org.postgresql.Driver";
Class.forName(driver).newInstance();
SqoopOptions options = new SqoopOptions();
options.setConnectString(("jdbc:postgresql://
127.0.0.1:5432/postgres"));
options.setTableName(("new"));
options.setUsername(("postgres"));
options.setPassword(("********"));
options.setNumMappers(1);
options.setTargetDir(("hdfs://
127.0.0.1:9000/usr/new11"));
options.setFileLayout(com.cloudera.sqoop.
SqoopOptions.FileLayout.AvroD ataFile);
new ImportTool().run((com.cloudera.sqoop.SqoopOptions)
options);
}
}
The error message is as follows:
cause:org.apache.hadoop.ipc.RemoteException: Server IPC
version 9
cannot communicate with client version 4
Aug 05, 2019 10:46:29 AM org.apache.sqoop.tool.ImportTool run
SEVERE: Encountered IOException running import job:
org.apache.hadoop.ipc.RemoteException: Server IPC version 9
cannot
communicate with client version 4
at org.apache.hadoop.ipc.Client.call(Client.java:1113)
at org.apache.hadoop.ipc.RPC$Invoker.invoke(RPC.java:229)
at com.sun.proxy.$Proxy6.getProtocolVersion(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
If you read this post, you will see that it's something similar to your problem.
Probably a version mismatch between the applications. Check the version of hadoop you are including vs the version of hadoop from your cluster.

How to close Pyqt5 program from QML?

I started a project in Qt Creator initially with a C++ backend, but then switched it to use PyQt5. I have a main.qml, where when I press a button called Exit, I call Qt.quit().
However, I get a General Message stating: Signal QQmlEngine::quit() emitted, but no receivers connected to handle it.
My question is, how do I receive this signal and handle it?
Code:
main.py:
import sys
import PyQt5
from PyQt5 import QtCore
from PyQt5 import QtGui
from PyQt5 import QtQml
from PyQt5.QtCore import QObject pyqtSignal
class DestinyManager,(QtGui.QGuiApplication):
"""the app self"""
def __init__(self, argv):
super(DestinyManager, self).__init__(argv)
# Define a new signal called 'trigger' that has no arguments.
trigger = pyqtSignal()
def connect_and_emit_trigger(self):
# Connect the trigger signal to a slot.
self.trigger.connect(self.handle_trigger)
self.menuItem_Exit.clicked.connect(self.close)
# Emit the signal.
self.trigger.emit()
def handle_trigger(self):
# Show that the slot has been called.
print("trigger signal received")
def main(argv):
app = DestinyManager(sys.argv)
engine = QtQml.QQmlEngine(app)
component = QtQml.QQmlComponent(engine)
component.loadUrl(QtCore.QUrl("exit.qml"))
topLevel = component.create()
if topLevel is not None:
topLevel.show()
else:
for err in component.errors():
print(err.toString())
app.exec()
if __name__ == '__main__':
QObject,main(sys.argv)
Exit.qml:
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
Window {
Button {
id: btn_Exit
text: "Exit"
onClicked: Qt.quit();
}
}
There are a few syntax errors in the python script, but ignoring those, the code can be made to work like this:
def main(argv):
app = DestinyManager(sys.argv)
engine = QtQml.QQmlEngine(app)
engine.quit.connect(app.quit)
...
Which is to say, you simply need to connect the qml quit signal to an appropriate slot in your python script.

Error : java.lang.NoClassDefFoundError: org/openqa/selenium/HasInputDevices , when running tests using ghostdriver

I am trying to run my webdriver test cases using ghostdriver (Phantomjs) but that's giving error java.lang.NoClassDefFoundError: org/openqa/selenium/HasInputDevices. Everything seems fine to me but I dont understand why there is error.
OS - WIN7
Coding - JAVA 1.7
Framework : java1.7+testng6.5.2+maven3
Selenium-java version 2.35.0
testcase
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
public class ghosttest {
WebDriver driver;
#Test
public void testing() {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
"D:/dumps/phantomjs-1.9.1-windows/phantomjs-1.9.1-windows/phantomjs.exe");
driver = new PhantomJSDriver(caps);
driver.get("http://www.google.com");
String Logintext = driver.findElement(By.linkText("Maps")).getText();
System.out.println(Logintext);
}
}
maven dependency for ghostdriver
<dependency>
<groupId>com.github.detro.ghostdriver</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.0.3</version>
</dependency>
Your problem is that ghostdriver is not compatible with Selenium 2.35.
If you change your dependency to 2.34 you will be fine. You will have to wait for a new PhantomJSDriver unfortunately if you specifically need Selenium 2.35.
Currently the latest version of phantomjsdriver is 1.0.4 as well, you had 1.0.3.

Single QTreeWidgetItem instance on multiple QTreeWidget?

I'm trying to show a single QTreeWidgetItem instance on 2 QTreeWidgets, which ends up the item shown only on the 1st tree without being notified. I haven't seen its API doc talks about a limitation if any. Is there a way to workaround?
#!/usr/bin/python
import os
import sys
from PySide.QtCore import QFile
from PySide.QtUiTools import QUiLoader
from PySide.QtGui import QApplication, QTreeWidget, QTreeWidgetItem, QWidget
class MyTreeWidgetItem(QTreeWidgetItem):
def __init__(self, *args):
super(MyTreeWidgetItem, self).__init__()
class MyWidget(QWidget):
def __init__(self, *args):
super(MyWidget, self).__init__()
loader = QUiLoader()
file = QFile('./src/prove_qtreewidget/qtree_mainwidget.ui')
file.open(QFile.ReadOnly)
self.widget_ui = loader.load(file, self)
file.close()
item1 = MyTreeWidgetItem(self)
item1.setText(0, 'Item 1')
_tw1 = self.widget_ui.findChild(QTreeWidget, '_tree_widget_1')
_tw2 = self.widget_ui.findChild(QTreeWidget, '_tree_widget_2')
_tw1.addTopLevelItem(item1)
_tw2.addTopLevelItem(item1)
if __name__ == '__main__':
print("Running in " + os.getcwd() + " .\n")
app = QApplication(sys.argv)
win = MyWidget()
win.show()
app.exec_()
.ui file above is available here.
Using Qt 4.8, Ubuntu 12.04
I haven't tried PyQt binding but I just assume shouldn't be any different w/o proof.
What you need is a model and a QTreeView, that's for what they are for:
Model/View Programming: Widgets do not maintain internal data containers. They access external data through a standardized interface and therefore avoid data duplication.

Resources