Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
I want to write a traditional console roguelike in Python. Originally I was going to not bother using an actual console and just use libtcod, but the documentation is way worse than it used to be and figuring out event handling is kind of frustrating me - I wanted to do an actual 80x24 console to begin with anyways, the kind of thing you could play remotely over SSH if so inclined. Python has curses built in, but...

quote:

The Windows version of Python doesn’t include the curses module. A ported version called UniCurses is available. You could also try the Console module written by Fredrik Lundh, which doesn’t use the same API as curses but provides cursor-addressable text output and full support for mouse and keyboard input.

I'd like this in theory* to be playable on Windows. Unicurses has kind of inadequate documentation that is just gonna have me look at the C documentation a lot, which isn't great but is livable. The Console project linked is a dead webpage - someoneupdated it to Python 3, but there's no documentation and if I have to dig through the source to understand everything I may as well just use libtcod.

Anyone have a suggestion of what to use, any package suggestions? Or will I just do it in Linux anyways and save letting Windows people play it until I get a webserver going?

(* really I wanna do it through a browser, like how DCSS's webtiles servers work, alongside ssh, but getting an actual playable game first might be a good idea)

Adbot
ADBOT LOVES YOU

NinpoEspiritoSanto
Oct 22, 2013




Depending on how fancy you want to get, click or urwid?

QuarkJets
Sep 8, 2008

Epsilon Plus posted:

I want to write a traditional console roguelike in Python. Originally I was going to not bother using an actual console and just use libtcod, but the documentation is way worse than it used to be and figuring out event handling is kind of frustrating me - I wanted to do an actual 80x24 console to begin with anyways, the kind of thing you could play remotely over SSH if so inclined. Python has curses built in, but...

I'd like this in theory* to be playable on Windows. Unicurses has kind of inadequate documentation that is just gonna have me look at the C documentation a lot, which isn't great but is livable. The Console project linked is a dead webpage - someoneupdated it to Python 3, but there's no documentation and if I have to dig through the source to understand everything I may as well just use libtcod.

Anyone have a suggestion of what to use, any package suggestions? Or will I just do it in Linux anyways and save letting Windows people play it until I get a webserver going?

(* really I wanna do it through a browser, like how DCSS's webtiles servers work, alongside ssh, but getting an actual playable game first might be a good idea)

Qt has great looking console features that are fully cross platform, but if you want to create a web app then it doesn't really matter what's running on the server

dorkanoid
Dec 21, 2004

QuarkJets posted:

Are you accidentally running against every file in the repo maybe, instead of just the committed files?

I've just run "pre-commit install" on the repo, but yeah, I think it's something like that happening when run from Github Desktop.

I mostly use PyCharm, and (at least when I set it up) could only add black/isort/flake8/mypy as "external commands" - have been thinking about moving over to VSCode, it seems to have more ways of customizing things.

Back when I set this up, the killer feature of PyCharm (Pro) was to code/commit locally, but have things run on a remote SSH server.

punished milkman
Dec 5, 2018

would have won

Epsilon Plus posted:

I want to write a traditional console roguelike in Python. Originally I was going to not bother using an actual console and just use libtcod, but the documentation is way worse than it used to be and figuring out event handling is kind of frustrating me - I wanted to do an actual 80x24 console to begin with anyways, the kind of thing you could play remotely over SSH if so inclined. Python has curses built in, but...

I'd like this in theory* to be playable on Windows. Unicurses has kind of inadequate documentation that is just gonna have me look at the C documentation a lot, which isn't great but is livable. The Console project linked is a dead webpage - someoneupdated it to Python 3, but there's no documentation and if I have to dig through the source to understand everything I may as well just use libtcod.

Anyone have a suggestion of what to use, any package suggestions? Or will I just do it in Linux anyways and save letting Windows people play it until I get a webserver going?

(* really I wanna do it through a browser, like how DCSS's webtiles servers work, alongside ssh, but getting an actual playable game first might be a good idea)

you can make really sweet looking console applications with Rich https://github.com/willmcgugan/rich

i’ve found it easy to use with very nice results, though i haven’t done anything too fancy with it.

duck monster
Dec 15, 2004

Data Graham posted:

And it was considered pretty archaic then

Poor old pascal had a bad reputation from the outset that it didn't really deserve. as a "educational language" with particular venom reserved for its IO primitives.

But this really just came from an early era where things where fairly glued into the stdout/stderr/stdin way of thinking about io. Turbo pascal was far more sophisticated, and that was the 1980s. Object Pascal, what most people mean by pascal at any point past about 1995 was a far more sophisticated beast. multiple OOP models (for some reason, I guess they wanted you to have the choice), generics, overloading, a much more sophisticated type system than the C languages, and for a while the big selling point, Delphi, a platform that had the RAD chops of visual basic, but with none of the associated brain damage. We wrote device driver dlls with the thing back in the 90s, and it was just fine. Object Pascal was a perfectly capable language and borlands pascal compiler generated binaries that benchmarked favorably, and sometimes even better than Microsoft or Intels C/C++ compilers (And Borlands C++ compiler ran rings around them, back in the 80s and 90s, that is. Though none of them where in the ball park of Intels Fortran compiler, speaking of other "dead" languages, seriously that thing was bullshit fast. Still is apparently.).

The real reason Delphi kinda died was because Borland where basically taken over by ridiculous C suite assholes who bumped the prices for borlands tools stratospherically so that it became unviable for students to learn and refocused the company on shitful enterprise "middleware" guff, "enterprise" message brokers and stuff. In the end, with most people unable to afford the licenses of $3K+ in 1990s money the universities all switched to teaching Java , and Microsoft poached Delphis braintrust to build dot net and C# which I maintain was not microsofts C or Java, but microsofts Delphi (The VLC has a *lot* in common with Dot Net, and C# is practically Object Pascal with a C-like syntax.) And with no new coders coming on time, Delphi just sort of lost relevance. And its a shame, because I liked Delphi a LOT. It was wild how productive that thing was.

duck monster fucked around with this message at 04:43 on Aug 9, 2021

D34THROW
Jan 29, 2012

RETAIL RETAIL LISTEN TO ME BITCH ABOUT RETAIL
:rant:
For those familiar with Tkinter, I'm using it to build a suite of tools to simplify my workflow - and hopefully the workflows of those at the company I work for. My background as far as UI design is MS Access, so it influences my design paradigm.

The idea I have is that I have the main window, with a number of classes extending Frames to contain the individual functions. Switch functions, it switches the frame. Is this as feasible as I'm thinking?

QuarkJets
Sep 8, 2008

As a long time ex-tkinter user, my advice is to not use tkinter. Use qt if you absolutely need the app to exist as a standalone application, but it kind of sounds to me like you should make a flask app that people access on the office intranet with a web browser. This will probably be the easiest option overall, but will require the cooperation of IT (can't say for sure without knowing more about what your app does)

D34THROW
Jan 29, 2012

RETAIL RETAIL LISTEN TO ME BITCH ABOUT RETAIL
:rant:
Can I ask why qt and not tkinter? Luckily, I've not gotten so far into development yet that it's impossible to change without major issues. So far all I have functional is the window itself, a menubar, and an option to exit.

I've considered that but yes, it would require IT cooperation and the server space to run it. Our IT is outsourced, they take a week to get back to you on something so simple as a printer issue, and they send admin username and password in cleartext over email. I can't imagine they'd allow a Python hobbyist to have a flask app running on the intranet, let alone an actual Python user.

P.S. They also store admin credentials on the company intranet...in PowerShell scripts. :doh:

QuarkJets
Sep 8, 2008

Whenever I've gotten into using tk on a project it works great for like, a single window with very little functionality. As soon as I need to do anything beyond the extremely basic, which always happens eventually, I spend way too much time struggling with tkinter's dogshit documentation just to wind up with something that's barely adequate and simply looks outdated.

It's great for getting rolling on something basic but there's always a turning point where I wish that I had just used qt from the start, which is about as easy to get started with but adds a dependency. Big whoop. Add that dependency. Eliminate tkinter's sole advantage, which is that it comes with python (a mistake that to this day the python devs talk about rectifying)

HOMOEROTIC JESUS
Apr 19, 2018

Verily I say unto thee, That this night, before the cock crow, thou shalt deny me thrice.

QuarkJets posted:

Whenever I've gotten into using tk on a project it works great for like, a single window with very little functionality. As soon as I need to do anything beyond the extremely basic, which always happens eventually, I spend way too much time struggling with tkinter's dogshit documentation just to wind up with something that's barely adequate and simply looks outdated.

It's great for getting rolling on something basic but there's always a turning point where I wish that I had just used qt from the start, which is about as easy to get started with but adds a dependency. Big whoop. Add that dependency. Eliminate tkinter's sole advantage, which is that it comes with python (a mistake that to this day the python devs talk about rectifying)

I echo these sentiments and have generally stopped using tkinter for anything other than basic mock-ups.

Qt/PyQt is great and is also what I also would recommend. I use PyQt5 now for most of my projects.

QuarkJets
Sep 8, 2008

Qt Designer is also really good, designing a gui graphically makes a lot more sense than programmatically! Your code is a lot more compact when all of your basic gui poo poo is taken care of in a ui file

D34THROW
Jan 29, 2012

RETAIL RETAIL LISTEN TO ME BITCH ABOUT RETAIL
:rant:
And this goes back to my Access (and, frankly, Excel add-in) background. I'm quite familiar with the Access form designer and the VBA UserForm designer, so graphically designing a GUI comes easily to me. What I really want to accomplish above all is a main window with a single container that switches contents based on user selections. Sort of like a subform inside a navigation form, in Access parlance.

PyQt5 has the designer, from what I see, which is a big plus, though everything I'm seeing says the Python documentation is more or less dogshit.

EDIT: Now I'm having fun. VSCode decided to randomly dump my venv and now pip is installing PyQt5 to my primary installation rather than the venv...even though I repointed my interpreter to the venv.

D34THROW fucked around with this message at 19:15 on Aug 9, 2021

duck monster
Dec 15, 2004

Use QT, absolutely.

If you need a *really* fancy ui, use QML. But theres a lot of caveats with QML being that it can be painful to translate datatypes between python and QML, but the end result can be stunning.

Regular QT however is perfectly fine, and can produce professional looking desktop apps with complicated layouts, and theres an absolute bucket of controls.

TBH I usually use QT with C++ becuase its broader ecosystem makes C++ a lot less painful to work with (Its network stack is a work of art). But it works fine with python.

Last major job I had we had a tonne of internal apps in PyQT used in manufacturing and process control stuff and it was reliable and we could even package it up for the plant in china without shipping actual code (Theres apps that wrap all the python into an executable).

D34THROW
Jan 29, 2012

RETAIL RETAIL LISTEN TO ME BITCH ABOUT RETAIL
:rant:
Alright, I need help. I have a handful of functions in logger.py that log to 3 places: debug.log, whiteutils.log, and stdout. It

Up until yesterday - when I started fiddling around with PyQt5 and added a command-line switch to enable the PyQt5 GUI as opposed to Tkinter - the StreamHandler logging was working as expected. Now, the formatting is broken on stdout, returning to what looks like the default schema of [level]:[appname]:[message] that would be associated with the root logger.

From what I'm seeing, the only way this should be happening is if I'm calling self.logger.basicConfig() somewhere...but I'm not. Not on the handler, not on the logger itself - the StreamHandler is being declared and

As far as the FileHandlers go, whiteutils.log should only be written to for logging.ERROR events and above - and that's functioning as intended. The debug.log file is accepting logging.DEBUG and higher as expected.

The StreamHandler is also accepting logging.DEBUG events even when the app is being run without the --debug command line switch.

In summary:
- debug.log is accepting the proper format as a declared FileHandler()
- stdout is not accepting the proper format as a declared StreamHandler()
- It appears stdout is being handled by the root logger, rather than the declared StreamHandler()
- stdout is logging DEBUG events when it should only be logging INFO and higher.

Python 3.8.10 since I'm on Win7Pro x64.

Code
Python code:
LOGGER_NAME = "whiteutil"
DEBUG_MODE = False

class AppLogger:
    def __init__(self):
        self.logger = logging.getLogger(LOGGER_NAME)
        self.logger.setLevel(logging.DEBUG)
        # Create our 3 handlers
        h_debug = logging.FileHandler("debug.log")
        h_norm = logging.FileHandler("whiteutils.log")
        h_cons = logging.StreamHandler()
        # Set the levels
        h_debug.setLevel(logging.DEBUG)
        h_norm.setLevel(logging.ERROR)
        if DEBUG_MODE:
            h_cons.setLevel(logging.DEBUG)
        else:
            h_cons.setLevel(logging.WARN)
        # Set the formatters
        formatter = logging.Formatter("[%(asctime)s] [%(levelname)s] " "%(message)s")
        h_debug.setFormatter(formatter)
        h_norm.setFormatter(formatter)
        h_cons.setFormatter(formatter)
        #if len(self.logger.handlers) == 0:
        self.logger.handlers.clear()
        self.logger.handlers = [h_debug, h_norm, h_cons]
debug.log
code:
[2021-08-10 10:46:06,747] [INFO] User <redacted> started WhiteUtils on <redacted> with the Tkinter GUI
[2021-08-10 10:46:06,960] [DEBUG] Creating window WhiteUtils
[2021-08-10 10:46:06,964] [DEBUG] Beginning main window setup
[2021-08-10 10:46:06,966] [DEBUG] Creating menu bar in WhiteUtils main window
[2021-08-10 10:46:07,020] [DEBUG] Creating outer_frame
[2021-08-10 10:46:16,105] [DEBUG] Checking if user wants to exit
[2021-08-10 10:46:16,989] [DEBUG] Destroying window WhiteUtils
[2021-08-10 10:46:16,994] [INFO] User <redacted> exited WhiteUtils on <redacted>.
whiteutils.log
code:
empty as expected
stdout
code:
INFO:whiteutil:User <redacted> started WhiteUtils on <redacted> with the Tkinter GUI
DEBUG:whiteutil:Creating window WhiteUtils
DEBUG:whiteutil:Beginning main window setup
DEBUG:whiteutil:Creating menu bar in WhiteUtils main window
DEBUG:whiteutil:Creating outer_frame
DEBUG:whiteutil:Checking if user wants to exit
DEBUG:whiteutil:Destroying window WhiteUtils
INFO:whiteutil:User <redacted> exited WhiteUtils on <redacted>.
EDIT: Upon looking more into it, I'm realizing that it looks like the root logger is hanging around for whatever reason - h_cons is properly being set to WARN and higher because I'm not running with the --debug flag. When I run with the debug flag, it's now doubling my console output again. Last time this happened, I simply removed logging.basicConfig() and it eradicated the issue. I am not calling that anywhere else in the code, so...what else is happening here?

stdout
code:
[2021-08-10 14:47:15,203] [INFO] User <redacted> started WhiteUtils on <redacted> with the Tkinter GUI
INFO:whiteutil:User <redacted> started WhiteUtils on <redacted> with the Tkinter GUI
[2021-08-10 14:47:15,209] [INFO] WhiteUtils is running in debug mode.
INFO:whiteutil:WhiteUtils is running in debug mode.
[2021-08-10 14:47:15,532] [DEBUG] Creating window WhiteUtils
DEBUG:whiteutil:Creating window WhiteUtils
[2021-08-10 14:47:15,534] [DEBUG] Currently in debug mode!
DEBUG:whiteutil:Currently in debug mode!
[2021-08-10 14:47:15,539] [DEBUG] Beginning main window setup
DEBUG:whiteutil:Beginning main window setup
[2021-08-10 14:47:15,545] [DEBUG] Creating menu bar in WhiteUtils main window
DEBUG:whiteutil:Creating menu bar in WhiteUtils main window
[2021-08-10 14:47:15,597] [DEBUG] Creating outer_frame
DEBUG:whiteutil:Creating outer_frame
[2021-08-10 14:47:17,021] [DEBUG] Checking if user wants to exit
DEBUG:whiteutil:Checking if user wants to exit
[2021-08-10 14:47:18,019] [DEBUG] Destroying window WhiteUtils
DEBUG:whiteutil:Destroying window WhiteUtils
[2021-08-10 14:47:18,060] [INFO] User <redacted> exited WhiteUtils on <redacted>.
INFO:whiteutil:User <redacted> exited WhiteUtils on <redacted>.

D34THROW fucked around with this message at 19:43 on Aug 10, 2021

Da Mott Man
Aug 3, 2012



It looks like your logging is getting pushed up into the root handler. You could try to see if this solves the issue https://docs.python.org/3.8/library/logging.html#logging.Logger.propagate

QuarkJets
Sep 8, 2008

I don't know if setting self.logger.handlers manually like that could cause unexpected behavior, but normally I would call addHandler(). Try doing that and see if the behavior changes

D34THROW
Jan 29, 2012

RETAIL RETAIL LISTEN TO ME BITCH ABOUT RETAIL
:rant:

Da Mott Man posted:

It looks like your logging is getting pushed up into the root handler. You could try to see if this solves the issue https://docs.python.org/3.8/library/logging.html#logging.Logger.propagate

I just don't understand how it suddenly...stopped working yesterday after working as expected for some time.

QuarkJets posted:

I don't know if setting self.logger.handlers manually like that could cause unexpected behavior, but normally I would call addHandler(). Try doing that and see if the behavior changes

It actually did fix the propagation issue before by clearing and manually setting the handlers.


I'm trying both of these fixes - QuarkJets, yours made no difference but Da Mott Man fixed it with self.logger.propagate = False! Thank you both for the help, I completely forgot about propagate.

mr_package
Jun 13, 2000
Is there an IDE that supports the "next gen" attrs API? @attr.define instead of @attr.s, attr.field, instead of attr.ib). PyCharm doesn't, although I imagine it will eventually.

D34THROW
Jan 29, 2012

RETAIL RETAIL LISTEN TO ME BITCH ABOUT RETAIL
:rant:
PyQt5 question - in the designer, I can't figure out how to anchor an MDI vertically and horizontally - I want it to stretch with the window size so that I keep the menubar, the toolbar, and the statusbar, but the MDI automatically fills the rest of the screen.


EDIT: So...once you have the .ui converted to a .py, how do you go about changing the design? Do it again and copy/paste relevant code?

D34THROW fucked around with this message at 20:35 on Aug 11, 2021

QuarkJets
Sep 8, 2008

D34THROW posted:

PyQt5 question - in the designer, I can't figure out how to anchor an MDI vertically and horizontally - I want it to stretch with the window size so that I keep the menubar, the toolbar, and the statusbar, but the MDI automatically fills the rest of the screen.


EDIT: So...once you have the .ui converted to a .py, how do you go about changing the design? Do it again and copy/paste relevant code?

You shouldn't convert the .ui to python code, you should define a class that loads it instead. You should have 1 ui file that defines the elements, layout, etc and 1 py file containing a class that loads the ui file and then makes any tweaks you want to make, specialized slot implementations, etc.

I don't really use MDIs, so I don't know how to help with that. I would consult the c++ documentation for whatever classes you're using and see if there's an obvious method you could call. Qt uses a lot of inheritance, so either check parent classes too or use the "Show all members" link that every Qt class page has

D34THROW
Jan 29, 2012

RETAIL RETAIL LISTEN TO ME BITCH ABOUT RETAIL
:rant:

QuarkJets posted:

You shouldn't convert the .ui to python code, you should define a class that loads it instead. You should have 1 ui file that defines the elements, layout, etc and 1 py file containing a class that loads the ui file and then makes any tweaks you want to make, specialized slot implementations, etc.

I don't really use MDIs, so I don't know how to help with that. I would consult the c++ documentation for whatever classes you're using and see if there's an obvious method you could call. Qt uses a lot of inheritance, so either check parent classes too or use the "Show all members" link that every Qt class page has

Yeah, I got there too. I've seen mixed opinions regarding signals and slots, defining them in the designer versus programatically within the code. Thoughts?

And I think I figured it out - the sizePolicy option should help with that on the MDI. What do you use for subwindows, or do you?

QuarkJets
Sep 8, 2008

D34THROW posted:

Yeah, I got there too. I've seen mixed opinions regarding signals and slots, defining them in the designer versus programatically within the code. Thoughts?

And I think I figured it out - the sizePolicy option should help with that on the MDI. What do you use for subwindows, or do you?

I define slots programmatically. There are a lot of good reasons to do it that way, but maybe the best reason is that it's just a lot easier that way imo

I don't ever really use subwindows

D34THROW
Jan 29, 2012

RETAIL RETAIL LISTEN TO ME BITCH ABOUT RETAIL
:rant:
I think I understand signals and slots - click button, button triggers slot A with signal A. I'm having a hard time finding any good resources on defining these programmatically. I'm guessing I need to note

In the case of this:
Python code:
class AppPyQt(QtWidgets.QMainWindow):
    def __init__(self, debug_mode: bool):
        super(AppPyQt, self).__init__()
        ui_file = os.path.abspath(os.path.join(GUI_FOLDER, 'main_window.ui'))
        uic.loadUi(ui_file, self)
        log_debug(f"Loading UI file '{ui_file}'")
        if debug_mode: self.setWindowTitle(f"[DEBUG] {self.windowTitle()}")
Ignoring the fluff, I'm guessing it that in the rest of __init__, I go through the controls on the form and define, control-by-control, the slots and signals, getting their names by going through the action editor in PyQt Designer. Only thing that's gonna kill me is not having the IntelliSense, I've gotten so used to that.

Python code:
class AppPyQt(QtWidgets.QMainWindow):
    def __init__(self, debug_mode: bool):
        ...
        self.action_panroof.clicked.connect(self.panroof_click)

def panroof_click()
        ...
And link those as signals with their respective buttons.

Seriously, goons, thank you for your help. :shobon:

Bad Munki
Nov 4, 2008

We're all mad here.


Google's not helping me out here: can you make dunders for non-standard types? Like say I want a __shapely__ dunder for some class I have. Is that even possible, or are we limited to the built in ones? I'm guessing not because it's probably un-possible for python to know when it would even want to use that, but still, thought I should ask before I just throw in a regular ol' method that returns what I want.

Like maybe this is a super dumb question but I dunno.

Bad Munki fucked around with this message at 02:00 on Aug 13, 2021

QuarkJets
Sep 8, 2008

D34THROW posted:

I think I understand signals and slots - click button, button triggers slot A with signal A. I'm having a hard time finding any good resources on defining these programmatically. I'm guessing I need to note

In the case of this:
Python code:
class AppPyQt(QtWidgets.QMainWindow):
    def __init__(self, debug_mode: bool):
        super(AppPyQt, self).__init__()
        ui_file = os.path.abspath(os.path.join(GUI_FOLDER, 'main_window.ui'))
        uic.loadUi(ui_file, self)
        log_debug(f"Loading UI file '{ui_file}'")
        if debug_mode: self.setWindowTitle(f"[DEBUG] {self.windowTitle()}")
Ignoring the fluff, I'm guessing it that in the rest of __init__, I go through the controls on the form and define, control-by-control, the slots and signals, getting their names by going through the action editor in PyQt Designer. Only thing that's gonna kill me is not having the IntelliSense, I've gotten so used to that.

Python code:
class AppPyQt(QtWidgets.QMainWindow):
    def __init__(self, debug_mode: bool):
        ...
        self.action_panroof.clicked.connect(self.panroof_click)

def panroof_click()
        ...
And link those as signals with their respective buttons.

Seriously, goons, thank you for your help. :shobon:

You pretty much got it I think

Signals are things that are emitted. When you click a button, that's going to emit the clicked() signal and a bunch of others. All that this does is put an event in the event loop that Qt manages in the background. You can arbitrarily emit a signal anytime you want, but generally you want signals to designate that something needs to happen now; someone pressed a button, now do a thing. For instance you could write a function that's just constantly reading SA comments and emits the "poo poo" signal every time that it detects a shitpost. The function doesn't stop when it emits the signal, that's just a new event sent out into the ether; the function continues its diligent work of looking for shitposts and emitting poo poo signals.

You connect signals to slots. Slots are basically just functions and methods that do something when they receive a signal. Here's a slot:
Python code:
def shitpost_found():
    print('shitpost detected')
The perfect slot for our poo poo signal, we connect the signal to this slot at some point when we're initializing our application. Then you run your application, and as it scans through SA posts it occasionally prints "shitpost detected" to stdout whenever it finds a shitpost.

There are many predefined signald and slots for things, you've already figured that out. So you can very easily connect the clicked signal from a button to the close() slot for your GUI, for instance, so that when you click the button your dialog closes.

Some signals also come with arguments that are passed to the slots connected to them. For example, whenever you alter the contents of a QSpinBox, the "valueChanged(int i)" signal is emitted, where the integer is the new value contained in the QSpinBox. Any slot that you hook up to this signal can accept that integer as an argument and then do something with it; you could call the "setValue(int val)" slot that some other GUI element has, or define your own function that does something else with that integer. You can hook up multiple slots to the same signal to trigger a bunch of things, or just define 1 slot that manually calls the others, it's all good. This is how you synchronize GUI elements and create professional GUIs that do cool things.

QuarkJets fucked around with this message at 01:52 on Aug 13, 2021

QuarkJets
Sep 8, 2008

Is anyone aware of a utility that lets you detect forbidden imports? e.g. say that I have a codebase and want module A to import from module B, but I never want module B to import from module A, so in my setup.cfg or whatever I write a rule that says "module B never imports from module A" and then I run a utility that checks whether that rule is violated. Does this exist?

Basically I want to know if there's a utility that can check for imports of specific module names and throw an error if it finds one

Hed
Mar 31, 2004

Fun Shoe
Maybe hack away at this one https://pypi.org/project/module-graph/#description and analyze the graph edges without using graphviz?

D34THROW
Jan 29, 2012

RETAIL RETAIL LISTEN TO ME BITCH ABOUT RETAIL
:rant:
The Qt5 designer is like an Access form designer with better layout functionality, on steroids. :unsmigghh:

So far I've got the main_window and the main_menu functioning. Now that I'm getting a hold of signal/slot and the quirks of Qt Designer, things are running more smoothly - enough so that I've decided to dump Tkinter for PyQt. I echo the sentiment and I'm barely a week in, Tkinter is okay for simple stuff, sort of like the VBA forms to PyQt's actual C# implementation of the full WinForms library or something like that.

Raygereio
Nov 12, 2012
Anyone have recommendations for terminal/text UIs?
I've made a script to automate measurements for a multiplexer and want to make it quicker to use (so a user doesn't have to edit the script when they want to change between measuring voltage or resistance, or tweak measurement intervals).
I could make an interface with tkinter, pysimplegui, QT, or whatever, but that feels like it would be to elaborate for the actual functionality it needs to have. I also could bash my head against curses until I get something nice, but that would go against my desire to not spend too much time on it.

Dawncloack
Nov 26, 2007
ECKS DEE!
Nap Ghost
Is there a module or framework that would allow me to recreate a google sheet/collaborative excel in python?

My dream would be to have some excels in my raspberry and serving them in my home network. I am aware of the bottle and similar frameworks but when I try to google this I get too many results about how to make the raspberry interact with google docs.

Thanks!

OnceIWasAnOstrich
Jul 22, 2006

Dawncloack posted:

Is there a module or framework that would allow me to recreate a google sheet/collaborative excel in python?

My dream would be to have some excels in my raspberry and serving them in my home network. I am aware of the bottle and similar frameworks but when I try to google this I get too many results about how to make the raspberry interact with google docs.

Thanks!

What are you hoping it gets you to do this in Python? If you just want a self-hosted browser-based spreadsheet system and you don't need to hack around in it in Python, maybe use something like OnlyOffice or Collabora that you can just start up as a Docker image and start using.

Dawncloack
Nov 26, 2007
ECKS DEE!
Nap Ghost
You are right! I didnt know of those. I was thinking of python because I have a little script to update the excel sheet automatically.

I'll look into those. Thanks!

Loezi
Dec 18, 2012

Never buy the cheap stuff

Bad Munki posted:

Google's not helping me out here: can you make dunders for non-standard types? Like say I want a __shapely__ dunder for some class I have. Is that even possible, or are we limited to the built in ones? I'm guessing not because it's probably un-possible for python to know when it would even want to use that, but still, thought I should ask before I just throw in a regular ol' method that returns what I want.

Like maybe this is a super dumb question but I dunno.

I don't understand what you are asking for, and I think you're falling into the XY Problem trap.

Dunders are, fundementally, for interacting with python buildins: you would implement a __len__ to describe what len(butts) means, or a __call__ to describe what butts() means. Or you could do things with __slots__ and __setattr__ to fiddle with what butts.farts = 1 does.

What are you trying to achieve with __shapely__, given that there would be no python builtin that knew to call it?

Is the point that you would like to look at an object and ask "do you have a __shapely__"? What are you, fundamentally, trying to achieve?

NinpoEspiritoSanto
Oct 22, 2013




Raygereio posted:

Anyone have recommendations for terminal/text UIs?
I've made a script to automate measurements for a multiplexer and want to make it quicker to use (so a user doesn't have to edit the script when they want to change between measuring voltage or resistance, or tweak measurement intervals).
I could make an interface with tkinter, pysimplegui, QT, or whatever, but that feels like it would be to elaborate for the actual functionality it needs to have. I also could bash my head against curses until I get something nice, but that would go against my desire to not spend too much time on it.

There's some on this very page

Mycroft Holmes
Mar 26, 2010

by Azathoth
having some trouble with a homework problem. If I enter the inputs: 10, .6, and 5 in the following code, the answer should be 36.8896. I am not getting that. I suspect something is wrong with my math. Please take a look.

code:
# variables
bounces1 = 1
height1 = float(0)

# input
height = float(input("Enter the height from which the ball is dropped:"))
index = float(input("Enter the bounciness index of the ball:"))
bounces = float(input("Enter the number of times the ball is allowed to continue bouncing:"))

# calcs
height1 = height + (height*index)
bounce = height * index
if index > 0:
    while bounces1 < (bounces+1):
        bounce = bounce * index
        height1 = height1 + bounce
        bounces1 = bounces1 + 1
    print("Total distance traveled is:" + str(height1) + " units")
else:
    print("Total distance traveled is:" + str(height1) + " units")

Gangsta Lean
Dec 3, 2001

Calm, relaxed...what could be more fulfilling?

Mycroft Holmes posted:

having some trouble with a homework problem. If I enter the inputs: 10, .6, and 5 in the following code, the answer should be 36.8896. I am not getting that. I suspect something is wrong with my math. Please take a look.

code:
# variables
bounces1 = 1
height1 = float(0)

# input
height = float(input("Enter the height from which the ball is dropped:"))
index = float(input("Enter the bounciness index of the ball:"))
bounces = float(input("Enter the number of times the ball is allowed to continue bouncing:"))

# calcs
height1 = height + (height*index)
bounce = height * index
if index > 0:
    while bounces1 < (bounces+1):
        bounce = bounce * index
        height1 = height1 + bounce
        bounces1 = bounces1 + 1
    print("Total distance traveled is:" + str(height1) + " units")
else:
    print("Total distance traveled is:" + str(height1) + " units")

Use a debugger or add more print statements. Learning to debug issues like this yourself is invaluable.

Loezi
Dec 18, 2012

Never buy the cheap stuff

Mycroft Holmes posted:

having some trouble with a homework problem. If I enter the inputs: 10, .6, and 5 in the following code, the answer should be 36.8896. I am not getting that. I suspect something is wrong with my math. Please take a look.

code:
# variables
bounces1 = 1
height1 = float(0)

# input
height = float(input("Enter the height from which the ball is dropped:"))
index = float(input("Enter the bounciness index of the ball:"))
bounces = float(input("Enter the number of times the ball is allowed to continue bouncing:"))

# calcs
height1 = height + (height*index)
bounce = height * index
if index > 0:
    while bounces1 < (bounces+1):
        bounce = bounce * index
        height1 = height1 + bounce
        bounces1 = bounces1 + 1
    print("Total distance traveled is:" + str(height1) + " units")
else:
    print("Total distance traveled is:" + str(height1) + " units")

Are you counting both the movement down and movement up in the total distance traveled?

I wrote my own solution to (what I intepreted to be) the original question and it produced the following helpful logging:
code:
Initial height: 10
Bounciness: .6
Max bounces: 5

Starting from 10.0 in the air
Dropped down to floor, total traveled distance is 10.0 units
Bounce 1: Bounced up to 6.0, total traveled distance is 16.0
Dropped down to floor, total traveled distance is 22.0 units
Bounce 2: Bounced up to 3.5999999999999996, total traveled distance is 25.6
Dropped down to floor, total traveled distance is 29.200000000000003 units
Bounce 3: Bounced up to 2.1599999999999997, total traveled distance is 31.360000000000003
Dropped down to floor, total traveled distance is 33.52 units
Bounce 4: Bounced up to 1.2959999999999998, total traveled distance is 34.816
Dropped down to floor, total traveled distance is 36.112 units
Bounce 5: Bounced up to 0.7775999999999998, total traveled distance is 36.8896
Dropped down to floor, total traveled distance is 37.6672 units
Reached maximum number of bounces, stopping
Came to rest, total distance traveled is 37.6672 units
E: Pasted the wrong thing initially

Loezi fucked around with this message at 13:44 on Aug 16, 2021

Mycroft Holmes
Mar 26, 2010

by Azathoth

Loezi posted:

Are you counting both the movement down and movement up in the total distance traveled?

I wrote my own solution to (what I intepreted to be) the original question and it produced the following helpful logging:
code:
Initial height: 10
Bounciness: .6
Max bounces: 5

Starting from 10.0 in the air
Dropped down to floor, total traveled distance is 10.0 units
Bounce 1: Bounced up to 6.0, total traveled distance is 16.0
Dropped down to floor, total traveled distance is 22.0 units
Bounce 2: Bounced up to 3.5999999999999996, total traveled distance is 25.6
Dropped down to floor, total traveled distance is 29.200000000000003 units
Bounce 3: Bounced up to 2.1599999999999997, total traveled distance is 31.360000000000003
Dropped down to floor, total traveled distance is 33.52 units
Bounce 4: Bounced up to 1.2959999999999998, total traveled distance is 34.816
Dropped down to floor, total traveled distance is 36.112 units
Bounce 5: Bounced up to 0.7775999999999998, total traveled distance is 36.8896
Dropped down to floor, total traveled distance is 37.6672 units
Reached maximum number of bounces, stopping
Came to rest, total distance traveled is 37.6672 units
E: Pasted the wrong thing initially

Oh! thats the issue.

Adbot
ADBOT LOVES YOU

Hollow Talk
Feb 2, 2014

Raygereio posted:

Anyone have recommendations for terminal/text UIs?
I've made a script to automate measurements for a multiplexer and want to make it quicker to use (so a user doesn't have to edit the script when they want to change between measuring voltage or resistance, or tweak measurement intervals).
I could make an interface with tkinter, pysimplegui, QT, or whatever, but that feels like it would be to elaborate for the actual functionality it needs to have. I also could bash my head against curses until I get something nice, but that would go against my desire to not spend too much time on it.

Have a look at https://github.com/chriskiehl/Gooey as well -- Gooey basically builds a UI over any command-line arguments as defined via argparse, so depending on your software's complexity, this might be useful without much overhead.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply