~darragh-ssa/d-cm/d-cm

« back to all changes in this revision

Viewing changes to DGO/dgo.py

  • Committer: Darragh van Tichelen
  • Date: 2010-05-14 10:30:14 UTC
  • Revision ID: darragh.ssa@gmail.com-20100514103014-5ycjt6xh40ea6y8k
First Import under bazaar

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- coding: utf-8 -*-
 
3
# generated by wxGlade 0.6.3 on Sat May  1 12:03:34 2010
 
4
 
 
5
import wx,os,sys,dac
 
6
sys.path.append(os.getcwd())
 
7
import basics
 
8
 
 
9
# begin wxGlade: extracode
 
10
# end wxGlade
 
11
 
 
12
class Settings(wx.Frame):
 
13
    def __init__(self, *args, **kwds):
 
14
        # begin wxGlade: Settings.__init__
 
15
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
 
16
        wx.Frame.__init__(self, *args, **kwds)
 
17
        self.list_ctrl_2 = wx.ListCtrl(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
 
18
        self.list_ctrl_3 = wx.ListCtrl(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
 
19
        self.list_ctrl_1 = wx.ListCtrl(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
 
20
        self.list_ctrl_4 = wx.ListCtrl(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
 
21
        self.list_ctrl_5 = wx.ListCtrl(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
 
22
        self.button_3 = wx.Button(self, wx.ID_OK, "")
 
23
 
 
24
        self.__set_properties()
 
25
        self.__do_layout()
 
26
 
 
27
        self.Bind(wx.EVT_BUTTON, self.setok, self.button_3)
 
28
        # end wxGlade
 
29
 
 
30
    def __set_properties(self):
 
31
        # begin wxGlade: Settings.__set_properties
 
32
        self.SetTitle("DGO: Settings.py")
 
33
        self.SetSize((1200, 300))
 
34
        # end wxGlade
 
35
 
 
36
    def __do_layout(self):
 
37
        # begin wxGlade: Settings.__do_layout
 
38
        sizer_4 = wx.BoxSizer(wx.VERTICAL)
 
39
        sizer_5 = wx.BoxSizer(wx.VERTICAL)
 
40
        sizer_6 = wx.BoxSizer(wx.HORIZONTAL)
 
41
        sizer_8 = wx.BoxSizer(wx.VERTICAL)
 
42
        sizer_7 = wx.BoxSizer(wx.VERTICAL)
 
43
        sizer_7.Add(self.list_ctrl_2, 1, wx.EXPAND, 0)
 
44
        sizer_7.Add(self.list_ctrl_3, 1, wx.EXPAND, 0)
 
45
        sizer_6.Add(sizer_7, 1, wx.EXPAND, 0)
 
46
        sizer_6.Add(self.list_ctrl_1, 1, wx.EXPAND, 0)
 
47
        sizer_8.Add(self.list_ctrl_4, 1, wx.EXPAND, 0)
 
48
        sizer_8.Add(self.list_ctrl_5, 1, wx.EXPAND, 0)
 
49
        sizer_6.Add(sizer_8, 1, wx.EXPAND, 0)
 
50
        sizer_5.Add(sizer_6, 1, wx.EXPAND, 0)
 
51
        sizer_5.Add(self.button_3, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0)
 
52
        sizer_4.Add(sizer_5, 1, wx.EXPAND, 0)
 
53
        self.SetSizer(sizer_4)
 
54
        self.Layout()
 
55
        # end wxGlade
 
56
        
 
57
    def init(self,loc,name):
 
58
        if loc.endswith("/"):
 
59
            ln=loc+name+"/settings.py"
 
60
        else:
 
61
            ln=loc+"/"+name+"/settings.py"
 
62
        try:
 
63
            f=open(ln,"r")
 
64
        except IOError:
 
65
            print "Not correct settings.py file"
 
66
        else:
 
67
            i=0
 
68
            ls=[]
 
69
            for line in f.readlines():
 
70
                if "=" in line:
 
71
                    x,y=line.strip().split(" = ")
 
72
                    if y=="(" or y=="{":
 
73
                        pass
 
74
                    else:
 
75
                        ls.append([x,y])
 
76
                    i+=1
 
77
            self.list_ctrl_1.InsertColumn(0, 'Variable')
 
78
            self.list_ctrl_1.InsertColumn(1, 'Value')
 
79
            self.list_ctrl_1.SetColumnWidth(0, 200)
 
80
            self.list_ctrl_1.SetColumnWidth(1, 200)
 
81
            for item in ls:
 
82
                num_items = self.list_ctrl_1.GetItemCount()
 
83
                self.list_ctrl_1.InsertStringItem(num_items, item[0])
 
84
                self.list_ctrl_1.SetStringItem(num_items, 1, item[1])
 
85
            self.list_ctrl_2.InsertColumn(0, 'Installed App\'s')
 
86
            self.list_ctrl_2.SetColumnWidth(0, 400)
 
87
            for item in self.gev("INSTALLED_APPS",ln):
 
88
                num_items = self.list_ctrl_2.GetItemCount()
 
89
                self.list_ctrl_2.InsertStringItem(num_items, item)
 
90
            self.list_ctrl_3.InsertColumn(0, 'Middleware Classes')
 
91
            self.list_ctrl_3.SetColumnWidth(0, 400)
 
92
            for item in self.gev("MIDDLEWARE_CLASSES",ln):
 
93
                num_items = self.list_ctrl_3.GetItemCount()
 
94
                self.list_ctrl_3.InsertStringItem(num_items, item)
 
95
            self.list_ctrl_4.InsertColumn(0, 'Template Dirs')
 
96
            self.list_ctrl_4.SetColumnWidth(0, 400)
 
97
            for item in self.gev("TEMPLATE_DIRS",ln):
 
98
                num_items = self.list_ctrl_4.GetItemCount()
 
99
                self.list_ctrl_4.InsertStringItem(num_items, item)
 
100
            self.list_ctrl_5.InsertColumn(0, 'Template Loaders')
 
101
            self.list_ctrl_5.SetColumnWidth(0, 400)
 
102
            for item in self.gev("TEMPLATE_LOADERS",ln):
 
103
                num_items = self.list_ctrl_5.GetItemCount()
 
104
                self.list_ctrl_5.InsertStringItem(num_items, item)
 
105
    
 
106
    def gev(self,varname,loc):
 
107
        f=open(loc,"r")
 
108
        i=0
 
109
        x=False
 
110
        lns=[]
 
111
        for line in f.readlines():
 
112
            if varname in line:
 
113
                x=True
 
114
            elif ")" in line:
 
115
                x=False
 
116
            elif x:
 
117
                lns.append(line.strip())
 
118
        return lns
 
119
 
 
120
    def setok(self, event): # wxGlade: Settings.<event_handler>
 
121
        self.Close()
 
122
 
 
123
# end of class Settings
 
124
 
 
125
 
 
126
class Welcome(wx.Frame):
 
127
    def __init__(self, *args, **kwds):
 
128
        # begin wxGlade: Welcome.__init__
 
129
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
 
130
        wx.Frame.__init__(self, *args, **kwds)
 
131
        self.label_2 = wx.StaticText(self, -1, "Starting a new djangoproject...")
 
132
        self.label_3 = wx.StaticText(self, -1, "project name")
 
133
        self.proname = wx.TextCtrl(self, -1, "")
 
134
        self.label_3_copy_copy = wx.StaticText(self, -1, "project location")
 
135
        self.proloc = wx.TextCtrl(self, -1, "")
 
136
        self.label_3_copy = wx.StaticText(self, -1, "media location")
 
137
        self.medloc = wx.TextCtrl(self, -1, "")
 
138
        self.label_3_copy_1 = wx.StaticText(self, -1, "admin location")
 
139
        self.adminloc = wx.TextCtrl(self, -1, "")
 
140
        self.label_1 = wx.StaticText(self, -1, "Continue?")
 
141
        self.button_1 = wx.Button(self, wx.ID_YES, "")
 
142
        self.button_2 = wx.Button(self, wx.ID_NO, "")
 
143
 
 
144
        self.__set_properties()
 
145
        self.__do_layout()
 
146
 
 
147
        self.Bind(wx.EVT_BUTTON, self.yes, self.button_1)
 
148
        self.Bind(wx.EVT_BUTTON, self.no, self.button_2)
 
149
        # end wxGlade
 
150
 
 
151
    def __set_properties(self):
 
152
        # begin wxGlade: Welcome.__set_properties
 
153
        self.SetTitle("Welcome")
 
154
        # end wxGlade
 
155
 
 
156
    def __do_layout(self):
 
157
        # begin wxGlade: Welcome.__do_layout
 
158
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
 
159
        sizer_2 = wx.BoxSizer(wx.VERTICAL)
 
160
        sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
 
161
        grid_sizer_1 = wx.GridSizer(3, 2, 0, 0)
 
162
        sizer_2.Add(self.label_2, 0, 0, 0)
 
163
        grid_sizer_1.Add(self.label_3, 0, wx.EXPAND, 0)
 
164
        grid_sizer_1.Add(self.proname, 0, wx.EXPAND, 0)
 
165
        grid_sizer_1.Add(self.label_3_copy_copy, 0, wx.EXPAND, 0)
 
166
        grid_sizer_1.Add(self.proloc, 0, wx.EXPAND, 0)
 
167
        grid_sizer_1.Add(self.label_3_copy, 0, wx.EXPAND, 0)
 
168
        grid_sizer_1.Add(self.medloc, 0, wx.EXPAND, 0)
 
169
        grid_sizer_1.Add(self.label_3_copy_1, 0, wx.EXPAND, 0)
 
170
        grid_sizer_1.Add(self.adminloc, 0, wx.EXPAND, 0)
 
171
        sizer_2.Add(grid_sizer_1, 0, wx.EXPAND, 0)
 
172
        sizer_3.Add(self.label_1, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0)
 
173
        sizer_3.Add(self.button_1, 0, 0, 0)
 
174
        sizer_3.Add(self.button_2, 0, 0, 0)
 
175
        sizer_2.Add(sizer_3, 0, wx.EXPAND, 0)
 
176
        sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
 
177
        self.SetSizer(sizer_1)
 
178
        sizer_1.Fit(self)
 
179
        self.Layout()
 
180
        # end wxGlade
 
181
 
 
182
    def yes(self, event): # wxGlade: Welcome.<event_handler>
 
183
        '''
 
184
        1.Check if django is installed, if not give the possibility between -distro or -recent stable or -recent dev
 
185
        2.create new project
 
186
        3.show settings.py in easy editable way
 
187
        4.apache or webserver configuration
 
188
        '''
 
189
        try:
 
190
            import django
 
191
        except ImportError:
 
192
            print "django not installed"
 
193
            #open install dialog
 
194
        try:
 
195
            if os.getcwd()!=self.proloc.GetValue():
 
196
                os.chdir(self.proloc.GetValue())
 
197
            os.system("django-admin.py startproject "+self.proname.GetValue())
 
198
            #Set media and admin media
 
199
        except:
 
200
            print "project creation error"
 
201
            #help dialog
 
202
        Set=Settings(None,-1,"")
 
203
        Set.Show()
 
204
        Set.init(self.proloc.GetValue(),self.proname.GetValue())
 
205
        self.Close()
 
206
 
 
207
    def no(self, event): # wxGlade: Welcome.<event_handler>
 
208
        self.Close()
 
209
 
 
210
# end of class Welcome
 
211
 
 
212
class DGOConf(wx.Frame):
 
213
    def __init__(self, *args, **kwds):
 
214
        # begin wxGlade: DGOConf.__init__
 
215
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
 
216
        wx.Frame.__init__(self, *args, **kwds)
 
217
        self.panel_1 = wx.Panel(self, -1)
 
218
        self.proloc = wx.TextCtrl(self.panel_1, -1, "")
 
219
        self.proname = wx.TextCtrl(self.panel_1, -1, "")
 
220
        self.confbut = wx.Button(self.panel_1, -1, "C&onfigure")
 
221
        self.cancbut = wx.Button(self.panel_1, wx.ID_CANCEL, "")
 
222
 
 
223
        self.__set_properties()
 
224
        self.__do_layout()
 
225
 
 
226
        self.Bind(wx.EVT_BUTTON, self.conf, self.confbut)
 
227
        self.Bind(wx.EVT_BUTTON, self.cancel, self.cancbut)
 
228
        # end wxGlade
 
229
 
 
230
    def __set_properties(self):
 
231
        # begin wxGlade: DGOConf.__set_properties
 
232
        self.SetTitle("DGO Configuration")
 
233
        # end wxGlade
 
234
 
 
235
    def __do_layout(self):
 
236
        # begin wxGlade: DGOConf.__do_layout
 
237
        sizer_17 = wx.BoxSizer(wx.VERTICAL)
 
238
        sizer_18 = wx.BoxSizer(wx.VERTICAL)
 
239
        sizer_19 = wx.BoxSizer(wx.HORIZONTAL)
 
240
        sizer_18.Add(self.proloc, 0, wx.ADJUST_MINSIZE, 0)
 
241
        sizer_18.Add(self.proname, 0, wx.ADJUST_MINSIZE, 0)
 
242
        sizer_19.Add(self.confbut, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
 
243
        sizer_19.Add(self.cancbut, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
 
244
        sizer_18.Add(sizer_19, 0, wx.EXPAND, 0)
 
245
        self.panel_1.SetSizer(sizer_18)
 
246
        sizer_17.Add(self.panel_1, 1, wx.EXPAND, 0)
 
247
        self.SetSizer(sizer_17)
 
248
        sizer_17.Fit(self)
 
249
        self.Layout()
 
250
        # end wxGlade
 
251
 
 
252
    def conf(self, event): # wxGlade: DGOConf.<event_handler>
 
253
        basics.config_set("proloc",'"'+self.proloc.GetValue()+'"',os.path.dirname(__file__)+"/dac.py")
 
254
        basics.config_set("proname",'"'+self.proname.GetValue()+'"',os.path.dirname(__file__)+"/dac.py")
 
255
        self.Close()
 
256
 
 
257
    def cancel(self, event): # wxGlade: DGOConf.<event_handler>
 
258
        self.Close()
 
259
 
 
260
# end of class DGOConf
 
261
 
 
262
if __name__ == "__main__":
 
263
    app = wx.PySimpleApp(0)
 
264
    wx.InitAllImageHandlers()
 
265
    if len(sys.argv)>1:
 
266
        if len(sys.argv)==4 and sys.argv[1]=="set":
 
267
            Set = Settings(None, -1, "")
 
268
            app.SetTopWindow(Set)
 
269
            Set.Show()
 
270
            Set.init(sys.argv[2],sys.argv[3])
 
271
        elif sys.argv[1]=="conf":
 
272
            Conf=DGOConf(None,-1,"")
 
273
            app.SetTopWindow(Conf)
 
274
            Conf.Show()
 
275
    else:
 
276
        Welcome = Welcome(None, -1, "")
 
277
        app.SetTopWindow(Welcome)
 
278
        Welcome.Show()
 
279
    app.MainLoop()