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


Python QDeclarativeView.setFixedWidth方法代码示例

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


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

示例1: TabsHandler

# 需要导入模块: from PyQt4.QtDeclarative import QDeclarativeView [as 别名]
# 或者: from PyQt4.QtDeclarative.QDeclarativeView import setFixedWidth [as 别名]
class TabsHandler(QFrame):
    def __init__(self, parent=None):
        super(TabsHandler, self).__init__(None, Qt.FramelessWindowHint | Qt.Popup)
        self._main_container = parent
        self.setAttribute(Qt.WA_TranslucentBackground)
        self.setStyleSheet("background:transparent;")
        # Create the QML user interface.
        self.view = QDeclarativeView()
        self.view.setResizeMode(QDeclarativeView.SizeRootObjectToView)
        self.view.setSource(ui_tools.get_qml_resource("TabsHandler.qml"))
        self._root = self.view.rootObject()
        vbox = QVBoxLayout(self)
        vbox.setContentsMargins(0, 0, 0, 0)
        vbox.setSpacing(0)
        vbox.addWidget(self.view)

        self._model = {}
        self._max_index = 0

        self.connect(self._root, SIGNAL("open(QString)"), self._open)
        self.connect(self._root, SIGNAL("close(QString)"), self._close)
        self.connect(self._root, SIGNAL("hide()"), self.hide)

    def _open(self, path):
        self._main_container.open_file(path)
        index = self._model[path]
        self._max_index = max(self._max_index, index) + 1
        self._model[path] = self._max_index
        self.hide()

    def _close(self, path):
        ninjaide = IDE.get_service("ide")
        nfile = ninjaide.get_or_create_nfile(path)
        nfile.close()

    def _add_model(self):
        ninjaide = IDE.get_service("ide")
        files = ninjaide.filesystem.get_files()
        files_data = list(files.values())
        # Update model
        old = set(self._model.keys())
        new = set([nfile.file_path for nfile in files_data])
        result = old - new
        for item in result:
            del self._model[item]
        current_editor = self._main_container.get_current_editor()
        current_path = None
        if current_editor:
            current_path = current_editor.file_path
        model = []
        for nfile in files_data:
            if nfile.file_path not in self._model:
                self._model[nfile.file_path] = 0
            neditable = ninjaide.get_or_create_editable(nfile.file_path)
            checkers = neditable.sorted_checkers
            checks = []
            for items in checkers:
                checker, color, _ = items
                if checker.dirty:
                    checks.append({"checker_text": checker.dirty_text, "checker_color": color})
            modified = neditable.document.isModified()
            model.append([nfile.file_name, nfile.file_path, checks, modified])
        if current_path:
            index = self._model[current_path]
            self._max_index = max(self._max_index, index) + 1
            self._model[current_path] = self._max_index
        model = sorted(model, key=lambda x: self._model[x[1]], reverse=True)
        self._root.set_model(model)

    def showEvent(self, event):
        self._add_model()
        width = max(self._main_container.width() / 3, 300)
        logger.debug("This is the width")
        logger.debug(width)
        height = max(self._main_container.height() / 2, 400)
        logger.debug("This is the height")
        logger.debug(height)
        self.view.setFixedWidth(width)

        self.view.setFixedHeight(height)
        super(TabsHandler, self).showEvent(event)
        self._root.show_animation()
        point = self._main_container.mapToGlobal(self.view.pos())
        y_diff = self._main_container.combo_header_size
        self.move(point.x(), point.y() + y_diff)
        self.view.setFocus()

    def hideEvent(self, event):
        super(TabsHandler, self).hideEvent(event)
        self._root.clear_model()

    def next_item(self):
        if not self.isVisible():
            self.show()
        self._root.next_item()

    def previous_item(self):
        if not self.isVisible():
            self.show()
        self._root.previous_item()
