473,769 Members | 3,329 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wxgrid multiline cell editor

wxpython 2.5.3

hi,

anyone know how to make a multiline cell editor for wxgrid?
thank you :)

best regards,

James
Jul 18 '05 #1
1 4948
"James" <c0******@gmail .com> a écrit dans le message de
news:42******** **@news.tm.net. my...
wxpython 2.5.3
anyone know how to make a multiline cell editor for wxgrid?


Hello,

You can do that by a "wxGridCellAuto WrapStringEdito r".
You can test it by modifying GridSimple.py in the demo by adding (at line 24
in my version):
self.SetRowSize (1, 45)
self.SetCellEdi tor(1, 1, wxGridCellAutoW rapStringEditor ())
Save it and now, when you launch the gridsimple in the demo (it's in core
windows control), you can enter multiple lines in the cell containing
"Another cell". It works in 2.4.2.4. I think it should also in 2.5.

I join the whole program.
Have fun.
++jm

#---------------------------------------------------------------
from wxPython.wx import *
from wxPython.grid import *
from wxPython.lib.mi xins.grid import wxGridAutoEditM ixin

#---------------------------------------------------------------------------

class SimpleGrid(wxGr id): ##, wxGridAutoEditM ixin):
def __init__(self, parent, log):
wxGrid.__init__ (self, parent, -1)
##wxGridAutoEdi tMixin.__init__ (self)
self.log = log
self.moveTo = None

EVT_IDLE(self, self.OnIdle)

self.CreateGrid (25, 25) #, wxGrid.wxGridSe lectRows)
##self.EnableEd iting(False)

# simple cell formatting
self.SetColSize (3, 200)
self.SetRowSize (4, 45)
self.SetCellVal ue(0, 0, "First cell")
self.SetCellVal ue(1, 1, "Another cell")
self.SetRowSize (1, 45)
self.SetCellEdi tor(1, 1, wxGridCellAutoW rapStringEditor ())
self.SetCellVal ue(2, 2, "Yet another cell")
self.SetCellVal ue(3, 3, "This cell is read-only")
self.SetCellFon t(0, 0, wxFont(12, wxROMAN, wxITALIC, wxNORMAL))
self.SetCellTex tColour(1, 1, wxRED)
self.SetCellBac kgroundColour(2 , 2, wxCYAN)
self.SetReadOnl y(3, 3, True)

self.SetCellEdi tor(5, 0, wxGridCellNumbe rEditor(1,1000) )
self.SetCellVal ue(5, 0, "123")
self.SetCellEdi tor(6, 0, wxGridCellFloat Editor())
self.SetCellVal ue(6, 0, "123.34")
self.SetCellEdi tor(7, 0, wxGridCellNumbe rEditor())

self.SetCellVal ue(6, 3, "You can veto editing this cell")
# attribute objects let you keep a set of formatting values
# in one spot, and reuse them if needed
attr = wxGridCellAttr( )
attr.SetTextCol our(wxBLACK)
attr.SetBackgro undColour(wxRED )
attr.SetFont(wx Font(10, wxSWISS, wxNORMAL, wxBOLD))

# you can set cell attributes for the whole row (or column)
self.SetRowAttr (5, attr)

self.SetColLabe lValue(0, "Custom")
self.SetColLabe lValue(1, "column")
self.SetColLabe lValue(2, "labels")

self.SetColLabe lAlignment(wxAL IGN_LEFT, wxALIGN_BOTTOM)

#self.SetDefaul tCellOverflow(F alse)
#r = wxGridCellAutoW rapStringRender er()
#self.SetCellRe nderer(9, 1, r)

