syphon.server_directory
1from dataclasses import dataclass 2from enum import Enum 3from typing import Callable, Any, List, Optional 4 5import objc 6from Cocoa import NSRunLoop, NSDefaultRunLoopMode, NSDate, NSImage 7 8 9class SyphonServerNotification(Enum): 10 """ 11 Enum representing Syphon server notifications. 12 13 Enum Values: 14 - Announce: A new SyphonServer is available on the system. 15 - Update: An existing SyphonServer instance has changed its description. 16 - Retire: A SyphonServer instance will no longer be available. 17 """ 18 Announce = "SyphonServerAnnounceNotification" 19 Update = "SyphonServerUpdateNotification" 20 Retire = "SyphonServerRetireNotification" 21 22 23@dataclass 24class SyphonServerDescription: 25 """ 26 Data class representing the description of a Syphon server. 27 28 Attributes: 29 - uuid (str): The UUID of the Syphon server. 30 - name (str): The name of the Syphon server. 31 - app_name (str): The name of the application associated with the Syphon server. 32 - icon (NSImage): The icon image of the Syphon server. 33 - raw (Any): The raw server information. 34 """ 35 uuid: str 36 name: str 37 app_name: str 38 icon: NSImage 39 raw: Any 40 41 42class SyphonServerDirectory: 43 """ 44 Class for interacting with the Syphon server directory. 45 46 Attributes: 47 - run_loop_interval (float): The interval for the run loop in seconds. 48 """ 49 50 def __init__(self): 51 """ 52 Initialize a SyphonServerDirectory. 53 """ 54 self._syphonServerDirectoryObjC = objc.lookUpClass("SyphonServerDirectory") 55 self._notification_center = objc.lookUpClass("NSNotificationCenter").defaultCenter() 56 57 self.run_loop_interval: float = 1.0 58 59 def add_observer(self, notification: SyphonServerNotification, handler: Callable[[Any], None]): 60 """ 61 Add an observer for a Syphon server notification. 62 63 Parameters: 64 - notification (SyphonServerNotification): The notification to observe. 65 - handler (Callable[[Any], None]): The handler function to be called when the notification is received. 66 """ 67 self._notification_center.addObserverForName_object_queue_usingBlock_( 68 notification.value, 69 None, 70 None, 71 handler 72 ) 73 74 @property 75 def servers(self) -> List[SyphonServerDescription]: 76 """ 77 Get a list of Syphon servers in the directory. 78 79 Returns: 80 - List[SyphonServerDescription]: A list of SyphonServerDescription objects. 81 """ 82 self.update_run_loop() 83 directory = self._syphonServerDirectoryObjC.sharedDirectory() 84 servers = directory.servers() 85 86 return [ 87 SyphonServerDescription( 88 str(s["SyphonServerDescriptionUUIDKey"]), 89 str(s["SyphonServerDescriptionNameKey"]), 90 str(s["SyphonServerDescriptionAppNameKey"]), 91 s["SyphonServerDescriptionIconKey"], 92 s 93 ) 94 for s in servers 95 ] 96 97 def update_run_loop(self): 98 """ 99 Update the run loop to process events. 100 """ 101 NSRunLoop.currentRunLoop().runMode_beforeDate_( 102 NSDefaultRunLoopMode, 103 NSDate.dateWithTimeIntervalSinceNow_(self.run_loop_interval) 104 ) 105 106 def servers_matching_name(self, 107 name: Optional[str] = None, 108 app_name: Optional[str] = None) -> List[SyphonServerDescription]: 109 """ 110 Get a list of Syphon servers that match the specified name or application name. 111 112 Parameters: 113 - name (Optional[str]): The name to match. 114 - app_name (Optional[str]): The application name to match. 115 116 Returns: 117 - List[SyphonServerDescription]: A list of SyphonServerDescription objects that match the criteria. 118 """ 119 filtered_servers = [] 120 121 for server in self.servers: 122 if name is not None and name == server.name: 123 filtered_servers.append(server) 124 continue 125 126 if app_name is not None and app_name == server.app_name: 127 filtered_servers.append(server) 128 continue 129 130 return filtered_servers
class
SyphonServerNotification(enum.Enum):
10class SyphonServerNotification(Enum): 11 """ 12 Enum representing Syphon server notifications. 13 14 Enum Values: 15 - Announce: A new SyphonServer is available on the system. 16 - Update: An existing SyphonServer instance has changed its description. 17 - Retire: A SyphonServer instance will no longer be available. 18 """ 19 Announce = "SyphonServerAnnounceNotification" 20 Update = "SyphonServerUpdateNotification" 21 Retire = "SyphonServerRetireNotification"
Enum representing Syphon server notifications.
Enum Values:
- Announce: A new SyphonServer is available on the system.
- Update: An existing SyphonServer instance has changed its description.
- Retire: A SyphonServer instance will no longer be available.
Announce =
<SyphonServerNotification.Announce: 'SyphonServerAnnounceNotification'>
Update =
<SyphonServerNotification.Update: 'SyphonServerUpdateNotification'>
Retire =
<SyphonServerNotification.Retire: 'SyphonServerRetireNotification'>
Inherited Members
- enum.Enum
- name
- value
@dataclass
class
SyphonServerDescription:
24@dataclass 25class SyphonServerDescription: 26 """ 27 Data class representing the description of a Syphon server. 28 29 Attributes: 30 - uuid (str): The UUID of the Syphon server. 31 - name (str): The name of the Syphon server. 32 - app_name (str): The name of the application associated with the Syphon server. 33 - icon (NSImage): The icon image of the Syphon server. 34 - raw (Any): The raw server information. 35 """ 36 uuid: str 37 name: str 38 app_name: str 39 icon: NSImage 40 raw: Any
Data class representing the description of a Syphon server.
Attributes:
- uuid (str): The UUID of the Syphon server.
- name (str): The name of the Syphon server.
- app_name (str): The name of the application associated with the Syphon server.
- icon (NSImage): The icon image of the Syphon server.
- raw (Any): The raw server information.
class
SyphonServerDirectory:
43class SyphonServerDirectory: 44 """ 45 Class for interacting with the Syphon server directory. 46 47 Attributes: 48 - run_loop_interval (float): The interval for the run loop in seconds. 49 """ 50 51 def __init__(self): 52 """ 53 Initialize a SyphonServerDirectory. 54 """ 55 self._syphonServerDirectoryObjC = objc.lookUpClass("SyphonServerDirectory") 56 self._notification_center = objc.lookUpClass("NSNotificationCenter").defaultCenter() 57 58 self.run_loop_interval: float = 1.0 59 60 def add_observer(self, notification: SyphonServerNotification, handler: Callable[[Any], None]): 61 """ 62 Add an observer for a Syphon server notification. 63 64 Parameters: 65 - notification (SyphonServerNotification): The notification to observe. 66 - handler (Callable[[Any], None]): The handler function to be called when the notification is received. 67 """ 68 self._notification_center.addObserverForName_object_queue_usingBlock_( 69 notification.value, 70 None, 71 None, 72 handler 73 ) 74 75 @property 76 def servers(self) -> List[SyphonServerDescription]: 77 """ 78 Get a list of Syphon servers in the directory. 79 80 Returns: 81 - List[SyphonServerDescription]: A list of SyphonServerDescription objects. 82 """ 83 self.update_run_loop() 84 directory = self._syphonServerDirectoryObjC.sharedDirectory() 85 servers = directory.servers() 86 87 return [ 88 SyphonServerDescription( 89 str(s["SyphonServerDescriptionUUIDKey"]), 90 str(s["SyphonServerDescriptionNameKey"]), 91 str(s["SyphonServerDescriptionAppNameKey"]), 92 s["SyphonServerDescriptionIconKey"], 93 s 94 ) 95 for s in servers 96 ] 97 98 def update_run_loop(self): 99 """ 100 Update the run loop to process events. 101 """ 102 NSRunLoop.currentRunLoop().runMode_beforeDate_( 103 NSDefaultRunLoopMode, 104 NSDate.dateWithTimeIntervalSinceNow_(self.run_loop_interval) 105 ) 106 107 def servers_matching_name(self, 108 name: Optional[str] = None, 109 app_name: Optional[str] = None) -> List[SyphonServerDescription]: 110 """ 111 Get a list of Syphon servers that match the specified name or application name. 112 113 Parameters: 114 - name (Optional[str]): The name to match. 115 - app_name (Optional[str]): The application name to match. 116 117 Returns: 118 - List[SyphonServerDescription]: A list of SyphonServerDescription objects that match the criteria. 119 """ 120 filtered_servers = [] 121 122 for server in self.servers: 123 if name is not None and name == server.name: 124 filtered_servers.append(server) 125 continue 126 127 if app_name is not None and app_name == server.app_name: 128 filtered_servers.append(server) 129 continue 130 131 return filtered_servers
Class for interacting with the Syphon server directory.
Attributes:
- run_loop_interval (float): The interval for the run loop in seconds.
SyphonServerDirectory()
51 def __init__(self): 52 """ 53 Initialize a SyphonServerDirectory. 54 """ 55 self._syphonServerDirectoryObjC = objc.lookUpClass("SyphonServerDirectory") 56 self._notification_center = objc.lookUpClass("NSNotificationCenter").defaultCenter() 57 58 self.run_loop_interval: float = 1.0
Initialize a SyphonServerDirectory.
def
add_observer( self, notification: SyphonServerNotification, handler: Callable[[Any], NoneType]):
60 def add_observer(self, notification: SyphonServerNotification, handler: Callable[[Any], None]): 61 """ 62 Add an observer for a Syphon server notification. 63 64 Parameters: 65 - notification (SyphonServerNotification): The notification to observe. 66 - handler (Callable[[Any], None]): The handler function to be called when the notification is received. 67 """ 68 self._notification_center.addObserverForName_object_queue_usingBlock_( 69 notification.value, 70 None, 71 None, 72 handler 73 )
Add an observer for a Syphon server notification.
Parameters:
- notification (SyphonServerNotification): The notification to observe.
- handler (Callable[[Any], None]): The handler function to be called when the notification is received.
servers: List[SyphonServerDescription]
Get a list of Syphon servers in the directory.
Returns:
- List[SyphonServerDescription]: A list of SyphonServerDescription objects.
def
update_run_loop(self):
98 def update_run_loop(self): 99 """ 100 Update the run loop to process events. 101 """ 102 NSRunLoop.currentRunLoop().runMode_beforeDate_( 103 NSDefaultRunLoopMode, 104 NSDate.dateWithTimeIntervalSinceNow_(self.run_loop_interval) 105 )
Update the run loop to process events.
def
servers_matching_name( self, name: Optional[str] = None, app_name: Optional[str] = None) -> List[SyphonServerDescription]:
107 def servers_matching_name(self, 108 name: Optional[str] = None, 109 app_name: Optional[str] = None) -> List[SyphonServerDescription]: 110 """ 111 Get a list of Syphon servers that match the specified name or application name. 112 113 Parameters: 114 - name (Optional[str]): The name to match. 115 - app_name (Optional[str]): The application name to match. 116 117 Returns: 118 - List[SyphonServerDescription]: A list of SyphonServerDescription objects that match the criteria. 119 """ 120 filtered_servers = [] 121 122 for server in self.servers: 123 if name is not None and name == server.name: 124 filtered_servers.append(server) 125 continue 126 127 if app_name is not None and app_name == server.app_name: 128 filtered_servers.append(server) 129 continue 130 131 return filtered_servers
Get a list of Syphon servers that match the specified name or application name.
Parameters:
- name (Optional[str]): The name to match.
- app_name (Optional[str]): The application name to match.
Returns:
- List[SyphonServerDescription]: A list of SyphonServerDescription objects that match the criteria.