Giter Club home page Giter Club logo

qtuiparser.jl's Introduction

Qt UI Parser

A Parser and generator for the .ui XML files used by Qt Designer and Creator. This is a file format used to store user interfaces designed using the Qt Designer tool, and which can be proccessed by the uic command.

Purpose and Motivation

Managing layouts in Qt Designer is difficult. The borders on the layout are 1 pixel wide and you have to pay a lot of attention to hit them. It is easy to accidentally pull a widget out of a layout and ruin it. A complex layout can be exceedingly difficult to change without breaking then, and then struggle with putting it back together.

I tried to overcome these problems by editing the .ui file XML format directly. However that proved difficult as the format was clearly not designed for manual editing.

That is the purpose of this package. To provide an assortment of tools to manipulate the .ui files with a more friendly interface.

Installation

This has been made for the new package manager in Julia 0.7. You hit the ] key in the Julia REPL (command line interface) and write.

pkg> add https://github.com/ordovician/QtUIParser.jl

This is because QtUIParser is presently not a registered package.

Usage

If you look in the example folder you can find several examples of .ui and .jl files describing different user interfaces. The .jl files contains GUIs described in what I am currently calling ERML format. ERML is a type of Julia domain specific language (DSL) for describing user interfaces. This is a simple ERML example in the colors.jl file:

Ui(
    class   = "ColorsForm",
    version = "4.0",
    root = QWidget(
        name        = "ColorsForm",
        class       = :QWidget,
        geometry    = Rect(0, 0, 121, 73),
        windowTitle = "Form",
        layout = VBoxLayout(
            name = "top_layout",
            items = [
                QCheckBox("red_box", "red"),
                QCheckBox("blue_box", "blue")
            ]
        )
    )
)

Because this is valid julia code you can run this file and get a Ui object by simply writing:

julia> ui = include("colors.jl")

You can turn the top node in this tree or subnodes into xml which can be stored in .ui files:

julia> xml(ui)
julia> xml(ui.root)

Use the read_ui function to read and parse a .ui file and turn it into ERML format:

julia> read_ui("colors.ui")
Ui(
    class   = "ColorsForm",
    version = "4.0",
    root = QWidget(
        name        = "ColorsForm",
        class       = :QWidget,
        geometry    = Rect(0, 0, 121, 73),
        windowTitle = "Form",
        layout = VBoxLayout(
            name = "top_layout",
            items = [
                QCheckBox("red_box", "red"),
                QCheckBox("blue_box", "blue")
            ]
        )
    )
)

Shortcuts and Practical Usage

When working with UI files there will be common patterns of usage. I have added functions in the tools.jl file to support this.

Loading .ui and .jl Files

The load convenience function alls you to load files regardless of whether they are .ui or .jl files.

julia> ui = load("colors.ui")
julia> ui = load("colors.jl")

It keeps track of which file was loaded, so in the case of .ui files you can load them again with

julia> ui = load()

Saving .ui and .jl Files

You use different functions depending on the storage format you want to use. Say you have create a user interface object and stored it in ui variable. You can save it in either Qt UI format or ERML format with:

julia> save_erml_as("colors.jl", ui)
julia> save_ui_as("colors.ui", ui)

It will remember what ui object and filepath was used so you don't have to specify them later.

julia> save_erml()
julia> save_ui()

Or you can specify another path:

julia> save_erml_as("foobar.jl")
julia> save_ui_as("foobar.ui")

Or use existing path but different ui object:

julia> save_erml(ui)
julia> save_ui(ui)

Locating Items

In search.jl you will find various functions for finding widgets or layout of particular name or type. To look for a widget with a particular name:

julia> ui = load("examples/slider.jl")
julia> findfirstitem(ui, "value_spinner")

Building UIs Quicker

A lot of UI building requires boilerplate code. Often you use the same layout with a bunch of components over and over again. In prefab.jl we have some functions for creating prefabricated composite widgets.

Tab("Foo Bar", "foobar.ui")

For instance Tab will load a widget from a file, foobar.ui in this case, and add an attribute for the tab title Foo Bar, so you can fill up a QTabWidget with individual tabs stored on separate .ui files.

qtuiparser.jl's People

Contributors

translusion avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.