Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

The way it works is you show us what you have done so far and where you are stuck. Then, if you have given us enough details we will try to help. The more effort you put into asking your question the more likely you are to get a useful answer.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I have had little success with connecting devices with Bluetooth. Connections, when they work, are unreliable. In many cases devices are just not recognized or fail to connect. I suggest using either an HDMI connection or Chromecast depending on how you intend to use the device.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I can't say whether or not this is illegal (I suspect it is) but I do think it is highly unethical.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

One of the suggestions worked. Much appreciated.

rproffitt commented: Thanks for that. I wish it was always the same thing but it rarely is. +15
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

It may be urgent for you but I don't consider doing someone else's homework for them urgent at all.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

When I access an api. it returns data in below format
n2035014,25 N2035014,25 B2035014,2944.40,250,3787.30,2400 o24,22971.20 h24,23064.15 l24,22641.40 c24,22945.05 i24,22744.40

I have my doubts as to the format of the returned data. Can you please be specific? For example, is the data returned as a blank-delimited string or as a series of strings? What do you mean by a dataset? You identify several prefixes (i, B, o, h, l, c) but not n or N. You mention field names like stock code and Current Value but not how they map onto the data returned by the api.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Sometimes you want to ensure that only one copy of a script can be run at time. Windows provides a facility called a mutex and you can use it to prevent multiple instances.

To create the mutex, all I have to do is

varname = GetMutex()

If the mutex already exists then IsRunning() will return True so the line

if (myapp := GetMutex()).IsRunning():

both creates the mutex (maybe) and tests if the app is already running. Note this this uses the walrus (:=) works only in Python 3.8.2 or newer.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Finally posted the VideoLib project that builds on the VLC wrapper. Enjoy. I might be a little tapped out for a bit.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

In the vein of "I told you that story so I could tell you this one"... I wrote the above project so that I could rebuild my VideoLib application (which I originally developed in vb.Net) in Python/wxPython. Taking the code from above, I created an expanded user interface and did some cleanup. What I ended up with was an app that I could use to browse my home movie library.

I have all of my videos tagged (keywords in the file names) and commented (expanded descriptions in :comment alternate data streams). Using the new application I can browse to a folder containing videos and filter the list of videos by entering one or more strings. With the entered strings I can restrict the list to

  1. Entries where the file or comment contains all of a set of filter strings
  2. Entries where the file or comment contains any of a set of filter strings
  3. Entries where the file or comment contains the exact filter string

Selecting a video causes it to immediately start playing. Using a slider I can seek to any part of the video. Standard controls allow me to pause/resume/stop playback and select an appropriate volume. Where possible, the display is adjusted to best-fit the video with no/minimal unused space.

Playback can also be controlled with hotkeys. Arrow left/right skips back/ahead 5 seconds. Shift left/right skips 15 seconds. Other hotkeys can be added as required.

Any comment associated with the video is displayed in a scrollable/wrapped …

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Sorry about the broken links. They should be good now.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

A more concise (and still clear) version of that would be

def fac(n):
    return 1 if n <= 1 else n * fac(n-1)
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Okie dokey. Two more tutorials posted. A short one on subclassing python objects, and an intermediate one on Creating a GUI Wrapper for VLC Media Player in python/wxpython which I will build on in a future post in the same thread shortly.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
Introduction

I have a pile of home movie videos created over more than seventy years. As with my many photos (all in digital form) they require some effort to find particular ones of interest. Typically, I name my videos (and photos) with tags. A file might look like

    2013-10-29 11-59 Tucker & Cooper playing in backyard.mp4

What I wanted was an integrated interface that would easily allow me to search and play videos. I had been using Everything for the searching, and VLC Media Player for the playback. I found this to be functional but clumsy so I decided to write my own application. I still wanted VLC as my back end because it plays just about everything. Fortunately all of the functionality is bundled in a core library, and the Python gods have seen to it that there is a Python module to interface with that library.

This tutorial will walk you through the creation of a GUI front end for VLC Media Player. It assumes that you are at least passingly familiar with Python and wxPython. If you are not I suggest that for an introduction to Python you read the excellent book Beginning Python: From Novice to Professional by Magnus Lie Hetland. For wxPython there is Creating GUI Applications with wxPython by Mike Driscoll.

Following the (hopefully) successful completion of the GUI front end I will provide the complete video library application. If you work through the tutorial you should be able to understand …

pritaeas commented: Nice +16
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
Subclassing python objects

Sometimes you want to add just a little more functionality to an existing python object. You can do that by subclassing it and adding on the missing parts. This example is based on a really mindless game of solitaire I used to play as a kid. In this game you start with a shuffled deck. You deal the cards face up one by one. Play doesn't actually start until you have four cards laid out (place them face up, left to right, or fan them out in your hand). Every time you add a card you examine the four most recent cards (rightmost).

