svlad

Check-in [f83fb14078]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Logic separated from presentation.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:f83fb14078a2d9283ccb0a56582f04659ee209f6
User & Date: severak 2012-05-05 16:30:53
Context
2012-05-05
21:20
SQLITE logic now works. Table editing needs to be solved. check-in: 4fc6193906 user: severak tags: trunk
16:30
Logic separated from presentation. check-in: f83fb14078 user: severak tags: trunk
2012-04-22
00:33
Added an example of using plotting tool together with jo.geometry . check-in: e2a2eb0dc2 user: severak tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added logic/basic.lua.





















































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
--
--Skeleton for Svlad's logic
--
module("logic.basic",package.seeall)
require "jo"

logic=jo.object:clone():rewriteSlots({

  init=function(self)
    print("logic:init()")
  end,
  
  close=function(self)
    print("logic:close()")
  end,
  
  tableListChange=function(self,text)
    print("logic:tableListChange("..text..")")
  end,
  
  editCell=function(self,x,y,text)
    print("logic:editCell("..x..", "..y..", "..text..")")
  end,
  
  getCellForEdit=function(self,x,y,text)
    print("logic:getCellForEdit("..x..", "..y..", "..text..")")
    return text
  end,
  
  processQuery=function(self,query)
    print("logic:processQuery("..query..")")
  end,
  
  colHeaderClick=function(self,index)
    print("logic:colHeaderClick("..index..")")
  end,

  rowHeaderClick=function(self,index)
    print("logic:rowHeaderClick("..index..")")
  end

})

Added logic/example.lua.



































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
--
--example/test logic
--
--some well known mathematical things
--
module("logic.example",package.seeall)
basic=require "logic.basic"

function showCoords()
  for x=0,100 do
    for y=0,100 do
      GUI.setCell(x,y,x.."x"..y)
    end
  end
end

function showMulti()
  for x=0,20 do
    for y=0,20 do
      if x==0 or y==0 then
        if x==0 then
          GUI.setCell(x,y,y)
        else
          GUI.setCell(x,y,x)  
        end
      else
        GUI.setCell(x,y,x*y)
      end 
    end
  end
end

function showPascal()
  pascal={}
  for x=0,20 do
    pascal[x]={}
    for y=0,20 do
      if x==0 or y==0 then
        pascal[x][y]=1
      else
        pascal[x][y]=pascal[x-1][y]+pascal[x][y-1]  
      end
      GUI.setCell(x,y,pascal[x][y])
    end
  end
end

logic=basic.logic:rewriteSlots({
  modes={"Coordinations","Multiplication table","Pascal triangle"},
  
  init=function(self)
    GUI.setTableList(self.modes)
  end,
  
  tableListChange=function(self,mode)
    GUI.resetTable()
    if mode==self.modes[1] then
      showCoords()
    elseif mode==self.modes[2] then
      showMulti()
    elseif mode==self.modes[3] then
      showPascal()
    end
  end
})

Added logic/sqlite.lua.



























































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module("logic.sqlite",package.seeall)
require "jo"
require "luasql.sqlite3"
original=require "logic.basic"

function showresult(dotaz)
  res=assert(conn:execute(dotaz))
  if type(res)=="number" then
    VCL.ShowMessage("Zmeneno "..res.." radek.")
  else
    cnames=res:getcolnames()
    tabl.colCount=#cnames+1
    tabl.rowCount=1
    for k,v in pairs(cnames) do
      tabl:SetCell(k,0,v)
    end
    row=res:fetch({})
    while row do
      r=tabl:AddRow()
      tabl:SetCell(0,r,r)
      for k,v in pairs(row) do
        tabl:SetCell(k,r,v)
      end
      row=res:fetch(row)   
    end
    res:close()
  end
end


logic=original:rewriteSlots({

   init=function(self)
      env=luasql.sqlite3()
      conn=assert(env:connect("prachy.db3"))
   end,

   processQuery=function(self,sql)
      passed,mesg=pcall(showresult,dotaz)
      if not passed then
        VCL.ShowMessage(mesg)  
      end  
   end  

})

Changes to svlad.lua.


1



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28



29
30
31
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

59
60



61
62
63
64
65
66
67
68
69
70
71
72




























73
74
75
76
77
78
79
..
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101



102
103
104
105
106
107
108

--Skeleton SVLADa



require "vcl"
require "luasql.sqlite3"

function showresult(dotaz)
  res=assert(conn:execute(dotaz))
  if type(res)=="number" then
    VCL.ShowMessage("Zmeneno "..res.." radek.")
  else
    cnames=res:getcolnames()
    tabl.colCount=#cnames+1
    tabl.rowCount=1
    for k,v in pairs(cnames) do
      tabl:SetCell(k,0,v)
    end
    row=res:fetch({})
    while row do
      r=tabl:AddRow()
      tabl:SetCell(0,r,r)
      for k,v in pairs(row) do
        tabl:SetCell(k,r,v)
      end
      row=res:fetch(row)   
    end
    res:close()
  end
end




function sql_dotaz(sender)
  dotaz=table.concat(sql:GetText())
  passed,mesg=pcall(showresult,dotaz)
  if not passed then
    VCL.ShowMessage(mesg)  
  end
end

function listtables()
  showresult("SELECT * FROM sqlite_master")

