当前位置: 首页>>代码示例>>Python>>正文


Python Gui.show_css_details方法代码示例

本文整理汇总了Python中gui.Gui.show_css_details方法的典型用法代码示例。如果您正苦于以下问题:Python Gui.show_css_details方法的具体用法?Python Gui.show_css_details怎么用?Python Gui.show_css_details使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gui.Gui的用法示例。


在下文中一共展示了Gui.show_css_details方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from gui import Gui [as 别名]
# 或者: from gui.Gui import show_css_details [as 别名]
class PyCSS:

    def __init__(self, master):
        self.gui = Gui(master)
        self.encodingerrors = []
        self.fetched_files = []
        self.used = []
        self.unused = []
        self.cssclasses = {}
        self.cssfilesnotfound = {}
        self.css_selectors = {}

    @staticmethod
    def update_status_bar(*args):
        _css_files.set(())
        selected_file = _file_listbox.get(_file_listbox.curselection())
        if selected_file:
            _status_msg.set(selected_file)

    def show_about_window(self, *args):
        self.gui.show_about_window(*args)

    def show_css_details(self, *args):
        selected_css_file = _css_listbox.get(_css_listbox.curselection())
        if selected_css_file:
            details = [selected_css_file, self.used, self.unused]
            self.gui.show_css_details(_menubar, *details)

    def get_directory(self):
        self.gui.get_directory(_directory)

    def fetch_files(self, recursive_search=True):
        directory = _directory.get()
        if not directory:
            messagebox.showerror('No Directory Selected', 'Please select a directory', icon='error')
            return
        _files.set(())
        self.fetched_files[:] = []
        for ext in ["shtml", "html", "xhtml"]:

            if recursive_search:
                files = [os.path.join(dirpath, f)
                         for dirpath, dirnames, files in os.walk(directory)
                         for f in files if f.endswith('.' + ext)]
            else:
                files = glob.glob(directory + "*." + ext)

            self.fetched_files += files

        _files.set(self.fetched_files)
        _status_msg.set('Search results for {}'.format(directory) if self.fetched_files else 'No files found')

    def parse_file(self, *args):
        self.css_selectors.clear()
        self.encodingerrors[:] = []
        self.cssclasses.clear()
        self.cssfilesnotfound.clear()

        file = self.fetched_files[_file_listbox.curselection()[0]]
        parser = PyCSSParser(file)

        try:

            with open(file, "r") as handle:

                for linenum, line in enumerate(handle.readlines()):

                    linenum += 1

                    parser.feed(line)  # parser looks for classes and ids in linked css files

                    classes = re.findall(r'class=\"(.+?)\"', line)
                    if classes:
                        for html_class in classes:
                            html_class = "." + html_class
                            self.css_selectors[html_class] = linenum

                    ids = re.findall(r'id=\"(.+?)\"', line)
                    if ids:
                        for html_id in ids:
                            html_id = "#" + html_id
                            self.css_selectors[html_id] = linenum

                handle.close()

        except UnicodeDecodeError:
            if file not in self.encodingerrors:
                self.encodingerrors.append(file)

        self.cssclasses, self.cssfilesnotfound = copy.deepcopy(parser.cssclasses), copy.deepcopy(parser.cssfilesnotfound)
        self._link_css_ids_and_classes(file)

    def _link_css_ids_and_classes(self, html_file):
        self.used[:] = []  # reset the class lists
        self.unused[:] = []  # reset the class lists

        if html_file in self.cssclasses:

            for cssfile, css in self.cssclasses[html_file].items():

#.........这里部分代码省略.........
开发者ID:ElanMan,项目名称:PyCSS,代码行数:103,代码来源:pycss.py


注:本文中的gui.Gui.show_css_details方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。