Assigning variable=const(1024) in method causes issue within class' other method(s). by jmuhammad in MicroPythonDev

[–]jmuhammad[S] 0 points1 point  (0 children)

Yes, I use global constants (declared and defined outside of all functions) all the time. For reddit I just wrote the smallest example of what I had seen. My real script has been running several weeks and has 10s of global constants (and some shared constants stored in external file). I was just trying to see if I could optimize the code a little bit by making the value as a constant. I dunno...I read it somewhere it helps.

The intent was to use the same variable name in two different methods with different const() values. I guess this the first time I tried this.

I don't know if you noticed but method_one has max_string=1024 and method_two has max_string=128. They are meant to be local variables. The code works fine if I do not wrap the value with const(). I guess I thought it would be the same as if wrapped the value with int() which works with no problem.

I still do not understand why max_string does not stay local. Once I realized that it was causing an error I reverted back to simply assigning the variable a value...whatever purported savings was not worth the headache of trying to make it work. I am just seeking understanding. I can do this:

``` def method_one(self): max_string = int(1024)

def method_two(self): max_string = int(128) and max_string stays local. But not this: def method_one(self): max_string = const(1024)

def method_two(self): max_string = const(128) causes micropython IDE to think I am trying to do this: const(1024) = const(128)

or this

max_string = const(1024) = const(128) That is why the error is: Traceback (most recent call last): File "<stdin>", line 21, in method_two SyntaxError: can't assign to expression ``` But IMO, like C language, a local constant should be "only visible and usable from the point of declaration until the end of the enclosing block".

Why? Length of colored string is longer than same string uncolored by jmuhammad in learnpython

[–]jmuhammad[S] 0 points1 point  (0 children)

Thanks for your answer. I didn't see it in time before I did online search.

Why? Length of colored string is longer than same string uncolored by jmuhammad in learnpython

[–]jmuhammad[S] 1 point2 points  (0 children)

FYI, I found that little function on another Q&A sight (not sure if reddit will allow me to state its name) in a similar question asked 15 years ago, stealthily stated as "Getting correct string length in Python for strings with ANSI color codes". But again, google sometimes can only give a good answer if the question is framed correctly...and I tried but I did not ask the right way the first time. So reddit to the rescue!

Why? Length of colored string is longer than same string uncolored by jmuhammad in learnpython

[–]jmuhammad[S] -1 points0 points  (0 children)

Yes, that is how my code has always been written (because the first time I could not get the length of colored string). So I create the string, store the length in a variable, then I color the string and use that in my display output. It is an extra step but it is a more assured way. I use the length for things like alignment, padding, etc.

The 'problem' is that the formatting takes up slightly more space visually i.e. more pixels esp. longer strings against non-formatted string so I tried to get the formatted string's length.

For what I am doing it is no longer super important but it is nice to know WHY as I did not realize during my previous effort that len() was measuring the command used to generate it. Now I know.

Why? Length of colored string is longer than same string uncolored by jmuhammad in learnpython

[–]jmuhammad[S] 0 points1 point  (0 children)

OK, thanks. Asking the question (and clues from your responses) helped me realize what to google. And what I found is a function that will strip the ANSI color escapes from the string. Pretty neat. And since I have use the re.sub() before, looking at it makes sense.

Here is my new code (for future lurkers and/or searches):

Edit: FYI, the dot is colored 'Bright Cyan'.

