Skip to content

Commit

Permalink
PubSubHub moved to flet_core
Browse files Browse the repository at this point in the history
  • Loading branch information
FeodorFitsner committed Feb 23, 2024
1 parent 5103072 commit 679144d
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 23 deletions.
1 change: 1 addition & 0 deletions sdk/python/packages/flet-core/src/flet_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
from flet_core.popup_menu_button import PopupMenuButton, PopupMenuItem
from flet_core.progress_bar import ProgressBar
from flet_core.progress_ring import ProgressRing
from flet_core.pubsub import PubSub, PubSubHub
from flet_core.querystring import QueryString
from flet_core.radio import Radio
from flet_core.radio_group import RadioGroup
Expand Down
8 changes: 1 addition & 7 deletions sdk/python/packages/flet-core/src/flet_core/connection.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
from typing import List, Optional

from flet_core.protocol import Command

try:
from flet_runtime.pubsub import PubSubHub
except ImportError:

class PubSubHub:
pass
from flet_core.pubsub import PubSubHub


class Connection:
Expand Down
17 changes: 6 additions & 11 deletions sdk/python/packages/flet-core/src/flet_core/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@
from flet_core.event import Event
from flet_core.event_handler import EventHandler
from flet_core.floating_action_button import FloatingActionButton
from flet_core.locks import AsyncNopeLock, NopeLock
from flet_core.locks import NopeLock
from flet_core.navigation_bar import NavigationBar
from flet_core.navigation_drawer import NavigationDrawer
from flet_core.padding import Padding
from flet_core.protocol import Command
from flet_core.pubsub import PubSub
from flet_core.querystring import QueryString
from flet_core.session_storage import SessionStorage
from flet_core.snack_bar import SnackBar
Expand All @@ -60,7 +61,6 @@
try:
from flet_runtime.auth.authorization import Authorization
from flet_runtime.auth.oauth_provider import OAuthProvider
from flet_runtime.pubsub import PubSub
except ImportError as e:
logger.warning("Authorization classes are not loaded, using fake implementations.")

Expand All @@ -70,10 +70,6 @@ class Authorization:
class OAuthProvider:
pass

class PubSub:
def __init__(self, pubsubhub, session_id) -> None:
pass


class PageDisconnectedException(Exception):
def __init__(self, message):
Expand Down Expand Up @@ -120,14 +116,13 @@ def __init__(
self.__next_control_id = 1
self.__snapshot: Dict[str, Dict[str, Any]] = {}
self.__expires_at = None
self.__query = QueryString(page=self) # Querystring
self.__query: QueryString = QueryString(page=self) # Querystring
self._session_id = session_id
self.__loop = loop
self.__pool = pool
self._index = {self._Control__uid: self} # index with all page controls

self.__lock = threading.Lock() if not is_pyodide() else NopeLock()
self.__async_lock = asyncio.Lock() if is_asyncio() else AsyncNopeLock()

self.__views = [View()]
self.__default_view = self.__views[0]
Expand All @@ -138,7 +133,7 @@ def __init__(
self.__theme = None
self.__dark_theme = None
self.__theme_mode = ThemeMode.SYSTEM # Default Theme Mode
self.__pubsub = PubSub(conn.pubsubhub, session_id)
self.__pubsub: PubSub = PubSub(conn.pubsubhub, session_id)
self.__client_storage = ClientStorage(self)
self.__session_storage = SessionStorage(self)
self.__authorization: Optional[Authorization] = None
Expand Down Expand Up @@ -444,7 +439,7 @@ async def on_event_async(self, e: Event):
logger.debug(f"page.on_event_async: {e.target} {e.name} {e.data}")

if e.target == "page" and e.name == "change":
async with self.__async_lock:
with self.__lock:
self.__on_page_change_event(e.data)

elif e.target in self._index:
Expand Down Expand Up @@ -1074,7 +1069,7 @@ async def window_close_async(self):

# QueryString
@property
def query(self):
def query(self) -> QueryString:
return self.__query

# url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import threading
from concurrent.futures import ThreadPoolExecutor
from typing import Any, Awaitable, Callable, Coroutine, Dict, Iterable, Optional, Union
from typing import Any, Awaitable, Callable, Dict, Iterable, Optional, Union
from warnings import warn

import flet_runtime
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flet_core import *
from flet_core.pubsub import PubSub
from flet_core.types import (
FLET_APP,
FLET_APP_HIDDEN,
Expand All @@ -8,4 +9,3 @@
WebRenderer,
)
from flet_runtime.app import app, app_async
from flet_runtime.pubsub import PubSub
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
PageCommandsBatchResponsePayload,
RegisterWebClientRequestPayload,
)
from flet_core.pubsub import PubSubHub
from flet_core.utils import random_string
from flet_runtime.pubsub import PubSubHub
from flet_runtime.utils import get_free_tcp_port, is_windows

logger = logging.getLogger(flet_runtime.__name__)
Expand Down
3 changes: 1 addition & 2 deletions sdk/python/packages/flet/src/flet/fastapi/flet_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from typing import Any, Dict, List, Optional

import flet.fastapi as flet_fastapi
import flet_core
from fastapi import WebSocket, WebSocketDisconnect
from flet.fastapi.flet_app_manager import app_manager
from flet.fastapi.oauth_state import OAuthState
Expand All @@ -24,8 +23,8 @@
PageCommandsBatchResponsePayload,
RegisterWebClientRequestPayload,
)
from flet_core.pubsub import PubSubHub
from flet_core.utils import random_string
from flet_runtime.pubsub import PubSubHub
from flet_runtime.uploads import build_upload_url

logger = logging.getLogger(flet_fastapi.__name__)
Expand Down

0 comments on commit 679144d

Please sign in to comment.