def _createWidgets(self): if self.widgetType == ZBlogInfoWidget.TYPE_ADD: registry = getResourceRegistry() bitmap = registry.getBitmap(u"images/common/add.png") #$NON-NLS-1$ self.imgButton = ZImageButton(self, bitmap, False, None, True) self.imgButton.SetToolTipString(_extstr(u"blogchooser.AddBlogTooltip")) #$NON-NLS-1$ bitmap = registry.getBitmap(u"images/common/add_disabled.png") #$NON-NLS-1$ self.imgButton.SetDisabledBitmap(bitmap) elif self.widgetType == ZBlogInfoWidget.TYPE_DEL: registry = getResourceRegistry() bitmap = registry.getBitmap(u"images/common/delete.png") #$NON-NLS-1$ self.imgButton = ZImageButton(self, bitmap, False, None, True) self.imgButton.SetToolTipString(_extstr(u"blogchooser.RemoveBlogTooltip")) #$NON-NLS-1$ self.blogSelectorCombo = ZBlogSelectorCombo(self, self.model) self.separator = wx.StaticLine(self, wx.VERTICAL) self.configureCombo = ZConfigureBlogCombo(self, None)
def _createWidget(self): return ZBlogSelectorCombo(self, self.model)
class ZBlogInfoWidget(wx.Panel): TYPE_NONE = 0 TYPE_ADD = 1 TYPE_DEL = 2 def __init__(self, parent, model, widgetType = TYPE_NONE): self.model = model self.widgetType = widgetType wx.Panel.__init__(self, parent, wx.ID_ANY) self.imgButton = None self._createWidgets() self._layoutWidgets() self._bindWidgetEvents() # end __init__() def _createWidgets(self): if self.widgetType == ZBlogInfoWidget.TYPE_ADD: registry = getResourceRegistry() bitmap = registry.getBitmap(u"images/common/add.png") #$NON-NLS-1$ self.imgButton = ZImageButton(self, bitmap, False, None, True) self.imgButton.SetToolTipString(_extstr(u"blogchooser.AddBlogTooltip")) #$NON-NLS-1$ bitmap = registry.getBitmap(u"images/common/add_disabled.png") #$NON-NLS-1$ self.imgButton.SetDisabledBitmap(bitmap) elif self.widgetType == ZBlogInfoWidget.TYPE_DEL: registry = getResourceRegistry() bitmap = registry.getBitmap(u"images/common/delete.png") #$NON-NLS-1$ self.imgButton = ZImageButton(self, bitmap, False, None, True) self.imgButton.SetToolTipString(_extstr(u"blogchooser.RemoveBlogTooltip")) #$NON-NLS-1$ self.blogSelectorCombo = ZBlogSelectorCombo(self, self.model) self.separator = wx.StaticLine(self, wx.VERTICAL) self.configureCombo = ZConfigureBlogCombo(self, None) # end _createWidgets() def _layoutWidgets(self): self.SetMinSize(wx.Size(-1, 20)) self.sizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer.Add(self.blogSelectorCombo, 1, wx.EXPAND) self.sizer.Add(self.separator, 0, wx.EXPAND) self.sizer.Add(self.configureCombo, 0, wx.EXPAND) if self.imgButton: self.sizer.Add(self.imgButton, 0, wx.ALIGN_RIGHT) self.separator.Show(False) self.configureCombo.Show(False) self.SetSizer(self.sizer) self.SetAutoLayout(True) self.Layout() # end _layoutWidgets() def _bindWidgetEvents(self): self.Bind(ZEVT_BLOG_SELECTOR_COMBO, self.onBlogSelection, self.blogSelectorCombo) self.Bind(wx.EVT_SIZE, self.onResize, self) if self.imgButton: self.Bind(wx.EVT_BUTTON, self.onImgButton, self.imgButton) # end _bindWidgetEvents() def onImgButton(self, event): if self.widgetType == ZBlogInfoWidget.TYPE_ADD: event = ZAddBlogInfoWidgetEvent(self.GetId()) self.GetEventHandler().AddPendingEvent(event) elif self.widgetType == ZBlogInfoWidget.TYPE_DEL: event = ZRemoveBlogInfoWidgetEvent(self.GetId(), self ) self.GetEventHandler().AddPendingEvent(event) # end onImgButton def showButton(self, show): if self.imgButton: self.imgButton.Enable(show) # end showButton() def _populateWidgets(self, pubMetaData): self.blogSelectorCombo.selectBlog(pubMetaData.getAccountId(), pubMetaData.getBlogId()) self.configureCombo.setBlog(self.blogSelectorCombo.getBlog()) self.configureCombo.setPubMetaData(pubMetaData) self.separator.Show(True) self.configureCombo.Show(True) self.Layout() # end _populateWidgets() def setPubMetaData(self, pubMetaData): if pubMetaData is not None: self._populateWidgets(pubMetaData) # end setPubMetaData() def getPubMetaData(self): blog = self.blogSelectorCombo.getBlog() if blog is None: return None pubMetaData = self.configureCombo.getPubMetaData() pubMetaData.setAccountId(blog.getAccount().getId()) pubMetaData.setBlogId(blog.getId()) return pubMetaData # end getPubMetaData() def onBlogSelection(self, event): blog = self.blogSelectorCombo.getBlog() if blog: self.configureCombo.setBlog(blog) self.separator.Show(True) self.configureCombo.Show(True) self.Layout() event.Skip() # end onBlogSelection() def onResize(self, event): self.Layout() event.Skip() # end onResize() def Layout(self): wx.Panel.Layout(self) self.blogSelectorCombo.setExtent(self.configureCombo.GetSizeTuple()[0]) self.configureCombo.setExtent(self.blogSelectorCombo.GetSizeTuple()[0])