Beispiel #1
0
    def getIcon(self):
        '''Return name/relative path of image file to use for the icon'''
        # first look for downloaded icons
        icon_known_exts = ['.bmp', '.gif', '.icns', '.jpg', '.jpeg', '.png',
                           '.psd', '.tga', '.tif', '.tiff', '.yuv']
        icon_name = self.get('icon_name') or self['name']
        if not os.path.splitext(icon_name)[1] in icon_known_exts:
            icon_name += '.png'
        icon_path = os.path.join(msclib.html_dir(), 'icons', icon_name)
        if os.path.exists(icon_path):
            return 'icons/' + quote(icon_name)
        # didn't find one in the downloaded icons
        # so create one if needed from a locally installed app
        for key in ['icon_name', 'display_name', 'name']:
            if key in self:
                name = self[key]
                icon_name = name
                if not os.path.splitext(icon_name)[1] in icon_known_exts:
                    icon_name += '.png'
                icon_path = os.path.join(msclib.html_dir(), icon_name)
                if (os.path.exists(icon_path)
                        or convertIconToPNG(name, icon_path, 350)):
                    return quote(icon_name)

        # use the Generic package icon
        return 'static/Generic.png'
Beispiel #2
0
    def getIcon(self):
        '''Return name/relative path of image file to use for the icon'''
        # first look for downloaded icons
        icon_known_exts = [
            '.bmp', '.gif', '.icns', '.jpg', '.jpeg', '.png', '.psd', '.tga',
            '.tif', '.tiff', '.yuv'
        ]
        icon_name = self.get('icon_name') or self['name']
        if not os.path.splitext(icon_name)[1] in icon_known_exts:
            icon_name += '.png'
        icon_path = os.path.join(msclib.html_dir(), 'icons', icon_name)
        if os.path.exists(icon_path):
            return 'icons/' + quote(icon_name)
        # didn't find one in the downloaded icons
        # so create one if needed from a locally installed app
        for key in ['icon_name', 'display_name', 'name']:
            if key in self:
                name = self[key]
                icon_name = name
                if not os.path.splitext(icon_name)[1] in icon_known_exts:
                    icon_name += '.png'
                icon_path = os.path.join(msclib.html_dir(), icon_name)
                if (os.path.exists(icon_path)
                        or convertIconToPNG(name, icon_path, 350)):
                    return quote(icon_name)

        # use the Generic package icon
        return 'static/Generic.png'
Beispiel #3
0
def write_page(page_name, html):
    '''write html to page_name in our local html directory'''
    html_file = os.path.join(msclib.html_dir(), page_name)
    try:
        f = open(html_file, 'w')
        f.write(html.encode('utf-8'))
        f.close()
    except (OSError, IOError), err:
        msclog.debug_log('write_page error: %s', str(err))
        raise
Beispiel #4
0
def write_page(page_name, html):
    '''write html to page_name in our local html directory'''
    html_file = os.path.join(msclib.html_dir(), page_name)
    try:
        f = open(html_file, 'w')
        f.write(html.encode('utf-8'))
        f.close()
    except (OSError, IOError), err:
        msclog.debug_log('write_page error: %s', str(err))
        raise
 def awakeFromNib(self):
     '''Stuff we need to intialize when we start'''
     self.configureFullScreenMenuItem()
     self.webView.setDrawsBackground_(NO)
     self.webView.setUIDelegate_(self)
     self.webView.setFrameLoadDelegate_(self)
     self.webView.setResourceLoadDelegate_(self)
     self.webView.setPolicyDelegate_(self)
     self.setNoPageCache()
     self.alert_controller = AlertController.alloc().init()
     self.alert_controller.setWindow_(self.window())
     self.html_dir = msclib.html_dir()
     self.registerForNotifications()
Beispiel #6
0
def get_template(template_name, raw=False):
    '''return an html template. If raw is True, just return the string; otherwise
    return a string Template object'''
    customTemplatesPath = os.path.join(msclib.html_dir(), 'custom/templates')
    resourcesPath = NSBundle.mainBundle().resourcePath()
    defaultTemplatesPath = os.path.join(resourcesPath, 'templates')
    for directory in [customTemplatesPath, defaultTemplatesPath]:
        templatePath = os.path.join(directory, template_name)
        if os.path.exists(templatePath):
            try:
                file_ref = open(templatePath)
                template_html = file_ref.read()
                file_ref.close()
                if raw:
                    return template_html.decode('utf-8')
                else:
                    return Template(template_html.decode('utf-8'))
            except (IOError, OSError):
                return None
    return None
Beispiel #7
0
def get_template(template_name, raw=False):
    '''return an html template. If raw is True, just return the string; otherwise
    return a string Template object'''
    customTemplatesPath = os.path.join(msclib.html_dir(), 'custom/templates')
    resourcesPath = NSBundle.mainBundle().resourcePath()
    defaultTemplatesPath = os.path.join(resourcesPath, 'templates')
    for directory in [customTemplatesPath, defaultTemplatesPath]:
        templatePath = os.path.join(directory, template_name)
        if os.path.exists(templatePath):
            try:
                file_ref = open(templatePath)
                template_html = file_ref.read()
                file_ref.close()
                if raw:
                    return template_html.decode('utf-8')
                else:
                    return Template(template_html.decode('utf-8'))
            except (IOError, OSError):
                return None
    return None