xemonity 4.0__tar.gz → 5.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: xemonity
3
- Version: 4.0
3
+ Version: 5.0
4
4
  Summary: Libraly for simple terminal ui
5
5
  Home-page: https://github.com/MurzikYEET/Xemonity
6
6
  Author: murzik_kukushnik
@@ -0,0 +1,6 @@
1
+ try:
2
+ from .classes import *
3
+ except ImportError:
4
+ from classes import *
5
+
6
+ print("Hello from Xemonity UI 'framework'\nGitHub : https://github.com/MurzikYEET/Xemonity")
@@ -1,12 +1,16 @@
1
1
  from time import sleep as delay
2
+ try:from .methods import *
3
+ except:from methods import *
4
+
2
5
  try:
3
- from .methods import *
6
+ import colorama
7
+ support_colorama = True
4
8
  except:
5
- from methods import *
9
+ support_colorama = False
6
10
 
7
11
  class XemonityAM:
8
12
  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"""
13
+ """WARNING : this class deprecated, please use XmntUIList with Button class"""
10
14
  self.cursor = 0
11
15
  self.elements = elements
12
16
  if append_cancel:self.elements.append(":Cancel")
@@ -53,7 +57,16 @@ class XmntUIList:
53
57
  self.elements = []
54
58
  self.cursor = 0
55
59
 
60
+ self._bupdate = None
61
+ self._aupdate = None
62
+
56
63
  self._breakme = False
64
+ def bind_action(self,action:str,method):
65
+ """Adds method for action (name of actions watch in DOCS.md)"""
66
+ match action.lower():
67
+ case "before update":self._bupdate = method
68
+ case "after update":self._aupdate = method
69
+ case _:raise Exception("Undefined action")
57
70
  def connect_element(self,element):
58
71
  """Add new element"""
59
72
  element.uilist = self
@@ -62,12 +75,24 @@ class XmntUIList:
62
75
  """Remove all elements"""
63
76
  for i in self.elements:i.uilist = None
64
77
  self.elements.clear()
78
+ def connect_element_list(self,elements:list,clear_before=True):
79
+ """Clears list of elements and add new"""
80
+ if clear_before:self.clear_elements_list()
81
+ for i in elements:
82
+ self.connect_element(i)
65
83
  def out_of(self):
66
84
  """Stop XmntUIList.show_sync()"""
67
85
  self._breakme = True
68
86
  def update_screen(self):
69
87
  clear_screen()
70
- print(self.title[:terminal_width()]+("_" * min(0,terminal_width() - len(self.title))))
88
+ if support_colorama:
89
+ print(colorama.Back.WHITE+
90
+ (self.title[:terminal_width()])+
91
+ (" " * (terminal_width() - len(self.title))))
92
+ print(colorama.Style.RESET_ALL,end="")
93
+ else:
94
+ print(self.title[:terminal_width()]+
95
+ ("_" * min(0,terminal_width() - len(self.title))))
71
96
 
72
97
  visible_height = terminal_height() - 2
73
98
  if visible_height < 1: visible_height = 1
@@ -85,12 +110,15 @@ class XmntUIList:
85
110
  def show_sync(self,intertime=0.05):
86
111
  """Show interface"""
87
112
  while True:
113
+ if self._bupdate != None:self._bupdate()
88
114
  if self._breakme:
89
- self._breakme = True
115
+ self._breakme = False
90
116
  break
91
117
  self.update_screen()
92
118
  try:pr = get_key()
93
- except KeyboardInterrupt:break
119
+ except KeyboardInterrupt:
120
+ self._breakme = True
121
+ continue
94
122
 
95
123
  match pr:
96
124
  case "DOWN":
@@ -107,6 +135,7 @@ class XmntUIList:
107
135
  self.elements[self.cursor].when_acted("LEFT")
108
136
  case "RIGHT":
109
137
  self.elements[self.cursor].when_acted("RIGHT")
138
+ if self._aupdate != None:self._aupdate()
110
139
  delay(intertime)
111
140
  to_out = {}
112
141
  for i in self.elements:
@@ -117,7 +146,7 @@ class XmntUIList:
117
146
 
118
147
  class XUIL_Element:
119
148
  def __init__(self,realname,name="XmntUIList template"):
120
- """its init"""
149
+ """Main class for all UI elements"""
121
150
  self.uilist:XmntUIList = None
122
151
  self.name = name
123
152
  self.realname = realname
@@ -132,19 +161,48 @@ class XUIL_Element:
132
161
  print(self.name)
133
162
 
134
163
  class Button(XUIL_Element):
135
- def __init__(self,realname,title="Button"):
164
+ def __init__(self,realname,title="Button",on_click=None):
136
165
  super().__init__(realname,title)
166
+ self.on_click = on_click
137
167
  self.stdout = False
138
168
  def when_acted(self, action):
139
169
  if action == "ENTER":
140
170
  self.stdout = True
141
- self.uilist.out_of()
171
+ if self.on_click:self.on_click()
172
+ else:self.uilist.out_of()
142
173
  def render(self):
143
174
  print("|"+self.name+"|")
144
175
 
145
176
  class Label(XUIL_Element):
146
- def __init__(self, realname, label="template"):
177
+ def __init__(self, realname, label="I lable"):
147
178
  super().__init__(realname, label)
148
179
  self.label = label
149
180
  def render(self):
150
- print(self.label[:terminal_width() - (2 if self.is_selected else 0)])
181
+ print(self.label[:terminal_width() - (2 if self.is_selected else 0)])
182
+
183
+ class Checkbox(XUIL_Element):
184
+ def __init__(self, realname, name="Checkbox",default=False):
185
+ super().__init__(realname, name)
186
+ self.stdout = default
187
+ def when_acted(self, action):
188
+ if action == "LEFT" or action == "RIGHT" or action == "ENTER":
189
+ self.stdout = not self.stdout
190
+ def render(self):
191
+ print(self.name + " : " + ("▉▉" if self.stdout else "░░"))
192
+
193
+ class Slider(XUIL_Element):
194
+ def __init__(self, realname, name="Slider", mini=0, default=50, maxi=100, step=1):
195
+ super().__init__(realname, name)
196
+ self.min = mini
197
+ self.max = maxi
198
+ self.stdout = default
199
+ self.step = step
200
+ def when_acted(self, action):
201
+ if action == "LEFT":self.stdout = self.stdout if self.stdout < (self.min + self.step) else self.stdout - self.step
202
+ if action == "RIGHT":self.stdout = self.stdout if self.stdout > (self.max - self.step) else self.stdout + self.step
203
+ def render(self):
204
+ normalized = (self.stdout - self.min) / (self.max - self.min)
205
+ bar_width = terminal_width() - len(self.name) - len(str(self.stdout)) - 7
206
+ to_fill = int(normalized * bar_width)
207
+ to_skip = bar_width - to_fill
208
+ print(self.name + f"({self.stdout})" + ":::" + ("▉" * to_fill) + ("░" * to_skip))
@@ -8,7 +8,7 @@ def readme():
8
8
 
9
9
  setup(
10
10
  name='xemonity',
11
- version='4.0',
11
+ version='5.0',
12
12
  author='murzik_kukushnik',
13
13
  author_email='siniykoshara@gmail.com',
14
14
  description='Libraly for simple terminal ui',
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: xemonity
3
- Version: 4.0
3
+ Version: 5.0
4
4
  Summary: Libraly for simple terminal ui
5
5
  Home-page: https://github.com/MurzikYEET/Xemonity
6
6
  Author: murzik_kukushnik
@@ -1,6 +0,0 @@
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")
File without changes
File without changes
File without changes
File without changes
File without changes