If the last card and the fourth last card are the same rank then you remove the last four cards.

If the last card and the fourth last card are the same suit then you remove the two cards between them.

Play continues until you have dealt all the cards. If you have no cards left in your hand at that point then you win.

I knew it was difficult to win a hand (based on never having done so). I wanted to know if it was even possible. Rather than playing and hoping for a win I decided to script it. My first attempt a couple of years back was written in vbScript. This version is written in python. For the record, the vbScript version is 143 lines. The python version is 54 (comments and blank lines not counted).

The basic unit of …

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I get to lick the spoon but Cooper get's to lick out the bowl. That's ok. My tongue isn't long enough anyway and the dough gets stuck in my beard.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Before I start thinking about this (whoops, it's already too late) do you have any initial ideas on how to map the hierarchical structure of XML onto a relational structure (SQLite)? Are there any restrictions on the level of nesting of the XML source?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I did not know that. My wife and I always sample the cookie dough before baking. Never had a problem. Of course, I grew up on a farm (vegetables) so pulling a carrot right out of the ground and eating it was no big deal. I probably developed immunities at an early age to things that would kill most bubble kids today.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

srand ([ int $seed ] ) : void

Seeds the random number generator with seed or with a random value if no seed is given.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Thanks for all the new content!!

You are welcome. I have a couple of finishing touches on the tutorial text (I have to create some new screen shots) and then I'll be posting

  1. A tutorial on using python/wx as a front end (wrapper) for VLC Media Player
  2. Creating a video library front end using the previous project as a basis
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

That was while drinking coffee as well. Makes you wonder why I can't make it through the night (pulling an all-nighter has a different meaning for seniors).

I posted the first project (a smallish one) as a code snippet multi-timer application. More to follow.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
This project implements a multiple timer application. It was written in
  1. Python 3.8.2
  2. wxPython 4.1.0

Feel free to experiment. Here are some possible enhancements:

  1. Add the ability to run a program when the timer expires. With a little scripting you could, for example, schedule the sending of an email.
  2. Add the option to auto-restart a timer after it has alarmed.
  3. Autosave timers on close and reload them on restart.
  4. Add a taskbar icon with pop-up summary of timers on mouse over.
The Files:
Timer.pyw

This file contains the mainline GUI code. It displays a list of custom timer entries and three control buttons. The three buttons allow the user to:

  1. create a new timer
  2. start all existing timers
  3. stop all existing timers

Timer entries are displayed one per line. Each timer contains the following controls:

  1. a button which will run/stop the timer
  2. a button that will stop and reset the timer (countdown only)
  3. a button that will delete a timer
  4. a checkbox to enable a popup message when the timer expires
  5. display of the time remaining
  6. description of the timer
TimerEntry.py

This is a custom control that is subclassed from a wx.BoxSizer. The fields mentioned above are arranged horizontally in this sizer.

A timer entry object can delete all of the controls within it, however, it is up to the parent object to delete the actual timer entry object. I decided that the easiest way to do this was to pass the …

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Six-foot distance and masks are pagan rituals of satanic worshipers. Where does 6 feet come from, people? Why is not 3? Why is it not 5? Why is it not 10? Why is it not 30? Why is it 6? We are Christians. Our children do not practice Satanic worship. We don’t have them stand six feet apart from each other with facial coverings.

  • Heidi Anderson (parent of a child in Elmbrook School District, Wisconsin),

Memorable for all the wrong reasons.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

In the news...

Six-foot distance and masks are pagan rituals of satanic worshipers. Where does 6 feet come from, people? Why is not 3? Why is it not 5? Why is it not 10? Why is it not 30? Why is it 6? We are Christians. Our children do not practice Satanic worship. We don’t have them stand six feet apart from each other with facial coverings.

  • Heidi Anderson - parent of a child in Elmbrook School District, Wisconsin

I'd add a comment but I think you pretty much know what I'd say.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Make the move to 3.0. The biggest problem is going to be modifying all your print statements but a simple Python script with a regex would handle that. The longer you stay with a defunct 2.x the harder it will be to change down the road. Do it now.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I don't think a regex will do what you want. I don't see how you can define a pattern, based on your example, that could distinguish things you want to <p></p>ify and things you do not. How would you determine that you want to modify basket, PVC thing, and Trash, but not let or someVariable. Also, removing the word let is something else entirely.

pritaeas commented: I had a problem I wanted to solve with a regex... now I have two problems. +16
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

the back reference is done with \# where you indicate (1-9) the desired group. You create the pattern for what you want to match by enclosing it in parentheses. In your case it would be

