コード例 #1
0
ファイル: InstancePage.py プロジェクト: skarphed/skarphed
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()
コード例 #2
0
ファイル: View.py プロジェクト: skarphed/skarphed
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