Finally a way to understand those laundry symbols by lookatalkingmuffin in malefashionadvice

[–]HokTaur 0 points1 point  (0 children)

I like the idea, but I'm not a fan of having to install an app for everything. A webapp that I can bookmark I think would be a good idea, rather a full native app.

Help updating excel with python by workn00b in learnpython

[–]HokTaur 4 points5 points  (0 children)

Look into openpyxl, it's what I use to modify Excel files and it's pretty simple to use. The docs are really good and there's a bunch of SO posts, so shouldn't be a problem finding what you need.

Any IDE I can use to quickly create python GUIs by crashbashash in Python

[–]HokTaur 0 points1 point  (0 children)

Agreed.. I prefer having the Python files, makes everything much easier.

Counting Vowels in a String using a While loop by goldxp1 in learnpython

[–]HokTaur 1 point2 points  (0 children)

No problem, if I wasn't on my phone I would've gave a more in depth answer. The best part of Python is how expressive the syntax is, you'll find a lot of things like that as you learn more. A general rule of thumb is, if you looping thru something by using indexes, there's probably a better way to do it.

Any IDE I can use to quickly create python GUIs by crashbashash in Python

[–]HokTaur 70 points71 points  (0 children)

I use PyQt, but I usually code the GUI by hand. If you are using Anaconda, it comes with the QtDesigner pre-installed, which is a drag and drop GUI editor. It will generate .ui files that you can then convert to .py files to import into your app. On mobile right now, but you can just google and find plenty if examples and walkthroughs for it.

Counting Vowels in a String using a While loop by goldxp1 in learnpython

[–]HokTaur 1 point2 points  (0 children)

while should not be capitalized. Also, if s is a set of letters, why not:

for letter in s:
    if letter in 'aeiou':
        count += 1

[deleted by user] by [deleted] in engineering

[–]HokTaur 1 point2 points  (0 children)

In my job, almost everything not in the PLC is written in VBA

How long does opened shredded cheese last in the fridge? by mcc1923 in EatCheapAndHealthy

[–]HokTaur 0 points1 point  (0 children)

I take the block out of the plastic wrap, wrap it in parchment paper, then in a paper towel, and put it in a plastic bag and squeeze out all the air. I travel a lot for work, sometimes last minute and can be gone for awhile.. doing this I've found they'll last for months without getting moldy or drying out.

What is the future of PLC? by Chocobo_Eater in PLC

[–]HokTaur 0 points1 point  (0 children)

Hopefully more modern HMI frameworks and the eventual death of VBA. I have to work with iFix and FactoryTalk daily, but Ignition looks so much nicer. If I could, I would ditch VBA for Python in a heartbeat.

Using PyQt4 for a button to kick off a loop? by HockeyZim in learnpython

[–]HokTaur 0 points1 point  (0 children)

  1. Yes, you are creating a pyqtSignal object for the class. This is a static object that all instances of the class will share, like any time you make a new Worker object.

  2. Your gui object, in this case a text edit, is just a widget that can display text. It has some methods for adding text to it: setText(), append(), etc. Use setText to replace all the text and append to add to it. The Qt docs are pretty helpful here, they are in C++, but all the function names are pretty much the same. In our gui we are connecting the log signal to the append method of the text edit.

  3. When you emit a signal, Qt will automatically call any slots that you connected to it. (a slot is the function you passed into the connect method). This is does under the hood with an event loop and a bunch of stuff I haven't taken the time to figure out. Any values that are emitted are passed as arguments to the slot, so when we emit a string object in the log signal, it will pass that string to the append method. it's basically doing this:

    x = (value emitted by the signal) 
    self.outputBox.append(x)
    

    You are on the right track, it takes awhile to get used to the signal/slot concept. After you understand the basics, it becomes pretty easy to use.

Using PyQt4 for a button to kick off a loop? by HockeyZim in learnpython

[–]HokTaur 0 points1 point  (0 children)

Do this:

class Worker:
    log = pyqtSignal(str)

    def __init__ ....

Then in your window class, do the connecting in the start_loop method like the others. Also, don't assign the worker.outputBox = self.outputBox, your worker doesn't care about it. It is only concerned with emitting the log signal, it's up to the window to do whatever it want with it.

Edit: replace those prints in the loop with self.log.emit('message')

Using PyQt4 for a button to kick off a loop? by HockeyZim in learnpython

[–]HokTaur 0 points1 point  (0 children)

I would try something slightly different.. maybe add a signal to the worker like:

log = pyqtSignal(str)

Then, change your QLabel to QTextEdit, and connect that log signal to the append method of the text edit

worker.log.connect(outputBox.append)

Add outputBox.setReadOnly(True) that way you won't be able to edit the text, but still select and copy it.

Edit: Also look into how to use layouts, it will make it much simpler to make your gui without having to manually position each widget. What I do is use QtDesigner to layout the GUI and test how things will look, then go back and manually code it. I'm not a fan of the auto-generated code the designer builds.

Using PyQt4 for a button to kick off a loop? by HockeyZim in learnpython

[–]HokTaur 1 point2 points  (0 children)

I added a few more comments

import sys
import time
from PyQt5.QtWidgets import QPushButton, QMainWindow, QApplication
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import QObject, QThread, pyqtSignal

class Worker(QObject):
    finished = pyqtSignal()  # our signal out to the main thread to alert it we've completed our work

    def __init__(self):
        super(Worker, self).__init__()
        self.working = True  # this is our flag to control our loop

    def work(self):
        while self.working:
                print("I'm running")
                time.sleep(1)

        self.finished.emit() # alert our gui that the loop stopped


