xemonity 2.0__tar.gz → 4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
xemonity-4.0/PKG-INFO ADDED
@@ -0,0 +1,36 @@
1
+ Metadata-Version: 2.2
2
+ Name: xemonity
3
+ Version: 4.0
4
+ Summary: Libraly for simple terminal ui
5
+ Home-page: https://github.com/MurzikYEET/Xemonity
6
+ Author: murzik_kukushnik
7
+ Author-email: siniykoshara@gmail.com
8
+ Project-URL: GitHub, https://github.com/MurzikYEET/Xemonity
9
+ Keywords: menu ui gui tui
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.6
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Dynamic: author
17
+ Dynamic: author-email
18
+ Dynamic: classifier
19
+ Dynamic: description
20
+ Dynamic: description-content-type
21
+ Dynamic: home-page
22
+ Dynamic: keywords
23
+ Dynamic: project-url
24
+ Dynamic: requires-python
25
+ Dynamic: summary
26
+
27
+ # Xemonity
28
+ Xemonity - Python3 lib for terminal interfaces ~~mained on pynput~~
29
+ ## Classes and methods
30
+ Retranslated in DOCS.md in GitHub page\
31
+ Examples also in GItHub page\
32
+ Also you can write your own `XmntUIList` elemenets, watch how methods and vars has `XUIL_Element` in DOCS.md
33
+ ## Credits
34
+ ~~[https://pypi.org/user/moses.palmer/] : made pynput lib~~ Pynput not more used
35
+ ## License
36
+ Licensed under MIT license
xemonity-4.0/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # Xemonity
2
+ Xemonity - Python3 lib for terminal interfaces ~~mained on pynput~~
3
+ ## Classes and methods
4
+ Retranslated in DOCS.md in GitHub page\
5
+ Examples also in GItHub page\
6
+ Also you can write your own `XmntUIList` elemenets, watch how methods and vars has `XUIL_Element` in DOCS.md
7
+ ## Credits
8
+ ~~[https://pypi.org/user/moses.palmer/] : made pynput lib~~ Pynput not more used
9
+ ## License
10
+ Licensed under MIT license
@@ -0,0 +1,6 @@
1
+ try:
2
+ from .classes import *
3
+ except ImportError:
4
+ from classes import *
5
+
6
+ print("Hello from Xemonity\nGitHub : https://github.com/MurzikYEET/Xemonity")
@@ -0,0 +1,150 @@
1
+ from time import sleep as delay
2
+ try:
3
+ from .methods import *
4
+ except:
5
+ from methods import *
6
+
7
+ class XemonityAM:
8
+ def __init__(self,elements:list,title:str,append_cancel=True):
9
+ """WARNING : this class deprecated and has been deleted in version 5.0, please use XmntUIList with Button class"""
10
+ self.cursor = 0
11
+ self.elements = elements
12
+ if append_cancel:self.elements.append(":Cancel")
13
+ self.title = title
14
+ def update_screen(self,intertime=0.05):
15
+ clear_screen()
16
+ print(self.title)
17
+ if self.cursor >= 4:print("...")
18
+ for i in range(0,len(self.elements)):
19
+ if i+3 < self.cursor:continue
20
+ if i == self.cursor: print(">>",end="")
21
+ print(self.elements[i])
22
+ delay(intertime)
23
+ def relist(self,newlist:list):
24
+ self.elements = newlist
25
+ self.cursor = 0
26
+ def show_sync(self):
27
+ try:
28
+ self.cursor = 0
29
+ open_alt_screen()
30
+ while True:
31
+ self.update_screen()
32
+ pressed = get_key()
33
+
34
+ match pressed:
35
+ case "DOWN":
36
+ self.cursor += 1
37
+ if self.cursor >= len(self.elements):self.cursor = 0
38
+ self.update_screen()
39
+ case "UP":
40
+ self.cursor -= 1
41
+ if self.cursor <= -1:self.cursor = len(self.elements)-1
42
+ self.update_screen()
43
+ case "ENTER":
44
+ close_alt_screen()
45
+ return self.elements[self.cursor]
46
+ except:
47
+ close_alt_screen()
48
+ return ":CANCELED"
49
+
50
+ class XmntUIList:
51
+ def __init__(self,title=""):
52
+ self.title = title
53
+ self.elements = []
54
+ self.cursor = 0
55
+
56
+ self._breakme = False
57
+ def connect_element(self,element):
58
+ """Add new element"""
59
+ element.uilist = self
60
+ self.elements.append(element)
61
+ def clear_elements_list(self):
62
+ """Remove all elements"""
63
+ for i in self.elements:i.uilist = None
64
+ self.elements.clear()
65
+ def out_of(self):
66
+ """Stop XmntUIList.show_sync()"""
67
+ self._breakme = True
68
+ def update_screen(self):
69
+ clear_screen()
70
+ print(self.title[:terminal_width()]+("_" * min(0,terminal_width() - len(self.title))))
71
+
72
+ visible_height = terminal_height() - 2
73
+ if visible_height < 1: visible_height = 1
74
+
75
+ offset = 0
76
+ if self.cursor >= visible_height:
77
+ offset = self.cursor - visible_height + 1
78
+
79
+ for i in range(offset, offset + visible_height):
80
+ if i >= len(self.elements):
81
+ break
82
+ if i == self.cursor:print("::",end="")
83
+ else: print(" ",end="")
84
+ self.elements[i].render()
85
+ def show_sync(self,intertime=0.05):
86
+ """Show interface"""
87
+ while True:
88
+ if self._breakme:
89
+ self._breakme = True
90
+ break
91
+ self.update_screen()
92
+ try:pr = get_key()
93
+ except KeyboardInterrupt:break
94
+
95
+ match pr:
96
+ case "DOWN":
97
+ if self.cursor >= len(self.elements)-1:self.cursor = 0
98
+ else:self.cursor += 1
99
+ self.elements[self.cursor].when_acted("DOWN")
100
+ case "UP":
101
+ if self.cursor <= 0:self.cursor = len(self.elements)-1
102
+ else:self.cursor -= 1
103
+ self.elements[self.cursor].when_acted("UP")
104
+ case "ENTER":
105
+ self.elements[self.cursor].when_acted("ENTER")
106
+ case "LEFT":
107
+ self.elements[self.cursor].when_acted("LEFT")
108
+ case "RIGHT":
109
+ self.elements[self.cursor].when_acted("RIGHT")
110
+ delay(intertime)
111
+ to_out = {}
112
+ for i in self.elements:
113
+ to_out[i.realname] = i.stdout
114
+ clear_screen()
115
+ close_alt_screen()
116
+ return to_out
117
+
118
+ class XUIL_Element:
119
+ def __init__(self,realname,name="XmntUIList template"):
120
+ """its init"""
121
+ self.uilist:XmntUIList = None
122
+ self.name = name
123
+ self.realname = realname
124
+ self.stdout = ""
125
+ def is_selected(self):
126
+ """Return true if cursor in element"""
127
+ return self.uilist.elements.count(self) >= 1
128
+ def when_acted(self,action:str):
129
+ """Called when user press arrows, enter and other buttons registred in get_key() method"""
130
+ def render(self):
131
+ """Called when XmntUIList.show_sync() try draw look"""
132
+ print(self.name)
133
+
134
+ class Button(XUIL_Element):
135
+ def __init__(self,realname,title="Button"):
136
+ super().__init__(realname,title)
137
+ self.stdout = False
138
+ def when_acted(self, action):
139
+ if action == "ENTER":
140
+ self.stdout = True
141
+ self.uilist.out_of()
142
+ def render(self):
143
+ print("|"+self.name+"|")
144
+
145
+ class Label(XUIL_Element):
146
+ def __init__(self, realname, label="template"):
147
+ super().__init__(realname, label)
148
+ self.label = label
149
+ def render(self):
150
+ print(self.label[:terminal_width() - (2 if self.is_selected else 0)])
@@ -0,0 +1,66 @@
1
+ import os
2
+ import sys
3
+ if os.name == "nt":
4
+ import msvcrt
5
+ else:
6
+ import termios
7
+ import tty
8
+
9
+ def open_alt_screen():
10
+ sys.stdout.write("\x1b[?1049h")
11
+ clear_screen()
12
+
13
+ def close_alt_screen():
14
+ #clear_screen()
15
+ sys.stdout.write("\x1b[?1049l")
16
+
17
+ def clear_screen():
18
+ if is_windows():
19
+ os.system('cls')
20
+ else:
21
+ os.system('clear')
22
+
23
+ def get_key_posix(): #for unix-like os (MacOS,Linux,*BSD and other)
24
+ fd = sys.stdin.fileno()
25
+ old_settings = termios.tcgetattr(fd)
26
+ try:
27
+ tty.setraw(fd)
28
+ ch = sys.stdin.read(1)
29
+ if ch == '\x1b': #Arrows
30
+ ch += sys.stdin.read(2)
31
+ if ch == '\x1b[A': return 'UP'
32
+ if ch == '\x1b[B': return 'DOWN'
33
+ if ch == '\x1b[C': return 'RIGHT'
34
+ if ch == '\x1b[D': return 'LEFT'
35
+ return None
36
+ elif ch == '\r': # Enter
37
+ return 'ENTER'
38
+ elif ch == '\x03': # Ctrl+C
39
+ raise KeyboardInterrupt
40
+ return ch
41
+ finally:
42
+ termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
43
+
44
+ def get_key_nt(): #for NT-like os (Windows)
45
+ ch = msvcrt.getch()
46
+ if ch in (b'\x00', b'\xe0'): #Arrows
47
+ ch = msvcrt.getch()
48
+ if ch == b'H': return 'UP'
49
+ if ch == b'P': return 'DOWN'
50
+ if ch == b'K': return 'LEFT'
51
+ if ch == b'M': return 'RIGHT'
52
+ return None
53
+
54
+ if ch == b'\r': return 'ENTER' #Enter
55
+ if ch == b'\x03': raise KeyboardInterrupt # Ctrl+C
56
+
57
+ return ch.decode('utf-8', errors='ignore')
58
+
59
+ def get_key(): #universal
60
+ if is_windows():return get_key_nt()
61
+ else:return get_key_posix()
62
+
63
+ def min(minval,x):return x if x > minval else minval
64
+ def is_windows():return os.name == "nt"
65
+ def terminal_width():return os.get_terminal_size().columns
66
+ def terminal_height():return os.get_terminal_size().lines
@@ -8,21 +8,21 @@ def readme():
8
8
 
9
9
  setup(
10
10
  name='xemonity',
11
- version='2.0',
11
+ version='4.0',
12
12
  author='murzik_kukushnik',
13
13
  author_email='siniykoshara@gmail.com',
14
- description='Libraly for simple menu with chosing',
14
+ description='Libraly for simple terminal ui',
15
15
  long_description=readme(),
16
16
  long_description_content_type='text/markdown',
17
17
  url='https://github.com/MurzikYEET/Xemonity',
18
18
  packages=find_packages(),
19
- install_requires=['pynput'],
19
+ install_requires=[],
20
20
  classifiers=[
21
21
  'Programming Language :: Python :: 3.11',
22
22
  'License :: OSI Approved :: MIT License',
23
23
  'Operating System :: OS Independent'
24
24
  ],
25
- keywords='menu choose choice',
25
+ keywords='menu ui gui tui',
26
26
  project_urls={
27
27
  "GitHub" : "https://github.com/MurzikYEET/Xemonity"
28
28
  },
@@ -0,0 +1,36 @@
1
+ Metadata-Version: 2.2
2
+ Name: xemonity
3
+ Version: 4.0
4
+ Summary: Libraly for simple terminal ui
5
+ Home-page: https://github.com/MurzikYEET/Xemonity
6
+ Author: murzik_kukushnik
7
+ Author-email: siniykoshara@gmail.com
8
+ Project-URL: GitHub, https://github.com/MurzikYEET/Xemonity
9
+ Keywords: menu ui gui tui
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.6
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Dynamic: author
17
+ Dynamic: author-email
18
+ Dynamic: classifier
19
+ Dynamic: description
20
+ Dynamic: description-content-type
21
+ Dynamic: home-page
22
+ Dynamic: keywords
23
+ Dynamic: project-url
24
+ Dynamic: requires-python
25
+ Dynamic: summary
26
+
27
+ # Xemonity
28
+ Xemonity - Python3 lib for terminal interfaces ~~mained on pynput~~
29
+ ## Classes and methods
30
+ Retranslated in DOCS.md in GitHub page\
31
+ Examples also in GItHub page\
32
+ Also you can write your own `XmntUIList` elemenets, watch how methods and vars has `XUIL_Element` in DOCS.md
33
+ ## Credits
34
+ ~~[https://pypi.org/user/moses.palmer/] : made pynput lib~~ Pynput not more used
35
+ ## License
36
+ Licensed under MIT license
@@ -5,8 +5,8 @@ setup.cfg
5
5
  setup.py
6
6
  Xemonity/__init__.py
7
7
  Xemonity/classes.py
8
+ Xemonity/methods.py
8
9
  xemonity.egg-info/PKG-INFO
9
10
  xemonity.egg-info/SOURCES.txt
10
11
  xemonity.egg-info/dependency_links.txt
11
- xemonity.egg-info/requires.txt
12
12
  xemonity.egg-info/top_level.txt
xemonity-2.0/PKG-INFO DELETED
@@ -1,60 +0,0 @@
1
- Metadata-Version: 2.2
2
- Name: xemonity
3
- Version: 2.0
4
- Summary: Libraly for simple menu with chosing
5
- Home-page: https://github.com/MurzikYEET/Xemonity
6
- Author: murzik_kukushnik
7
- Author-email: siniykoshara@gmail.com
8
- Project-URL: GitHub, https://github.com/MurzikYEET/Xemonity
9
- Keywords: menu choose choice
10
- Classifier: Programming Language :: Python :: 3.11
11
- Classifier: License :: OSI Approved :: MIT License
12
- Classifier: Operating System :: OS Independent
13
- Requires-Python: >=3.6
14
- Description-Content-Type: text/markdown
15
- License-File: LICENSE
16
- Requires-Dist: pynput
17
- Dynamic: author
18
- Dynamic: author-email
19
- Dynamic: classifier
20
- Dynamic: description
21
- Dynamic: description-content-type
22
- Dynamic: home-page
23
- Dynamic: keywords
24
- Dynamic: project-url
25
- Dynamic: requires-dist
26
- Dynamic: requires-python
27
- Dynamic: summary
28
-
29
- # Xemonity
30
- Xemonity - Python3 lib for simple menu with choose mained on pynput
31
- ## How to use?
32
- Code look as
33
- ```python
34
- import Xemonity #import lib
35
- am = Xemonity.XemonityAM(elements=['one','two','three'],'Its a title') #make class with elements and title
36
- result = am.show_sync() #show menu (only sync) and return choosed string as str()
37
- print(result) #print result to screen
38
- ```
39
- If you run this code, then you see next:
40
- ```
41
- Test menu
42
- >>One
43
- Two
44
- Three
45
- :Cancel
46
- ```
47
- `Test menu` is title. `>>` is choosen element. `:Cancel` for exit with output `:CANCELED`
48
- ## Classes and methods
49
- `Xemonity.XemonityAM(elements:list,title:str)`
50
- Main class for menu
51
- 1. `XemonityAM.cursor` : int var : return a current selected element index
52
- 2. `XemonityAM.title` : str var : just a title, shows over elements
53
- 3. `XemonityAM.elements` : list var : list of elements (this is not recommended for modification)
54
- 4. `XemonityAM.relist(newlist:list)` : None func : change list of elements
55
- 5. `XemonityAM.show_sync()` : str func : show menu and return choosed element, if choosen ":Cancel" then method returns ":CANCELED"
56
- Other methods not for you
57
- ## Credits
58
- [https://pypi.org/user/moses.palmer/] : made pynput lib
59
- ## License
60
- Licensed under MIT license
xemonity-2.0/README.md DELETED
@@ -1,32 +0,0 @@
1
- # Xemonity
2
- Xemonity - Python3 lib for simple menu with choose mained on pynput
3
- ## How to use?
4
- Code look as
5
- ```python
6
- import Xemonity #import lib
7
- am = Xemonity.XemonityAM(elements=['one','two','three'],'Its a title') #make class with elements and title
8
- result = am.show_sync() #show menu (only sync) and return choosed string as str()
9
- print(result) #print result to screen
10
- ```
11
- If you run this code, then you see next:
12
- ```
13
- Test menu
14
- >>One
15
- Two
16
- Three
17
- :Cancel
18
- ```
19
- `Test menu` is title. `>>` is choosen element. `:Cancel` for exit with output `:CANCELED`
20
- ## Classes and methods
21
- `Xemonity.XemonityAM(elements:list,title:str)`
22
- Main class for menu
23
- 1. `XemonityAM.cursor` : int var : return a current selected element index
24
- 2. `XemonityAM.title` : str var : just a title, shows over elements
25
- 3. `XemonityAM.elements` : list var : list of elements (this is not recommended for modification)
26
- 4. `XemonityAM.relist(newlist:list)` : None func : change list of elements
27
- 5. `XemonityAM.show_sync()` : str func : show menu and return choosed element, if choosen ":Cancel" then method returns ":CANCELED"
28
- Other methods not for you
29
- ## Credits
30
- [https://pypi.org/user/moses.palmer/] : made pynput lib
31
- ## License
32
- Licensed under MIT license
@@ -1,12 +0,0 @@
1
- try:
2
- from .classes import *
3
- except ImportError:
4
- from classes import *
5
-
6
- if __name__ == "__main__":
7
- menu = XemonityAM(["One","Two","Three","Four","Five","Six","Seven"],"Test menu")
8
- answer = menu.show_sync()
9
- print(answer)
10
- menu.elements = ["Yes","No"]
11
- answer = menu.show_sync()
12
- print(answer)
@@ -1,72 +0,0 @@
1
- from pynput import keyboard
2
- from time import sleep as delay
3
- import sys
4
- import os
5
- import termios
6
-
7
- def open_alt_screen():
8
- sys.stdout.write("\x1b[?1049h")
9
- clear_screen()
10
-
11
- def close_alt_screen():
12
- #clear_screen()
13
- sys.stdout.write("\x1b[?1049l")
14
-
15
- def clear_screen():
16
- if os.name == 'nt':
17
- os.system('cls')
18
- else:
19
- os.system('clear')
20
-
21
- class XemonityAM:
22
- def __init__(self,elements:list,title:str):
23
- self.cursor = 0
24
- self.elements = elements
25
- self.elements.append(":Cancel")
26
- self.title = title
27
- def update_screen(self,intertime=0.05):
28
- clear_screen()
29
- print(self.title)
30
- if self.cursor >= 4:print("...")
31
- for i in range(0,len(self.elements)):
32
- if i+3 < self.cursor:
33
- continue
34
- if i == self.cursor: print(">>",end="")
35
- print(self.elements[i])
36
- delay(intertime)
37
-
38
- def on_press(self,key:keyboard.Key):
39
- try:
40
- if key == keyboard.Key.down:
41
- self.cursor += 1
42
- if self.cursor >= len(self.elements):
43
- self.cursor = 0
44
- self.update_screen()
45
- elif key == keyboard.Key.up:
46
- self.cursor -= 1
47
- if self.cursor <= -1:
48
- self.cursor = len(self.elements)-1
49
- self.update_screen()
50
- elif key == keyboard.Key.enter:
51
- self.returned = self.elements[self.cursor]
52
- return False
53
- except AttributeError:
54
- pass
55
- def on_release(self,key):
56
- if key == keyboard.Key.esc:
57
- return False
58
-
59
- def relist(self,newlist:list):
60
- self.elements = newlist
61
- self.cursor = 0
62
- def show_sync(self):
63
- try:
64
- self.cursor = 0
65
- open_alt_screen()
66
- self.update_screen()
67
- with keyboard.Listener(on_press=self.on_press, on_release=self.on_release) as listener:listener.join()
68
- if os.name != "nt":termios.tcflush(sys.stdin.fileno(), termios.TCIFLUSH)
69
- if self.elements[self.cursor] == ":Cancel":return ":CANCELED"
70
- else:return self.elements[self.cursor]
71
- finally:
72
- close_alt_screen()
@@ -1,60 +0,0 @@
1
- Metadata-Version: 2.2
2
- Name: xemonity
3
- Version: 2.0
4
- Summary: Libraly for simple menu with chosing
5
- Home-page: https://github.com/MurzikYEET/Xemonity
6
- Author: murzik_kukushnik
7
- Author-email: siniykoshara@gmail.com
8
- Project-URL: GitHub, https://github.com/MurzikYEET/Xemonity
9
- Keywords: menu choose choice
10
- Classifier: Programming Language :: Python :: 3.11
11
- Classifier: License :: OSI Approved :: MIT License
12
- Classifier: Operating System :: OS Independent
13
- Requires-Python: >=3.6
14
- Description-Content-Type: text/markdown
15
- License-File: LICENSE
16
- Requires-Dist: pynput
17
- Dynamic: author
18
- Dynamic: author-email
19
- Dynamic: classifier
20
- Dynamic: description
21
- Dynamic: description-content-type
22
- Dynamic: home-page
23
- Dynamic: keywords
24
- Dynamic: project-url
25
- Dynamic: requires-dist
26
- Dynamic: requires-python
27
- Dynamic: summary
28
-
29
- # Xemonity
30
- Xemonity - Python3 lib for simple menu with choose mained on pynput
31
- ## How to use?
32
- Code look as
33
- ```python
34
- import Xemonity #import lib
35
- am = Xemonity.XemonityAM(elements=['one','two','three'],'Its a title') #make class with elements and title
36
- result = am.show_sync() #show menu (only sync) and return choosed string as str()
37
- print(result) #print result to screen
38
- ```
39
- If you run this code, then you see next:
40
- ```
41
- Test menu
42
- >>One
43
- Two
44
- Three
45
- :Cancel
46
- ```
47
- `Test menu` is title. `>>` is choosen element. `:Cancel` for exit with output `:CANCELED`
48
- ## Classes and methods
49
- `Xemonity.XemonityAM(elements:list,title:str)`
50
- Main class for menu
51
- 1. `XemonityAM.cursor` : int var : return a current selected element index
52
- 2. `XemonityAM.title` : str var : just a title, shows over elements
53
- 3. `XemonityAM.elements` : list var : list of elements (this is not recommended for modification)
54
- 4. `XemonityAM.relist(newlist:list)` : None func : change list of elements
55
- 5. `XemonityAM.show_sync()` : str func : show menu and return choosed element, if choosen ":Cancel" then method returns ":CANCELED"
56
- Other methods not for you
57
- ## Credits
58
- [https://pypi.org/user/moses.palmer/] : made pynput lib
59
- ## License
60
- Licensed under MIT license
@@ -1 +0,0 @@
1
- pynput
File without changes
File without changes
File without changes