Package pyanaconda :: Package iw :: Module network_gui
[hide private]
[frames] | no frames]

Source Code for Module pyanaconda.iw.network_gui

  1  # 
  2  # network_gui.py: Network configuration dialog 
  3  # 
  4  # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006,  Red Hat, Inc. 
  5  #               2007, 2008, 2009 
  6  # 
  7  # This program is free software; you can redistribute it and/or modify 
  8  # it under the terms of the GNU General Public License as published by 
  9  # the Free Software Foundation; either version 2 of the License, or 
 10  # (at your option) any later version. 
 11  # 
 12  # This program is distributed in the hope that it will be useful, 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 15  # GNU General Public License for more details. 
 16  # 
 17  # You should have received a copy of the GNU General Public License 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 19  # 
 20  # Author(s): Michael Fulbright <msf@redhat.com> 
 21  #            David Cantrell <dcantrell@redhat.com> 
 22  # 
 23   
 24  import string 
 25  from iw_gui import * 
 26  from pyanaconda import gui 
 27  from pyanaconda import network 
 28  from pyanaconda import iutil 
 29  from pyanaconda.flags import flags 
 30  import gobject 
 31  import subprocess 
 32  import gtk 
 33  from pyanaconda import isys 
 34   
 35  from pyanaconda.constants import * 
 36  import gettext 
 37  _ = lambda x: gettext.ldgettext("anaconda", x) 
 38   