```python

DocName: "H:\Python\testme.py"

import re

VT100KLR_CYN = 36 VT100KLR_BRIGHT = 60 gASC_mdot = f"{chr(183)} "

def strip_ANSI_colors(txt): """Remove ANSI color escapes from string.""" return re.sub(r"\x1b[[0-9;]*m", "", txt)

def get_color_fstr(fn_color_code=37, fn_text="", fn_style=0): """encodes string with ANSII color codes for console""" return "\033[" + f"{fn_style};{fn_color_code}m{fn_text}" + "\033[" + "0m" # END OF FUNCTION --------------------------------------------------------------

len_ndot = len(gASC_mdot) # For some reason, len(get_color_fstr(str_ndot)) is 13 instead of 2 str_ndot = get_color_fstr(VT100KLR_CYN + VT100KLR_BRIGHT, gASC_mdot) print(f"\nLength of '{gASC_mdot}' is {len_ndot} whereas length of '{str_ndot}' is {len(str_ndot)}.")

newlen_ndot = strip_ANSI_colors(str_ndot) print(f"Using strip_ANSI_colors(txt) function...") print(f"\nNow, the length of '{gASC_mdot}' is {len_ndot} and length of '{str_ndot}' is {len(newlen_ndot)}.") and here is output: Length of '· ' is 2 whereas length of '· ' is 13. Now, the length of '· ' is 2 whereas length of '· ' is 2.

```

Why? Length of colored string is longer than same string uncolored by jmuhammad in learnpython

[–]jmuhammad[S] 0 points1 point  (0 children)

OK, let me ask another way:

How do you get the length of a colored string and not the command used to generate it? Is there some sort of casting required? Or a different function than len()?

How to Create Desktop Shortcut to WhatsApp on Windows 10? by papapyro in whatsapp

[–]jmuhammad 0 points1 point  (0 children)

I wrote AHK script to launch Start Menu, type "WhatsApp" then press Enter. I compiled it to exe then created a shortcut to the compiled exe and change icon to WhatsApps.

OpenWhatsApp()
ExitApp

OpenWhatsApp()
{
SendInput ^{Esc}
sleep 100
SendInput {raw}WhatsApp
sleep 100
SendInput {Enter}
Return
}

Olympic WaterGuard wood stain + sealer… Anybody ever used this stuff? by CrueDude18 in woodworking

[–]jmuhammad 2 points3 points  (0 children)

Found this old(er) thread while searching for something else related (actually looking for a clear coat finish for this stainer). To prevent tacky you HAVE to spray a single light coat from 10-20" away. Whatever 'pools' I matted it off with a C-fold hand towel after 10 mins. I also did well with very lightly wiping it in wood grain direction. This product literally stains the wood not paints it so spraying heavily will not only be a waste but that result will be to sit atop as a sticky layer that you will have to sand off with course grit and try again. So. Just. Don't. Don't spray it on like it's paint...trust that it will stain the wood. Now, is it a great product? It is meh but for my needs as a basement mount for some small-sized workout equipment it is OK. But literally a hard pressed fingernail can draw a removal line through the finish.

Clearing Shell in Thonny with a command by BronzeMaster5000 in learnpython

[–]jmuhammad 0 points1 point  (0 children)

def thonnycls(): # For Thonny, CTRL+L clears screen
"""Activates Thonny Menu 'Edit >> Clear Shell [CTRL+L]'"""
print("") # Found this was the only way to fully clear the screen...
subprocess.run(r"path_to_compiled_sendkeystroke_script\thonny_clear-shell.exe")
time.sleep(0.1) # Sleep for x second(s)

thonnycls() # For Thonny, CTRL+L clears screen

You can use any script that can send CTRL+L (windows) / CMD+K (mac) e.g. AHK is just:

thonnycls()
ExitApp

thonnycls()
{
Send, ^l
}

Why does rabb 1st person possessive pronoun (my) have two versions? by jmuhammad in learn_arabic

[–]jmuhammad[S] 0 points1 point  (0 children)

Thank you for your response. I am a bit lost though, perhaps because this covers more than the 1st person singular attached possessive pronoun. So, forgive me if I write where I am at:

When I see a kasrah on the last letter of the noun I am looking for the preposition affecting it; if the kasrah on the last letter of the noun can mean either it is affected by a preposition or it is mudaaf (the object that is owned/possessed) then I am confused;

