qltool 0.0.3__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.
qltool-0.0.3/PKG-INFO ADDED
@@ -0,0 +1,33 @@
1
+ Metadata-Version: 2.1
2
+ Name: qltool
3
+ Version: 0.0.3
4
+ Summary: Automatically created environment for python package
5
+ Home-page: https://gitlab.com/ojr/qltool
6
+ Author: me
7
+ Author-email: ojr@gmail.com
8
+ License: GPL2
9
+ Description-Content-Type: text/markdown
10
+
11
+ qltool
12
+ ======
13
+
14
+ *barebones made by codeframe*
15
+
16
+ **Purpose:** `qltool` is
17
+
18
+ Example
19
+ -------
20
+
21
+ ``` {.python}
22
+ # example
23
+ ```
24
+
25
+ Installation
26
+ ------------
27
+
28
+ ``` {.bash org-language="sh"}
29
+ pip3 install qltool
30
+ ```
31
+
32
+ Usage
33
+ -----
qltool-0.0.3/README.md ADDED
@@ -0,0 +1,23 @@
1
+ qltool
2
+ ======
3
+
4
+ *barebones made by codeframe*
5
+
6
+ **Purpose:** `qltool` is
7
+
8
+ Example
9
+ -------
10
+
11
+ ``` {.python}
12
+ # example
13
+ ```
14
+
15
+ Installation
16
+ ------------
17
+
18
+ ``` {.bash org-language="sh"}
19
+ pip3 install qltool
20
+ ```
21
+
22
+ Usage
23
+ -----
@@ -0,0 +1,374 @@
1
+ #!/usr/bin/env python3
2
+
3
+ # to override print <= can be a big problem with exceptions
4
+ #
5
+ # colors in df_table _fg _bg columns:
6
+ # see
7
+ # https://github.com/mixmastamyk/console/blob/master/console/color_tables_x11.py#L112
8
+ #
9
+ # from __future__ import print_function # must be 1st
10
+ # import builtins
11
+ import sys
12
+ from fire import Fire
13
+ from qltool.version import __version__
14
+ # from qltool import unitname
15
+ from qltool import config
16
+ from qltool import topbar
17
+ from qltool import key_enter
18
+ # from qltool import df_table
19
+ from qltool.df_table import create_dummy_df, show_table, \
20
+ inc_dummy_df
21
+ from qltool.config import move_cursor
22
+ from qltool import mmapwr
23
+ from qltool import interpreter
24
+ from qltool import objects # I have no reach from remote-keyboard BUT from mainkb
25
+
26
+ import time
27
+ import datetime as dt
28
+ from console import fg, bg, fx
29
+ from blessings import Terminal
30
+ import os
31
+ from pyfiglet import Figlet
32
+ import signal
33
+
34
+ # ====================== for separate terminal keyboard using mmap
35
+ #from prompt_toolkit.styles import Style
36
+ from prompt_toolkit.cursor_shapes import CursorShape, ModalCursorShapeConfig
37
+
38
+ from prompt_toolkit import PromptSession, prompt
39
+ from prompt_toolkit.history import FileHistory
40
+
41
+ from prompt_toolkit.completion import WordCompleter
42
+ from prompt_toolkit.completion import NestedCompleter
43
+
44
+ from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
45
+
46
+ import json # transfe list to string and back
47
+ # ========================
48
+ SHOW_LOGO_TABLE = False
49
+ SHOW_TIME = False
50
+ SHOW_COMMAND_LINE = True
51
+ RUN_MMAP_INPUT = True # INTERACTIVE MMAP-INTERACTIVE
52
+ RUN_SELECT_FROM_TABLE = False
53
+
54
+ termsize = os.get_terminal_size().columns
55
+
56
+ # import pandas as pd
57
+ # import numpy as np
58
+ # from terminaltables import SingleTable
59
+
60
+ # ------- this defended the project from winch error
61
+ # from simple_term_menu import TerminalMenu
62
+
63
+
64
+ def handle_sigwinch(signum: signal.Signals, qqq):
65
+ # pylint: disable=unused-argument
66
+ #print("WINCH SIGNAL:",type(qqq), qqq)
67
+ #os.system("reset")
68
+ return None
69
+
70
+
71
+ # ----this DOES IT
72
+ # for FONTS in `pyfiglet -l`; do echo $FONTS; pyfiglet $FONTS -f $FONTS; done | less
73
+ figlet = Figlet(font="slant")
74
+ # figle2 = Figlet(font="roman")
75
+ # figle2 = Figlet(font="standard")
76
+ figle2 = Figlet(font="ansi_regular")
77
+
78
+
79
+ def print_logo():
80
+ """
81
+ print fromt page + time
82
+ """
83
+ global termsize
84
+ # global figlet, filg
85
+
86
+ word = " qltool"
87
+ # os.system('reset')
88
+ print("")
89
+ print(figlet.renderText(word))
90
+ print(figle2.renderText(dt.datetime.now().strftime("%H:%M:%S ")))
91
+ print(
92
+ f"DO YOU WANT TO INSTALL ME ?... Run me with your \
93
+ {fg.green}'projectname'{fg.default} as a parameter"
94
+ )
95
+ print("do you want to quit ? type '.q' ")
96
+ #print(f" terminal width = {termsize} {os.get_terminal_size().columns}")
97
+
98
+ def autoreset_terminal():
99
+ global termsize
100
+ termsize2 = os.get_terminal_size().columns
101
+ #print("TS???", termsize, termsize2)
102
+ if termsize != termsize2:
103
+ print("i... RESET TERMINAL")
104
+ os.system("reset")
105
+ #terminal.clear()
106
+ termsize = termsize2
107
+ move_cursor(3, 1)
108
+ #print("X")
109
+
110
+ def main(projectname=None, debug=False, keyboard_remote_start = False, servermode = False, logo = False):
111
+ """
112
+ Main function of the project. When 'projectname' given: new project is created
113
+
114
+ Parameters:
115
+ projectname: THIS WILL GENERATE NEW PROJECT with these modules
116
+ keyboard_remote_start: just start a standalone prompt
117
+ servermode: wait for commands via mmap... to be used with -k
118
+ """
119
+ global RUN_SELECT_FROM_TABLE, SHOW_LOGO_TABLE, SHOW_TIME, RUN_MMAP_INPUT
120
+ config.CFG_DEBUG = debug
121
+ SHOW_LOGO_TABLE = logo
122
+ SHOW_TIME = logo
123
+
124
+ if not servermode: RUN_MMAP_INPUT = False
125
+ # GLobal clear terminal
126
+ if debug:
127
+ print(__version__)
128
+ #else:
129
+
130
+ signal.signal(signal.SIGWINCH, handle_sigwinch)
131
+
132
+ # ======== DEFINE THE CONFIG FILE HERE ========
133
+
134
+ config.CONFIG["filename"] = "~/.config/qltool/cfg.json"
135
+ config.CONFIG["history"] = "~/.config/qltool/history"
136
+ # solely LOAD will create ....from_memory files
137
+ # config.load_config()
138
+ # solely SAVE will create cfg.json only
139
+ # config.save_config()
140
+
141
+ # ==================================================== #########################
142
+ # ==================================================== ######################### remote
143
+ # ==================================================== #########################
144
+ # command prompt - separate thread
145
+ # ==============================================================================
146
+ if keyboard_remote_start:
147
+ #prompt_completer = WordCompleter( interpreter.KNOWN_COMMANDS )
148
+ prompt_completer = NestedCompleter.from_nested_dict( interpreter.KNOWN_COMMANDS_DICT )
149
+ #allobjects = interpreter.allobjects # ['obj1']
150
+ multilineinput = False
151
+ config.myPromptSession = PromptSession(
152
+ history=FileHistory( os.path.expanduser(config.CONFIG["history"]) )
153
+ ) #, multiline=Trueinp
154
+ inp = ""
155
+ myname = os.path.splitext(os.path.basename(__file__))[0]
156
+
157
+ print(f"i... input interface to {fg.orange}{myname}{fg.default} application. .q to quit all; .h to help.")
158
+ #loopn = 0
159
+ while (inp!=".q"):
160
+ #loopn+=1
161
+ inp = config.myPromptSession.prompt("> ",
162
+ cursor=CursorShape.BLINKING_UNDERLINE,
163
+ multiline=multilineinput,
164
+ completer=prompt_completer,
165
+ complete_while_typing=False,
166
+ wrap_lines=True, # no noew lines
167
+ mouse_support=False, #middlemouse
168
+ auto_suggest=AutoSuggestFromHistory()
169
+ )
170
+ if inp==".h":
171
+ print("H... HELP:")
172
+ print("H... .t table+logo")
173
+ print("H... .d disable logo and time")
174
+ print("H... .r reset terminal")
175
+ print("H... known commands: ", " ".join(interpreter.KNOWN_COMMANDS ) )
176
+ elif inp==".q":
177
+ mmapwr.mmwrite(inp)
178
+ else:
179
+ # SOME REAL COMMUNICATION WITH THE OPERATION THREAD ----
180
+ # If not finished -->> wait for it;
181
+ # and get name of
182
+ #print(loopn)
183
+ mmapwr.mmwrite(inp)
184
+ done = False
185
+ ii = 1
186
+ #esc = chr(27)
187
+ #cc=f'a{esc}[5m_'
188
+ cc=" "
189
+ spinner = ["🌑", "🌒", "🌓", "🌔", "🌕", "🌖", "🌗", "🌘"]
190
+ while not done:
191
+ # res = mmapwr.mmread( ) # read response
192
+ ii+=1
193
+ res = mmapwr.mmread_n_clear( mmapwr.MMAPRESP )
194
+ res = res.strip() # strin newline
195
+ print("\r",spinner[ii%8], end=cc, flush=True)
196
+
197
+ # if ii%2==0:
198
+ # print(spinner[0], end="\r", flush=True)
199
+ # else:
200
+ # print(spinner[3], end="\r", flush=True)
201
+ #print(f"... input was /{inp}/==/{res}/..result of read len(inp):", len(inp), " ...res:",len(res) )
202
+ # if res.strip()==inp.strip(): # BEFORE SENDING OBJ
203
+ if res.strip().find( inp.strip() )==0:
204
+ parts = res.strip().split("###")
205
+ if len(parts)>1:
206
+ obj_names = json.loads( parts[-1] )
207
+ #print("D... received objnames:", obj_names, type(obj_names))
208
+ #print(f" YES::::.../{inp}/==/{res}/.. ?")
209
+ # I need to append newly created objects to the autocomplete.....DIFFICULTY 9
210
+ interpreter.allobjects = obj_names #.append( f"o{loopn}" ) # TSTING
211
+ print(f" {fg.dimgray}... known:",interpreter.allobjects,fg.default)
212
+ #objects.get_objects_list_names()
213
+ for i in interpreter.KNOWN_COMMANDS_LOCAL_OBJ:
214
+ interpreter.KNOWN_COMMANDS_DICT[i] = {}
215
+ for j in interpreter.allobjects:
216
+ interpreter.KNOWN_COMMANDS_DICT[i][j] = None
217
+ prompt_completer = NestedCompleter.from_nested_dict( interpreter.KNOWN_COMMANDS_DICT )
218
+
219
+ done = True
220
+ #else:
221
+ # print(f" NONO:::.../{inp}/==/{res}/.. ?")
222
+ time.sleep(0.25)
223
+ #print("... konec prikazu")
224
+
225
+
226
+ # print(inp)
227
+ return
228
+ # ==================================================== #########################
229
+ # command prompt - separate thread
230
+ # ==================================================== #########################
231
+ # ==================================================== #########################
232
+
233
+
234
+ if projectname is None:
235
+ print()
236
+ elif projectname == "usage":
237
+ print(
238
+ """ ... usage:
239
+ _
240
+ """
241
+ )
242
+ sys.exit(0)
243
+ else:
244
+ sys.exit(0)
245
+
246
+ # ===================== top bar and commads from kdb ==========
247
+ # # DEBUG
248
+ os.system("reset")
249
+ # when I put reset later, it occludes the 1st red inpput command
250
+
251
+ top = topbar.Topbar(bgcolor=bg.blue)
252
+ top2 = top.add(bgcolor=bg.black)
253
+
254
+ # top.print_to(
255
+ # 10,
256
+ # f" {fg.white}{fx.bold}{dt.datetime.now().strftime('%H:%M:%S')}\
257
+ # {fx.default}{fg.default} ",
258
+ # )
259
+ # top.place()
260
+ # # start after top
261
+
262
+ # ========================= INITIAL cmd key setting....
263
+ cmd = ""
264
+ enter = False
265
+ key = None
266
+ a, b = (" ", " ")
267
+
268
+ # KEYTHREAD THIS MUST BE HERE.....toi catch 1st letter
269
+ # only return key, enter, abc = kthread.get_global_key()
270
+ # key:mayreact on q; enter==hit ; abc=>(a,b) for display.
271
+ kthread = None
272
+ if RUN_MMAP_INPUT:
273
+ # THis goes when mmap active
274
+ #print("i... MMAP ACTIVE ...........................")
275
+ kthread = key_enter.MmapSimulatedKeyboard(ending=".q")
276
+ else:
277
+ #print("D... MMAP NOT ACTIVE, using SSHKEYB.............")
278
+ kthread = key_enter.KeyboardThreadSsh(ending=".q")
279
+ # whatabout to have other terminal feeding mmapfile
280
+ #
281
+
282
+ df = create_dummy_df()
283
+ terminal = Terminal()
284
+ selection = None
285
+ #terminal.clear()
286
+ move_cursor(3, 1)
287
+ #################################################################
288
+ # L O O P
289
+ #################################################################
290
+ while True: # ================================= LOOP
291
+
292
+ autoreset_terminal()
293
+ if (SHOW_LOGO_TABLE):
294
+ # DEBUG terminal.clear()
295
+ move_cursor(3, 9)
296
+ if SHOW_TIME:
297
+ print_logo()
298
+
299
+ # time.sleep(0.05)
300
+ show_table(df, selection)
301
+ #
302
+ # RUN OPERATION ON TABLE
303
+ #
304
+ df = inc_dummy_df(df)
305
+
306
+ key, enter, abc = kthread.get_global_key()
307
+ (a, b) = abc # unpack tuple
308
+
309
+ if enter:
310
+ #print()
311
+ #print("--------------------------------------ENTER pressed")
312
+ if len(key.strip()) == 0:
313
+ pass
314
+ elif key.strip() == ".q":
315
+ break
316
+ else:
317
+ cmd = key.strip()
318
+ # ======================================================== INTERPRETER
319
+ if cmd==".t":
320
+ SHOW_LOGO_TABLE = not SHOW_LOGO_TABLE
321
+ elif cmd==".d":
322
+ SHOW_TIME = not SHOW_TIME
323
+ elif cmd==".r":
324
+ os.system("reset")
325
+ move_cursor(3,1)
326
+ else:
327
+ if config.CFG_DEBUG: print(f"{fg.gray}D... calling interpreter from bin*main {fg.default}")
328
+ interpreter.main( cmd )
329
+ if RUN_SELECT_FROM_TABLE:
330
+ # list of row numbers from column 'n' : assume whole word is list of rows:
331
+ if selection is not None and selection != "":
332
+ selection = ""
333
+ else:
334
+ selection = cmd
335
+ # ======================================================== INTERPRETER
336
+ #print(f"----------- {cmd}; table_selection:{selection}--------------------- ***")
337
+ #print("...writeback try:", key)
338
+ #print(" oL=", objects.get_objects_list_names() )
339
+
340
+ feedback = f"{key}###{json.dumps(objects.get_objects_list_names())}"
341
+ mmapwr.mmwrite( feedback , mmapwr.MMAPRESP) #
342
+ #print("...writeback done",key)
343
+ else:
344
+ cmd = ""
345
+
346
+ top.print_to(
347
+ 10,
348
+ f" {fg.white}{fx.bold}{dt.datetime.now().strftime('%H:%M:%S')}\
349
+ {fx.default}{fg.default}",
350
+ )
351
+
352
+ #
353
+ # commandline at TOP#2, cursor a_b; option not to show
354
+ #
355
+ if (not SHOW_COMMAND_LINE) or ( (key is not None) and (len(key) == 0) ):
356
+ top2.print_to(0, f"{fg.cyan}{bg.black}{' '*termsize}{bg.black}")
357
+ else:
358
+ top2.print_to(
359
+ 0,
360
+ f"{fg.white}{bg.red} > {fx.bold}{a.strip()}{fg.yellow}_{fg.white}{b.strip()}\
361
+ {fx.default}{fg.default}{bg.default} ",
362
+ )
363
+
364
+ # PLACE THE TOPBAR INPLACE
365
+ top.place()
366
+ time.sleep(0.1)
367
+
368
+
369
+ # ====================================================================
370
+
371
+
372
+ if __name__ == "__main__":
373
+ Fire(main)
374
+ #print("*********************************")
@@ -0,0 +1,8 @@
1
+ import sys
2
+ sys.path.append(".") # can find version in . by pytest
3
+ sys.path.append("./qltool") # can find version from Jupyter
4
+ #from version import __version__
5
+ # try:
6
+ # from qltool.version import __version__
7
+ # except:
8
+ # print("")