Skip to main content

Parser implementation of NeXTSTEP Interface Builder (NIB) files

Project description

NIBArchive-Parser

python Codestyle License PyPi Build and Deploy Sphinx Documentation

Parser implementation of NeXTSTEP Interface Builder (NIB) files in Python3.

NIBArchive

The .nib file is primarily associated with Interface Builder, a graphical user interface (GUI) design tool used to create the visual layout of user interfaces for applications. The purpose of a NIB file is to store the information about the user interface elements, their properties, and their relationships with each other.

The file format has been described in detail in the nibsqueeze repository.

Installation

Just use pip:

$ pip install nibarchive

and to build the docs you need make to be installed:

$ pip install -r docs/requirements.txt
$ cd docs && make html

Usage

The python package provided with this repository supports parsing NIB archives into an object model. More detailed information about the implementation and fields of each class, please refer to the documentation available on Github-Pages.

Parsing NIB files

As the NIBArchiveParser only accepts IOBase objects, we can either parse opened files directly or use io.BytesIO for a reader on existing byte structures.

from nibarchive import NIBArchiveParser

# Create the parser instance
parser = NIBArchiveParser(verify=True)

# Parse an input file from scratch
with open("path/to/file.nib", "rb") as fp:
    archive: NIBArchive = parser.parse(fp)

Or with BytesIO:

from io import BytesIO

# assue the file content is stored here
buffer = bytes(...)
parser = NIBArchiveParser()

# parse using BytesIO wrapper class
archive = parser.parse(BytesIO(buffer))

Working with NIBArchive objects

At this point we can use the returned object to inspect the files content. But, the parser does not organize the returned archive, so we have to do it afterwards:

# Get an object
obj: NIBObject = archive.objects[0]

# Get the object's class name
class_name: ClassName = archive.get_class_name(obj)

# Retrieve the object's values
values: list[NIBValue] = archive.get_object_values(obj)
for value in values:
    # Each value is mapped to a NIBKey
    key: NIBKey = archive.get_value_key(value)

There is a convienient method named get_object_items which automatically maps all values of an object to their corresponding keys. The return value is of type dict[NIBKey, NIBValue]

License

Distributed under the GNU GPLv3. See LICENSE for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nibarchive-1.1.0-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

Details for the file nibarchive-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: nibarchive-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for nibarchive-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f50c5fc7600ec32ebc22d25da7651eef1ff8ddf7ce2406ff234c17b6f57d796
MD5 f67c7dc47985b2dcd8423455b3553574
BLAKE2b-256 b0ee678268d7e696ac78741876c6e6f685451ffac284fca0d2c02ea8322f6072

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page