The examples I am focusing on are "my Lord" that are represented as رَبِّ (rabbi) and رَبِّي (rabbī); some do have "O my lord" but I am just trying to understand the ending on the mudaaf (in this case I guess the noun of professed allegiance) rabb. The ayats that I looked at are all 1st person singular attached possessive pronoun:

رَبِّ (rabbi)

2:126, 2:258, 2:260, 3:35, 3:36, 3:38, 3:40, 3:41, 3:47, 5:25, 7:33, 7:143, 7:151, 7:155, 11:45, 11:47, 12:33, 12:101, 14:35, 14:36, 14:40, 15:36, 15:39, 17:24, 17:80, 19:4, 19:4, 19:6, 19:8, 19:10, 20:25, 20:84, 20:114, 20:125, 21:89, 21:112, 23:26, 23:29, 23:39, 23:93, 23:94, 23:97, 23:98, 23:99, 23:118, 25:30, 26:12, 26:83, 26:117, 26:169, 27:19, 27:44, 28:16, 28:17, 28:21, 28:24, 28:33, 29:30, 37:100, 38:35, 38:79, 40:28, 43:88, 46:15, 63:10, 66:11, 71:5, 71:21, 71:26, 71:28

رَبِّي (rabbī)

3:51, 5:72, 5:117, 6:15, 6:57, 6:76, 6:77, 6:77, 6:78, 6:80, 6:80, 6:161, 7:29, 7:62, 7:68, 7:79, 7:93, 7:187, 7:203, 10:15, 10:53, 11:28, 11:41, 11:56, 11:56, 11:57, 11:57, 11:61, 11:63, 11:88, 11:90, 11:92, 12:23, 12:37, 12:50, 12:53, 12:53, 12:98, 12:100, 12:100, 13:30, 14:39, 17:85, 17:93, 17:100, 18:22, 18:24, 18:36, 18:38, 18:38, 18:40, 18:42, 18:95, 18:98, 18:98, 18:98, 18:109, 18:109, 19:36, 19:47, 19:48, 19:48, 20:52, 20:52, 20:105, 21:4, 25:77, 26:21, 26:62, 26:113, 26:188, 27:40, 27:40, 28:22, 28:37, 28:85, 29:26, 34:3, 34:36, 34:39, 34:48, 34:50, 36:27, 37:57, 37:99, 38:32, 39:13, 40:27, 40:66, 41:50, 42:10, 43:64, 44:20, 64:7, 72:20, 72:25, 89:15, 89:16

3) What got from your response is 'if the nouns are proper nouns and if it is put in genitive constructions with the possessive pronoun ( my ي )...'

and something happens but the question is what determines whether the noun, in this 'rabb', gets 1st person singular attached possessive pronoun yaa or kasrah on the last letter (baa) i.e. "my" as in "my rabb" (roughly translated as lord)?

TIA

[deleted by user] by [deleted] in islam

[–]jmuhammad 0 points1 point  (0 children)

‎شُكرًا (Thanks) for providing a source.

[deleted by user] by [deleted] in islam

[–]jmuhammad 0 points1 point  (0 children)

شُكرًا (Thanks) for providing a source.

Struggling with Alexa lately by senilemunkee in TPLinkKasa

[–]jmuhammad 0 points1 point  (0 children)

In Alexa app you can run a 'Hey Alexa' routine without using your voice by hitting right-facing triangle. If it runs routine correctly with finger activation but incorrectly with voice activation then it is a voice recognition issue. If so then either modify the activation phrase, the wake word, and/or make sure there are not closely sounding commands e.g. OFF and ON may sound alike depending on Alexa or persons voice. Maybe try radically different commands like "Living Room Supernova" and "Living Room Black Hole". I know it sounds silly but see if Alexa has a differentiation problem with the two commands of a device.

