Debian Codegraph @

wxgeometrie/modules/traceur/tableau.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 #import param
4 #from pylib import *
5 import wx.grid as gridlib
6 import wx
7 #---------------------------------------------------------------------------
8
9 class EditorsAndRenderersGrid(gridlib.Grid):
10 def __init__(self, parent):
11 gridlib.Grid.__init__(self, parent)
12 self.SetDefaultCellAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
13 self.CreateGrid(8, 2)
14 self.EnableDragRowSize(False)
15 self.SetColLabelValue(0, "X")
16 self.SetColLabelValue(1, "Y")
17 self.SetCellValue(0, 0, "Valeurs")
18 self.SetCellValue(0, 1, "Valeur libre")
19 self.liste = ["Valeur libre"] + ["Y%s"%(i+1) for i in range(param.nombre_courbes)]
20 self.choix = gridlib.GridCellChoiceEditor(self.liste, False)
21 self.SetCellEditor(0, 1, self.choix)
22 self.SetReadOnly(0, 0, True)
23 #self.SetCellAlignment(0, 1, wx.CENTER, wx.CENTER)
24 self.SetRowLabelSize(30)
25 self.SetColSize(0, 75)
26 self.SetColSize(1, 75)
27 self.AutoSizeRows(True)
28 self.Bind(gridlib.EVT_GRID_CELL_LEFT_DCLICK, self.OnLeftDClick)
29 self.Bind(gridlib.EVT_GRID_CELL_CHANGE, self.OnChange)
30 self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
31 self.SetGridCursor(1, 0)
32 #self.SetScrollbars(0, 0, 0, 0)
33
34
35 def OnKeyDown(self, evt):
36 if evt.KeyCode() != wx.WXK_DELETE:
37 evt.Skip()
38 else:
39 print(self.GetSelectedCells())
40 for couple in self.GetSelectedCells():
41 self.SetCellValue(couple[0], couple[1], "")
42 print(self.GetSelectionBlockTopLeft())
43 print(self.GetSelectionBlockBottomRight())
44 for (couple0, couple1) in zip(self.GetSelectionBlockTopLeft(), self.GetSelectionBlockBottomRight()):
45 i0, j0 = couple0
46 i1, j1 = couple1
47 couples = ((i,j) for i in range(i0, i1 + 1) for j in range(j0, j1 + 1))
48 for couple in couples:
49 self.SetCellValue(couple[0], couple[1], "")
50 self.SetCellValue(self.GetGridCursorRow(), self.GetGridCursorCol(), "")
51 #self.SetScrollbars(0, 0, 0, 0)
52
53
54 # I do this because I don't like the default behaviour of not starting the
55 # cell editor on double clicks, but only a second click.
56 def OnLeftDClick(self, event = None):
57 if self.CanEnableCellControl():
58 self.EnableCellEditControl()
59 #self.SetScrollbars(0, 0, 0, 0)
60
61 def OnChange(self, event = None):
62 #print help(event.__class__)
63 l = event.GetRow()
64 c = event.GetCol()
65 print(event.__class__.__name__)
66 if c == 0 and l != 0:
67 try:
68 choix_fonction = self.choix.GetValue()
69 if choix_fonction != self.liste[0]:
70 i = int(choix_fonction[1:])
71 intervalles = self.intervalles[i].GetValue().split("|")
72 equations = self.equations[i].GetValue().split("|")
73 self.SetCellValue(l, 1, str(float(self.GetCellValue(l, 0))**2))
74 except:
75 event.Veto()
76 if l == self.GetNumberRows() - 1:
77 self.AppendRows()
78 self.MoveCursorDown(False)
79 #self.SetScrollbars(0, 0, 0, 0)
80
81
82 #---------------------------------------------------------------------------
83 class TableauValeurs(wx.MiniFrame):
84 def __init__(self, parent):
85 wx.MiniFrame.__init__(self, parent, "Tableau de valeurs", style=wx.DEFAULT_FRAME_STYLE | wx.TINY_CAPTION_HORIZ, size=(250,300))
86 self.parent = parent
87 p = self.panel = QWidget(self)
88
89 sizer = QVBoxLayout()
90 barre = QHBoxLayout()
91 creer = QPushButton(p, -1, "Creer les points")
92 effacer = QPushButton(p, -1, "Effacer")
93 barre.Add(creer, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5)
94 barre.Add(effacer, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5)
95
96 self.grid = grid = EditorsAndRenderersGrid(p)
97 self.Bind(wx.EVT_BUTTON, self.efface, effacer)
98 sizer.addWidget(barre, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5)
99 sizer.addWidget(grid, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.EXPAND , 5)
100
101 #p.SetSizer(sizer)
102 p.setLayout(sizer)
103 x, y = p.GetSize().GetWidth(), p.GetSize().GetHeight()
104 self.SetClientSize(wx.Size(x + 15, y + 15))
105 grid.AdjustScrollbars()
106
107 def efface(self, event = None):
108 self.grid.ClearGrid()
109
110 #---------------------------------------------------------------------------
111 if __name__ == '__main__':
112 import sys
113 app = wx.PySimpleApp()
114 frame = TableauValeurs(None)
115 frame.Show(True)
116 app.MainLoop()
117 #---------------------------------------------------------------------------