I have been using Gtk Entry till now which offers set_placeholder_text method to set a placeholder text in it however, looking in the documentation , I found no such method for TextView .
Is there any way I can set placeholder text in Gtk Textview ?
I think there was a question almost similar to this one. The idea is to, eg, use the focus-in-event and focus-out-event to check the text buffer content.
Example:
Set placeholder text as a variable
Set the placeholder text as the default treeview text buffer
content
On focus in, if the text buffer equals the placeholder, means no
previous input, so delete the text (placeholder text). Otherwise
keep the content.
On focus out, if the text buffer has no text then set the content
as the placeholder text. Otherwise do nothing.
The idea is that if no text or the existing text is the placeholder text it means there's no user input.
Python example
Glade ui file (save it as placeholder-textview.ui):
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkTextBuffer" id="textbuffer1">
<property name="text" translatable="yes">Please input text here...</property>
</object>
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">button</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="placeholder_text" translatable="yes">This is an entry and below is a textview</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTextView" id="textview1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="vexpand">False</property>
<property name="buffer">textbuffer1</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
Python code:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
def onFocusIn(self, event):
if (textbuf.get_text(textbuf.get_start_iter(), textbuf.get_end_iter(), True) == placeholderStr):
textbuf.set_text("")
return False
def onFocusOut(self, event):
if (textbuf.get_text(textbuf.get_start_iter(), textbuf.get_end_iter(), True) == ""):
textbuf.set_text(placeholderStr)
return False
placeholderStr = "This is the placeholder text..."
builder = Gtk.Builder()
builder.add_from_file("placeholder-textview.ui")
window = builder.get_object("window1")
textbuf = builder.get_object("textbuffer1")
textbuf.set_text(placeholderStr)
textview = builder.get_object("textview1")
textview.connect("focus-in-event", onFocusIn)
textview.connect("focus-out-event", onFocusOut)
window.connect ("destroy", Gtk.main_quit)
window.show_all()
Gtk.main()
Resulting UI:
Added a few widgets to keep the initial focus on other widgets.
Compare the behavior with the Gtk.Entry. It's very similar.
Related
I am using PySide 1.2.1 with Python 2.7 and I need a widget to draw a colored background.
In Qt Designer I created a simple window consisting of a label, a widget containing three other items and another label. For the widget containing the button, radio button and checkbox I set the styleSheet property to background-color: #FFFFFF.
In Qt Designer everything renders as desired:
But in Pyside the widget does not draw the background color - but the items on it inherit the color correctly:
Here's the ui-XML:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>276</width>
<height>133</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,1,1">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>The following should have white background:</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<property name="styleSheet">
<string notr="true">background-color: #FFFFFF</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton">
<property name="text">
<string>RadioButton</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>But it hasn't :-(</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>276</width>
<height>18</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
Here's my Python code doing nothing special:
import sys
from PySide import QtCore, QtGui
from generated.test import Ui_MainWindow
class MainWindow(Ui_MainWindow,QtCore.QObject):
def __init__(self, *args, **kwargs):
Ui_MainWindow.__init__(self, *args, **kwargs)
QtCore.QObject.__init__(self)
def setupUi(self, MainWindow):
Ui_MainWindow.setupUi(self, MainWindow)
def main(argv):
app = QtGui.QApplication(argv)
mainwindow = QtGui.QMainWindow()
ui = MainWindow()
ui.setupUi(mainwindow)
mainwindow.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main(sys.argv)
I already tried self.widget.setAutoFillBackground(True), but according to the documentation this property is disabled anyway as soon as there's a valid styleSheet value for the background.
This does not work as well:
p = self.widget.palette()
p.setColor(self.widget.backgroundRole(), QtCore.Qt.white)
self.widget.setPalette(p)
(Got these hints from How to set QWidget background color?)
How can I get the widget to draw the white background color?
Set the WA_StyledBackground attribute on the container widget:
ui = MainWindow()
ui.setupUi(mainwindow)
ui.widget.setAttribute(QtCore.Qt.WA_StyledBackground, True)
(PS: for performance reasons, this attribute isn't set by default for some widget classes - but the documentation doesn't seem to specifiy which ones).
Im trying to generate VDMs using the below metadata-
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="1.0"
xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns:sap="http://www.sap.com/Protocols/SAPData">
<edmx:DataServices m:DataServiceVersion="2.0">
<Schema Namespace="myService" xml:lang="en" sap:schema-version="1" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<Annotation Term="Core.SchemaVersion" String="1.0.0" xmlns="http://docs.oasis-open.org/odata/ns/edm"/>
<EntityType Name="myPlant" sap:content-version="1">
<Key>
<PropertyRef Name="Plant"/>
<PropertyRef Name="PlantName"/>
</Key>
<Property Name="Plant" Type="Edm.String" Nullable="false" MaxLength="4" sap:unicode="false" sap:label="Plant" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="PlantName" Type="Edm.String" Nullable="false" MaxLength="30" sap:unicode="false" sap:label="PurchasinPlant" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="ValuationArea" Type="Edm.String" Nullable="false" MaxLength="4" sap:unicode="false" sap:label="Valuation Area" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="PlantCustomer" Type="Edm.String" Nullable="false" MaxLength="10" sap:unicode="false" sap:label="CustomerNoPlant" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="PlantSupplier" Type="Edm.String" Nullable="false" MaxLength="10" sap:unicode="false" sap:label="Sppl. No. Plnt" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="DefaultPurchasingOrganization" Type="Edm.String" Nullable="false" MaxLength="4" sap:unicode="false" sap:label="Purchasing Org." sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="FactoryCalendar" Type="Edm.String" Nullable="false" MaxLength="2" sap:unicode="false" sap:label="Factory Calend." sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="SalesOrganization" Type="Edm.String" Nullable="false" MaxLength="4" sap:unicode="false" sap:label="Sales Org. ICB" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="AddressId" Type="Edm.String" Nullable="false" MaxLength="10" sap:unicode="false" sap:label="Address" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="PlantCategory" Type="Edm.String" Nullable="false" MaxLength="1" sap:unicode="false" sap:label="Plant cat." sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Distributionchannel" Type="Edm.String" Nullable="false" MaxLength="2" sap:unicode="false" sap:label="Distrib.channel" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
</EntityType>
<EntityContainer Name="myService_Entities" m:IsDefaultEntityContainer="true" sap:supported-formats="atom json xlsx">
<EntitySet Name="myPlantSet" EntityType="myService.myPlant" sap:creatable="false" sap:updatable="false" sap:deletable="false" sap:pageable="false" sap:content-version="1"/>
</EntityContainer>
<atom:link rel="self" href="https://sap/myService/$metadata" xmlns:atom="http://www.w3.org/2005/Atom"/>
<atom:link rel="latest-version" href="https://sap/myService/$metadata" xmlns:atom="http://www.w3.org/2005/Atom"/>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
On running the maven profile, I get below error-
Error: URI=file:/C:../src/main/resources/connectedsystem/metadata/myService.xml Line=5: Document root element "edmx:Edmx", must match DOCTYPE root "null".
Error: URI=file:/C:../src/main/resources/connectedsystem/metadata/myService.xml Line=5: Document is invalid: no grammar found.
Warning: validation was turned on but an org.xml.sax.ErrorHandler was not set, which is probably not what is desired. Parser will use a default ErrorHandler to print the first 0 errors. Please call the setErrorHandler method to fix this.
Error: URI=file:/C:../src/main/resources/connectedsystem/metadata/myService.xml Line=5: Document root element "edmx:Edmx", must match DOCTYPE root "null".
Error: URI=file:/C:../src/main/resources/connectedsystem/metadata/myService.xml Line=5: Document is invalid: no grammar found.
The cloud-sdk version used is 3.42.0
These error messages typically occur because the XML document is not valid according to the XML standard. However, this does not jeopardize the code generation in most of the cases. So please tell us whether the code generation also fails.
I can successfully generate the code using the provided metadata, hence I believe there is no problem.
Environment:
Python 3.7.7
Qt5
Qt Designer 5.11
Problem:
I designed a GUI with Qt Designer and I added some images in the background of labels and icons in buttons.
I can see the images and icons properly from the software Qt designer. But when I execute my python script to load my UI, I don't see the images anymore.
Code:
I have my main python script on root folder and the ui, qrc and image files in the folder "ui":
main.py
ui/config.qrc
ui/doc.qrc
ui/document.png
ui/gear.png
ui/logo.qrc
ui/logo_MyUI_300.jpg
ui/MyUI.ui
ui/play-button.png
ui/play.png
ui/question.png
ui/quit.png
ui/quit.qrc
ui/report.qrc
ui/run.qrc
ui/save.png
ui/save.qrc
ui/scan.qrc
ui/search.png
ui/seo-report.png
ui/support.qrc
ui/telegram.png
ui/telegram.qrc
ui/watch_videos.qrc
main.py:
from PyQt5 import QtWidgets, uic
gui = QtWidgets.QApplication([])
ui=uic.loadUi('ui/MyUI.ui')
ui.show()
gui.exec()
MyUI.ui:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<author>MyUI.co</author>
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>580</height>
</rect>
</property>
<property name="windowTitle">
<string>MyUI.co</string>
</property>
<property name="windowIcon">
<iconset>
<normalon>:/logo/logo_MyUI_300.jpg</normalon>
</iconset>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 255);</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QLineEdit" name="lineEdit_Email">
<property name="geometry">
<rect>
<x>126</x>
<y>190</y>
<width>221</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="placeholderText">
<string>i.e: johndoe#gmail.com</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_License">
<property name="geometry">
<rect>
<x>126</x>
<y>220</y>
<width>221</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="placeholderText">
<string>i.e: gold89DE-B4JI-HQ3E-D8UT</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>76</x>
<y>190</y>
<width>41</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>Email</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>75</width>
<height>75</height>
</rect>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="styleSheet">
<string notr="true">background-image: url(:/logo/logo_MyUI_300.jpg);</string>
</property>
<property name="text">
<string/>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="pixmap">
<pixmap resource="logo.qrc">:/logo/logo_MyUI_300.jpg</pixmap>
</property>
<property name="openExternalLinks">
<bool>false</bool>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>36</x>
<y>220</y>
<width>81</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>License Key</string>
</property>
</widget>
<widget class="QLabel" name="label_1">
<property name="geometry">
<rect>
<x>36</x>
<y>140</y>
<width>31</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>20</pointsize>
</font>
</property>
<property name="text">
<string>1.</string>
</property>
</widget>
<widget class="QLabel" name="label_1_Title">
<property name="geometry">
<rect>
<x>66</x>
<y>146</y>
<width>231</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="text">
<string>Activate your MyUI</string>
</property>
</widget>
<widget class="QPushButton" name="button_SaveLicense">
<property name="geometry">
<rect>
<x>256</x>
<y>260</y>
<width>91</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(199, 199 199);</string>
</property>
<property name="text">
<string>Save</string>
</property>
<property name="icon">
<iconset>
<normalon>:/save/save.png</normalon>
</iconset>
</property>
</widget>
<widget class="QLabel" name="label_5">
<property name="geometry">
<rect>
<x>36</x>
<y>304</y>
<width>31</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>20</pointsize>
</font>
</property>
<property name="text">
<string>2.</string>
</property>
</widget>
<widget class="QLabel" name="label_2_Title">
<property name="geometry">
<rect>
<x>66</x>
<y>310</y>
<width>331</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="text">
<string>Required Softwares are Installed?</string>
</property>
</widget>
<widget class="QLabel" name="label_8">
<property name="geometry">
<rect>
<x>86</x>
<y>350</y>
<width>101</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>Java Runtime:</string>
</property>
</widget>
<widget class="QLabel" name="label_9">
<property name="geometry">
<rect>
<x>186</x>
<y>350</y>
<width>41</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>No</string>
</property>
</widget>
<widget class="QLabel" name="label_10">
<property name="geometry">
<rect>
<x>186</x>
<y>370</y>
<width>41</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>No</string>
</property>
</widget>
<widget class="QLabel" name="label_11">
<property name="geometry">
<rect>
<x>126</x>
<y>370</y>
<width>61</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>NodeJS:</string>
</property>
</widget>
<widget class="QLabel" name="label_12">
<property name="geometry">
<rect>
<x>186</x>
<y>390</y>
<width>41</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>No</string>
</property>
</widget>
<widget class="QLabel" name="label_13">
<property name="geometry">
<rect>
<x>90</x>
<y>390</y>
<width>91</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>SDKManager:</string>
</property>
</widget>
<widget class="QLabel" name="label_14">
<property name="geometry">
<rect>
<x>186</x>
<y>410</y>
<width>41</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>No</string>
</property>
</widget>
<widget class="QLabel" name="label_15">
<property name="geometry">
<rect>
<x>106</x>
<y>410</y>
<width>81</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>Build-Tools:</string>
</property>
</widget>
<widget class="QLabel" name="label_16">
<property name="geometry">
<rect>
<x>186</x>
<y>430</y>
<width>41</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>No</string>
</property>
</widget>
<widget class="QLabel" name="label_17">
<property name="geometry">
<rect>
<x>126</x>
<y>430</y>
<width>61</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>Appium:</string>
</property>
</widget>
<widget class="QLabel" name="label_18">
<property name="geometry">
<rect>
<x>186</x>
<y>450</y>
<width>41</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>No</string>
</property>
</widget>
<widget class="QLabel" name="label_19">
<property name="geometry">
<rect>
<x>110</x>
<y>450</y>
<width>71</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>Tesseract:</string>
</property>
</widget>
<widget class="QPushButton" name="button_Run">
<property name="geometry">
<rect>
<x>100</x>
<y>20</y>
<width>71</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(85, 255, 127);</string>
</property>
<property name="text">
<string>Run</string>
</property>
<property name="icon">
<iconset>
<normalon>:/run/play-button.png</normalon>
</iconset>
</property>
</widget>
<widget class="QPushButton" name="button_Quit">
<property name="geometry">
<rect>
<x>180</x>
<y>20</y>
<width>71</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 112, 93);</string>
</property>
<property name="text">
<string>Quit</string>
</property>
<property name="icon">
<iconset>
<normalon>:/quit/quit.png</normalon>
</iconset>
</property>
</widget>
<widget class="QPushButton" name="button_Report">
<property name="geometry">
<rect>
<x>280</x>
<y>20</y>
<width>101</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(199, 199, 199);</string>
</property>
<property name="text">
<string>See Report</string>
</property>
<property name="icon">
<iconset>
<normalon>:/report/seo-report.png</normalon>
</iconset>
</property>
</widget>
<widget class="QPushButton" name="button_Doc">
<property name="geometry">
<rect>
<x>390</x>
<y>20</y>
<width>121</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(199, 199, 199);</string>
</property>
<property name="text">
<string>Read the Doc</string>
</property>
<property name="icon">
<iconset>
<normalon>:/doc/document.png</normalon>
</iconset>
</property>
</widget>
<widget class="QPushButton" name="button_Support">
<property name="geometry">
<rect>
<x>650</x>
<y>20</y>
<width>131</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(199, 199, 199);</string>
</property>
<property name="text">
<string>Contact Support</string>
</property>
<property name="icon">
<iconset>
<normalon>:/support/question.png</normalon>
</iconset>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>430</x>
<y>140</y>
<width>31</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>20</pointsize>
</font>
</property>
<property name="text">
<string>3.</string>
</property>
</widget>
<widget class="QLabel" name="label_3_Title">
<property name="geometry">
<rect>
<x>460</x>
<y>146</y>
<width>331</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="text">
<string>Connect your Smartphone(s)</string>
</property>
</widget>
<widget class="QPlainTextEdit" name="plainTextEdit_Smartphones">
<property name="geometry">
<rect>
<x>440</x>
<y>175</y>
<width>311</width>
<height>171</height>
</rect>
</property>
<property name="plainText">
<string>No smartphones were detected... Please verify you enable USB debug mode and you plug correctly your smartphone(s) to your computer through USB, and press the "SCAN" button.</string>
</property>
</widget>
<widget class="QPushButton" name="button_ScanSmartphones">
<property name="geometry">
<rect>
<x>660</x>
<y>355</y>
<width>91</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(199, 199 199);</string>
</property>
<property name="text">
<string>Scan</string>
</property>
<property name="icon">
<iconset>
<normalon>:/scan/search.png</normalon>
</iconset>
</property>
</widget>
<widget class="QPushButton" name="button_Videos">
<property name="geometry">
<rect>
<x>520</x>
<y>20</y>
<width>121</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(199, 199, 199);</string>
</property>
<property name="text">
<string>Watch videos</string>
</property>
<property name="icon">
<iconset>
<normalon>:/whatch_videos/play.png</normalon>
</iconset>
</property>
</widget>
<widget class="QLabel" name="label_6">
<property name="geometry">
<rect>
<x>430</x>
<y>390</y>
<width>31</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>20</pointsize>
</font>
</property>
<property name="text">
<string>4.</string>
</property>
</widget>
<widget class="QLabel" name="label_4_Title">
<property name="geometry">
<rect>
<x>460</x>
<y>396</y>
<width>331</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="text">
<string>Configure the tasks</string>
</property>
</widget>
<widget class="QLabel" name="label_info1">
<property name="geometry">
<rect>
<x>40</x>
<y>265</y>
<width>201</width>
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Your MyUI is activated.</string>
</property>
</widget>
<widget class="QLabel" name="label_info2">
<property name="geometry">
<rect>
<x>40</x>
<y>480</y>
<width>281</width>
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>The softwares are correctly installed.</string>
</property>
</widget>
<widget class="QLabel" name="label_info3">
<property name="geometry">
<rect>
<x>440</x>
<y>360</y>
<width>201</width>
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>MyUI detected smartphones.</string>
</property>
</widget>
<widget class="QLabel" name="label_info4">
<property name="geometry">
<rect>
<x>440</x>
<y>470</y>
<width>201</width>
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Some tasks were configured.</string>
</property>
</widget>
<widget class="QPushButton" name="button_Config">
<property name="geometry">
<rect>
<x>440</x>
<y>430</y>
<width>311</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(199, 199 199);</string>
</property>
<property name="text">
<string>Open configuration page</string>
</property>
<property name="icon">
<iconset>
<normalon>:/config/gear.png</normalon>
</iconset>
</property>
</widget>
<widget class="QLabel" name="label_HeaderMsg">
<property name="geometry">
<rect>
<x>100</x>
<y>90</y>
<width>671</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Everything is correct. Start your MyUI by pressing the button "Run" in top left corner.</string>
</property>
</widget>
<widget class="QLabel" name="label_HeaderMsg_2">
<property name="geometry">
<rect>
<x>220</x>
<y>530</y>
<width>421</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Join our community on Telegram: myurl</string>
</property>
</widget>
<widget class="QLabel" name="label_7">
<property name="geometry">
<rect>
<x>180</x>
<y>525</y>
<width>32</width>
<height>32</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-image: url(:/telegram/telegram.png);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="Line" name="line">
<property name="geometry">
<rect>
<x>10</x>
<y>120</y>
<width>781</width>
<height>20</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="Line" name="line_2">
<property name="geometry">
<rect>
<x>10</x>
<y>500</y>
<width>781</width>
<height>20</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources>
<include location="logo.qrc"/>
<include location="telegram.qrc"/>
<include location="config.qrc"/>
<include location="scan.qrc"/>
<include location="save.qrc"/>
<include location="watch_videos.qrc"/>
<include location="support.qrc"/>
<include location="doc.qrc"/>
<include location="report.qrc"/>
<include location="quit.qrc"/>
<include location="run.qrc"/>
</resources>
<connections/>
</ui>
Here is one qrc file (All the source codes of qrc files are all identical except the image filename and the prefix are changing).
logo.qrc:
<RCC>
<qresource prefix="logo">
<file>logo_MyUI_300.jpg</file>
</qresource>
</RCC>
What I tried:
I edited the images paths from MyUI.ui file in order to add the '/ui/' folder path, but it didn't change anything.
I did the same in qrc files, and no changes.
Do you have any idea please what is blocking the display of images?
The uic.loadUi function is not the same method that Qt Designate uses to show the preview, uic.loadUi generates the classes and attributes dynamically allowed by python, so it needs you to compile the rc using pyrcc5 and import them into your script, for example:
pyrcc5 ui/logo.qrc -o logo_rc.py
from PyQt5 import QtWidgets, uic
import logo_rc
gui = QtWidgets.QApplication([])
ui=uic.loadUi('ui/MyUI.ui')
ui.show()
gui.exec()
I am using VDM to get the navigation property which has multiplicity as 0..1.
Whenever the response returned from S4 is 0 (that is "204 No Content"), I am getting a NullPointerException.
HeaderCDSForPRForGuidedBuying requisitionHeader = isActiveEntity ? readActivatedHeader(purchaseRequisition) : readHeaderInternal(draftUUID);
GuidedProcurementDeliveryAddressAtHeader requisitionHeaderAddress;
requisitionHeaderAddress = requisitionHeader.getGuidedProcmtReqnDelivAddrOrFetch();
return S4ToGBServiceMapper.mapToRequisitionHeader(requisitionHeader, requisitionHeaderAddress);
Here requisitionHeader.getGuidedProcmtReqnDelivAddrOrFetch(); is the navigation entity which is resulting in "204 No Content" from S4 whenever there are no data.
Metadata of the entity
<EntityType Name="C_GuidedProcmtReqnHdrTPType" sap:label="Header CDS
for PR for guided buying" sap:content-version="1">
<Key>
<PropertyRef Name="PurchaseRequisition"/>
<PropertyRef Name="DraftUUID"/>
<PropertyRef Name="IsActiveEntity"/>
</Key>
<Property Name="Activation_ac" Type="Edm.Boolean" sap:label="Dyn. Action Control" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Edit_ac" Type="Edm.Boolean" sap:label="Dyn. Action Control" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Preparation_ac" Type="Edm.Boolean" sap:label="Dyn. Action Control" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Validation_ac" Type="Edm.Boolean" sap:label="Dyn. Action Control" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="PurReqnDescription_fc" Type="Edm.Byte" sap:label="Dyn. Field Control" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="PurReqnSSPRequestor_fc" Type="Edm.Byte" sap:label="Dyn. Field Control" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="PurchaseRequisition" Type="Edm.String" Nullable="false" MaxLength="10" sap:display-format="UpperCase" sap:label="Purchase requisition" sap:quickinfo="Purchase requisition number" sap:value-list="standard"/>
<Property Name="PurReqnDescription" Type="Edm.String" MaxLength="40" sap:field-control="PurReqnDescription_fc" sap:label="Purchase Requisition Name" sap:quickinfo="Short Text"/>
<Property Name="PurReqnSSPRequestor" Type="Edm.String" MaxLength="60" sap:field-control="PurReqnSSPRequestor_fc" sap:label="Requestor" sap:value-list="standard"/>
<Property Name="PurReqnSSPAuthor" Type="Edm.String" MaxLength="12" sap:display-format="UpperCase" sap:label="Author" sap:quickinfo="Author of Requisition"/>
<Property Name="PurchaseRequisitionType" Type="Edm.String" MaxLength="4" sap:display-format="UpperCase" sap:label="Document Type" sap:quickinfo="Purchase Requisition Document Type"/>
<Property Name="CreationDate" Type="Edm.DateTime" Precision="0" sap:display-format="Date" sap:label="Created On"/>
<Property Name="EmployeeFullName" Type="Edm.String" MaxLength="80" sap:label="Requested By" sap:quickinfo="Full Name of Person"/>
<Property Name="PurReqnOrigin" Type="Edm.String" MaxLength="1" sap:display-format="UpperCase" sap:label="Creation indicator" sap:quickinfo="Creation indicator (purchase requisition/schedule lines)"/>
<Property Name="PurReqnLifeCycleStatus" Type="Edm.String" MaxLength="2" sap:display-format="UpperCase" sap:label="LifeCycle Status" sap:quickinfo="Purchase requistion status" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="PurReqnLifeCycleStatusName" Type="Edm.String" MaxLength="60" sap:label="Status" sap:quickinfo="Short Text for Fixed Values" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="NumberOfItems" Type="Edm.Int32" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="TotalNetAmount" Type="Edm.Decimal" Precision="16" Scale="3" sap:unit="Currency" sap:label="Total Net Value" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Currency" Type="Edm.String" MaxLength="5" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false" sap:semantics="currency-code"/>
<Property Name="IsSrchEnabled" Type="Edm.Boolean" sap:display-format="UpperCase" sap:label="Hide Search Bar" sap:creatable="false" sap:updatable="false"/>
<Property Name="IsExtPurgScenario" Type="Edm.Boolean" sap:display-format="UpperCase" sap:label="Is External Purch." sap:quickinfo="Indicator for external purchasing scenario" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="IsOnBehalfCart" Type="Edm.String" MaxLength="1" sap:display-format="UpperCase" sap:label="Shop On Behalf Ind." sap:quickinfo="Shop on behalf indicator"/>
<Property Name="PurReqnIsCopyDraft" Type="Edm.Boolean" sap:display-format="UpperCase" sap:label="Draft Is Copied" sap:quickinfo="Draft is copied from active document"/>
<Property Name="BusinessUser" Type="Edm.String" MaxLength="12" sap:display-format="UpperCase" sap:label="User ID"/>
<Property Name="PurReqnIsCreatedInExpertMode" Type="Edm.Boolean" sap:display-format="UpperCase" sap:label="PR in Expert Mode" sap:quickinfo="PR Created in Expert Mode"/>
<Property Name="AccountAssignmentCategory" Type="Edm.String" MaxLength="1" sap:display-format="UpperCase" sap:label="Acct Assignment Cat." sap:quickinfo="Account Assignment Category" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="AcctAssignmentCategoryName" Type="Edm.String" MaxLength="20" sap:label="AcctAssgntCateg Desc" sap:quickinfo="Account Assignment Category Description" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="PrimaryCostObject" Type="Edm.String" MaxLength="30" sap:display-format="UpperCase" sap:label="Primary Cost Object" sap:quickinfo="Account Assignment Primary Cost Object" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="PrimaryCostObjectName" Type="Edm.String" MaxLength="60" sap:display-format="UpperCase" sap:label="Prim. Cost Obj. Name" sap:quickinfo="Account Assignment Primary Cost Object Name" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="DeliveryDurationInDays" Type="Edm.Decimal" Precision="3" Scale="0" sap:label="Delivery time (days)" sap:quickinfo="Delivery time in days" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="DeliveryTime" Type="Edm.Decimal" Precision="3" Scale="0" sap:label="Delivery time (days)" sap:quickinfo="Delivery time in days" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="DeliveryDate" Type="Edm.DateTime" Precision="0" sap:display-format="Date" sap:label="Delivery date" sap:quickinfo="Item delivery date" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="HasDraftEntity" Type="Edm.Boolean" sap:display-format="UpperCase" sap:label="Has Draft" sap:heading="" sap:quickinfo="" sap:creatable="false" sap:updatable="false"/>
<Property Name="DraftUUID" Type="Edm.Guid" Nullable="false" sap:label="Key" sap:heading="" sap:quickinfo="" sap:creatable="false" sap:updatable="false"/>
<Property Name="DraftEntityCreationDateTime" Type="Edm.DateTimeOffset" Precision="7" sap:label="Draft Created On" sap:heading="" sap:quickinfo="" sap:creatable="false" sap:updatable="false"/>
<Property Name="DraftEntityLastChangeDateTime" Type="Edm.DateTimeOffset" Precision="7" sap:label="Draft Last Changed On" sap:heading="" sap:quickinfo="" sap:creatable="false" sap:updatable="false"/>
<Property Name="HasActiveEntity" Type="Edm.Boolean" sap:display-format="UpperCase" sap:label="Has active" sap:heading="" sap:quickinfo="" sap:creatable="false" sap:updatable="false"/>
<Property Name="IsActiveEntity" Type="Edm.Boolean" Nullable="false" sap:display-format="UpperCase" sap:label="Is active" sap:heading="" sap:quickinfo="" sap:creatable="false" sap:updatable="false"/>
<NavigationProperty Name="DraftAdministrativeData" Relationship="MMPUR_REQ_GPR_MAINTAIN_SRV.assoc_76A4502D0F516EE52DD3CBBBE346E4D9" FromRole="FromRole_assoc_76A4502D0F516EE52DD3CBBBE346E4D9" ToRole="ToRole_assoc_76A4502D0F516EE52DD3CBBBE346E4D9"/>
<NavigationProperty Name="SiblingEntity" Relationship="MMPUR_REQ_GPR_MAINTAIN_SRV.assoc_3CC1A0E5A29B95AA58385E4B4E670133" FromRole="FromRole_assoc_3CC1A0E5A29B95AA58385E4B4E670133" ToRole="ToRole_assoc_3CC1A0E5A29B95AA58385E4B4E670133"/>
<NavigationProperty Name="to_GuidedProcmtReqnDelivAddr" Relationship="MMPUR_REQ_GPR_MAINTAIN_SRV.assoc_ABFFAA8E73382AA60F058244C4ABBB35" FromRole="FromRole_assoc_ABFFAA8E73382AA60F058244C4ABBB35" ToRole="ToRole_assoc_ABFFAA8E73382AA60F058244C4ABBB35"/>
<NavigationProperty Name="to_GuidedProcmtReqnUserDefaults" Relationship="MMPUR_REQ_GPR_MAINTAIN_SRV.assoc_1579C23A5F4ED87BDC6BD58F2005A338" FromRole="FromRole_assoc_1579C23A5F4ED87BDC6BD58F2005A338" ToRole="ToRole_assoc_1579C23A5F4ED87BDC6BD58F2005A338"/>
<NavigationProperty Name="to_Purchaserequisitionitem_Wd" Relationship="MMPUR_REQ_GPR_MAINTAIN_SRV.assoc_3F09BE43BBC7F408BF50540B885968FB" FromRole="FromRole_assoc_3F09BE43BBC7F408BF50540B885968FB" ToRole="ToRole_assoc_3F09BE43BBC7F408BF50540B885968FB"/>
<NavigationProperty Name="to_PurReqnEmplByCoOfAuthorVH" Relationship="MMPUR_REQ_GPR_MAINTAIN_SRV.assoc_F51CC3D827FD02E8485693F0D8E2BECB" FromRole="FromRole_assoc_F51CC3D827FD02E8485693F0D8E2BECB" ToRole="ToRole_assoc_F51CC3D827FD02E8485693F0D8E2BECB"/>
<NavigationProperty Name="to_SSPReqnConfiguration" Relationship="MMPUR_REQ_GPR_MAINTAIN_SRV.assoc_8453857C8C3E316B4D665A8FF57BD512" FromRole="FromRole_assoc_8453857C8C3E316B4D665A8FF57BD512" ToRole="ToRole_assoc_8453857C8C3E316B4D665A8FF57BD512"/>
</EntityType>
Here the problem is for navigation
<NavigationProperty Name="to_GuidedProcmtReqnDelivAddr" Relationship="MMPUR_REQ_GPR_MAINTAIN_SRV.assoc_ABFFAA8E73382AA60F058244C4ABBB35" FromRole="FromRole_assoc_ABFFAA8E73382AA60F058244C4ABBB35" ToRole="ToRole_assoc_ABFFAA8E73382AA60F058244C4ABBB35"/>
<Association Name="assoc_ABFFAA8E73382AA60F058244C4ABBB35" sap:content-version="1">
<End Type="MMPUR_REQ_GPR_MAINTAIN_SRV.C_GuidedProcmtReqnHdrTPType" Multiplicity="1" Role="FromRole_assoc_ABFFAA8E73382AA60F058244C4ABBB35"/>
<End Type="MMPUR_REQ_GPR_MAINTAIN_SRV.C_GuidedProcmtReqnDelivAddrType" Multiplicity="0..1" Role="ToRole_assoc_ABFFAA8E73382AA60F058244C4ABBB35"/>
</Association>
Thanks for your detailed question.
It seems like you indeed have found a bug in one of the indirectly consumed components related to SAP Cloud SDK. I have created an incident (#1970496164) in the ticketing system. It's not clear when precisely this NullPointerException will be fixed, hopefully in one of the next upcoming versions.
In the meantime, I'd suggest using the Try API of the VAVR library as a workaround - to handle the error at runtime.
import io.vavr.control.Try;
// ...
#Nonnull
HeaderCDSForPRForGuidedBuying requisitionHeader;
#Nullable
GuidedProcurementDeliveryAddressAtHeader requisitionHeaderAddress;
// tolerant error handling
requisitionHeaderAddress = Try.of(requisitionHeader::getGuidedProcmtReqnDelivAddrOrFetch).getOrNull();
return S4ToGBServiceMapper.mapToRequisitionHeader(requisitionHeader, requisitionHeaderAddress);
(assuming your mapToRequisitionHeader method expects the second parameter to be #Nullable)
Add the dependency to your pom:
<dependency>
<groupId>io.vavr</groupId>
<artifactId>vavr</artifactId>
<version>0.10.2</version>
</dependency>
As an alternative to my proposal, you could just use the bulky try-catch block of course.
Ran into an issue that seems like the event loop is blocked (or I didn't start one?) and I haven't been able to chase it down.
The GUI comes up, and the menus are responsive, but clicking File->Open, which should create an near immediate print statement doesn't happen.
I know I have the correct signal mapped to the slot because as soon as you do a File->Quit or close the window, the print statement comes out.
I implemented this same example in C++ with the identical UI file and it works as expected.
Problem exhibits in the following configurations:
Windows 10, Python 3.6.4, pyside2-5.11.1a1.dev1530708810518
Windows 10, Python 2.7.14, pyside2-5.11.0a1.dev1528378291
test.ui:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>200</height>
</rect>
</property>
<property name="windowTitle">
<string>Qt for Python</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout"/>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>940</width>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionOpen"/>
<addaction name="actionQuit"/>
</widget>
<addaction name="menuFile"/>
</widget>
<action name="actionQuit">
<property name="text">
<string>Quit</string>
</property>
</action>
<action name="actionOpen">
<property name="text">
<string>Open</string>
</property>
</action>
</widget>
<resources/>
<connections>
<connection>
<sender>actionQuit</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>close()</slot>
</connection>
</connections>
</ui>
test.py:
#!/usr/bin/env python
import sys
from PySide2 import QtCore, QtGui, QtWidgets
from PySide2.QtUiTools import QUiLoader
from PySide2.QtWidgets import QApplication
from PySide2.QtCore import QFile
class MyWidget(QtCore.QObject):
def __init__(self):
QtCore.QObject.__init__(self)
file = QFile("test.ui")
file.open(QFile.ReadOnly)
loader = QUiLoader()
self.ui = loader.load(file)
openAction = self.ui.findChild(QtWidgets.QAction, 'actionOpen')
openAction.triggered.connect(self.func)
#QtCore.Slot()
def func(self):
print("func has been called!")
app = QtWidgets.QApplication(sys.argv)
myWidget = MyWidget()
myWidget.ui.show()
sys.exit(app.exec_())
Issue with PySide2 on Windows, opened bug PYSIDE-767