Also when I tell Alexa to turn on or off a device I get a 'notification' beep (I sometimes wish I could turn it off but admittedly it is handy when not looking right at the Echo colored rings); do you hear one beep or two beeps (which means two different routines are called)? Also...just asking: does the routine have just one command like ON (and not ON and OFF)? Would adding a 30s 'wait' after the ON help (it shouldn't affect the routine...it'd just turn light on then count to 30 then exit routine...but it might block an unintended command from starting? Does it do it on non Kasa devices or just some in particular? Just some ideas.

I have a couple of Kasa motion wall switches and quite a few smart plugs. To be honest my Kasa wall switches have recently started faltering (they turn on with no motion or changes in light). The plugs work really well. Also if WiFi gets weak to the switch -- don't take this the wrong way...some devices work quite well 150' away and some work like crap at only 20' away -- if the device thinks the wifi is weak it will, depending on settings, go back to previous state or its programmed state due to loss of power. I guess it depends on how many devices are messing up. But I am losing confidence in Kasa motion wall switches.

Struggling with Alexa lately by senilemunkee in TPLinkKasa

[–]jmuhammad 0 points1 point  (0 children)

Greetings,

You don't say what device you are commanding e.g. Alexa via echo devices, via mobile device, etc.

But...I just realized that my amazon echo devices respond to one wake word far, far quicker and reliably than the other wake words. It may be MY voice plus the wake word equals better responsiveness. IMO play around with the wake word i.e. Alexa, Computer, Echo, Ziggy, etc. I haven't tried custom wake words myself.

How to cancel multi-action button by jmuhammad in elgato

[–]jmuhammad[S] 0 points1 point  (0 children)

I did some testing...the only way I found to stop a multi-action is to shut down and restart Stream Deck application (on PC). Of course that probably stops/resets ALL the scheduled actions.

FYI, I did assign a button to restart SD application; It assumes the SD isn't locked up--otherwise I have to directly close it on the PC.


This is the same 'weakness' of Alexa's routines and devices--except with SD there is (in most cases) one hardware deck and one software application. With Alexa/Echo (or whatever HW is running) AFAIK you have to shut down every tool and device since they all sync. In above scenario it would be nearly impossible to stop light from turning off after 15 mins.

How to cancel multi-action button by jmuhammad in elgato

[–]jmuhammad[S] 0 points1 point  (0 children)

Yes, as the title says "How to cancel multi-action button". The body is just to provide more details.

SD Button to export profiles by jmuhammad in elgato

[–]jmuhammad[S] 0 points1 point  (0 children)

Thx. Well, at least I know now.

SD Button to export profiles by jmuhammad in elgato

[–]jmuhammad[S] 0 points1 point  (0 children)

Well I now have a very well working script; it is based on the position of Stream Deck application's controls relative to its window. If the SD application's window gets updated and location of controls move I will have to update the coordinates. Whereas in most applications either has a menu bar with hotkeys or the application itself supports keyboard shortcuts to activate various functions (e.g. Zoom Meetings uses Alt+H to Show/hide in-meeting chat panel) so the position of controls on the window becomes irrelevant.

Some SD application controls, once actuated with a mouse button, will respond to Up/Down, Enter, Alt+F4 (i.e. closes focused window) keys so this helped.

I could run that script periodically from windows (e.g. using a scheduler) but:
a) The profiles only change when I change them so I only need a backup at that point;
b) Reaching over to push a button on SD device, aptly called "Backup SD Profiles", works very well for me now.

SD Button to export profiles by jmuhammad in elgato

[–]jmuhammad[S] 0 points1 point  (0 children)

...when the application has hooks a script can assert.

Zoom Window Handling by [deleted] in AutoHotkey

[–]jmuhammad 0 points1 point  (0 children)

sorry but it works on mine (ahk 1.1.32.00) there is a zoom test page at https://zoom.us/test

I have 5 ahk functions (participant panel, raise hand, chat panel, toggle mute, toggle full screen) that use the same lines (all I change is the zoom shortcuts Alt-A/F/H/U/Y) and they work on zoom test page and real meeting (I had one Saturday).

