[20] | 1 | import wx, sys, os, gettext, string, time |
---|
| 2 | import wx.wizard as wiz |
---|
| 3 | from config import generate_ip_list, drbl_dcs, remote_functions |
---|
| 4 | |
---|
| 5 | cat = gettext.GNUTranslations(open('../langs/%s.mo' % os.getenv('LANG'))) |
---|
| 6 | _ = cat.gettext |
---|
| 7 | |
---|
| 8 | global selected_clients, selected_func |
---|
| 9 | selected_clients = ['-nl',''] |
---|
| 10 | selected_func = [''] |
---|
| 11 | |
---|
| 12 | #---------------------------------------------------------------------- |
---|
| 13 | def makePageTitle(wizPg, title): |
---|
| 14 | sizer = wx.BoxSizer(wx.VERTICAL) |
---|
| 15 | wizPg.SetSizer(sizer) |
---|
| 16 | title = wx.StaticText(wizPg, -1, title) |
---|
| 17 | title.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD)) |
---|
| 18 | sizer.Add(title, 0, wx.ALIGN_CENTRE|wx.ALL, 5) |
---|
| 19 | sizer.Add(wx.StaticLine(wizPg, -1), 0, wx.EXPAND|wx.ALL, 5) |
---|
| 20 | return sizer |
---|
| 21 | |
---|
| 22 | #---------------------------------------------------------------------- |
---|
| 23 | class remoteLinuxPage(wiz.PyWizardPage): |
---|
| 24 | def __init__(self, parent, title): |
---|
| 25 | wiz.PyWizardPage.__init__(self, parent) |
---|
| 26 | self.next = self.prev = None |
---|
| 27 | self.sizer = makePageTitle(self, title) |
---|
| 28 | |
---|
| 29 | list = [] |
---|
| 30 | for i in range(0, len(remote_functions)): |
---|
| 31 | list.append(remote_functions[i][0] + ' ' + remote_functions[i][1]) |
---|
| 32 | |
---|
| 33 | self.rb = wx.RadioBox(self, -1, '', wx.DefaultPosition, wx.DefaultSize, list, 1, wx.RA_SPECIFY_COLS|wx.NO_BORDER) |
---|
| 34 | self.sizer.Add(self.rb, 0, wx.ALIGN_CENTER|wx.ALL, 50) |
---|
| 35 | self.Bind(wx.EVT_RADIOBOX, self.EvtRadioBox, self.rb) |
---|
| 36 | self.rb.SetSelection(0) |
---|
| 37 | selected_func[0] = remote_functions[0][2] |
---|
| 38 | |
---|
| 39 | def EvtRadioBox(self, event): |
---|
| 40 | selected_func[0] = remote_functions[event.GetSelection()][2] |
---|
| 41 | |
---|
| 42 | def SetNext(self, next): |
---|
| 43 | self.next = next |
---|
| 44 | |
---|
| 45 | def SetPrev(self, prev): |
---|
| 46 | self.prev = prev |
---|
| 47 | |
---|
| 48 | def GetNext(self): |
---|
| 49 | return self.next |
---|
| 50 | |
---|
| 51 | def GetPrev(self): |
---|
| 52 | return self.prev |
---|
| 53 | |
---|
| 54 | #---------------------------------------------------------------------- |
---|
| 55 | class setAllClientsPage(wiz.PyWizardPage): |
---|
| 56 | def __init__(self, parent, title): |
---|
| 57 | wiz.PyWizardPage.__init__(self, parent) |
---|
| 58 | self.next = self.prev = None |
---|
| 59 | self.sizer = makePageTitle(self, title) |
---|
| 60 | self.fuse_next = 0 |
---|
| 61 | |
---|
| 62 | wx.StaticText(self, -1, _('msg_select_all_clients_or_select_part_them'), pos=(10,60), size=(500,100), style=wx.TE_MULTILINE) |
---|
| 63 | wx.StaticText(self, -1, _('msg_set_all_clients_des'), pos=(10,80), size=(500,100), style=wx.TE_MULTILINE) |
---|
| 64 | ox = ['Yes', 'No'] |
---|
| 65 | self.rb = wx.RadioBox(self, -1, _('msg_set_all_clients'), (10,150), (250,75), ox, 1, wx.RA_SPECIFY_COLS|wx.NO_BORDER) |
---|
| 66 | self.Bind(wx.EVT_RADIOBOX, self.EvtRadioBox, self.rb) |
---|
| 67 | |
---|
| 68 | def EvtRadioBox(self, event): |
---|
| 69 | if event.GetSelection() == 0: |
---|
| 70 | selected_clients[0] = '-nl' |
---|
| 71 | if event.GetSelection() == 1: |
---|
| 72 | selected_clients[0] = '-h' |
---|
| 73 | |
---|
| 74 | def SetNext(self, next): |
---|
| 75 | self.next = next |
---|
| 76 | |
---|
| 77 | def SetPrev(self, prev): |
---|
| 78 | self.prev = prev |
---|
| 79 | |
---|
| 80 | def GetNext(self): |
---|
| 81 | next = self.next |
---|
| 82 | self.fuse_next = self.fuse_next + 1 |
---|
| 83 | if self.fuse_next == 2: |
---|
| 84 | if self.rb.GetSelection() == 0: |
---|
| 85 | Command.SetLabel('%s %s %s' % (drbl_dcs, selected_clients[0], selected_func[0])) |
---|
| 86 | #CommandLog.WriteText(os.popen('%s %s %s' % (drbl_dcs, selected_clients[0], selected_func[0])).read()) |
---|
| 87 | next = next.GetNext() |
---|
| 88 | return next |
---|
| 89 | |
---|
| 90 | def GetPrev(self): |
---|
| 91 | self.fuse_next = 0 |
---|
| 92 | prev = self.prev |
---|
| 93 | return prev |
---|
| 94 | |
---|
| 95 | #---------------------------------------------------------------------- |
---|
| 96 | class selectClientsPage(wiz.PyWizardPage): |
---|
| 97 | def __init__(self, parent, title): |
---|
| 98 | wiz.PyWizardPage.__init__(self, parent) |
---|
| 99 | self.next = self.prev = None |
---|
| 100 | self.sizer = makePageTitle(self, title) |
---|
| 101 | |
---|
| 102 | self.SelectedClientsArray = [] |
---|
| 103 | self.SelectedClientsStr = '' |
---|
| 104 | self.fuse_next = self.fuse_prev = 0 |
---|
| 105 | |
---|
| 106 | AllClientsArray = os.popen(generate_ip_list).read().split('\n') |
---|
| 107 | AllClientsArray.remove('') |
---|
| 108 | self.lb = wx.CheckListBox(self, -1, (10,50), (470,250), AllClientsArray) |
---|
| 109 | self.Bind(wx.EVT_CHECKLISTBOX, self.EvtCheckListBox, self.lb) |
---|
| 110 | self.lb.SetSelection(0) |
---|
| 111 | |
---|
| 112 | def EvtCheckListBox(self, event): |
---|
| 113 | index = event.GetSelection() |
---|
| 114 | label = self.lb.GetString(index) |
---|
| 115 | if self.lb.IsChecked(index): |
---|
| 116 | self.SelectedClientsArray.append(label) |
---|
| 117 | if not (self.lb.IsChecked(index)): |
---|
| 118 | self.SelectedClientsArray.remove(label) |
---|
| 119 | self.lb.SetSelection(index) #so that (un)checking also selects (moves the highlight) |
---|
| 120 | |
---|
| 121 | def SetNext(self, next): |
---|
| 122 | self.next = next |
---|
| 123 | |
---|
| 124 | def SetPrev(self, prev): |
---|
| 125 | self.prev = prev |
---|
| 126 | |
---|
| 127 | def GetNext(self): |
---|
| 128 | next = self.next |
---|
| 129 | self.fuse_prev = 0 |
---|
| 130 | self.fuse_next = self.fuse_next + 1 |
---|
| 131 | if self.fuse_next == 2: |
---|
| 132 | if (selected_clients[0] == '-h'): |
---|
| 133 | if len(self.SelectedClientsArray) == 0: |
---|
| 134 | war = wx.MessageDialog(self, 'YOU MUST CHOOSE ONE!!', 'WARNNING!!', wx.OK|wx.ICON_INFORMATION) |
---|
| 135 | war.ShowModal() |
---|
| 136 | war.Destroy() |
---|
| 137 | return self |
---|
| 138 | else: |
---|
| 139 | for x in self.SelectedClientsArray: |
---|
| 140 | self.SelectedClientsStr = x + ' ' + self.SelectedClientsStr |
---|
| 141 | self.SelectedClientsStr = '\"' + self.SelectedClientsStr + '\"' |
---|
| 142 | selected_clients[1] = self.SelectedClientsStr |
---|
| 143 | CommandLog.WriteText('The commands are : %s %s %s %s' % (drbl_dcs, selected_clients[0], selected_clients[1], selected_func[0])) |
---|
| 144 | #CommandLog.WriteText(os.popen('%s %s %s %s' % (drbl_dcs, selected_clients[0], selected_clients[1], selected_func[0])).read()) |
---|
| 145 | return next |
---|
| 146 | |
---|
| 147 | def GetPrev(self): |
---|
| 148 | prev = self.prev |
---|
| 149 | self.fuse_next = 0 |
---|
| 150 | return prev |
---|
| 151 | |
---|
| 152 | #------------------------------------------------------------------------ |
---|
| 153 | class remoteLinuxFinalPage(wiz.PyWizardPage): |
---|
| 154 | def __init__(self, parent, title): |
---|
| 155 | wiz.PyWizardPage.__init__(self, parent) |
---|
| 156 | self.next = self.prev = None |
---|
| 157 | self.sizer = makePageTitle(self, title) |
---|
| 158 | global Command, CommandLog |
---|
| 159 | |
---|
| 160 | Command = wx.StaticText(self, -1, '', pos=(10,60), size=(150,100), style=wx.TE_MULTILINE) |
---|
| 161 | CommandLog = wx.TextCtrl(self, -1, '', pos=(10,100), size=(480,200), style=wx.TE_MULTILINE|wx.TE_READONLY) |
---|
| 162 | |
---|