# overflow cells
self.SetCellVal ue( 9, 1, "This default cell will overflow into
neighboring cells, but not if you turn overflow off.");
self.SetCellSiz e(11, 1, 3, 3);
self.SetCellAli gnment(11, 1, wxALIGN_CENTRE, wxALIGN_CENTRE) ;
self.SetCellVal ue(11, 1, "This cell is set to span 3 rows and 3
columns");
editor = wxGridCellTextE ditor()
editor.SetParam eters('10')
self.SetCellEdi tor(0, 4, editor)
self.SetCellVal ue(0, 4, "Limited text")
# test all the events
EVT_GRID_CELL_L EFT_CLICK(self, self.OnCellLeft Click)
EVT_GRID_CELL_R IGHT_CLICK(self , self.OnCellRigh tClick)
EVT_GRID_CELL_L EFT_DCLICK(self , self.OnCellLeft DClick)
EVT_GRID_CELL_R IGHT_DCLICK(sel f, self.OnCellRigh tDClick)

EVT_GRID_LABEL_ LEFT_CLICK(self , self.OnLabelLef tClick)
EVT_GRID_LABEL_ RIGHT_CLICK(sel f, self.OnLabelRig htClick)
EVT_GRID_LABEL_ LEFT_DCLICK(sel f, self.OnLabelLef tDClick)
EVT_GRID_LABEL_ RIGHT_DCLICK(se lf, self.OnLabelRig htDClick)

EVT_GRID_ROW_SI ZE(self, self.OnRowSize)
EVT_GRID_COL_SI ZE(self, self.OnColSize)

EVT_GRID_RANGE_ SELECT(self, self.OnRangeSel ect)
EVT_GRID_CELL_C HANGE(self, self.OnCellChan ge)
EVT_GRID_SELECT _CELL(self, self.OnSelectCe ll)

EVT_GRID_EDITOR _SHOWN(self, self.OnEditorSh own)
EVT_GRID_EDITOR _HIDDEN(self, self.OnEditorHi dden)
EVT_GRID_EDITOR _CREATED(self, self.OnEditorCr eated)

def OnCellLeftClick (self, evt):
self.log.write( "OnCellLeftClic k: (%d,%d) %s\n" %
(evt.GetRow(), evt.GetCol(), evt.GetPosition ()))
evt.Skip()

def OnCellRightClic k(self, evt):
self.log.write( "OnCellRightCli ck: (%d,%d) %s\n" %
(evt.GetRow(), evt.GetCol(), evt.GetPosition ()))
evt.Skip()

def OnCellLeftDClic k(self, evt):
self.log.write( "OnCellLeftDCli ck: (%d,%d) %s\n" %
(evt.GetRow(), evt.GetCol(), evt.GetPosition ()))
evt.Skip()

def OnCellRightDCli ck(self, evt):
self.log.write( "OnCellRightDCl ick: (%d,%d) %s\n" %
(evt.GetRow(), evt.GetCol(), evt.GetPosition ()))
evt.Skip()

def OnLabelLeftClic k(self, evt):
self.log.write( "OnLabelLeftCli ck: (%d,%d) %s\n" %
(evt.GetRow(), evt.GetCol(), evt.GetPosition ()))
evt.Skip()

def OnLabelRightCli ck(self, evt):
self.log.write( "OnLabelRightCl ick: (%d,%d) %s\n" %
(evt.GetRow(), evt.GetCol(), evt.GetPosition ()))
evt.Skip()

def OnLabelLeftDCli ck(self, evt):
self.log.write( "OnLabelLeftDCl ick: (%d,%d) %s\n" %
(evt.GetRow(), evt.GetCol(), evt.GetPosition ()))
evt.Skip()

def OnLabelRightDCl ick(self, evt):
self.log.write( "OnLabelRightDC lick: (%d,%d) %s\n" %
(evt.GetRow(), evt.GetCol(), evt.GetPosition ()))
evt.Skip()
def OnRowSize(self, evt):
self.log.write( "OnRowSize: row %d, %s\n" %
(evt.GetRowOrCo l(), evt.GetPosition ()))
evt.Skip()

def OnColSize(self, evt):
self.log.write( "OnColSize: col %d, %s\n" %
(evt.GetRowOrCo l(), evt.GetPosition ()))
evt.Skip()

def OnRangeSelect(s elf, evt):
if evt.Selecting() :
self.log.write( "OnRangeSel ect: top-left %s, bottom-right %s\n" %
(evt.GetTopLeft Coords(),
evt.GetBottomRi ghtCoords()))
evt.Skip()
def OnCellChange(se lf, evt):
self.log.write( "OnCellChan ge: (%d,%d) %s\n" %
(evt.GetRow(), evt.GetCol(), evt.GetPosition ()))

# Show how to stay in a cell that has bad data. We can't just
# call SetGridCursor here since we are nested inside one so it
# won't have any effect. Instead, set coordinates to move to in
# idle time.
value = self.GetCellVal ue(evt.GetRow() , evt.GetCol())
if value == 'no good':
self.moveTo = evt.GetRow(), evt.GetCol()
def OnIdle(self, evt):
if self.moveTo != None:
self.SetGridCur sor(self.moveTo[0], self.moveTo[1])
self.moveTo = None
evt.Skip()
def OnSelectCell(se lf, evt):
self.log.write( "OnSelectCe ll: (%d,%d) %s\n" %
(evt.GetRow(), evt.GetCol(), evt.GetPosition ()))

# Another way to stay in a cell that has a bad value...
row = self.GetGridCur sorRow()
col = self.GetGridCur sorCol()
if self.IsCellEdit ControlEnabled( ):
self.HideCellEd itControl()
self.DisableCel lEditControl()
value = self.GetCellVal ue(row, col)
if value == 'no good 2':
return # cancels the cell selection
evt.Skip()
def OnEditorShown(s elf, evt):
if evt.GetRow() == 6 and evt.GetCol() == 3 and \
wxMessageBox("A re you sure you wish to edit this cell?",
"Checking", wxYES_NO) == wxNO:
evt.Veto()
return

self.log.write( "OnEditorSh own: (%d,%d) %s\n" %
(evt.GetRow(), evt.GetCol(), evt.GetPosition ()))
evt.Skip()
def OnEditorHidden( self, evt):
if evt.GetRow() == 6 and evt.GetCol() == 3 and \
wxMessageBox("A re you sure you wish to finish editing this
cell?",
"Checking", wxYES_NO) == wxNO:
evt.Veto()
return

self.log.write( "OnEditorHidden : (%d,%d) %s\n" %
(evt.GetRow(), evt.GetCol(), evt.GetPosition ()))
evt.Skip()
def OnEditorCreated (self, evt):
self.log.write( "OnEditorCreate d: (%d, %d) %s\n" %
(evt.GetRow(), evt.GetCol(), evt.GetControl( )))

#---------------------------------------------------------------------------

class TestFrame(wxFra me):
def __init__(self, parent, log):
wxFrame.__init_ _(self, parent, -1, "Simple Grid Demo",
size=(640,480))
grid = SimpleGrid(self , log)

#---------------------------------------------------------------------------

if __name__ == '__main__':
import sys
app = wxPySimpleApp()
frame = TestFrame(None, sys.stdout)
frame.Show(True )
app.MainLoop()

#---------------------------------------------------------------------------
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3146
by: sivaprasad06 | last post by:
Hi, I have a editable combo box editor as a cell editor for JTable. I want use only key board to enter data into jtable. so i am using ALT+Down comobination for making cell editiable in the jtable. when user clicks that combination what ever editor present in that cell will appear. I am using tab for traversing all cells in table.
1
7087
by: matthiasjanes | last post by:
dear all, I just need a little help. could anyone give real code example (simple) how to read the value of a grid cell. i could not figure it out and really would like to do a simple spreadsheet application in wxpython (my first try with wxpython gui)
4
5380
by: Piet | last post by:
Hello. I am working on an XML editor that will not display the xml file as plain text, but will rather work with a combination of a tree view for the main element nodes and some kind of tabular view to view attributes. By this way, the user (i.e. me) will only have the opportunity to change textual contents and attribute values, but neither element nor attribute names. Building the tree view was not a problem, but I haven´t found a good...
0
1240
by: fowlertrainer | last post by:
Hi ! I have a little problem with wxGrid. In Delphi I can set in grids how I want to select cells. I can select only individual cells, or ranges. In my program I don't wanna use ranges. But I don't find any methods or properties what can set this option. The range selection mode is disturb the users.
40
4640
by: Edward Elliott | last post by:
At the risk of flogging a dead horse, I'm wondering why Python doesn't have any multiline comments. One can abuse triple-quotes for that purpose, but that's obviously not what it's for and doesn't nest properly. ML has a very elegant system for nested comments with (* and *). Using an editor to throw #s in front of every line has limitations. Your editor has to support it and you have to know how to use that feature. Not exactly...
1
1975
by: John | last post by:
Can anyone give me hints on how to do this? I need to have a single column in a dataviewgrid whose cells can be set to either a combo box, a text edit or a check box, different for each row of the grid. -- "I have nothing but the greatest respect for other peoples' crackpot beliefs". -- Sam the Eagle.
3
25072
by: Richard Lewis Haggard | last post by:
I have a DataGridView which has a cell that is going to contain what might be a large amount of text data. The UI designed has decreed that each row will have a button that toggles the row's multiline display such that, when the button is up, the row is a single line and when the button is down, the row enters a multiline mode so that the cell can expand to a height great enough to display all of the cell's contents. I've figured out how to...
3
7452
by: Richard Lewis Haggard | last post by:
I have an unbound DataGridView control that has some cells that may contain more multi-line text than can be completely displayed in the available screen space. When the height of its row to exceeds the DataGridView's height, it becomes impossible to view the out of sight portion of the row. Down arrow of the text cursor simply moves the caret down out of sight. Contrary to expectations, the DataGridView's scroll bar doesn't smoothly...
0
973
by: pieandpeas | last post by:
Hi, I've got a table with a column which is frequently used to store paragraphs, some with new lines in between. for example a aaaaa aa aaaaaaa. bbb bb. cc ccccccccccccc. I'd like to filter these results in vb, so that the new lines (or whatever it is seperating the lines) is removed, making it so that i can instead have a cell, or a representation of a cell on a page as one long string, spaces and full stops still included. e.g
0
9587
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.