Skip to content

Commit

Permalink
Updated to 5.40
Browse files Browse the repository at this point in the history
  • Loading branch information
martastain committed Mar 7, 2022
1 parent 82e930c commit ecaf2d0
Show file tree
Hide file tree
Showing 63 changed files with 4,275 additions and 2,309 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ _res/
_old/
templates/
mpv-1.dll
poetry.lock
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ Firefly
=======

![GitHub release (latest by date)](https://img.shields.io/github/v/release/nebulabroadcast/firefly?style=for-the-badge)
![Maintenance](https://img.shields.io/maintenance/yes/2021?style=for-the-badge)
![Maintenance](https://img.shields.io/maintenance/yes/2022?style=for-the-badge)
![Last commit](https://img.shields.io/github/last-commit/immstudios/nebula?style=for-the-badge)
![Python version](https://img.shields.io/badge/python-3.7-blue?style=for-the-badge)
![Python version](https://img.shields.io/badge/python-3.8-blue?style=for-the-badge)

Firefly is a desktop client application for [Nebula](https://github.com/nebulabroadcast/nebula) broadcast automation system.

Expand Down
8 changes: 1 addition & 7 deletions firefly.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#!/usr/bin/env python3

try:
import rex
except ImportError:
# Frozen application does not need package manager
pass

from nxtools import *
from nxtools import log_traceback
from firefly.application import FireflyApplication

if __name__ == "__main__":
Expand Down
5 changes: 0 additions & 5 deletions firefly/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
from .common import *
from .base_module import BaseModule
from .widgets import *
from .view import *

from .application import FireflyApplication
53 changes: 28 additions & 25 deletions firefly/api.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
__all__ = ["api"]

import time
import json
import queue
import functools

from nx import *
from pyqtbs import *
from nebulacore import *
from nxtools import logging, log_traceback

from .version import FIREFLY_VERSION
from firefly.core.common import config, NebulaResponse
from firefly.common import CLIENT_ID
from firefly.objects import asset_cache
from firefly.version import FIREFLY_VERSION
from firefly.qt import (
QApplication,
QNetworkAccessManager,
QNetworkRequest,
QNetworkReply,
QVariant,
QUrlQuery,
QUrl,
)


class NebulaAPI():
class NebulaAPI:
def __init__(self):
self.manager = QNetworkAccessManager()
self.queries = []


def run(self, method, callback, **kwargs):
logging.debug("Executing {}{} query".format("" if callback == -1 else "async ", method))
logging.debug(
"Executing {}{} query".format("" if callback == -1 else "async ", method)
)
kwargs["session_id"] = config["session_id"]
kwargs["initiator"] = CLIENT_ID

Expand All @@ -34,15 +45,12 @@ def run(self, method, callback, **kwargs):
mime = QVariant("application/json")
data = json.dumps(kwargs).encode("ascii")

request = QNetworkRequest(QUrl(config["hub"] + method))
request.setHeader(
QNetworkRequest.ContentTypeHeader,
mime
)
request = QNetworkRequest(QUrl(config["hub"] + method))
request.setHeader(QNetworkRequest.ContentTypeHeader, mime)
request.setHeader(
QNetworkRequest.UserAgentHeader,
QVariant(f"nebula-firefly/{FIREFLY_VERSION}")
)
QNetworkRequest.UserAgentHeader,
QVariant(f"nebula-firefly/{FIREFLY_VERSION}"),
)

try:
query = self.manager.post(request, data)
Expand All @@ -61,32 +69,27 @@ def run(self, method, callback, **kwargs):

if callback == -1:
while not query.isFinished():
time.sleep(.0001)
time.sleep(0.0001)
QApplication.processEvents()
return self.handler(query, -1)



def handler(self, response, callback):
er = response.error()
if er == QNetworkReply.NoError:
bytes_string = response.readAll()
data = str(bytes_string, 'ascii')
result = NebulaResponse(
**json.loads(data)
)
data = str(bytes_string, "ascii")
result = NebulaResponse(**json.loads(data))
else:
result = NebulaResponse(500, response.errorString())
self.queries.remove(response)
if callback and callback != -1:
callback(result)
return result



def __getattr__(self, method_name):
def wrapper(callback=-1, **kwargs):
return self.run(method_name, callback, **kwargs)

return wrapper


Expand Down
92 changes: 54 additions & 38 deletions firefly/application.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
import os
import sys
import time
import locale

from .common import *
from .filesystem import load_filesystem
from nxtools import logging, log_traceback, critical_error

from .dialogs.login import *
from .dialogs.site_select import *
from firefly.filesystem import load_filesystem

from .main_window import FireflyMainWindow, FireflyMainWidget
from nebulacore.meta_utils import clear_cs_cache
from firefly.dialogs.login import show_login_dialog
from firefly.dialogs.site_select import show_site_select_dialog

from firefly.api import api
from firefly.common import pixlib
from firefly.core.common import config
from firefly.core.metadata import clear_cs_cache
from firefly.objects import user
from firefly.main_window import FireflyMainWindow, FireflyMainWidget
from firefly.objects import asset_cache
from firefly.version import FIREFLY_VERSION
from firefly.qt import (
Qt,
QApplication,
QMessageBox,
QSplashScreen,
app_settings,
app_dir,
app_skin,
)


def check_login(wnd):
Expand All @@ -20,38 +38,38 @@ def check_login(wnd):
config["session_id"] = session_id
return user_meta
if data["response"] > 403:
QMessageBox.critical(
wnd,
f"Error {data['response']}",
data["message"]
)
QMessageBox.critical(wnd, f"Error {data['response']}", data["message"])
return False
return login_dialog()
return show_login_dialog()


class FireflyApplication(Application):
class FireflyApplication(QApplication):
def __init__(self, **kwargs):
title = f"Firefly {FIREFLY_VERSION}"
super(FireflyApplication, self).__init__(name="firefly", title=title)
locale.setlocale(locale.LC_NUMERIC, 'C')
self.splash = QSplashScreen(pix_lib['splash'])
super(FireflyApplication, self).__init__(sys.argv)
self.app_state = {"name": "firefly", "title": f"Firefly {FIREFLY_VERSION}"}
self.app_state_path = os.path.join(app_dir, f"{app_settings['name']}.appstate")
self.setStyleSheet(app_skin)
locale.setlocale(locale.LC_NUMERIC, "C")
self.splash = QSplashScreen(pixlib["splash"])
self.splash.show()

# Which site we are running

i = 0
if "sites" in config:
if len(config["sites"]) > 1:
i = site_select_dialog()
i = show_site_select_dialog()
else:
i = 0

self.local_keys = list(config["sites"][i].keys())
config.update(config["sites"][i])
del(config["sites"])
del config["sites"]

self.app_state_path = os.path.join(app_dir, f"ffdata.{config['site_name']}.appstate")
self.auth_key_path = os.path.join(app_dir, f"ffdata.{config['site_name']}.key")
self.app_state_path = os.path.join(
app_dir, f"ffdata.{config['site_name']}.appstate"
)
self.auth_key_path = os.path.join(app_dir, f"ffdata.{config['site_name']}.key")

# Login

Expand All @@ -64,7 +82,6 @@ def __init__(self, **kwargs):
log_traceback()
config["session_id"] = session_id


user_meta = check_login(self.splash)
if not user_meta:
logging.error("Unable to log in")
Expand All @@ -81,7 +98,6 @@ def __init__(self, **kwargs):
self.splash_message("Loading user workspace...")
self.main_window = FireflyMainWindow(self, FireflyMainWidget)


def start(self):
self.splash.hide()
try:
Expand All @@ -102,20 +118,20 @@ def on_exit(self):
self.main_window.listener.halt()
i = 0
while not self.main_window.listener.halted:
time.sleep(.1)
time.sleep(0.1)
if i > 10:
logging.warning("Unable to shutdown listener. Forcing quit", handlers=False)
logging.warning(
"Unable to shutdown listener. Forcing quit", handlers=False
)
break
i+=1
i += 1
sys.exit(0)

def splash_message(self, msg):
if self.splash.isVisible:
self.splash.showMessage(
msg,
alignment=Qt.AlignBottom|Qt.AlignLeft,
color=Qt.white
)
msg, alignment=Qt.AlignBottom | Qt.AlignLeft, color=Qt.white
)

def load_settings(self):
self.splash_message("Loading site settings")
Expand All @@ -132,14 +148,14 @@ def load_settings(self):

# Fix indices
for config_group in [
"storages",
"playout_channels",
"ingest_channels",
"folders",
"views",
"actions",
"services",
]:
"storages",
"playout_channels",
"ingest_channels",
"folders",
"views",
"actions",
"services",
]:
ng = {}
for id in config[config_group]:
ng[int(id)] = config[config_group][id]
Expand Down
4 changes: 3 additions & 1 deletion firefly/base_module.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from .common import *
from firefly.core.common import config
from firefly.qt import QWidget

__all__ = ["BaseModule"]


class BaseModule(QWidget):
def __init__(self, parent):
super(BaseModule, self).__init__(parent)
Expand Down
Loading

0 comments on commit ecaf2d0

Please sign in to comment.