class InstancePage(gtk.Frame): def __init__(self,parent, server=None, instance = None): gtk.Frame.__init__(self) self.par = parent self.serverId = None if server is not None: self.serverId = server.getLocalId() self.instanceId = None if instance is not None: self.instanceId = instance.getLocalId() self.instanceTypes = self.getApplication().getInstanceTypes() self.set_label(_("Skarphed Admin :: Configure Instance")) self.vbox = gtk.VBox() self.label = gtk.Label(_("Please configure the Instance")) self.vspace = gtk.Label("") self.vbox.pack_start(self.label,False) self.vbox.pack_start(self.vspace,True) self.table = gtk.Table(2,4,False) self.typeLabel = gtk.Label(_("InstanceType:")) self.typeStore = gtk.ListStore(str) self.typeCombo = gtk.ComboBox(self.typeStore) self.typeRenderer = gtk.CellRendererText() self.typeCombo.pack_start(self.typeRenderer, True) self.typeCombo.add_attribute(self.typeRenderer, 'text', 0) for instanceType in self.instanceTypes: self.typeStore.append((instanceType.displayName,)) self.typeCombo.set_active(0) self.urlLabel = gtk.Label(_("URL:")) self.urlEntry = DefaultEntry(default_message="http://instance.org") self.urlEntry.set_text("http://") self.userLabel = gtk.Label(_("Username:"******"username")) self.passLabel = gtk.Label(_("Password:"******"●") self.table.attach(self.typeLabel,0,1,0,1) self.table.attach(self.typeCombo,1,2,0,1) self.table.attach(self.urlLabel,0,1,1,2) self.table.attach(self.urlEntry,1,2,1,2) self.table.attach(self.userLabel,0,1,2,3) self.table.attach(self.userEntry,1,2,2,3) self.table.attach(self.passLabel,0,1,3,4) self.table.attach(self.passEntry,1,2,3,4) self.vbox.pack_start(self.table,False) self.buttonBox = gtk.HBox() self.ok = gtk.Button(stock=gtk.STOCK_OK) self.cancel = gtk.Button(stock=gtk.STOCK_CANCEL) self.viewpass = ViewPasswordButton() self.viewpass.addEntry(self.passEntry) self.space = gtk.Label("") self.buttonBox.pack_start(self.space,True) self.buttonBox.pack_start(self.viewpass,False) self.buttonBox.pack_start(self.cancel,False) self.buttonBox.pack_start(self.ok,False) self.ok.connect("clicked",self.cb_Ok) self.cancel.connect("clicked",self.cb_Cancel) self.vbox.pack_start(self.buttonBox,False) self.add(self.vbox) self.getApplication().getMainWindow().openDialogPane(self) if instance is not None: self.urlEntry.set_sensitive(False) self.render() def render(self): try: instance = self.getApplication().getLocalObjectById(self.instanceId) except GenericObjectStoreException: self.getApplication().getMainWindow().closeDialogPane(self) return self.urlEntry.set_text(instance.getUrl()) self.userEntry.set_text(instance.getUsername()) self.passEntry.set_text(instance.getPassword()) def getInstanceType(self,text): for instanceType in self.instanceTypes: if instanceType.displayName == text: return instanceType return None def cb_Cancel(self, widget=None, data=None): self.getApplication().getMainWindow().closeDialogPane() def cb_Ok (self, widget=None, data=None): def errorMessage(msgId): msgs = (_("This URL cannot be resolved"), ) dia = gtk.MessageDialog(parent=self.getPar().getPar(), flags=0, type=gtk.MESSAGE_WARNING, \ buttons=gtk.BUTTONS_OK, message_format=msgs[msgId]) dia.run() dia.destroy() instance = None if self.instanceId is not None: instance = self.getApplication().getLocalObjectById(self.instanceId) server = self.getApplication().getLocalObjectById(self.serverId) if instance is not None: instance.setUsername(self.userEntry.get_text()) instance.setPassword(self.passEntry.get_text()) instance.establishConnections() else: url = self.urlEntry.get_text() if server is None: try: server = self.getApplication().createServerFromInstanceUrl(url) except DNSError: errorMessage(0) return selection = self.typeStore[self.typeCombo.get_active()][0] instanceType = self.getInstanceType(selection) username = self.userEntry.get_text() password = self.passEntry.get_text() try: if not server.createInstance(instanceType, url, username, password): MessagePage(self, _("This URL resolves to another server. You can't add that here.")) return except None: return self.getApplication().getMainWindow().closeDialogPane() def getPar(self): return self.par def getApplication(self): return self.par.getApplication()
class ServerPropertyPage(gtk.Frame): addWindowOpen = False MODE_EDIT = 0 MODE_NEW = 1 def __init__(self, parent, server=None): gtk.Frame.__init__(self) self.par = parent self.serverId = None if server is None: self.set_label(_("Skarphed Admin Pro :: New Server")) self.mode = ServerPropertyPage.MODE_NEW else: self.serverId = server.getLocalId() self.set_label(_("Skarphed Admin Pro :: Server Properties of ") + server.getIp()) self.mode = ServerPropertyPage.MODE_EDIT self.vbox = gtk.VBox() self.instructionlabel = gtk.Label(_("Please enter the Server credentials")) self.vbox.pack_start(self.instructionlabel, False) self.ipFrame = gtk.Frame(_("Common")) self.ipFrameT = gtk.Table(2, 3, False) self.ipFrame_IPLabel = gtk.Label(_("IP:")) self.ipFrame_IPEntry = DefaultEntry(default_message="172.16.13.37") self.ipFrameT.attach(self.ipFrame_IPLabel, 0, 1, 0, 1) self.ipFrameT.attach(self.ipFrame_IPEntry, 1, 2, 0, 1) self.ipFrame_NameLabel = gtk.Label(_("Name:")) self.ipFrame_NameEntry = DefaultEntry(default_message="Server1") self.ipFrameT.attach(self.ipFrame_NameLabel, 0, 1, 1, 2) self.ipFrameT.attach(self.ipFrame_NameEntry, 1, 2, 1, 2) self.ipFrame_Target_Label = gtk.Label("Target system:") self.ipFrame_Target_model = gtk.ListStore(str) for target in Server.INSTALLATION_TARGETS: self.ipFrame_Target_model.append((target.getName(),)) self.ipFrame_Target_renderer = gtk.CellRendererText() self.ipFrame_Target = gtk.ComboBox(self.ipFrame_Target_model) self.ipFrame_Target.pack_start(self.ipFrame_Target_renderer, True) self.ipFrame_Target.add_attribute(self.ipFrame_Target_renderer, "text", 0) self.ipFrameT.attach(self.ipFrame_Target_Label, 0, 1, 2, 3) self.ipFrameT.attach(self.ipFrame_Target, 1, 2, 2, 3) self.ipFrame.add(self.ipFrameT) self.vbox.pack_start(self.ipFrame, False) self.sshFrame = gtk.Frame(_("SSH")) self.sshFrameT = gtk.Table(2, 2, False) self.sshFrame_NameLabel = gtk.Label(_("Username:"******"root") self.sshFrame_PassLabel = gtk.Label(_("Password:"******"●") self.sshFrameT.attach(self.sshFrame_NameLabel, 0, 1, 0, 1) self.sshFrameT.attach(self.sshFrame_NameEntry, 1, 2, 0, 1) self.sshFrameT.attach(self.sshFrame_PassLabel, 0, 1, 1, 2) self.sshFrameT.attach(self.sshFrame_PassEntry, 1, 2, 1, 2) self.sshFrame.add(self.sshFrameT) self.vbox.pack_start(self.sshFrame, False) self.instFrame = gtk.Frame(_("Instances")) self.instFrameT = gtk.Table(2, 4, False) self.instList = gtk.TreeView() self.instStore = gtk.ListStore(gtk.gdk.Pixbuf, str, int) self.instList.set_model(self.instStore) self.instCol_Icon = gtk.TreeViewColumn() self.instCol_Name = gtk.TreeViewColumn(_("Instance")) self.instRen_Icon = gtk.CellRendererPixbuf() self.instRen_Name = gtk.CellRendererText() self.instCol_Icon.pack_start(self.instRen_Icon, False) self.instCol_Name.pack_start(self.instRen_Name, True) self.instCol_Icon.add_attribute(self.instRen_Icon, "pixbuf", 0) self.instCol_Name.add_attribute(self.instRen_Name, "text", 1) self.instList.append_column(self.instCol_Icon) self.instList.append_column(self.instCol_Name) self.instAdd = gtk.Button(stock=gtk.STOCK_ADD) self.instRemove = gtk.Button(stock=gtk.STOCK_REMOVE) self.instEdit = gtk.Button(stock=gtk.STOCK_EDIT) self.instFrameT.attach(self.instList, 0, 1, 0, 4) self.instFrameT.attach(self.instAdd, 1, 2, 0, 1) self.instFrameT.attach(self.instRemove, 1, 2, 1, 2) self.instFrameT.attach(self.instEdit, 1, 2, 2, 3) self.instAdd.connect("clicked", self.cb_Add) self.instRemove.connect("clicked", self.cb_Remove) self.instEdit.connect("clicked", self.cb_Edit) self.instList.connect("cursor-changed", self.cb_cursorChanged) self.instFrame.add(self.instFrameT) self.vbox.pack_start(self.instFrame, False) self.fill = gtk.Label("") self.vbox.pack_start(self.fill, True) self.buttons = gtk.HBox() self.ok = gtk.Button(stock=gtk.STOCK_OK) self.cancel = gtk.Button(stock=gtk.STOCK_CANCEL) self.viewpass = ViewPasswordButton() self.viewpass.addEntry(self.sshFrame_PassEntry) self.ok.connect("clicked", self.cb_OK) self.cancel.connect("clicked", self.cb_Cancel) self.buttons.pack_end(self.ok, False) self.buttons.pack_end(self.cancel, False) self.buttons.pack_end(self.viewpass, False) self.vbox.pack_start(self.buttons, False) self.add(self.vbox) if server is not None: self.ipFrame_IPEntry.set_text(server.getIp()) self.ipFrame_NameEntry.set_text(server.getRawName()) self.sshFrame_NameEntry.set_text(server.getSSHName()) self.sshFrame_PassEntry.set_text(server.getSSHPass()) server.addCallback(self.render) self.getApplication().getMainWindow().openDialogPane(self) self.render() def render(self): def search(model, path, rowiter, target): text = model.get_value(rowiter, 0) if text == target.getName(): self.ipFrame_Target.set_active_iter(rowiter) server = None try: server = self.getApplication().getLocalObjectById(self.serverId) except GenericObjectStoreException: if self.mode == ServerPropertyPage.MODE_EDIT: self.getApplication().getMainWindow().closeDialogPane() return self.instFrame.set_visible(self.mode == ServerPropertyPage.MODE_EDIT) if server is not None and server.isTargetUsable(): self.ipFrame_Target_model.foreach(search, server.getTarget()) self.instStore.clear() if server is not None: for instance in server.getInstances(): icon = IconStock.SKARPHED # TODO: Implement Icon self.instStore.append((icon, instance.getName(), instance.getLocalId())) self.cb_cursorChanged() def getPar(self): return self.par def getApplication(self): return self.par.getApplication() def cb_Add(self, widget=None, data=None): server = self.getApplication().getLocalObjectById(self.serverId) InstancePage(self, server) def cb_Remove(self, widget=None, data=None): instance = self.getCurrentInstance() if instance is None: return try: server = self.getApplication().getLocalObjectById(self.serverId) except GenericObjectStoreException: server = None server.removeInstance(instance) selection = self.instList.get_selection() rowiter = selection.get_selected()[1] self.instStore.remove(rowiter) self.render() def cb_Edit(self, widget=None, data=None): instance = self.getCurrentInstance() try: server = self.getApplication().getLocalObjectById(self.serverId) except GenericObjectStoreException: server = None if instance is None or server is None: return InstancePage(self, server, instance) def cb_cursorChanged(self, tree=None, path=None, data=None): selection = self.instList.get_selection() if selection is None: state = False else: rowiter = selection.get_selected()[1] state = rowiter is not None self.instEdit.set_sensitive(state) self.instRemove.set_sensitive(state) def getCurrentInstance(self, onlyId=True): try: server = self.getApplication().getLocalObjectById(self.serverId) except GenericObjectStoreException: server = None if server is None: return None selection = self.instList.get_selection() rowiter = selection.get_selected()[1] return self.getApplication().getLocalObjectById(self.instStore.get_value(rowiter, 2)) def cb_OK(self, widget=None, data=None): try: concernedServer = self.getApplication().getLocalObjectById(self.serverId) except GenericObjectStoreException: concernedServer = None if self.serverId is None: server = self.getApplication().getData().createServer() self.mode = ServerPropertyPage.MODE_EDIT else: server = concernedServer server.setIp(self.ipFrame_IPEntry.get_text()) server.setName(self.ipFrame_NameEntry.get_text()) server.setSSHName(self.sshFrame_NameEntry.get_text()) server.setSSHPass(self.sshFrame_PassEntry.get_text()) server.setTarget(self.ipFrame_Target.get_active_text()) server.load = server.LOADED_PROFILE server.establishConnections() self.getApplication().getMainWindow().closeDialogPane() def cb_Cancel(self, widget=None, data=None): self.getApplication().getMainWindow().closeDialogPane()
class ActionWidgetConfig(gtk.Table): def __init__(self, par, action): self.par = par gtk.Table.__init__(self,4,4,False) self.actionId = action.getLocalId() self.radio_url = gtk.RadioButton(None, _("URL:")) self.radio_widgetSpaceConstellation = gtk.RadioButton(self.radio_url, _("Widget into Space:")) self.radio_view = gtk.RadioButton(self.radio_url, _("Other View:")) self.entry_url = DefaultEntry(default_message=_("http://www.example.org")) self.entry_widget = ObjectCombo(self, Widget, selectFirst=True, virtualRootObject=action.getActionList().getMenuItem().getMenu().getSite().getSkarphed()) self.entry_space = SpaceCombo(self,action.getActionList().getMenuItem().getMenu().getSite()) self.entry_view = ObjectCombo(self, View, selectFirst=True, virtualRootObject=action.getActionList().getMenuItem().getMenu().getSite().getSkarphed()) self.entry_url.connect("focus-in-event",self.focusCallback) self.entry_widget.connect("popup",self.focusCallback) self.entry_widget.connect("changed",self.focusCallback) self.entry_space.connect("focus-in-event",self.focusCallback) self.entry_view.connect("popup",self.focusCallback) self.entry_widget.connect("changed",self.focusCallback) self.deleteButton = gtk.Button(stock=gtk.STOCK_DELETE) self.increaseOrderButton = gtk.Button(stock=gtk.STOCK_GO_UP) self.decreaseOrderButton = gtk.Button(stock=gtk.STOCK_GO_DOWN) self.saveButton = gtk.Button(stock=gtk.STOCK_SAVE) self.deleteButton.connect("clicked", self.deleteCallback) self.increaseOrderButton.connect("clicked", self.increaseOrderCallback) self.decreaseOrderButton.connect("clicked", self.decreaseOrderCallback) self.saveButton.connect("clicked", self.saveCallback) self.attach(self.radio_url,0,1,0,1) self.attach(self.entry_url,1,3,0,1) self.attach(self.radio_widgetSpaceConstellation,0,1,1,2) self.attach(self.entry_widget,1,2,1,2) self.attach(self.entry_space,2,3,1,2) self.attach(self.radio_view,0,1,2,3) self.attach(self.entry_view,1,3,2,3) self.attach(self.deleteButton,0,1,3,4) self.attach(self.increaseOrderButton,1,2,3,4) self.attach(self.decreaseOrderButton,2,3,3,4) self.attach(self.saveButton,3,4,3,4) action.addCallback(self.render) self.show_all() self.render() def render(self): try: action = self.getApplication().getLocalObjectById(self.actionId) except GenericObjectStoreException: self.getPar().destroy() return if action.data['type'] == 'url': self.radio_url.set_active(True) self.entry_url.set_text(action.data['url']) elif action.data['type'] == 'widgetSpaceConstellation': self.radio_widgetSpaceConstellation.set_active(True) widget=action.getWidget() space=action.getSpaceId() self.entry_space.setSpaceId(space) self.entry_widget.setSelected(widget) elif action.data['type'] == 'view': self.radio_view.set_active(True) view=action.getView() self.entry_view.setSelected(view) def focusCallback(self,widget=None,event=None): if widget == self.entry_url: self.radio_url.activate() elif widget == self.entry_space or widget == self.entry_widget: self.radio_widgetSpaceConstellation.activate() elif widget == self.entry_view: self.radio_view.activate() def deleteCallback(self, widget=None, data=None): action = self.getApplication().getLocalObjectById(self.actionId) action.getPar().deleteChildAction(action) def increaseOrderCallback(self, widget=None, data=None): action = self.getApplication().getLocalObjectById(self.actionId) action.increaseOrder() def decreaseOrderCallback(self, widget=None, data=None): action = self.getApplication().getLocalObjectById(self.actionId) action.decreaseOrder() def saveCallback(self, widget=None,data=None): action = self.getApplication().getLocalObjectById(self.actionId) if self.radio_url.get_active(): action.setUrl(self.entry_url.get_text()) elif self.radio_widgetSpaceConstellation.get_active(): widget = self.entry_widget.getSelected() action.setWidgetSpaceConstellation(widget.getLocalId(),self.entry_space.getSpaceId()) elif self.radio_view.get_active(): action.setView(self.entry_view.getSelected().getLocalId()) def getPar(self): return self.par def getApplication(self): return self.par.getApplication()
class ViewPage(ObjectPageAbstract): def __init__(self, par, view): ObjectPageAbstract.__init__(self, par, view) self.view = PageFrame(self, _("View"), IconStock.VIEW) self.view_hbox = gtk.HBox(spacing=10) self.view_label = gtk.Label(_("Name of this View: ")) self.view_entry = DefaultEntry() self.view_entry.set_default_message(_("name_of_view")) self.view_hbox.pack_start(self.view_label,False) self.view_hbox.pack_start(self.view_entry,True) self.view.add(self.view_hbox) self.pack_start(self.view, False) self.page = PageFrame(self, _("Site"), IconStock.SITE) self.page_hbox = gtk.HBox(spacing=10) self.page_label = gtk.Label(_("Site to Render: ")) self.page_combobox = ObjectCombo(self, \ Site, \ virtualRootObject=view.getViews().getSkarphed().getSites()) self.page_hbox.pack_start(self.page_label,False) self.page_hbox.pack_start(self.page_combobox,False) self.page.add(self.page_hbox) self.pack_start(self.page,False) self.compose = PageFrame(self, _("Compositing"), IconStock.WIDGET) self.compose_dummy = gtk.Label() self.compose_scroll = gtk.ScrolledWindow() self.compose_scroll.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC) self.compose_vbox = gtk.VBox(spacing=10) self.compose_vbox.set_border_width(10) self.compose_spacewidgets = {} self.compose_boxwidgets = {} self.compose_vbox.pack_end(self.compose_dummy,True) self.compose_scroll.add_with_viewport(self.compose_vbox) self.compose.add(self.compose_scroll) self.pack_start(self.compose, True) self.saveframe = gtk.HBox() self.savedummy = gtk.Label() self.savebutton = gtk.Button(stock=gtk.STOCK_SAVE) self.saveframe.pack_start(self.savedummy,True) self.saveframe.pack_start(self.savebutton,False) self.pack_start(self.saveframe, False) self.savebutton.connect("clicked", self.saveCallback) self.page_combobox.connect("changed", self.changedPageCallback) if not view.isFullyLoaded(): view.loadFull() else: self.render() def render(self): view = self.getMyObject() if not view: return self.view_entry.set_text(view.data['name']) if view.data['default']: self.view_entry.set_sensitive(False) site = view.getPage() if site is not None: self.page_combobox.setSelected(site) spaces = site.getSpaces() processed_spaces = [] boxes = site.getBoxes() processed_boxes = [] for spaceId, spaceName in spaces.items(): if self.compose_spacewidgets.has_key(spaceId): self.compose_spacewidgets[spaceId].render() else: self.compose_spacewidgets[spaceId] = SpaceWidget(self,view,spaceId=spaceId) self.compose_vbox.pack_start(self.compose_spacewidgets[spaceId],False) processed_spaces.append(spaceId) for spaceId in self.compose_spacewidgets.keys(): if spaceId not in processed_spaces: self.compose_spacewidgets[spaceId].destroy() for boxId, boxInfo in boxes.items(): if self.compose_boxwidgets.has_key(boxId): self.compose_boxwidgets[boxId].render() else: self.compose_boxwidgets[boxId] = BoxWidget(self, boxId, view) self.compose_vbox.pack_start(self.compose_boxwidgets[boxId],False) processed_boxes.append(boxId) for boxId in self.compose_boxwidgets.keys(): if boxId not in processed_boxes: self.compose_boxwidgets[boxId].destroy() def saveCallback(self, widget=None, data=None): try: view = self.getMyObject() except GenericObjectStoreException: return mapping = {} used_widgetIds = [] for spacewidget in self.compose_spacewidgets.values(): wgt = spacewidget.getWidget() if wgt is not None: widgetId = wgt.getId() if widgetId in used_widgetIds: raise ViewException(ViewException.get_msg(8,wgt.getName())) mapping[spacewidget.getSpaceId()]= widgetId used_widgetIds.append(widgetId) view.changeSpaceWidgetMapping(mapping) boxmapping = {} for boxwidget in self.compose_boxwidgets.values(): widgets = boxwidget.getWidgets() for wgt in widgets: widgetId = wgt.getId() if widgetId in used_widgetIds: raise ViewException(ViewException.get_msg(8,wgt.getName())) if not boxmapping.has_key(boxwidget.getBoxId()): boxmapping[boxwidget.getBoxId()] = [] boxmapping[boxwidget.getBoxId()].append(widgetId) used_widgetIds.append(widgetId) view.changeBoxMapping(boxmapping) def changedPageCallback(self, widget=None, data=None): pass