fltkcc.cpp

来源:百度文库 编辑:神马文学网 时间:2024/04/29 03:14:15
# data file for the Fltk User Interface Designer (fluid)version 1.0106 header_name {.h} code_name {.cxx}class stxcc {open} { Function {make_window(self)} {open } { Fl_Window window { label {STX Control Centre} open xywh {414 268 740 560} type Double color 137 align 0 visible } { Fl_Group grpLogo {open xywh {3 473 735 65} align 17 } {} Fl_Tabs tabs {open xywh {15 15 185360} box NO_BOX color 138 selection_color 96 align 0 } { Fl_Group grpCat { label { Categories } open xywh {15 40 185 320} box RFLAT_BOX color 96 selection_color 96 labelsize 12 labelcolor 7 } { Fl_Pack pckCat {open xywh {20 50 175 300} labelcolor 7 code0 {self.show_categories(self.basedir + "items/")} } {} } Fl_Group grpHelp { label { Help } open xywh {15 40 185 320} box RFLAT_BOX color 96 selection_color 96 labelsize 12 labelcolor 7 hide } { Fl_Text_Display txtHelp { xywh {20 50 175 300} box NO_BOX color 96 labelcolor 7 } } } Fl_Group grpIcons {open xywh {250 40 445 405} labelfont 1 labelcolor 7 align 145 } {} } } Function {__init__(self)} {open } { code {global sys, os, stat, desktopimport sys, os, stat, desktopfrom ConfigParser import SafeConfigParserself.basedir = "./"self.winMain = self.make_window()self.imgWelcome = Fl_PNG_Image(self.basedir + "welcome.png")grpLogo.image(Fl_PNG_Image(self.basedir + "stxcc.png"))grpIcons.image(self.imgWelcome)self.config = SafeConfigParser()self.config.read(self.basedir + "stxcc.theme")self.apply_theme()bufHelp = Fl_Text_Buffer(1000)txtHelp.buffer(bufHelp)txtHelp.wrap_mode(1, 0)self.load_help(self.basedir + "items/help.txt")self.show_categories(self.basedir + "items/")self.prevButton = Noneself.winMain.show()} {} } Function {show_categories(self, dir)} {open } { code {fileList = os.listdir(dir)dirList = []self.names = []for file in fileList: mode = os.stat(dir + "/" + file)[stat.ST_MODE] if stat.S_ISDIR(mode): dirList.append(file)for item in dirList: dirItem = desktop.DirItem(dir + "/" + item, self) self.make_category(dirItem)} {} } Function {make_category(self, item)} {open } { code {try: imageFile = item.get("icon") button = Fl_Button(0, 0, 100, 50, item.get("name")) image = Fl_PNG_Image(imageFile) button.image(image) button.labelcolor(255) button.labelsize(12) button.box(FL_NO_BOX) button.down_box(FL_FLAT_BOX) button.selection_color(fl_rgb_color(0, 66, 163)) button.callback(self.select_category, item)except: print "Unable to display control center item. (Malformed .desktop file?)"} {} } Function {select_category(self, button, category)} {open } { code {grpIcons.clear()dir = category.get("dirname")fileList = os.listdir(dir)deskList = []dirList = []self.names = []self.iconX = 250self.iconY = 60helpFile = Noneif dir == self.basedir + "items/": grpIcons.image(self.imgWelcome) grpIcons.label(None) grpIcons.align(FL_ALIGN_TOP|FL_ALIGN_INSIDE) self.load_help(dir + "/help.txt") returnelse: grpIcons.image(None) grpIcons.align(FL_ALIGN_TOP) grpIcons.label(category.get("name"))for file in fileList: if file.find(".desktop") == (len(file) - 8) and file.find(".desktop") > 0: deskList.append(file) continue if file == "help.txt": helpFile = file continue mode = os.stat(dir + "/" + file)[stat.ST_MODE] if stat.S_ISDIR(mode): dirList.append(file)if not dir == "items": dirItem = desktop.DirItem(dir + "/..", self) self.show_item(dirItem)for item in dirList: dirItem = desktop.DirItem(dir + "/" + item, self) if not dir == "items": print dir self.show_item(dirItem)for item in deskList: deskItem = desktop.DeskItem(dir + "/" + item) self.show_item(deskItem) if helpFile: self.load_help(dir + "/help.txt")else: self.load_help(None)} {} } Function {show_item(self, item)} {open } { code {try: self.names.append(item.get("name")) currentName = len(self.names) - 1 image = Fl_PNG_Image(item.get("icon")) button = Fl_Button(self.iconX, self.iconY, 150, 64, self.names[currentName]) self.iconX += 155 if self.iconX > 645: self.iconX = 250 self.iconY += 70 button.image(image) button.box(FL_NO_BOX) button.down_box(FL_FLAT_BOX) button.labelcolor(self.get_config("button", "text", 0)) button.labelsize(self.get_config("button", "size", 12)) button.selection_color(self.get_config("button", "select", 255)) button.tooltip(item.get("genericname")) button.callback(item.clicked) grpIcons.add(button)except: print "Unable to display control center item. (Malformed .desktop file?)"} {} } Function {load_help(self, helpFile)} {open } { code {if helpFile: help = open(helpFile).readlines() helpStr = "" for line in help: helpStr += lineelse: helpStr = "Sorry, no help is available for this category."bufHelp = txtHelp.buffer()bufHelp.replace(0, 1000, helpStr)} {} } Function {apply_theme(self)} {open } { code {helptext = self.get_config("help", "text", 0)txtHelp.textcolor(helptext)helpsize = self.get_config("help", "size", 12)txtHelp.textsize(helpsize)helpselect = self.get_config("help", "select", 255)txtHelp.selection_color(helpselect)helpbackground = self.get_config("help", "background", 0)txtHelp.color(helpbackground)grpHelp.color(helpbackground)catbackground = self.get_config("categories", "background", 0)grpCat.color(catbackground)tabsbackground = self.get_config("tabs", "background", 0)tabs.color(tabsbackground)tabsselect = self.get_config("tabs", "select", 255)tabs.selection_color(tabsselect)mainbackground = self.get_config("main", "background", 0)window.color(mainbackground)titletext = self.get_config("title", "text", 0)grpIcons.labelcolor(titletext)titlesize = self.get_config("title", "size", 14)grpIcons.labelsize(titlesize)} {selected } } Function {get_config(self, section, option, default)} {open } { code {try: tmp = self.config.get(section, option)except: return defaulttry: tmp = int(tmp) return tmpexcept: try: r, g, b = tmp.split(", ") except: try: r, g, b = tmp.split(",") except: return defaultr = int(int(r) / 2)g = int(g)b = int(b)tmp = fl_rgb_color(r, g, b)return tmp} {} }}