Ejemplo n.º 1
0
def main():
    app = QApplication()
    window = QMainWindow()
    window.setMinimumSize(QSize(640, 480))

    imageFlow = FlowWidget(window)

    proxy = QSortFilterProxyModel()
    proxy.setFilterRole(FlowModel.FileNameRole)
    proxy.setSortRole(FlowModel.FileNameRole)
    imageFlow.setProxyModel(proxy)

    searchFilter = QLineEdit()
    searchFilter.textChanged.connect(
        lambda text: proxy.setFilterWildcard(text))

    layout = QVBoxLayout()
    layout.addWidget(searchFilter)
    layout.addWidget(imageFlow)

    widget = QWidget()
    widget.setLayout(layout)

    window.setCentralWidget(widget)
    window.show()

    # 画像を同期読み込み
    # for i, filePath in enumerate(glob.glob('C:/tmp/test_images2/*.png')):
    #     image = QImage(filePath).scaled(100, 100)
    #     item = FlowItem(filePath)
    #     item.setImage(image)
    #     imageFlow.appendItem(item)

    # 画像を非同期読み込み
    loader = BatchImageLoader()
    loader.addCallback(ImageLoadingCallback.LOADED,
                       lambda img: img.scaled(100, 100))
    tasks = {}

    def _on_load_image(taskId):
        filePath = tasks[taskId]
        image = loader.image(taskId)
        item = FlowItem(filePath, image)
        imageFlow.appendItem(item)

    def _on_load_complete():
        proxy.sort(0)

    loader.loaded.connect(_on_load_image)
    loader.completed.connect(_on_load_complete)
    for filePath in glob.iglob('C:/tmp/test_images/*.png'):
        taskId = loader.addFile(filePath)
        tasks[taskId] = filePath

    loader.loadAsync()

    sys.exit(app.exec_())
Ejemplo n.º 2
0
def main():
    _create_dirs()
    """
    Main function that starts everything
    """
    if is_wayland(
    ) and gdk_backend().lower() != 'x11' and not is_wayland_compatibility_on():
        warn = """
                    [!]
        Looks like you are in Wayland session
        Please run Ulauncher with env var
        GDK_BACKEND set to 'x11' like this:
        GDK_BACKEND=x11 ulauncher
        """
        print(warn, file=sys.stderr)
        sys.exit(1)

    # start DBus loop
    DBusGMainLoop(set_as_default=True)
    bus = dbus.SessionBus()
    instance = bus.request_name(DBUS_SERVICE)

    if instance != dbus.bus.REQUEST_NAME_REPLY_PRIMARY_OWNER:
        toggle_window = dbus.SessionBus().get_object(
            DBUS_SERVICE, DBUS_PATH).get_dbus_method("toggle_window")
        toggle_window()
        # return

    options = get_options()
    # setup_logging(options)
    logger = logging.getLogger('everylauncher')
    logger.info('EveryLauncher version %s' % get_version())
    logger.info("Is Wayland: %s" % is_wayland())
    logger.info("Wayland compatibility: %s" %
                ('on' if is_wayland_compatibility_on() else 'off'))

    # log uncaught exceptions
    # def except_hook(exctype, value, tb):
    #     logger.error("Uncaught exception", exc_info=(exctype, value, tb))

    # sys.excepthook = except_hook

    app = QApplication(sys.argv)
    app.setQuitOnLastWindowClosed(False)
    QApplication.setOrganizationName(ORGANIZATION_NAME)
    QApplication.setOrganizationDomain(ORGANIZATION_DOMAIN)
    QApplication.setApplicationName(APPLICATION_NAME)

    # engine = QQmlApplicationEngine()
    view = myQuickWidget()
    view.setWindowFlags(Qt.WindowStaysOnTopHint)
    view.setWindowFlags(QtCore.Qt.WindowCloseButtonHint \
                        | QtCore.Qt.FramelessWindowHint)
    # view.setWindowTitle(QObject.tr("EveryLauncher"))
    # TODO hide when lise focus
    view.move((QApplication.desktop().width() - view.width()) / 2,
              QApplication.desktop().height() / 1.7 - view.height())
    engine = view.engine()

    model = recollQueryModel(RECOLL_CONFIG_DIR, [])
    proxy = QSortFilterProxyModel()
    proxy.setSourceModel(model)
    proxy.setFilterRole(recollQueryModel.Role_TYPE)

    # qmlRegisterType(recollQueryModel, 'RecollQuery', 1, 0, 'EveryQueryModel')

    tray = SystemTray.get_instance(view)

    desktop_servers = QDesktopServices()
    engine.rootContext().setContextProperty("queryModel", model)
    engine.rootContext().setContextProperty("filterModel", proxy)
    engine.rootContext().setContextProperty("systemTray", tray)
    engine.rootContext().setContextProperty("desktopServices", desktop_servers)

    EveryLauncherDbusService(tray)
    if not options.hide_window:
        tray.showMainWindow(True)
    # engine.load(QUrl("ui/QML/main.qml"))
    # if not engine.rootObjects():
    #     sys.exit(-1)

    dir = os.path.dirname(os.path.abspath(__file__))
    view.setSource(QUrl(os.path.join(dir, "ui/QML/main.qml")))

    setting = QSettings()
    setting.beginGroup("General")
    if trans_to_bool(setting.value(SHOW_INDICATOR, True)):
        tray.show()
    if trans_to_bool(setting.value(SHOW_WINDOW_ON_START, True)):
        view.show()
    setting.endGroup()

    # w=PreferenceWindow()
    # w.show()

    # tray.show()
    # if Settings.get_instance().get_property('show-indicator-icon'):

    # workaround to make Ctrl+C quiting the app
    # signal_handler = SignalHandler(window)
    # TODO add shortkey in deepin control

    sys.exit(app.exec_())