end

function appEnd()
  conn:close()
  --main:Free()
end

function getEdit(sender,x,y,v)
  print("getEdit")
  print(x,y,v)
  return v
end

function setEdit(sender,x,y,v)
  print("setEdit")
  print(x,y,v)
  return false
end

function OnHeaderClick(sender,IsColumn,index)

  print("OnHeaderClick")
  print(IsColumn,index)



end

function showAbout(sender)
  VCL.ShowMessage("SVLAD\n\nTable editor by Severak")
end

function showTables(sender)
  showresult("SELECT * FROM sqlite_master WHERE type='table' ORDER BY name ASC")
end

env=luasql.sqlite3()
conn=assert(env:connect("prachy.db3"))





























menu={
  {caption="&Databases",submenu={
    {caption="&Attach"},
    {caption="&Import"},
    {caption="&Export"}
  }},
................................................................................
    {name="about",caption="&About",onclick="showAbout"},
    {caption="-"},
    {caption="&Info"}
  }}
}

main=VCL.Form("mainWin")
main._={ caption="Svlad", width=500, height=500, onshow="listtables", onclose="appEnd" }

mainMenu=VCL.MainMenu("mm")
mainMenu:LoadFromTable(menu)

tabl=VCL.StringGrid(main,"table")
tabl._={ align="alClient", rowCount=99, ColCount=99,  AutoEdit=1, Options="goEditing,goRowSizing,goColSizing", OnSetEditText="setEdit", OnGetEditText="getEdit", OnHeaderClick="OnHeaderClick" }

p=VCL.Panel(main,"panel")
p._={ align="alBottom", height=90 }




sql=VCL.Memo(p,"sql")
sql._={ align="alClient",  font={name="Courier"} }

fire=VCL.Button(p,"fire")
fire._={ align="alBottom", caption="PAL!", onclick="sql_dotaz" }

main:ShowModal()
>
|
>
>
>

<
<
<
<
|
|
|
|
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<

>
>
>

|
<
<
<
<
<
<
<
<
>



|




|
<
<



<
|




>
|
<
>
>
>







|


|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|










>
>
>







1
2
3
4
5
6




7
8
9
10




11












12
13
14
15
16
17








18
19
20
21
22
23
24
25
26
27


28
29
30

31
32
33
34
35
36
37

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
..
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
--
--SVLAD
--
--custom spreadsheet with changeable logic
--
require "vcl"




logicName="basic"
if arg and type(arg)=="table" then
  logicName=arg[1]
  print("Loading custom logic "..logicName)




end













brain=require("logic."..logicName)
logic=brain.logic

function sql_dotaz(sender)
  dotaz=table.concat(sql:GetText(),"\n")








  logic:processQuery(dotaz)
end

function appEnd()
  logic:close()
  --main:Free()
end

function getEdit(sender,x,y,v)
  return logic:getCellForEdit(x,y,v)


end

function setEdit(sender,x,y,v)

  logic:editCell(x,y,v)
  return false
end

function OnHeaderClick(sender,IsColumn,index)
  if IsColumn then
    logic:colHeaderClick(index)

  else
    logic:rowHeaderClick(index)
  end
end

function showAbout(sender)
  VCL.ShowMessage("SVLAD\n\nTable editor by Severak")
end

function showTables(sender)
  --showresult("SELECT * FROM sqlite_master WHERE type='table' ORDER BY name ASC")
end

function tableListChange(sender)
  logic:tableListChange(tablelist.Text)
end

function appStart()
  logic:init()
end

GUI={
  setTableList=function(tabl)
    tablelist:SetText(tabl)
  end,
  
  resetTable=function()
    tabl.colCount=1
    tabl.rowCount=1
  end,
  
  setCell=function(x,y,v)
    if tabl.rowCount<y+1 then
      tabl.rowCount=y+1
      print("+col")
    end
    if tabl.colCount<x+1 then
      tabl.colCount=x+1
      print("+row")
    end
    tabl:SetCell(x,y,v)
  end
}

menu={
  {caption="&Databases",submenu={
    {caption="&Attach"},
    {caption="&Import"},
    {caption="&Export"}
  }},
................................................................................
    {name="about",caption="&About",onclick="showAbout"},
    {caption="-"},
    {caption="&Info"}
  }}
}

main=VCL.Form("mainWin")
main._={ caption="Svlad", width=500, height=500, onshow="appStart", onclose="appEnd" }

mainMenu=VCL.MainMenu("mm")
mainMenu:LoadFromTable(menu)

tabl=VCL.StringGrid(main,"table")
tabl._={ align="alClient", rowCount=99, ColCount=99,  AutoEdit=1, Options="goEditing,goRowSizing,goColSizing", OnSetEditText="setEdit", OnGetEditText="getEdit", OnHeaderClick="OnHeaderClick" }

p=VCL.Panel(main,"panel")
p._={ align="alBottom", height=90 }

tablelist=VCL.ComboBox(main,"tbllist")
tablelist._={ align="alTop", onchange="tableListChange"}

sql=VCL.Memo(p,"sql")
sql._={ align="alClient",  font={name="Courier"} }

fire=VCL.Button(p,"fire")
fire._={ align="alBottom", caption="PAL!", onclick="sql_dotaz" }

main:ShowModal()