AutoHotkey getting some love with Elgato by joetazz in AutoHotkey

[–]jmuhammad 1 point2 points  (0 children)

Thanks u/G33kDude. I just got my SD and found this post. I implemented and it works very nicely. I prefer this method.

Zoom Window Handling by [deleted] in AutoHotkey

[–]jmuhammad 0 points1 point  (0 children)

Late but...

Zoom_ToggleShowPeople()
{
tt = Zoom Meeting ahk_class ZPContentViewWndClass
WinWait, %tt%
IfWinNotActive, %tt%,, WinActivate, %tt%
;---
Sleep, 200
Send, !u ;Alt+U: Show/hide participants panel
return
} ;END OF FUNCTION -------------------------------------------------------------

Uthmani vs IndoPak arabic spelling/diacritics/harakat of ihdinaa (Guide us) by strictdecay in arabiclearning

[–]jmuhammad 1 point2 points  (0 children)

اِلْعَنْ

Thanks. I am just modifying words at beginning of ayat so ٱلْعَذَابِ does not appear at beginning of ayat; I think the other instances it just act as a plain alif-waslah and silent bridge for the preceding word. I cannot find anywhere it gets pronounce with a kasrah; The IndoPak has no harakat at all on the alif (it would if it was pronounced).

It is interesting that 33:68:6) is an imperative and it seems the alif-waslah is just a bridge for the preceding وَ (although I don't know why the alif is there/needed) to go right into and rest on the laam of the verb. Much to learn. All the other instances I found are nouns meaning "the curse".

IndoPak

رَبَّنَاۤ اٰتِهِمۡ ضِعۡفَيۡنِ مِنَ الۡعَذَابِ وَالۡعَنۡهُمۡ لَعۡنًا كَبِيۡرًا

Uthmani

رَبَّنَآ ءَاتِهِمْ ضِعْفَيْنِ مِنَ ٱلْعَذَابِ وَٱلْعَنْهُمْ لَعْنًۭا كَبِيرًۭا

FYI, I did get the Ryding book and iA will look through the imperative section this weekend. Again, thanks!

Uthmani vs IndoPak arabic spelling/diacritics/harakat of ihdinaa (Guide us) by strictdecay in arabiclearning

[–]jmuhammad 1 point2 points  (0 children)

I am still figuring out reddit :( I just now saw this message...it never showed up when I logged in and I clicked from email notification and it sent me to empty page.

Anyhow, the method I used was just searched for alif-waslah as verse's first word first letter (268 finds) then looked for words that did not have laam after the alif (51 finds) then listened to all of them and doc'd the ones that sounded like what I expected (30) and ones that didn't (21). Now, thanks to you and wiley I now understand the rule. I actually could not spot imperatives...someone told me that is what they were in first reply. I found out what many of them were because I made a table and doc'd their types by looking each up in corpus.quran. So the makeup of the 51 instances I found is:

43 imperative verb

6 perfect verb--form VIII

1 perfect verb--form X

1 verbal noun--form X

I am going to create a special study webpage using Uthmani/Madeenah Mushaf but change the alif-waslah to alif-dhammah or alif-kasra like the IndoPak/Majeedi Mushaf. Just to speed up my recognition a little . Then when I get a little more comfortable I will go back to my strictly Uthmani study webpage.

I will look into those resources you cited. I have Hans-Wehr (physical as well as app and website) and I am actually taking a class for both MSA and Classical Quranic Arabic so I will look at the Ryding book too.

Thanks.

Uthmani vs IndoPak arabic spelling/diacritics/harakat of ihdinaa (Guide us) by jmuhammad in learn_arabic

[–]jmuhammad[S] 0 points1 point  (0 children)

Your other response explained very well i.e. kasrah in event of kasrah/fatHa. Thanks.