Solved: Is it possible to make readonly just a single column ?
MRES1 opened this issue · comments
If this is possible, can someone help with some advice?
Thank you all in advance!
This is my first attempt and gives me some idea of where I need to start:
Navigating in class TableCanvas(Canvas)
look for def drawCellEntry(self, row, col, text=None):
Original :
def drawCellEntry(self, row, col, text=None):
"""When the user single/double clicks on a text/number cell, bring up entry window"""
if self.read_only == True:
return`
What I did:
def drawCellEntry(self, row, col, text=None):
"""When the user single/double clicks on a text/number cell, bring up entry window"""
if self.read_only == True or self.currentcol == 0: # HERE
return`
It works good and I think it's a great starting point... :)
EDIT:
To make one or more columns readonly is really simple, so this is what I'm working on, and it works perfectly till now.
-
add a new field in
class TableCanvas(Canvas)
for example:class TableCanvas(Canvas): """A tkinter class for providing table functionality"""
def __init__(self, parent=None, model=None, data=None, read_only=False, width=None, height=None, rows=10, cols=5,readonlycolname=None, **kwargs):
-
Notice "
readonlycolname=None
" thevalue passed here will be may readonly col, you can do it for multiple columns. -
Create and set the value to a field(In the constructor):
self.first_column_name = readonlycolname
-
Go to
def drawCellEntry(self, row, col, text=None):
and modify the first if clause( Just at the begining of the method) :
if self.read_only == True or self.first_column_name == self.get_currentColName(): return
- You might have to make other change in
def get_currentColName(self):
:
def get_currentColName(self):
"""Get the currently selected record name"""
# colname = self.mo(self.currentcol) # WHAT I HAD ORIGINALLY, RAISED EXCEPTION because of "mo"
colname = self.model.getColumnName(self.currentcol) # Worked like a charm
return colname