if \(isset\((\$[a-zA-Z_][a-zA-Z_0-9]*)\) AND \1\)

Note that to put in a literal ( or ) you have to escape with a backslash.

Dani commented: Thanks! +34
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Phew!

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

OK. Try this

(\$[a-zA-Z_][a-zA-Z_0-9]*)(?=.*\1[^a-zA-Z_0-9])

(\$[a-zA-Z_][a-zA-Z_0-9]*)      a php variable (grouped)
(?=.*\1[^a-zA-Z_0-9])           a look-ahead expression 

The second part says "look ahead for the matched php variable as long as it isn't part of a longer variable name." If you get a line with a hit then you have a repeated php variable in that line.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You might try Everything Indexer by VoidTools. It's free and awesome.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

A good first step would be to tell us what the code is supposed to do. A good second step would be to tell us how familiar you are with Python. And a good third step would be to tell us how much you are willing to pay to have someone do it for you.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

PS I hope you are still safe and healthy.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

What have you tried so far?

What you have to keep in mind is that if the number of months you are subtracting is greater than the number of months in the given date you will have to subtract from the given year. For example, if your tuple is

(2020, 5, 9)

your result will be

(2019, 8)

and if your tuple is

(2020, 5, 21)

your result will be

(2018, 8)

If you write out a few examples your steps should be clear.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Manitoba is down to 16 active cases so things are loosening up. And the Thunder Bay area has only 2 active cases, so we packed up and headed to our cottage at Shebandowan Lake. We'll probably have less contact with people out here than we would back home and there is lots to keep us occupied out here. The cottage itself (at least the original portion) is over 90 years old so there is always something that needs fixing.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Yes, they did publish a new one.

Doh! I just noticed that the dates were out of order. Still blurry though.

rproffitt commented: "It's a beautiful chart." +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

On a related note (not intended to derail this thread), a while back the US government gutted consumer protection laws. It used to be that financial planners were legally required to operate in the best interest of the client (I believe that is called fiduciary duty). That is no longer the case. If you want to be safe make sure you go to an explicitly stated fiduciary financial planner. At least for now, with that designation they are required to put the customer first.

But in general the rule is rofits are first. Everything else comes after.

rproffitt commented: "Excellent idea Smithers." The contact I have at a brokerage cringes when I ask "Are you a fiduciary?" They answer no then lower their head in shame. +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Just a thought...

A number of big-pharma companies are currently working on a vaccine. Knowing how much that industry values profits over all else, what do you suppose is their primary focus:

  1. A vaccine that they can sell you once to protect you
  2. A drug they can sell you repeatedly to keep symptoms in check (like they did with HIV)

Call me cynical, but from their point of view a treatment is much more profitable than a cure.

rproffitt commented: On Feb 18, 2020 I woke up and bought stock in 2 vaccine companies. I've sold them at a tidy profit. Yes, you're right. +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

As I recall, that image was from the beginning of the outbreak in the US when Faux News was screaming that since nobody there had died yet it was a fake problem.

rproffitt commented: Yesterday at the shops, someone was upset over the fake virus, having to wear a mask and so on. They are among us. +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

That image is a tad blurry but I couldn't figure out what it was saying. Incidentally, Georgia has been caught three times fudging their data. And it seems Florida keeps their deaths low by recording/reporting only the deaths of aFlorida residents. If you are only visiting you don't count. Literally.

rproffitt commented: Looked for clearer but didn't find it. Across the bottom, April, May then April again? +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

For the record, the US ranks a poor 38th when it comes to testing.

rproffitt commented: “We’ve tested more than every country combined.” - Trump on April 27, 2020 +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Welcome to Daniweb. Quick movie reference - is it pronounced ee-gore, or eye-gore? Bonus points if you get the movie.

JamesCherrill commented: Frau Buchner - don't frighten the horses +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Glad I could help.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If you are looking for a Windows bootable system that you can customize you can try bart's PE builder. If you just want a bootable Windows PE system to access files on a bricked system (non-customizable) you could use Macrium Reflect Free and build a recovery boot USB. It gives you minimal tools but you can use a command shell and things like robocopy from the bootable environment.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

from Settings import * thats is what i was asking about to create a different file and import it in a different file.

I've never gotten into the finer points of setting up modules for import so I can't explain how they work. However, what I did for my own use was set up a folder, D:\include. I then set the Windows environment variable, PYTHONPATH to D:\include. When I want to include a file (like autoit.py) from my include library I do

from autoit import *        # from include

The comment is so I can do a grep to check what scripts reference my include folder.

If you don't want to use PYTHONPATH you can add the folder at run time like

import sys
sys.path.append('d:\include')

its not increasing at all

Is that block of code being executed? i.e. is collision==True? If noth then you'll have to debug the isCollision method.

