Hikayeler

Reklam vermek için turkmmo@gmail.com

Python Dynamic Table [QoL]

a✘seee;

Manager
Telefon Numarası Onaylanmış Üye TC Kimlik Numarası Doğrulanmış Üye
TM Üye
Katılım
16 Eyl 2009
Konular
123
Mesajlar
2,377
Online süresi
1ay 5g
Reaksiyon Skoru
1,255
Altın Konu
0
Başarım Puanı
304
TM Yaşı
16 Yıl 7 Ay 9 Gün
MmoLira
8,388
DevLira
-19

Metin2 EP, Valorant VP dahil tüm oyun ürünlerini en uygun fiyatlarla bulabilir, Item ve Karakterlerinizi hızlıca satabilirsiniz. HEMEN TIKLA!

hkQguIgfR4-TuEf4aeDxdw.png

ui.py:
class Table(Window):
    def __init__(self, width, head_height, colors):
        Window.__init__(self, "UI")
        self.width = width
        self.head_height = head_height
        self.table_height = head_height
        self.colors = colors
        self.row_heights = []
        self.__children = {}
        self.SetSize(width, head_height)
    def __del__(self):
        Window.__del__(self)
    def Destroy(self):
        self.__children = {}
    def CreateTitleBar(self):
        self.__children["title_base"] = MakeWindow(Bar(), self, ["not_pick"], (0,0), self.colors[1], "", (self.width, self.head_height))
        self.__children["title_tl"] = MakeWindow(Line(), self, ["not_pick"], (0,0), self.colors[0], "", (self.width, 0))
        self.__children["title_bl"] = MakeWindow(Line(), self, ["not_pick"], (0,self.head_height), self.colors[0], "", (self.width, 0))
        self.__children["title_ll"] = MakeWindow(Line(), self, ["not_pick"], (0,0), self.colors[0], "", (0, self.head_height))
        self.__children["title_rl"] = MakeWindow(Line(), self, ["not_pick"], (self.width,0), self.colors[0], "", (0, self.head_height))
    def set_columns(self, headers, widths):
        if len(headers) != len(widths): import dbg; dbg.LogBox("set_columns len(headers) != len(widths)"); return
        self.headers = headers
        self.widths = widths
        self.CreateTitleBar()
        count = len(headers)
        cumulative_width = 0
        for i in xrange(count):
            wnd = MakeWindow(Window(), self.__children["title_base"], ["not_pick"], (cumulative_width,0), "", "", (self.widths[i], self.__children["title_base"].GetHeight()))
            self.__children["title_w%d" % (i)] = wnd
            self.__children["title_t%d" % (i)] = MakeWindow(TextLine(), wnd, ["not_pick"], (0,0), self.headers[i], "all:center")
            if i < count - 1: self.__children["title_s%d" % (i)] = MakeWindow(Line(), wnd, ["not_pick"], (self.widths[i],0), self.colors[0], "", (0, self.__children["title_w%d" % (i)].GetHeight()))
            cumulative_width += self.widths[i]
    def add_row(self, data, height):
        if len(data) != len(self.widths): import dbg; dbg.LogBox("add_row: Data length does not match column count"); return
        row_index = len(self.row_heights)
        self.row_heights.append(height)
        cumulative_width = 0
        y_position = self.head_height + sum(self.row_heights[:row_index])
        for i, value in enumerate(data):
            wnd = MakeWindow(Window(), self, [], (cumulative_width, y_position), "", "", (self.widths[i], height))
            self.__children["row_%d_b%d" % (row_index, i)] = MakeWindow(Bar(), wnd, ["not_pick"], (0,0), self.colors[2], "", (self.widths[i], height))
            self.__children["row_%d_c%d" % (row_index, i)] = wnd
            self.__children["row_%d_t%d" % (row_index, i)] = MakeWindow(TextLine(), wnd, [], (0, 0), str(value), "all:center")
            if i < len(self.widths) - 1: self.__children["row_%d_s%d" % (row_index, i)] = MakeWindow(Line(), wnd, [], (self.widths[i], 0), self.colors[0], "", (0, height))
            cumulative_width += self.widths[i]
        hline_y_position = self.head_height + sum(self.row_heights[:row_index + 1])
        self.__children["row_%d_hline" % (row_index)] = MakeWindow(Line(), self, [], (0, hline_y_position), self.colors[0], "", (self.width, 0))
        self.table_height = self.head_height + sum(self.row_heights)
        self.SetSize(self.width, self.table_height)
        self.__children["title_ll"].SetSize(0, self.table_height)
        self.__children["title_rl"].SetSize(0, self.table_height)

