Friday, April 30, 2021

Moving Images on a Tkinter Canvas

The stock analysis and comparator app I made was somewhat quick, just a few hours over a weekend. And most of that was just trying different things to formulate the data I wanted to see and compare. The latest project, will take some time and I'm not expecting it to be easy. Really looking forward to learning more how to use Tkinter and other packages that can be used with it.

Purpose of the application: I currently work in a helpdesk for a medium sized company. How we keep track of equipment and the frequency of moving things to different locations brings rise to a glaring need. How do we know where everything is physically located? Of course we have software to keep track of inventory and in what department it is supposedly located. We can also know what switch something is ultimately patched in to. But how do we know the physical location of each device? APs generally have a web UI where you can be place each one on a map. One could have a diagram of what each drop is labeled and where it is in the room. But that could still be a somewhat unclear as to where a PC, printer, or other device is located. I wanted to develop a simple application that would show a floor plan and a user could drag and drop different icons to show where each device is. It's entirely possible this exists but I am coding this to learn, not necessarily to market an application. Although if I were to develop it enough I would not be opposed to monetizing it someday.

What I've done so far: The first thing I wanted to make sure I could do was to drag and drop an image in a window. I figured if I can just write something to make that one thing work, then I can move on to whatever next function I needed to make the vision complete. Tkinter is a basic library for Python so I figured I would just start there. Through searching a few things I found a decent YouTube video series from codemy.com. One of his videos showed how to drag and drop an image. An issue I found with the way it is coded is that it basically creates a brand new image every time it moves (at least that's how I am understanding it). While I realize the final solution I found might technically do the same thing, I still needed the image to be an object of my own creation. Then I could put all the objects in a list and serialize certain attributes of the object to save them (Pickle might just be my next post). It also moved the image to wherever was clicked. I needed it to work so that it would only move when that particular image was clicked. After a decent amount of searching I finally came across something that worked!




























The first few lines are part of the initialization of the object, but the two functions in the snippet of the code will actually drag the object only when clicked and stop moving it when the mouse button is released. I admittedly don't fully understand how it works quite yet.

I believe the canvas.tag_bind binds the actual object to the mouse event and runs the code. Although I don't exactly understand what tag_bind does, it does seem to work fine. I am satisfied with how this part turned out. I just wanted to make the one thing work. Then I wanted to be able to save the locations of the images (I wanted to try this without a database). Then I could make a floor plan/blueprint and put that on the canvas. Then I would work on saving that in it's own folder. Next I want to be able to delete a device(image) or move it to a different floor plan, etc. Stay tuned for more progress on this!

25 Words or Less: You cannot write a whole program at once. Break it down and focus on completing one function, then continue to the next.





Thursday, April 15, 2021

Personal Application

Most of what I've coded so far was to solve a problem. Such as an efficiency system or documentation system. I recently have gotten in to trading. I started getting into it before GME craziness, so it's not like that was what got me into it. I was just curious about how it worked. I also had ideas earlier in 2020 of a few companies that I thought would do well, such as Zoom, and lo-and-behold, they did well and I could have made a decent return. So after making a few investments, some good some bad, and listening to a few podcasts I decided to do more research. This let me to want to look into companies' financials and balance sheets to make better decisions on what would be a more profitable, or potentially safer, investment. But after looking at a few companies I wanted to be able to compare companies. After looking at some data, to really compare I would have to write everything down. Which would be fine but I wanted something that would be quicker and would display the information I felt was most important.

Import yfinance python library.

From what I've read this is not the most reliable, but it is good to get started. Also the principles it uses would transfer to a more robust/reliable API. At least as far as what I read up on it, I felt it would not be a waste to write a small program to parse some data. So I just made a simple cli application. You put in any number of tickers and it compares YOY earnings and really any other data that I would have it return. The data is presented in a way that I feel most comfortable reading.

All in all, I feel it was a good little project. I could add more and may in the future and expand it any number of ways. At the moment however, I'm satisfied with how it works. It got me enough data for me to decide to invest in a particular restaurant company. QSR anyone? (not financial advice, or whatever one is supposed to say)

I'll have to see if I want to revisit this and make it more dynamic in the future, but I think it's good for now.

25 Words or Less: Simple and small programs can return important and profitable data.

Tuesday, April 6, 2021

Looking at Something From a Different Angle

As I thought about this post, I feel like I've written something to this effect before. Struggling with an issue when there is a very simple solution right in front of my face. Then finally seeing the more simple solution and implementing it. It does actually feel good in the end and that's what I will write about today.

I am developing a personal efficiency program. I enter certain activities and they have point values. I also put how many minutes I spend on each activity. Then when I look back I can see if I have been productive with my time and can make adjustments accordingly. I know it's impossible to reach, but 100% efficiency is the dream! I don't factor in my job or sleep, or even eating and such. But, things like watching TV is generally not efficient. Coding or studying Hindi on the other hand...

I designed it so that there is a database table for "ActivityTypes" and "ActivityEntries" I actually do. The problem is: what if an activity type is no longer valid and needs removed? Then I would have to have the program go through all entries that include that activity type and remove data from the column for an activity type on that row. Then before I knew it I was going down a rabbit hole of creating a new activity type of "Deleted Activity" and then using that to enter into the Activity Type column in the Entries table for when an Activity Type was deleted. That was just causing some confusion in my brain.

At last I had an epiphany of sorts. Why not just add a column in the Activity Type table for whether or not the activity type is valid/still in use or not? Then if an Entry had an activity type that was not valid it would just display a message letting the user know that the data might be inaccurate. That was very easy to implement. Then I just have 'activate' and 'deactivate' toggles if an Activity Type needs removed. It also makes it very easy to make an activity valid again. Data integrity is also there so that if something is deleted by mistake it can easily be undone.

Do you remember the scene in Big Hero 6 where Tadashi holds Hiro upside-down so he can get a new perspective and stimulate an idea? That's somewhat how I felt. Looking at the problem one way was not leading to progress. But doing something a completely new way gives just the inspiration needed to accomplish what was needed.

I know there will be bigger problems in the future. Ones that will require a different function or library to implement to solve a problem. If I keep in mind that there might just be a simple solution outside of my field of vision, I have to remember to lean back, or upside down perhaps, to find the obvious and easy solution.

25 Words or Less: Take a step back and try to see a problem from another angle. The solution might just be easier than you think.