|
3 | 3 |
|
4 | 4 | from abc import ABCMeta, abstractmethod |
5 | 5 | from .window import WindowBase |
6 | | -#from . import __os_name |
| 6 | +from platform import system |
7 | 7 |
|
8 | 8 |
|
9 | 9 | class DSIBase(object, metaclass=ABCMeta): |
10 | | - @staticmethod |
11 | 10 | @abstractmethod |
12 | | - def get_active_window() -> WindowBase: |
| 11 | + def get_active_window(self) -> WindowBase: |
13 | 12 | """ |
14 | 13 | Gets the active window. |
15 | 14 | Returns None if no window is active. |
16 | 15 | """ |
17 | 16 | pass |
18 | 17 |
|
19 | | - @staticmethod |
20 | 18 | @abstractmethod |
21 | | - def get_all_windows() -> list: |
| 19 | + def get_all_windows(self) -> list: |
22 | 20 | """ |
23 | 21 | Returns a list of all Windows. |
24 | 22 | """ |
25 | 23 | pass |
26 | 24 |
|
27 | | - @classmethod |
28 | | - def get_window_by_pid(cls, pid: int) -> WindowBase: |
| 25 | + def get_window_by_pid(self, pid: int) -> WindowBase: |
29 | 26 | """ |
30 | 27 | Get window by pid. |
31 | 28 | Returns None if no window found. |
32 | 29 | """ |
33 | | - all_window = cls.get_all_windows() |
| 30 | + all_window = self.get_all_windows() |
34 | 31 |
|
35 | 32 | for window in all_window: |
36 | 33 | if window.pid == pid: |
37 | 34 | return window |
38 | 35 |
|
39 | | - @classmethod |
40 | | - def get_window_by_name(cls, name: str) -> WindowBase: |
| 36 | + def get_window_by_name(self, name: str) -> WindowBase: |
41 | 37 | """ |
42 | 38 | Get a window by name. |
43 | 39 | Returns None if no window with that name is found. |
44 | 40 | """ |
45 | | - all_window = cls.get_all_windows() |
| 41 | + all_window = self.get_all_windows() |
46 | 42 |
|
47 | 43 | for window in all_window: |
48 | 44 | if window.name is not None and name in window.name: |
49 | 45 | return window |
50 | 46 |
|
51 | | - # @property |
52 | | - # def platform(self) -> str: |
53 | | - # """ |
54 | | - # Returns the platform name. |
55 | | - # """ |
56 | | - # return __os_name |
| 47 | + @property |
| 48 | + def platform(self) -> str: |
| 49 | + """ |
| 50 | + Returns the platform name. |
| 51 | + """ |
| 52 | + return system().lower() |
| 53 | + |
| 54 | + @property |
| 55 | + def linux(self) -> bool: |
| 56 | + """ |
| 57 | + Returns True if the platform is linux. |
| 58 | + """ |
| 59 | + return self.platform == "linux" |
| 60 | + |
| 61 | + @property |
| 62 | + def windows(self) -> bool: |
| 63 | + """ |
| 64 | + Returns True if the platform is windows. |
| 65 | + """ |
| 66 | + return self.platform == "windows" |
| 67 | + |
| 68 | + @property |
| 69 | + def mac(self) -> bool: |
| 70 | + """ |
| 71 | + Returns True if the platform is mac. |
| 72 | + """ |
| 73 | + return self.platform == "darwin" |
57 | 74 |
|
58 | | - # @property |
59 | | - # def linux(self) -> bool: |
60 | | - # """ |
61 | | - # Returns True if the platform is linux. |
62 | | - # """ |
63 | | - # return self.platform == "linux" |
| 75 | + # Allow dsi to be called with ’with’ |
64 | 76 |
|
65 | | - # @property |
66 | | - # def windows(self) -> bool: |
67 | | - # """ |
68 | | - # Returns True if the platform is windows. |
69 | | - # """ |
70 | | - # return self.platform == "windows" |
| 77 | + def __enter__(self): |
| 78 | + return self |
71 | 79 |
|
72 | | - # @property |
73 | | - # def mac(self) -> bool: |
74 | | - # """ |
75 | | - # Returns True if the platform is mac. |
76 | | - # """ |
77 | | - # return self.platform == "darwin" |
| 80 | + def __exit__(self, *_): |
| 81 | + pass |
0 commit comments