#.........这里部分代码省略.........
开发者ID:emilioramirez,项目名称:ninja-ide,代码行数:103,代码来源:tabs_handler.py

示例2: FilesHandler

# 需要导入模块: from PyQt4.QtDeclarative import QDeclarativeView [as 别名]
# 或者: from PyQt4.QtDeclarative.QDeclarativeView import setFixedWidth [as 别名]

#.........这里部分代码省略.........
            files_in_project = locator.files_paths[project_path]
            base_project = os.path.basename(project_path)
            for file_path in files_in_project:
                file_path = os.path.join(
                    base_project, os.path.relpath(file_path, project_path))
                if pattern.search(file_path):
                    model.append([os.path.basename(file_path), file_path,
                                  project_path])
        self._root.set_fuzzy_model(model)

    def _add_model(self):
        ninjaide = IDE.get_service("ide")
        files = ninjaide.opened_files
        # Update model
        old = set(self._model.keys())
        new = set([nfile.file_path for nfile in files])
        result = old - new
        for item in result:
            del self._model[item]
        current_editor = self._main_container.get_current_editor()
        current_path = None
        if current_editor:
            current_path = current_editor.file_path
        model = []
        for nfile in files:
            if (nfile.file_path not in self._model and
                    nfile.file_path is not None):
                self._model[nfile.file_path] = 0
            neditable = ninjaide.get_or_create_editable(nfile=nfile)
            checkers = neditable.sorted_checkers
            checks = []
            for items in checkers:
                checker, color, _ = items
                if checker.dirty:
                    checks.append(
                        {"checker_text": checker.dirty_text,
                         "checker_color": color})
            modified = neditable.document.isModified()
            temp_file = str(uuid.uuid4()) if nfile.file_path is None else ""
            filepath = nfile.file_path if nfile.file_path is not None else ""
            model.append([nfile.file_name, filepath, checks, modified,
                          temp_file])
            if temp_file:
                self._temp_files[temp_file] = nfile
        if current_path:
            index = self._model[current_path]
            self._max_index = max(self._max_index, index) + 1
            self._model[current_path] = self._max_index
        model = sorted(model, key=lambda x: self._model.get(x[1], False),
                       reverse=True)
        self._root.set_model(model)

    def showEvent(self, event):
        self._add_model()
        widget = self._main_container.get_current_editor()
        if widget is None:
            widget = self._main_container
        if self._main_container.splitter.count() < 2:
            width = max(widget.width() / 2, 500)
            height = max(widget.height() / 2, 400)
        else:
            width = widget.width()
            height = widget.height()
        self.view.setFixedWidth(width)
        self.view.setFixedHeight(height)

        super(FilesHandler, self).showEvent(event)
        self._root.show_animation()
        point = widget.mapToGlobal(self.view.pos())
        self.move(point.x(), point.y())
        self.view.setFocus()
        self._root.activateInput()

    def hideEvent(self, event):
        super(FilesHandler, self).hideEvent(event)
        self._temp_files = {}
        self._root.clear_model()

    def next_item(self):
        if not self.isVisible():
            self.show()
        self._root.next_item()

    def previous_item(self):
        if not self.isVisible():
            self.show()
        self._root.previous_item()

    def keyPressEvent(self, event):
        if event.key() == Qt.Key_Escape:
            self.hide()
        elif (event.modifiers() == Qt.ControlModifier and
                event.key() == Qt.Key_PageDown) or event.key() == Qt.Key_Down:
            self._root.next_item()
        elif (event.modifiers() == Qt.ControlModifier and
                event.key() == Qt.Key_PageUp) or event.key() == Qt.Key_Up:
            self._root.previous_item()
        elif event.key() in (Qt.Key_Return, Qt.Key_Enter):
            self._root.open_item()
        super(FilesHandler, self).keyPressEvent(event)
开发者ID:AnyBucket,项目名称:ninja-ide,代码行数:104,代码来源:files_handler.py


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