While I'm thinking about it, when you post code, could you please post the code as text using the code insertion </> tool? That way it is easier if someone (like me) wants to copy the code into a local file to test. It makes it easier for us to help you.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

the code u showed me only calcualates distance but collision doesn't happen

It returns True if the objects are closer than 27 units apart. I presume your object positions are defined by a centre point. In that case you should probably pass the object widths (or radii) and use those numbers to determine dynamically what constitutes a collision. For example, assuming round objects for simplicity, if object a has a radius of 23 and object b has a radius of 9 then they are touching if they are coser than 23+9 or 32 units apart. I also assume a bullet has a much smaller radius than a target.

the format that i asked might not be understandable but what i meant was that to find the distance between the bullet and the enemy and to fire the bullet if the enemy and player distance is less than 27 u can't fire any bullet.sorry for confusion

I didn't understand that but in order to make the code more general and perhaps clearer you might want to create a distance method that does nothing but return the distance between two objects. Then your code looks something like

if distance(objecta, objectb) < mindistance:

You could also define your objects as classes (actual objects) and use notation like

fighter1.pos
fighter1.pos.x
fighter1.pos.y

or just

fighter1.x
fighter1.y

instead of polluting your namespace.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I'd add a print statment to see exactly what is happening. If you are using a debugger with breakpoints then also add one at the start of your dead function.

collision = isCollision(fighterX[i], fighterY[i], playerX, playerY)
if collision:
    dead()
collision = isCollision(fighterX[i], fighterY[i], bulletX, bulletY)
if collision:
    print("shot")

def isCollision(fighterX, fighterY, playerX, playerY):
    distance = math.sqrt(math.pow(fighterX - playerX, 2) + math.pow(fighterY - playerY, 2))
    print("distance=", distance)
    if distance < 27:
        return True
    else:
        return False

I don't know if you need to keep the value of collision for later but your code could also be written

if isCollision(fighterX[i], fighterY[i], playerX, playerY)
    dead()

if isCollision(fighterX[i], fighterY[i], bulletX, bulletY)
    print("shot")

def isCollision(fighterX, fighterY, playerX, playerY):
    distance = math.sqrt(math.pow(fighterX - playerX, 2) + (math.pow(fighterY - playerY, 2)))
    print("distance=", distance)
    return distance < 27:

I might also suggest you change the naming of the parameters to make them more generic such as

def isCollision(object1X, object1Y, object2X, object2Y):
    """Return True if object1 and object2 are closer than 27 units"""
    distance = math.sqrt(math.pow(object1X - object2X, 2) + math.pow(object1Y - object2Y, 2))
    print("distance=", distance)
    return distance < 27:

If you are running the latest (3.8x) version of Python they have added a self documenting print formatter which is used like

print(f'{distance=}')

If, for example, distance is 43.9 then the output is

distance=43.9

Also note that I removed a redundant pair of parentheses in your distance calculation.

rproffitt commented: Science. +1 +15
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Google bartpe windows 10 and check the results. There are several youtube videos on how to make a bootable Windows 10 PE USB.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Isn't that pretty much the same thing you asked here? Why start a new thread?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

The difference is your brain is young and smart and mine is not as much ;-P

I interpreted AUTO_INCREMENT as AUTO_INCREMENTED.

rproffitt commented: What to do versus what is done. +15
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I don't understand how that works. From what I read the code says

Get a new id which is one more than the last inserted key and
if the new id already exists then
    just update the existing record
else
    insert a new record

To me that seems, what's the technical term? Oh yeah. Bonkers. Using lastid+1 should guarantee no duplicate key. If multiple people are inserting records and there is a duplicate key then someone's newly inserted record is going to get clobbered. Can you give me a scenario where this behaviour is desirable?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

This thread is a continuation of a conversation that I started here. As Dani correctly pointed out, the discussion belonged in its own thread and should not have taken over the thread in which it started. It wasn't my intention to hijack that thread (and I apologize) but that's what happened.

you find advertising largely unethical

I find false advertising unethical. I find the other advertising merely annoying and only sometimes useful.

It’s not against the TOS or copyright rules of the library to use it in the way you are. It just wasn’t what the library was designed for.

So it's ok to use bots for unethical purposes as long as it's not what they were designed for?

Suddenly someone who is not in your industry at all, and has no programming experience, comes in and personally calls you an unethical person and a disgrace for using things not the way they were initially intended, citing their reason as because ten years ago their mother fell off a chair trying to use it as a step stool to reach a top shelf, and she permanently injured herself. And so now, anyone who publicly promotes using things not in the way they were designed is an unethical person.

For the record, finding new and useful (and ethical) ways to use things for which they were not designed is awesome. I think your example is a real stretch. If I was caught at work …