class SidebarWindow(ui.Board): BUTTON_WIDTH = 32 BUTTON_HEIGHT = 32 BUTTON_GAP_X = 16 BUTTON_GAP_Y = 10 def __init__(self, wndInventory): ui.Board.__init__(self) self.AddFlag("float") self.children = [] self.wndInventory = wndInventory # NOTE: Add your buttons self.SIDEBAR_BUTTON = [ { 'text' : 'Biyolog', 'default_image' : 'd:/ymir work/ui/sidebar/bio1.png', 'down_image' : 'd:/ymir work/ui/sidebar/bio2.png', 'over_image' : 'd:/ymir work/ui/sidebar/bio3.png', 'function' : self.wndInventory.ClickBiologButton }, { 'text' : 'Button2', 'default_image' : 'd:/ymir work/ui/public/slot_base.sub', 'down_image' : 'd:/ymir work/ui/public/slot_base.sub', 'over_image' : 'd:/ymir work/ui/public/slot_base.sub', 'function' : self.wndInventory.ClickDeleteItem } ] self.CreateButtons() def Destroy(self): self.children = [] self.wndInventory = None def __del__(self): ui.Board.__del__(self) def CreateButtons(self): y_pos = self.BUTTON_GAP_Y for item in self.SIDEBAR_BUTTON: button = ui.Button() button.SetParent(self) button.SetUpVisual(item['default_image']) button.SetDownVisual(item['down_image']) button.SetOverVisual(item['over_image']) button.SetToolTipText(item['text']) button.SetEvent(lambda : item['function']()) button.SetPosition(self.BUTTON_GAP_X, y_pos) button.Show() self.children.append(button) y_pos += (self.BUTTON_GAP_Y + button.GetHeight()) self.SetSize( self.BUTTON_GAP_X + self.BUTTON_WIDTH + self.BUTTON_GAP_X, len(self.SIDEBAR_BUTTON) * (self.BUTTON_HEIGHT + self.BUTTON_GAP_Y) + self.BUTTON_GAP_Y ) self.AdjustPosition() def AdjustPosition(self): x, y = self.wndInventory.GetGlobalPosition() # NOTE: Adjust pos here self.SetPosition(x - self.GetWidth(), y)