def addProgramControl(self, program, info, relX, relY, width, height): """ Adds a control (button overlayed with a label) for a program in the guide """ mlog.debug("> addProgramControl(program=%s, info=%s, relX=%d, relY=%d, width=%d, height=%d)"%( program, info, relX, relY, width, height)) info['program'] = program if not program: info['nodata'] = True info['starttime'] = None info['title'] = self.translator.get(108) # 'No data' category = None else: info['nodata'] = False info['starttime'] = program.starttime() info['title'] = program.title() if program.starttimeAsTime() < self.startTime: info['title'] = "< " + info['title'] if program.endtimeAsTime() > self.endTime: info['title'] += " >" category = program.category() info['start'] = relX info['end'] = relX + width # Create a button for navigation and hilighting. For some reason, # button labels don't get truncated properly. info['control'] = c = xbmcgui.ControlButton( relX + self.guide_x, relY + self.guide_y, width, height, "", # Text empty on purpose. Label overlay responsible for this util.findMediaFile('button-focus.png'), # TODO: Find better focus texture #util.findMediaFile( self.getTexture(category, isFocus=True) ), util.findMediaFile( self.getTexture(category, isFocus=False) ), alignment=(ui.ALIGN_CENTER_Y | ui.ALIGN_TRUNCATED ) ) self.addControl(c) # Create a label to hold the name of the program. Label text seems to # get truncated correctly... info['label'] = c = xbmcgui.ControlLabel( relX + self.guide_x, relY + self.guide_y, width, height, info['title'], alignment=ui.ALIGN_CENTER_Y | ui.ALIGN_TRUNCATED ) self.addControl(c) self.progButtonCtls.append( info ) mlog.debug( "< addProgramControl()" ) return c
def renderChannels(self): """Method to draw the channel labels. """ try: for c in self.channelCtls: if 'icon' in c: self.removeControl( c['icon'] ) if 'label' in c: self.removeControl( c['label'] ) if 'shade' in c: self.removeControl( c['shade'] ) del c self.channelCtls = [] x = self.channel_x y = self.guide_y h = (self.guide_h - self.channelSpan * self.guide_dy) / self.channelSpan iconW = h labelW = self.channel_w - iconW - self.guide_dx for i in range( self.startChan, self.endChan+1 ): c = {} # create shade image around channel label/icon c['shade'] = xbmcgui.ControlImage(x, y, self.channel_w, h, util.findMediaFile("shade_50.png")) self.addControl( c['shade'] ) # create label control l = "%s %s"%(self.channels[i].channum(),self.channels[i].callsign()) c['label'] = xbmcgui.ControlLabel( x+iconW+self.channel_dx, y, labelW, h, l, self.getoption( "channel_font" ), alignment=ui.ALIGN_CENTER_Y ) self.addControl( c['label'] ) shost = str(self.settings.get( "mythtv_host" )) file = ui.picBase + os.sep + 'channels' + os.sep + str(self.channels[i].channum()) + ui.picType if not os.path.exists(file): try: file = self.iconCache.findFile( self.channels[i], shost ) except: log.debug(" renderChannels: nothing assigned to file") log.debug( "file=[%s]"%file ) if file: # set channel icon c['icon'] = xbmcgui.ControlImage( x, y, iconW, h, file ) self.addControl( c['icon'] ) self.channelCtls.append( c ) y += h + self.guide_dy except: log.exception("Failed to render channels") raise
def showIconImg( self, img, path="" ): c = self.controls['popup_icon'].control self.removeControl( c ) del c x = int(self.getvalue(self.getoption("popup_channel_x"))) y = int(self.getvalue(self.getoption("popup_channel_y"))) w = int(self.getvalue(self.getoption("popup_channel_w"))) h = int(self.getvalue(self.getoption("popup_channel_h"))) texture = img tx = util.findMediaFile( texture ) if tx == None: tx = path + texture c = xbmcgui.ControlImage(x, y, w, h, tx) self.addControl( c ) self.controls['popup_icon'].control = c
def showIconImg(self, img, path=""): c = self.controls['popup_icon'].control self.removeControl(c) del c x = int(self.getvalue(self.getoption("popup_channel_x"))) y = int(self.getvalue(self.getoption("popup_channel_y"))) w = int(self.getvalue(self.getoption("popup_channel_w"))) h = int(self.getvalue(self.getoption("popup_channel_h"))) texture = img tx = util.findMediaFile(texture) if tx == None: tx = path + texture c = xbmcgui.ControlImage(x, y, w, h, tx) self.addControl(c) self.controls['popup_icon'].control = c
def showIconImg(self, img, path=""): c = self.controls['popup_icon'].control self.removeControl(c) del c x = int(self.getvalue(self.getoption("popup_channel_x"))) y = int(self.getvalue(self.getoption("popup_channel_y"))) w = int(self.getvalue(self.getoption("popup_channel_w"))) h = int(self.getvalue(self.getoption("popup_channel_h"))) myW = w * 1.172 myH = h * 0.95 log.debug("New Width: %s New Height: %s" %(myW, myH)) y -= (( myW - w ) / 2) texture = img tx = util.findMediaFile(texture) if tx == None: tx = path + texture c = xbmcgui.ControlImage(x, y, myW, myH, tx) self.addControl(c) self.controls['popup_icon'].control = c
def create(self): """ internal: creates the control and adds it to the page assumes width/height etc are already set does not do navigation """ # get generic stuff, position, type, etc id = string.lower(self.getoption("id")) t = string.lower(self.getoption("type")) x = int(self.getvalue(self.getoption("posx"))) y = int(self.getvalue(self.getoption("posy"))) c=None # 0 means auto (afaik) w = 0 h = 0 t1 = self.getoption("width") if t1 != "": w = int(self.getvalue(t1)) t1 = self.getoption("height") if t1 != "": h = int(self.getvalue(t1)) l = self.getoption("label") try: t1 = int(l) l = self.translator.get(t1) except: pass help = self.getoption("help") try: t1 = int(help) help = self.translator.get(t1) except: pass self.options['help'] = help tx = self.getoption("texture") if tx != "": tx = util.findMediaFile( tx ) # if it didn't find the script skin file then use the xbmc skin file if tx == None: tx = self.getoption("texture") tx1 = self.getoption("texturefocus") if tx1 != "": tx1 = util.findMediaFile( tx1 ) tx2 = self.getoption("texturenofocus") if tx2 != "": tx2 = util.findMediaFile( tx2 ) ck = self.getoption("colorkey") aspectRatio = self.getoption("aspectratio") fnt = self.getvalue(self.getoption("font")) tcol = self.getoption("textcolor") log.debug( "id=[%s] x=[%d] y=[%d] w=[%d] h=[%d] font=[%s]"%(id,x,y,w,h,fnt) ) c = None if t == "image": try: if ck == "" and aspectRatio == "": c = xbmcgui.ControlImage(x,y,w,h,tx) elif aspectRatio != "": c = xbmcgui.ControlImage(x,y,w,h,tx, aspectRatio=int(aspectRatio)) else: c = xbmcgui.ControlImage(x,y,w,h,tx,ck) except Exception: log.exception("Unable to load image id:%s filename:%s" %(id, tx)) elif t == "button": try: tox = int(self.getvalue(self.getoption("offsetx"))) except: tox = 17 try: toy = int(self.getvalue(self.getoption("offsety"))) except: toy = 2 try: align = int(self.getvalue(self.getoption("alignment"))) except: align = 0 # left log.debug( "font=[%s] tox=[%d] toy=[%d] align=[%d]"%(fnt,tox,toy,align) ) if tx1 == "": if fnt == "": c = xbmcgui.ControlButton( x,y,w,h,l, textXOffset=int(tox),textYOffset=int(toy), alignment=align) else: c = xbmcgui.ControlButton( x,y,w,h,l,font=str(fnt), textXOffset=int(tox),textYOffset=int(toy), alignment=align) elif tx2 == "": if fnt == "": c = xbmcgui.ControlButton( x,y,w,h,l,tx1, textXOffset=int(tox),textYOffset=int(toy), alignment=align) else: c = xbmcgui.ControlButton( x,y,w,h,l,tx1,font=fnt, textXOffset=int(tox),textYOffset=int(toy), alignment=align) else: if fnt == "": c = xbmcgui.ControlButton( x, y, w, h, l, tx1, tx2, textXOffset=int(tox), textYOffset=int(toy), alignment=align) else: c = xbmcgui.ControlButton( x, y, w, h, l, tx1, tx2, font=fnt, textXOffset=int(tox), textYOffset=int(toy), alignment=align) elif t == "fadelabel": try: align = int(self.getvalue(self.getoption("alignment"))) except Exception: ## traceback.print_exc() ## print ( "XBMCMYTHTV: %s " % str(ex) ) align = 6 # left c = xbmcgui.ControlFadeLabel(x,y,w,h,str(fnt),tcol,alignment=align) elif t == "label": try: align = int(self.getvalue(self.getoption("alignment"))) except: align = 0 # left c = xbmcgui.ControlLabel(x,y,w,h,l,str(fnt),tcol,alignment=align) elif t == "listcontrol": try: tox = int(self.getvalue(self.getoption("offsetx"))) except: tox = 17 try: spc = int(self.getvalue(self.getoption("space"))) except: spc = 1 try: ih = int(self.getvalue(self.getoption( "itemheight" ))) except: ih = 20 # ALIGN_LEFT = 0 # ALIGN_RIGHT = 1 # ALIGN_CENTER_X = 2 # ALIGN_CENTER_Y = 4 # ALIGN_TRUNCATED = 8 bt = util.findMediaFile('button-focus.png') aly = ui.ALIGN_TRUNCATED | ui.ALIGN_CENTER_Y log.debug( "font=[%s] tox=[%d] ih=[%d]"%(fnt,tox,ih) ) if tx1 == "": if fnt == "": c = xbmcgui.ControlList(x,y,w,h,itemTextXOffset=int(tox),space=int(spc),itemHeight=int(ih), alignmentY = aly, buttonFocusTexture=bt) else: c = xbmcgui.ControlList(x,y,w,h,font=fnt,itemTextXOffset=int(tox),space=int(spc),itemHeight=int(ih), alignmentY = aly, buttonFocusTexture=bt) log.debug( "xbmcgui.ControlList(x,y,w,h)" ) elif tx2 == "": if fnt == "": c = xbmcgui.ControlList(x,y,w,h,tx1,itemTextXOffset=int(tox),space=int(spc),itemHeight=int(ih), alignmentY = aly, buttonFocusTexture=bt) else: c = xbmcgui.ControlList(x, y, w, h, tx1, font=fnt, itemTextXOffset=int(tox), space=int(spc), itemHeight=int(ih), alignmentY = aly, buttonFocusTexture=bt) log.debug( "xbmcgui.ControlList(x,y,w,h,tx1)" ) else: if fnt == "": c = xbmcgui.ControlList(x,y,w,h,tx1,tx2,itemTextXOffset=int(tox),space=int(spc),itemHeight=int(ih), alignmentY = aly, buttonFocusTexture=bt) else: c = xbmcgui.ControlList(x,y,w,h,tx1,tx2,font=fnt,itemTextXOffset=int(tox),space=int(spc),itemHeight=int(ih), alignmentY = aly, buttonFocusTexture=bt) log.debug( "xbmcgui.ControlList(x,y,w,h,tx1,tx2)" ) elif t == "textbox": c = xbmcgui.ControlTextBox(x,y,w,h,fnt,tcol) # c.setText() elif t == "checkmark": try: cw = int(self.getoption( "checkwidth" )) except: cw = 30 try: ch = int(self.getoption( "checkheight" )) except: ch = 30 try: align = int(self.getvalue(self.getoption("alignment"))) except: align = 1 # right if tx1 == "": c = xbmcgui.ControlCheckMark( x,y,w,h,l, checkWidth=cw, checkHeight=ch, alignment=align, textColor=tcol) elif tx2 == "": c = xbmcgui.ControlCheckMark( x,y,w,h,l,tx1, checkWidth=cw, checkHeight=ch, alignment=align, textColor=tcol) else: c = xbmcgui.ControlCheckMark( x,y,w,h,l,tx1,tx2,cw,ch,align,textColor=tcol) log.debug( "created '%s' control"%t ) # TODO: Remove OS specific checks if c != None: if os.name != "nt": self.owner.addControl(c) else: # lists are acting funny. trying remove instead of hide t1 = self.owner.getoption("defaultgroup") if t1 == self.getoption("group") or \ self.getoption("group") == "": self.owner.addControl(c) self.control = c