I have a field in a property browser where the user sets a file path. I would like for them to get a file browser when the click on the line to edit it.
the file browser is
class TargetPropertiesBrowser(QtTreePropertyBrowser):
def __init__(self):
self._variantManager = QtVariantPropertyManager()
general_group = self._variantManager.addProperty(QtVariantPropertyManager.groupTypeId(), "General")
self._outputPath = self._variantManager.addProperty(QVariant.String, Target.OUTPUT_PATH)
self._outputPath.setToolTip("Output Directory")
general_group.addSubProperty(self._outputPath)
Now lets say I have some class PopUpBrowser that defines the popup I want displayed when they click in the property browser on the file path line. I can't find an example or documentation on how to alter the behavior or the QtTreePropertyBrowser.
Edit:
If there is a signal I can connect to for when a user clicks on the line that would be fine, however I don't see such a signal in the docs. I'm also not seeing any Enum for a variant manager (or any alternate managers) that supports a widget or button that could link a widget. Sorry if I was unclear.
Connect one of the Widget's Signals (e.g. clicked()) to a slot method in your class: http://pyqt.sourceforge.net/Docs/PyQt5/signals_slots.html
Related
I have 2 files. one is for the login GUI using tkinter and the other is for the login/verification process. In the screenshot the root file runs just fine. When I run the login file the gui box pops up, but when I close it I get an error ---->
'''File "c:/Users/j/Desktop/pyth/login.py", line 20, in <module>
Log.auth()
File "c:/Users/j/Desktop/pyth/login.py", line 10, in auth
if (self.user == Application.capture(self).verify and self.pw == Application.capture(self).verify2):
File "c:\Users\j\Desktop\pyth\root.py", line 24, in capture
self.verify=self.username.get()
AttributeError: 'Acess' object has no attribute 'username'''
I understand what the error means, but I'm not sure how to go about fixing it. Ultimately I'm trying to get the input from the login box once the "LOGIN" button is clicked and see if it matches the assigned user and pw which is what's going on in the login file.
What happens is that when you run login.py, the code you wrote in root.py is executed due to the from root import Application. This is why the GUI shows up.
Then when you close the GUI, the code Log = Acess(.., ...) then Log.auth() is executed and at line 10 of login.py you pass self to the capture method of Application.
And in the capture method, self.username is trying to access username of Acess which does not exists and thus crash the code
You could move the code in the root.py file and pass the application to the Acess class and store it in an attribute which will be used in the auth function instead of Application
root = tk.tk()
app = Application(master=root)
root.mainloop
Log = Acess("user", "pwd")
Log.auth()
Hi I am creating a browser in python using PyQt, I am trying to allow the user to disable all Java Script alerts which is a protected function under qwebpage called javaScriptAlert, is there a way to disable this function or protected functions in general?
in the main class where browser can be defined as
self.browser = QWebView()
and then do another class
class MyWebPage(QWebPage):
def javaScriptAlert(self):
pass
then back in the main class do
self.page = MyWebPage()
self.browser.setPage(self.page)
class Browser(QWebView):
def __init__(self):
QWebView.__init__(self)
self.loadFinished.connect(self._result_available)
self.loadStarted.connect(self._load_started)
self.page().frameCreated.connect(self.onFrame)
# ...
browser = Browser()
browser.setHtml('<html>...</html>', baseUrl=QUrl('http://www.google.com/'))
After that, i need to catch content of all external resources loaded by QWebView. I need to get content of all CSS/Javascript files. How can i do that ? Related questions: question 1, question 2
I know i need to use QNetworkAccessManager somehow, but i don't have any example to use.
We need to make custom QNetworkReply class and get results in readyRead event results.
I have extended the UI file resulting from the Plugin builder with Qt Creator.
Just added some checkboxes and a combobox, named layercombo to the form.
The application is named jacktest.py. It uses an intermediate file jackdialog.py (generated from the plugin builder, left unchanged).
Compiled the UI file and the resource file. Then added some code to the plugin and tested this. It's no problem to get the available layer names in a QMessagebox. But how to add these to the combobox ?
Should be simple, but no option succeeds in referencing the combobox.
Error message: AttributeError: jacktest instance has no attribute 'layercombo'.
Result from my latest try:
# run method that performs all the real work
def run(self):
# create and show the dialog
dlg = jacktestDialog()
# show the dialog
dlg.show()
result = dlg.exec_()
for layer in self.iface.legendInterface().layers():
if layer.type() == QgsMapLayer.VectorLayer:
QMessageBox.information( self.iface.mainWindow(), "Info", layer.name())
self.layercombo.Items.Insert(0, layer.name())
# See if OK was pressed
if result == 1:
# do something useful (delete the line containing pass and
# substitute with your code
pass
You are trying to reference the current class (which is not your dialog) when you are setting the layercombo items
Replace:
self.layercombo.Items.Insert(0, layer.name())
with
dlg.ui.layercombo.Items.Insert(0, layer.name())
but you code still won't work correctly as exec_() is blocking and waits until it returns so you are adding items to an invisible dialog.
Try this instead:
# create and show the dialog
dlg = jacktestDialog()
# show the dialog
for layer in self.iface.legendInterface().layers():
if layer.type() == QgsMapLayer.VectorLayer:
QMessageBox.information( self.iface.mainWindow(), "Info", layer.name())
dlg.ui.layercombo.Items.Insert(0, layer.name())
result = dlg.exec_()
Went on in developing a Signal within the run module (code: def run (self):)
QObject.connect(dlg.ui.layercombo,SIGNAL('currentIndexChanged (int)'),self.select_one)
and the code of select_one is:
def select_one(self):
comboindex = dlg.ui.layercombo.currentIndex()
QMessageBox.information(self.iface.mainWindow(), "Info", comboindex)
Error message:
comboindex = dlg.ui.layercombo.currentIndex()
NameError: global name 'dlg' is not defined
Suppose I have to reference dlg as a parameter in the function call, but this is not working until now.
Is there an easy way to show the properties dialog for a file in Windows using Python?
I'm trying to show the same window that pops up when you right click a file in Explorer and choose Properties.
The way to do this is to call the Windows ShellExecuteEx() API passing the properties verb. There are various high-level Python wrappers of this but I have not succeeded in getting any of them to work with the properties verb. Instead I would use good old ctypes.
import time
import ctypes
import ctypes.wintypes
SEE_MASK_NOCLOSEPROCESS = 0x00000040
SEE_MASK_INVOKEIDLIST = 0x0000000C
class SHELLEXECUTEINFO(ctypes.Structure):
_fields_ = (
("cbSize",ctypes.wintypes.DWORD),
("fMask",ctypes.c_ulong),
("hwnd",ctypes.wintypes.HANDLE),
("lpVerb",ctypes.c_char_p),
("lpFile",ctypes.c_char_p),
("lpParameters",ctypes.c_char_p),
("lpDirectory",ctypes.c_char_p),
("nShow",ctypes.c_int),
("hInstApp",ctypes.wintypes.HINSTANCE),
("lpIDList",ctypes.c_void_p),
("lpClass",ctypes.c_char_p),
("hKeyClass",ctypes.wintypes.HKEY),
("dwHotKey",ctypes.wintypes.DWORD),
("hIconOrMonitor",ctypes.wintypes.HANDLE),
("hProcess",ctypes.wintypes.HANDLE),
)
ShellExecuteEx = ctypes.windll.shell32.ShellExecuteEx
ShellExecuteEx.restype = ctypes.wintypes.BOOL
sei = SHELLEXECUTEINFO()
sei.cbSize = ctypes.sizeof(sei)
sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_INVOKEIDLIST
sei.lpVerb = "properties"
sei.lpFile = "C:\\Desktop\\test.txt"
sei.nShow = 1
ShellExecuteEx(ctypes.byref(sei))
time.sleep(5)
The reason I put in the call to sleep is that the properties dialog is shown as a window in the calling process. If the Python executable terminates immediately following the call to ShellExecuteEx, then there is nothing there to service the dialog and it does not show.