I've been facing a problem for several days now. I'm using a QTableView to display data from a model. I activated the complete line selection when the user click on a cell, to make the interface user friendly:
self.tableau.selectRow(element.row())
But, when the user presses F2, I would like to edit only the column 1. So, the expected behavior is:
if I selected the column 4, this one is not editable
if I press F2 when column 4 is selected, the column 1 is edited
But with the complete row selection, F2 can not know which cell is selected. So, I re-implemented the event handler:
def keyPressEvent(self, e):
"""It reimplements event management in this method """
# TODO: find a way to re-select the cell after editing
# We get the name of current file
nom_courant = self.tableau.model().index(self.row_selected, 1).data()
print(nom_courant)
if e.key() == QtCore.Qt.Key_F2:
try:
# We edit the cell name of the selected line
#http://stackoverflow.com/questions/8157688/specifying-an-index-in-qtableview-with-pyqt
self.tableau.edit(self.tableau.model().index(self.row_selected, 1))
except:
print("Pas de cell sélectionnée")
pass
# It retrieves the new file name. CAN NOT do in the
# if the model is not updated yet.
nouveau_nom = self.tableau.model().index(self.row_selected, 1).data()
print(nouveau_nom)
# Call the fct renaming only if the name has changed
if nom_courant != nouveau_nom:
#liste.renameFile(self.current_video, self.tableau.model().index(self.row_selected, 1).data())
print("entropie")
The matter now is this line:
self.tableau.edit(self.tableau.model().index(self.row_selected, 1))
I have no way to detect the end of the edition of the QLineEdit generated, and I need it to perform actions on the new content of the cell edited, because nouveau_nom is not updated if no keyboard event occurs.
Do you have an idea about how to get the end edition signal ?
(Please forgive my english, I'm french...)
First, you don't need to actually intercept and change the cell selection to a row selection. You can just set the behavior on the view:
self.tableau.setSelectionBehavior(self.tableau.SelectRows)
This will automatically select rows.
When you use a custom QLineEdit widgets in your table, then you need to connect QLineEdit.editingFinished() to whatever handler you want. Most likely you want it to call dataChanged on your model.
Related
For some reason the Visible function in my Powerapps won't work I just wrote in OnSelect() Mail.Visible = false
The Mail is in this case a Textinput/ TextBox.
When I click on the button nothing happens. I can't find a documentation about it on the MS Website but I have in Powerapps a fuction called "Visible"
You need to create a variable in the button's (or another control) OnSelect property:
UpdateContext({ mailVisible: false })
And set the Visible property of the Mail control to mailVisible. You may need to initialize that variable to true, for example, in the screen's OnVisible property:
UpdateContext({ mailVisible: true })
PowerApps works similarly to Excel - you cannot, by an action, change directly the value of a cell (e.g., A1 = 42). But you can make the A1 cell reference another cell (say, =A4), so when you change the value of the cell A4, A1 will be updated as well. The same principle applies in PowerApps - you cannot change the value of a property from an action, but you can update the value that the property references.
Credit #SeaDude
This worked perfectly for me toggling the variable back and forth to show/hide a few layers.
Set(mailVisible, !mailVisible)
So I have a few items like this. I'm not sure if this is the BEST way but I know it works.
Set a variable on the app start:
App = Set(variable_visable, "");
Button code:
Onselect = Set(variable_visable.,"1");
Item that you want visible:
Visibility = If(variable_visable="1", true, false);
Edit: You can reset your variable at any point to hide that section.
Sometimes power apps fights you on things that seem correct.
The Visible will the condition that is true to make it show.
For example
If I have one TextBox named TextInput1 and I want a control to be visible when the Text entered = true it will be. For this example use a label.
Label1's visible function will be TextInput1.Text = "true"
This will show when the input text will be true. if it's false or anything else the label won't show. This is a very basic use of the visible but can be used in many ways.
In On select property of button you can't set any other control property directly.
you need to follow the steps as:
1- you need to set a boolean type variable on OnSelect of button e.g.
Set(varShowMail,false)
2- go to TextInput Mail and select its Visible property and assign the variable "varShowMail"
It will work 100%.
Set on visible of screen property UpdateContext({ Var_Visible: false})
set a variable on control "select" or "change" to true"UpdateContext({ Var_Visible: true})" and use the variable in other control visible property that you want to show or hide, if required you can use condition to set a variable to true or false
I have a program written in python 3.5 which scans a directory and stores the info in a SQLITE3 db. This info can be displayed in a ttk.treeview in the client.
The 2 main functions are 1) "scan" which adds the information to the db and 2) viewFiles which is below (it just grabs data from the db and displays it in the treeview).
During the scan function, a second tkinter window is opened and displays information on whats been scanned. If I try to use the viewFiles fucntion without a restart, the data displayed is invisible but I know the data is there because I can copy paste it into a text document). If I restart the client, the text is displayed correctly after pressing the button linked to the viewFiles function.
I think it must be something to do with the the focus shift thanks to this 2nd window opening during the scan process but I'm not sure and can't find any similar case to learn from.
def viewFiles(self):
global dataTreeView
results = []
foldersContentsToView = yieldFoldersToView()
for dpath in foldersContentsToView:
sqlstring= "SELECT * FROM DBDATA WHERE directorypath=:dpath"
values = {"dpath": dpath}
[results.append(i) for i in databaseFunctions.getDBobject().returnSelectQueryResults(sqlstring, values)]
for e in results:
dataTreeView.insert('', 'end', values=list(e))
Does anyone have any ideas?
The issue was that the columns were being set up in the moment the treeview was created by querying the fields in the database. However before the first scan, there were no records in the db and so the columns were not being configured properly until a restart, after which data existed and could be queried on treeview creation.
To fix the issue, I moved the column configure data to the viewFiles function like so:
def viewFiles(self):
global dataTreeView
audioDataTree['columns'] = returnListTableFields()
#Configure Columns
for column in listofdbtablefields():
dataTree.column(column,width=len(column)*10)
dataTree.heading(column, text=column)
dataTree.column(column, anchor='center')
#Hide First Column (TreeLabel)
dataTree.column('#0',width=0)
results = []
foldersContentsToView = yieldFoldersToView()
for dpath in foldersContentsToView:
sqlstring= "SELECT * FROM DBDATA WHERE directorypath=:dpath"
values = {"dpath": dpath}
[results.append(i) for i in databaseFunctions.getDBobject().returnSelectQueryResults(sqlstring, values)]
for e in results:
dataTreeView.insert('', 'end', values=list(e))
I am implementing a search function in python with Tkinter and would like to select the first match it comes to. I have seen many examples with creating a tag_config to highlight the background of the indexed range, however I would like to select the text (the same way one would by clicking at the first index, then shift clicking the last index).
Thus far I have got both the start and end index of the area I need to select, I just don't know the command to "select" the text with that information.
My current code (that uses a highlight approach) is:
def search_command():
word = askstring("Search", "Enter word to search")
length = len(str(word))
pos = textPad.search(word, '1.0', stopindex=END)
row, col = pos.split('.')
endlen = int(col) + length
end = row + '.' + str(endlen)
textPad.tag_add("found", pos, end)
The "found" tag just highlights the background of the text rather than selecting it.
Any help with finding the correct function would be greatly appreciated.
The selection is defined by the "sel" tag. Apply that tag to the range of text you want selected:
textPad.tag_add("sel", pos, end)
First post so I'll try my best to make it a good one (please tell me if I'm doing it wrong).I can't seem to write the code properly to change the value of a check box or option button on a sheet using a variable.
Suppose the name of the check box name is "Chk1", normally I would write :
Worksheets("AP-1").Chk1.value=X
Where X is (either True or False). Since it is a Loop, I use a range variable called FoundRange and it's value is the name of the check box, so I tried:
dim chkname as string
chkname=foundrange.value
Worksheets("AP-1").Chkname.value=X
I also tried
Worksheets("AP-1").CheckBoxes(chkname).Value = X
and
Worsheets("AP-1").Shapes(chkname).ControlFormat.Value=X
I also had a linked cell that I used to change the value, but when it writes either false or true in it, the check box becomes gray and I need to press F2+Enter in the linked cell to make the check box show the proper value. I also tried to select the linked cell after changing its value and use that code:
Application.SendKeys "{F2}"
Application.SendKeys "{ENTER}"
but it did not work.
Please help me :)
Based on your initial code, it must be an ActiveX control, not a Form one, so:
dim chkname as string
chkname=foundrange.value
Worksheets("AP-1").OLEObjects(Chkname).Object.value = X
Q1) I have a Entry widget and I want it to be per-initilized with a value and I want the user to have the open to erase that value and type in what ever value they want.
So for example:
Year: 2016 <----- By deafult 2016 is already inputted and visible
Is there a way I can do this?
Q2) Is there a way I can set a limit to the number of a same window that can be opened? For example: If i have a drop down menu which has a "help" option. Currently the way I have it set up, if I click the help once the help window will pop up, and if I click it again (while the first window is still open) another help window will pop up. How do I set it so that only 1 help window can be opened at a time?
Any help is greatly appreciated.
1) you can use a string variable
self.example = StringVar()
self.example.set("put what you want it to say at the start here")
#note put this before you make your entry
self.example_txt = Entry(self,textvariable = self.example)
self.example_txt.place(row = 1, column = 1)
#note iv purposely missed out class declaration ectra as i am assuming you already have that)
2) there is probably a better way to do this but you could use a global variable which is set to false when the help button is clicked and set back to true when help window closed
global valid
valid = True
#not put this at start of your program
def opennewindow():
global valid
if valid == True:
valid = False
#put code for opening new window here assuming you already have that code as
#you haven't asked for code for that
def closewindow():
global valid
valid = True
self.master.destroy()
To insert something into an entry widget you can use the insert method:
e1 = tk.Entry(...)
e1.insert(0, "hello, world")
To only allow a single help window, create the help window once and hide it. Then, make your help function merely show the window rather than create it. Or, have the function check to see if the window exists; if it doesn't, create it before making it visible.