39 -class NetworkWindow(InstallWindow):
40 - def getScreen(self, anaconda):
41 self.intf = anaconda.intf 42 self.anaconda = anaconda 43 self.hostname = network.getDefaultHostname(anaconda) 44 45 # load the UI 46 (self.xml, self.align) = gui.getGladeWidget("network.glade", 47 "network_align") 48 self.icon = self.xml.get_widget("icon") 49 self.hostnameEntry = self.xml.get_widget("hostnameEntry") 50 self.hostnameEntry.set_text(self.hostname) 51 52 self.netconfButton = self.xml.get_widget("netconfButton") 53 self.netconfButton.connect("clicked", self._setupNetwork) 54 if (len(self.anaconda.network.netdevices) == 0 55 or flags.imageInstall 56 or flags.livecdInstall): 57 self.netconfButton.set_sensitive(False) 58 59 # pressing Enter in confirm == clicking Next 60 self.hostnameEntry.connect("activate", 61 lambda w: self.ics.setGrabNext(1)) 62 63 # load the icon 64 gui.readImageFromFile("network.png", image=self.icon) 65 66 return self.align
67
68 - def _setupNetwork(self, *args):
69 self.intf.enableNetwork(just_setup=True)
70
71 - def focus(self):
72 self.hostnameEntry.grab_focus()
73
74 - def hostnameError(self):
75 self.hostnameEntry.grab_focus() 76 raise gui.StayOnScreen
77
78 - def getNext(self):
79 hostname = string.strip(self.hostnameEntry.get_text()) 80 herrors = network.sanityCheckHostname(hostname) 81 82 if not hostname: 83 self.intf.messageWindow(_("Error with Hostname"), 84 _("You must enter a valid hostname for this " 85 "computer."), custom_icon="error") 86 self.hostnameError() 87 88 if herrors is not None: 89 self.intf.messageWindow(_("Error with Hostname"), 90 _("The hostname \"%(hostname)s\" is not " 91 "valid for the following reason:\n\n" 92 "%(herrors)s") 93 % {'hostname': hostname, 94 'herrors': herrors}, 95 custom_icon="error") 96 self.hostnameError() 97 98 self.anaconda.network.setHostname(hostname) 99 return None
100
101 -def NMCEExited(pid, condition, anaconda):
102 if anaconda: 103 anaconda.intf.icw.window.set_sensitive(True)
104 105 # TODORV: get rid of setting sensitive completely?
106 -def runNMCE(anaconda=None, blocking=True):
107 if not blocking and anaconda: 108 anaconda.intf.icw.window.set_sensitive(False) 109 cmd = ["/usr/bin/nm-connection-editor"] 110 out = open("/dev/tty5", "w") 111 try: 112 proc = subprocess.Popen(cmd, stdout=out, stderr=out) 113 except Exception as e: 114 if not blocking and anaconda: 115 anaconda.intf.icw.window.set_sensitive(True) 116 import logging 117 log = logging.getLogger("anaconda") 118 log.error("Could not start nm-connection-editor: %s" % e) 119 return None 120 else: 121 if blocking: 122 proc.wait() 123 else: 124 gobject.child_watch_add(proc.pid, NMCEExited, data=anaconda, priority=gobject.PRIORITY_DEFAULT)
125 126
127 -def selectInstallNetDeviceDialog(network, devices = None):
128 129 devs = devices or network.netdevices.keys() 130 if not devs: 131 return None 132 devs.sort() 133 134 dialog = gtk.Dialog(_("Select network interface")) 135 dialog.add_button('gtk-cancel', gtk.RESPONSE_CANCEL) 136 dialog.add_button('gtk-ok', 1) 137 dialog.set_position(gtk.WIN_POS_CENTER) 138 gui.addFrame(dialog) 139 140 dialog.vbox.pack_start(gui.WrappingLabel( 141 _("This requires that you have an active " 142 "network connection during the installation " 143 "process. Please configure a network interface."))) 144 145 combo = gtk.ComboBox() 146 cell = gtk.CellRendererText() 147 combo.pack_start(cell, True) 148 combo.set_attributes(cell, text = 0) 149 cell.set_property("wrap-width", 525) 150 combo.set_size_request(480, -1) 151 store = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_STRING) 152 combo.set_model(store) 153 154 ksdevice = network.getKSDevice() 155 if ksdevice: 156 ksdevice = ksdevice.iface 157 preselected = None 158 159 for dev in devices: 160 i = store.append(None) 161 if not preselected: 162 preselected = i 163 164 desc = network.netdevices[dev].description 165 if desc: 166 desc = "%s - %s" %(dev, desc) 167 else: 168 desc = "%s" %(dev,) 169 170 hwaddr = network.netdevices[dev].get("HWADDR") 171 172 if hwaddr: 173 desc = "%s - %s" %(desc, hwaddr,) 174 175 if ksdevice and ksdevice == dev: 176 preselected = i 177 178 store[i] = (desc, dev) 179 180 combo.set_active_iter(preselected) 181 dialog.vbox.pack_start(combo) 182 183 dialog.show_all() 184 185 rc = dialog.run() 186 187 if rc in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT]: 188 install_device = None 189 else: 190 active = combo.get_active_iter() 191 install_device = combo.get_model().get_value(active, 1) 192 193 dialog.destroy() 194 return install_device
195
196 -def selectSSIDsDialog(devssids):
197 """Dialog for access point selection. 198 199 devssids - dict iface->[ssid1, ssid2, ssid3, ...] 200 returns - dict iface->[ssidX] or None on Cancel 201 """ 202 203 # If there are no choices, don't ask 204 for dev, ssids in devssids.items(): 205 if len(ssids) > 1: 206 break 207 else: 208 return devssids 209 210 rv = {} 211 dialog = gtk.Dialog(_("Select APs")) 212 dialog.add_button('gtk-cancel', gtk.RESPONSE_CANCEL) 213 dialog.add_button('gtk-ok', 1) 214 dialog.set_position(gtk.WIN_POS_CENTER) 215 gui.addFrame(dialog) 216 217 dialog.vbox.pack_start(gui.WrappingLabel( 218 _("Select APs for wireless devices"))) 219 220 table = gtk.Table(len(devssids), 2) 221 table.set_row_spacings(5) 222 table.set_col_spacings(5) 223 224 combos = {} 225 for i, (dev, ssids) in enumerate(devssids.items()): 226 227 label = gtk.Label(dev) 228 table.attach(label, 0, 1, i, i+1, gtk.FILL, gtk.FILL) 229 230 combo = gtk.combo_box_new_text() 231 for ssid in ssids: 232 combo.append_text(ssid) 233 table.attach(combo, 1, 2, i, i+1, gtk.FILL, gtk.FILL) 234 combo.set_active(0) 235 combos[dev] = combo 236 237 dialog.vbox.pack_start(table) 238 239 dialog.show_all() 240 241 rc = dialog.run() 242 243 # cancel 244 if rc in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT]: 245 rv = None 246 else: 247 for dev, combo in combos.items(): 248 rv[dev] = [combo.get_active_text()] 249 250 dialog.destroy() 251 return rv
252