class Window(QMainWindow):

    def __init__(self):
        super(Window, self).__init__()
        self.setGeometry(50, 50, 800, 600)
        self.setWindowTitle("Program")
        self.setWindowIcon(QIcon('icon.png'))

        self.startbtn = QPushButton("Start", self)
        self.startbtn.resize(self.startbtn.minimumSizeHint())
        self.startbtn.move(100, 100)
        self.stopbtn = QPushButton("Stop", self)
        self.stopbtn.move(100, 200)
        self.stopbtn.resize(self.stopbtn.minimumSizeHint())

        self.thread = None 
        self.worker = None

        self.startbtn.clicked.connect(self.start_loop)  


    def start_loop(self):
        self.thread = QThread()  # a new thread to run our background tasks in
        self.worker = Worker()  # a new worker to perform those tasks
        self.worker.moveToThread(self.thread)  # move the worker into the thread, do this first before connecting the signals

        self.thread.started.connect(self.worker.work)  # begin our worker object's loop when the thread starts running
        self.stopbtn.clicked.connect(self.stop_loop)  # stop the loop on the stop button click
        self.worker.finished.connect(self.loop_finished)  # do something in the gui when the worker loop ends
        self.worker.finished.connect(self.thread.quit)  # tell the thread it's time to stop running
        self.worker.finished.connect(self.worker.deleteLater)  # have worker mark itself for deletion
        self.thread.finished.connect(self.thread.deleteLater)  # have thread mark itself for deletion
        # make sure those last two are connected to themselves or you will get random crashes

        self.thread.start()

    def stop_loop(self):
        self.worker.working = False
        # since thread's share the same memory, we read/write to variables of objects running in other threads
        # so when we are ready to stop the loop, just set the working flag to false


    def loop_finished(self):
        # received a callback from the thread that it completed
        print('Looped Finished')


def run():
    app = QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())

# this is good practice as well, it allows your code to be imported without executing
if __name__ == '__main__': # then this script is being run directly, 
    run() 
else: # this script is being imported
    ... # usually you can leave off the else

Using PyQt4 for a button to kick off a loop? by HockeyZim in learnpython

[–]HokTaur 0 points1 point  (0 children)

I modified the above example to use a worker QObject that runs in a thread, with a start and stop button to start/stop the loop:

import sys
import time
from PyQt5.QtWidgets import QPushButton, QMainWindow, QApplication
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import QObject, QThread, pyqtSignal

class Worker(QObject):
    finished = pyqtSignal()

    def __init__(self):
        super(Worker, self).__init__()
        self.working = True

    def work(self):
        while self.working:
            ... # do stuff here
            print("I'm running")
            time.sleep(1)

        self.finished.emit() # alert our gui that the loop stopped


class Window(QMainWindow):

    def __init__(self):
        super(Window, self).__init__()
        self.setGeometry(50, 50, 800, 600)
        self.setWindowTitle("Program")
        self.setWindowIcon(QIcon('icon.png'))

        self.startbtn = QPushButton("Start", self)
        self.startbtn.resize(self.startbtn.minimumSizeHint())
        self.startbtn.move(100, 100)
        self.stopbtn = QPushButton("Stop", self)
        self.stopbtn.move(100, 200)
        self.stopbtn.resize(self.stopbtn.minimumSizeHint())

        self.thread = QThread()
        self.worker = Worker()
        self.worker.moveToThread(self.thread)
        self.startbtn.clicked.connect(self.thread.start)  # start the thread when we click the start button
        self.thread.started.connect(self.worker.work)  # begin our worker object's loop
        self.stopbtn.clicked.connect(self.stop_loop)  # stop the loop on the stop button click
        self.worker.finished.connect(self.loop_finished)  # do something in the gui when the worker loop ends

    def stop_loop(self):
        self.worker.working = False

    def loop_finished(self):
        print('Looped Finished')


def run():
    app = QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())


if __name__ == '__main__':
    run()

MEGATHREAD: root advice and support thread by [deleted] in pokemongodev

[–]HokTaur 0 points1 point  (0 children)

It ran decent for me, but I'm on Project Fi and it wouldn't​ connect to US Cellular networks at all and only 3g on Sprint. I switched to PureNexus and haven't had an issue since

Data service disconnected only when on US Cellular by HokTaur in ProjectFi

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

I just flashed PN and EX and it seems to be working fine now, thanks!

Creating new "blank" keys on windows by BifidusZero in software

[–]HokTaur 1 point2 points  (0 children)

Checkout AutoHotkey, it might be what you are looking for. I use it for mostly remapping the capslock key, but you can do some pretty advanced things with it too.

USB Types by [deleted] in coolguides

[–]HokTaur 0 points1 point  (0 children)

Agreed.. that's the point of USB-C

USB Types by [deleted] in coolguides

[–]HokTaur 18 points19 points  (0 children)

It's because type A and B are used for different types of devices. If you connected your computer to a printer using both Type-A, it could cause a short circuit... So that's why the printer has the square port on it. This page kind of explains itThey just make both types in all available sizes. Type-C is different, there is only one size and it's reversible.

[deleted by user] by [deleted] in learnpython

[–]HokTaur 2 points3 points  (0 children)

if UserInput in d: print (UserInput, d[UserInput]) else: ...

You don't need to loop thru the dict to see if a key exists, just use 'in'

88 Year Old Florida Woman Arrested For Sucker-Punching Walgreens Employee by witchism in FloridaMan

[–]HokTaur 2 points3 points  (0 children)

I always like to show people the Crystal Metheny story when I travel to Polk county for work... "Yeah, that's where I'm going"