def MakeWindow(window, parent, windowFlags, windowPos, windowArgument = "", windowPositionRule = "", windowSize = (-1, -1), windowFontName = -1, windowColor = 0, windowIsOutline = False):
    if parent: window.SetParent(parent)
    for flag in windowFlags: window.AddFlag(flag)
    window.SetPosition(*windowPos)
    if windowSize != (-1, -1): window.SetSize(*windowSize)
    if windowColor != 0:
        if isinstance(window, TextLine): window.SetPackedFontColor(windowColor)
    if windowIsOutline:
        if isinstance(window, TextLine): window.SetOutline()
    if windowArgument:
        if isinstance(window, TextLine):
            if windowFontName != -1: window.SetFontName(windowFontName)
            window.SetText(windowArgument)
        elif isinstance(window, NumberLine):
            window.SetNumber(windowArgument)
        elif isinstance(window, Button) or isinstance(window, RadioButton) or isinstance(window, ToggleButton):
            if isinstance(windowArgument, list):
                window.SetUpVisual(windowArgument[0])
                window.SetOverVisual(windowArgument[1] if len(windowArgument) >= 2 else windowArgument[0])
                window.SetDownVisual(windowArgument[2] if len(windowArgument) >= 3 else windowArgument[0])
                if len(windowArgument) == 4: window.SetDisableVisual(windowArgument[3])
        elif isinstance(window, ExpandedImageBox) or isinstance(window, ImageBox):
            window.LoadImage(windowArgument if windowArgument.find("gr2") == -1 else "icon/item/27995.tga")
        elif isinstance(window, Line) or isinstance(window, Bar) or isinstance(window, Box):
            window.SetColor(windowArgument)
    if windowPositionRule:
        splitList = windowPositionRule.split(":")
        if len(splitList) == 2:
            (type, mode) = (splitList[0], splitList[1])
            if type == "all":
                window.SetHorizontalAlignCenter()
                window.SetVerticalAlignCenter()
                window.SetWindowHorizontalAlignCenter()
                window.SetWindowVerticalAlignCenter()
            elif type == "horizontal":
                if isinstance(window, TextLine):
                    if mode == "center": window.SetHorizontalAlignCenter()
                    elif mode == "right": window.SetHorizontalAlignRight()
                    elif mode == "left": window.SetHorizontalAlignLeft()
                else:
                    if mode == "center": window.SetWindowHorizontalAlignCenter()
                    elif mode == "right": window.SetWindowHorizontalAlignRight()
                    elif mode == "left": window.SetWindowHorizontalAlignLeft()
            elif type == "vertical":
                if isinstance(window, TextLine):
                    if mode == "center": window.SetVerticalAlignCenter()
                    elif mode == "top": window.SetVerticalAlignTop()
                    elif mode == "bottom": window.SetVerticalAlignBottom()
                else:
                    if mode == "top": window.SetWindowVerticalAlignTop()
                    elif mode == "center": window.SetWindowVerticalAlignCenter()
                    elif mode == "bottom": window.SetWindowVerticalAlignBottom()
    window.Show()
    return window

Örnek kullanım;

Python:
tableS = ui.Table(190, 26, [0xff746653, 0xff231811, 0x804b3f29])
tableS.SetPosition(0,0)
tableS.set_columns(["Nesne", "Olasılık"], [150, 40])
tableS.add_row(["abc", "%100"], 34)
tableS.Show()
 
Güzel paylaşım, eline sağlık
 
Eline sağlık teşekkürler. ^^
 
paylaşım için teşekkürler yararlı
 
Paylaşımın için teşekkürler
 

Şu an konuyu görüntüleyenler (Toplam : 1, Üye: 0, Misafir: 1)

Geri
Üst