|
Jose Cuervo posted:For better or worse I chose PySide and am having reasonable success. I can make the tabbed layout work as accipter suggested below by locking the tabs (disabling them), and maybe if I have more time on my hands than I know what to do with I will look into prettying things up. Each time that you call add_tanker_type, you're explicitly reassigning the contents of self.tanker_type_gb. Since modify_gb_title is operating on self.tanker_type_gb, it's operating on whatever was last assigned. One thing that you can do instead is append to an internal list of that holds QGroupBox items, then in modify_gb_title you modify the title of whatever index has been selected. You can do this because the currentIndexChanged signal won't just call the function that you connect to it, it'll also call that function with the value of the new index (if you let it). Python code:
Basically QComboBox.currentIndexChanged will call whatever function that you give it with an integer, if you let it. That integer is the new selected index in that QComboBox. By passing that integer to modify_gb_title, you can modify the correct QGroupBox by using that index to access your list of QGroupBox items. This also solves the problem where you don't have easy access to those QGroupBox items. Instead of reassigning an attribute each time that you create a new QGroupBox, just append the new QGroupBox to a list. Then you have access to any of the created QGroupBox items.
|
# ? Apr 14, 2016 04:05 |
|
|
# ? May 9, 2024 17:41 |
|
Fergus Mac Roich posted:It's better if the object doesn't know how to construct its dependencies. If the dependencies are available via the API at the time you construct the object, you should make the API call somewhere in the calling code and then supply the dependencies as arguments to the constructor. Or maybe I write too much java. This is what I typically do as well. I try to make the only logic in __init__ be assigning parameters to attributes. If I want to supply these by some kind of dependency I will make a classmethod, e.g. Employee.from_file, Employee.from_api, whatever.
|
# ? Apr 14, 2016 04:07 |
|
Jose Cuervo posted:So the for loop that iterates over the n simulation replications is in the main_gui function. Each time a simulation replication is completed, I would like the progress bar to update. I don't know how I would send a signal from the for loop in main_gui to the progress bar. Any pointers? Take a look at this simple example: https://gist.github.com/arkottke/7c1c33fc6fd697cde9c88c2b47fa06ea I would also point you to the mandelbrot example (https://github.com/PySide/Examples/blob/master/examples/threads/mandelbrot.py).
|
# ? Apr 14, 2016 05:04 |
|
QuarkJets posted:Each time that you call add_tanker_type, you're explicitly reassigning the contents of self.tanker_type_gb. Since modify_gb_title is operating on self.tanker_type_gb, it's operating on whatever was last assigned. If I understand the code correctly, modify_gb_title is now being passed the index of the option selected in the QComboBox, correct? If so, the line tanker_type_gb = self.tanker_type_gb_list[ind] will not work because ind does NOT refer to the index of the QGroupBox whose QComboBox was changed, correct? So how do I get a reference to the QGroupBox that had a child widget edited? Assuming I am able to figure out how to get the index of the QGroupBox that had a child widget edited, I would now like to find the QLineEdit corresponding to the row in the QFormLayout titled 'Number of tankers'. I know I can get a reference to the QFormLayout with: Python code:
Python code:
|
# ? Apr 14, 2016 15:47 |
|
accipter posted:Take a look at this simple example: https://gist.github.com/arkottke/7c1c33fc6fd697cde9c88c2b47fa06ea Thank you for this example, I am looking through it currently and trying to make sure I understand what everything does. EDIT: I think I now have a better grasp on signals and slots. updateRange is a signal that sends out two values (min and max of the range), and you connect it to self.progressBar.setRange which is a slot that takes two values, correct? The .emit() part means that the signal gets sent, correct? I am still running into the warning message from the joblib library. Is the answer to that in the Mandelbrot example? I haven't had a chance to look at it line by line, but on a quick read through I did not see that I could find the answer to the joblib question in there. Jose Cuervo fucked around with this message at 18:01 on Apr 14, 2016 |
# ? Apr 14, 2016 15:48 |
|
Jose Cuervo posted:Thank you for this example, I am looking through it currently and trying to make sure I understand what everything does. Emit sends data out. If nothing is connected to that signal nothing happens s. Slots and Signals are the way to transfer data betweens objects. In your code it looks like you are passing your main window instance to the simulation class. I don't know why you are doing that and I would guess that's the issue. You need to listen to the simulation class's signals instead of directly interacting with it.
|
# ? Apr 15, 2016 01:23 |
|
Ok so I have this problem that I can't seem to figure out the best way to approach: I have two lists list1 = A bunch of strings list2 = another group of strings that are also all present in list1 What I want to do is take every item in list2 and check if it's in list1. If it is found then it should be removed from the corresponding item. The problem is that the list2 items are embedded within the list1 items, surrounded by other things. So what I was trying to do was figure a way to insert the list2 item into a regex search and then check that against the items in list1.
|
# ? Apr 15, 2016 02:02 |
|
Jose Cuervo posted:If I understand the code correctly, modify_gb_title is now being passed the index of the option selected in the QComboBox, correct? If so, the line tanker_type_gb = self.tanker_type_gb_list[ind] will not work because ind does NOT refer to the index of the QGroupBox whose QComboBox was changed, correct? So how do I get a reference to the QGroupBox that had a child widget edited? Oh, right, my bad. You could create a subclass of QGroupBox (for demonstration purposes I'll call it Foo) that contains a QComboBox, and then you connect the items' signals to a Foo method, which would then cause that Foo instance to change its own title. That would do it for sure, since each QComboBox would be emitting a signal that is only connected to its own instance of the Foo class. quote:Assuming I am able to figure out how to get the index of the QGroupBox that had a child widget edited, I would now like to find the QLineEdit corresponding to the row in the QFormLayout titled 'Number of tankers'. I know I can get a reference to the QFormLayout with: If you never change the order in which you're adding things to the QFormLayout, then yes, that children order will be the same every time. Don't do this though, because it's sloppy and a very fragile implementation. If you just define your own TankerType class then you can easily avoid having to do that.
|
# ? Apr 15, 2016 08:26 |
|
Pumpy Dumper posted:Ok so I have this problem that I can't seem to figure out the best way to approach: Not sure if I understand the question, but something like this? Python code:
|
# ? Apr 15, 2016 08:35 |
|
code:
|
# ? Apr 15, 2016 15:18 |
|
Sweet thanks. I actually learned an easier way to do what I wanted originally but that will come in handy later.
|
# ? Apr 15, 2016 15:20 |
|
QuarkJets posted:Oh, right, my bad. OK, I will rewrite the code as a class. Slots/Signals question: I would like to run a function that takes arguments (for instance my_func(int, str, int)) when a QtGui.QPushButton is clicked. The following code Python code:
How can I accomplish this?
|
# ? Apr 16, 2016 15:47 |
|
Jose Cuervo posted:Slots/Signals question: That's impossible. The "clicked" signal passes no arguments. The way you get around this is that you can create another method that takes no arguments and retrieves values from the GUI widgets and passes them to my_func.
|
# ? Apr 16, 2016 17:38 |
|
I'm working on a python thing where I have to talk with a server over tcp on the same host, and I'm seeing quite a lot of latency. I suspect the issue is in how I'm dealing with the socket, but my networking is very rusty. This is how I set it up:code:
code:
I've tried setting TCP_NODELAY quote:s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) This is on an osx machine, python 2.7, and I've seen the same kind of behavior on linux. Does anybody have any ideas, or see what I might be doing wrong?
|
# ? Apr 16, 2016 20:59 |
|
Jose Cuervo posted:OK, I will rewrite the code as a class. I was going to say what accipter already said. You need to examine the signal being emitted (by reading the docs for QPushButton) and then define a function that can be connected to that signal, and that function can expect to receive the same argument types (or fewer). Write a function that expects no arguments and that calls my_func, and then connect that function to QPushButton.clicked. Alternatively, you could turn my_int, my_str, my_second_int, and my_func into class members, eliminating the need for my_func to expect any arguments at all, then connect self.my_func to QPushButton.clicked
|
# ? Apr 17, 2016 08:54 |
|
Does anybody have experience with scipy's interpolate.griddata? I have 3 1d arrays that I want interpolated with the purpose of retrieving values. This is in python 2.7. I have: Python code:
Edit: Nvm. I figured it out. I was complicating things. Simply using zi = scipy.interpolate.interp2d(x,y,z, kind='cubic') and then doing zi_ = zi(x_, y_) where x_ and y_ are the values I want interpolated works. Lpzie fucked around with this message at 23:01 on Apr 20, 2016 |
# ? Apr 20, 2016 20:38 |
|
This is probably more of an IDE question, but is there any way to get code completion from a .NET DLL in IntelliJ/PyCharm, either natively or through some document specification? Have a cross language engine and API using Iron Python and it would be nice to have documentation in editor.
|
# ? Apr 21, 2016 18:02 |
|
Question: I don't really understand how zip() works. I managed to find an example to create tuples of n=2 with the following code:code:
edit: was able to get it working with the following code: code:
creatine fucked around with this message at 23:48 on Apr 21, 2016 |
# ? Apr 21, 2016 23:36 |
|
Pumpy Dumper posted:Question: I don't really understand how zip() works. I managed to find an example to create tuples of n=2 with the following code: The zip function takes any number of iterables and returns an iterator that returns tuples that exactly match the first, second, third, etc. values of those iterables. code:
e: Sounds like you've fixed the issue
|
# ? Apr 21, 2016 23:53 |
|
QuarkJets posted:The zip function takes any number of iterables and returns an iterator that returns tuples that exactly match the first, second, third, etc. values of those iterables. Yeah the problem was I was coming from one list and I wanted to create tuples of 3 using 3 different starting points.
|
# ? Apr 22, 2016 01:10 |
|
Pumpy Dumper posted:Question: I don't really understand how zip() works. I managed to find an example to create tuples of n=2 with the following code: Your original question is, How does zip() work? It takes any number of iterables, and iterates over all of them simultaneously. A list is an iterable, a tuple is an iterable, a dictionary is iterable, a set is iterable, a string is iterable. Even classes you create can be iterable. Here's an example using two lists. code:
1. It no longer produces a pair, it is a triple - so, pairwise is a bad name for the method. 2. Your method argument is named iterable, but by using slicing, you prevent iterables that don't support slicing. 3. You created multiple (shallow) copies of the input (see further below). An input that is iterable but doesn't support slicing, such as a dictionary (iterating over a dictionary gives you the keys), does this when using your pairwise function: code:
code:
code:
* next() advances an iterator by one item. To set the desired starting points, we need to do this once to skip one item in b, and twice to skip two items in c. * zip() was explained earlier. Does this demonstrate it well enough?
|
# ? Apr 22, 2016 01:19 |
|
Gangsta Lean posted:Your original question is, How does zip() work? This is perfect, thank you. I had no idea that I had to create to instances of tee() in order for what I was trying to do to work. The explanation is fantastic too, thanks!
|
# ? Apr 22, 2016 01:58 |
|
That is an awesomely thorough explanation of how those various functions work! Nice!
|
# ? Apr 22, 2016 06:30 |
|
What's the preferred method to do a calculation multiple times and store them in a list? My goto method is Python code:
|
# ? Apr 22, 2016 06:53 |
|
Don't even need a lambda, just a list comprehension:Python code:
|
# ? Apr 22, 2016 07:03 |
|
Thanks. It's surface gravity, yeah. EDIT: VVV Thanks. Lpzie fucked around with this message at 00:49 on Apr 23, 2016 |
# ? Apr 22, 2016 07:13 |
|
Lpzie, I see you're using numpy. If m and r in your real data are large numpy arrays, neither your original code nor list comprehensions are efficient. You can do it all with numpy, where it will be much faster since all the calculations take place in non-interpreted code.code:
|
# ? Apr 22, 2016 23:55 |
|
Python code:
Dominoes fucked around with this message at 13:29 on Apr 24, 2016 |
# ? Apr 24, 2016 13:24 |
|
Dominoes posted:
Quick guess was right. It's not doing what you think it is. It's doing -(2^2) rather than (-2)^2 like you're expecting. ^ has precedence even in scenarios with a prefixed -, which to me is a little silly that they all treat "-2" as a shorthand for the operation "0 - 2" internally instead of treating it like a single number and giving it max precedence, but I guess that's how it is!
|
# ? Apr 24, 2016 13:35 |
|
Thx. Thought I was losing it! This works: (-2) ** 2 Scratching my head as to why they'd all set it up that way.
|
# ? Apr 24, 2016 13:44 |
|
I think that those languages do recognize that "-2" is its own integer rather than the result of the operation "0-2", but they also respect a specific order of operations when evaluating a line, and in doing so the negative sign attached to the 2 gets ignored until after the exponent gets evaluated. There are a few languages that make an exception for this case by giving unary minus a higher precedence, so that -2**2 results in +4 (I know that Excel is one of them but I don't use any of the others)
|
# ? Apr 24, 2016 20:17 |
|
QuarkJets posted:I think that those languages do recognize that "-2" is its own integer rather than the result of the operation "0-2", but they also respect a specific order of operations when evaluating a line, and in doing so the negative sign attached to the 2 gets ignored until after the exponent gets evaluated. There are a few languages that make an exception for this case by giving unary minus a higher precedence, so that -2**2 results in +4 (I know that Excel is one of them but I don't use any of the others) It seems like the statement is being evaluated as -1*2**2 which, following the order of operations I learned in whatever grade, would mean 2^2 then multiplied by -1.
|
# ? Apr 25, 2016 02:38 |
|
Tigren posted:It seems like the statement is being evaluated as -1*2**2 which, following the order of operations I learned in whatever grade, would mean 2^2 then multiplied by -1. I think that's a fair interpretation. It's not really storing a -1 in memory or anything like that, but the minus operator is definitely being interpreted last, which is common. The way around that is to slam parens around the value in question (because parens are always evaluated first)
|
# ? Apr 25, 2016 04:02 |
|
It's interpreted the same way as -x**2.
|
# ? Apr 25, 2016 09:29 |
|
Dominoes posted:Thx. Thought I was losing it! This works: (-2) ** 2 I don't know any language that would determine " - x [op] y" as "(-x) [op] y" (in the general case).
|
# ? Apr 26, 2016 01:24 |
|
Hubis posted:I don't know any language that would determine " - x [op] y" as "(-x) [op] y" (in the general case). A language with negative numeric literals would presumably parse it as "(-x) [op] y" but that requires negative numeric literals. I know C and Python specifically do not have negative numeric literals -- unary minus in each is an actual operator that negates an expression's value, and is parsed according to operator precedence -- and I'm not familiar with any language that does include them. Fake edit: I now know that Common Lisp has negative numeric literals as well as rational literals, I imagine as a convenience for allowing e.g. (* -3e2 2/5) instead of (* (- (* 3 (EXP 10 2))) (/ 2 5)), since there's no operator precedence to worry about anyway (outside the parsing of those numeric literals but that's pretty restricted, with no general exponentiation). ...but this is pretty far afield of Python and the question I was tangent'ing from!
|
# ? Apr 26, 2016 07:24 |
|
I was trying to think of where this might not be true, and in Rust, it seems like the unary operators (including -) have higher precedence than binary operators.code:
taqueso fucked around with this message at 17:24 on Apr 26, 2016 |
# ? Apr 26, 2016 17:21 |
|
I feel like this falls into the same category as floating-point peculiarities, and Python 2's [floor] division: there's a technical reason behind them that makes the language consistent on some level, but it produces counter-intuitive results to someone who's not familiar with how the language works under-the-hood.
|
# ? Apr 26, 2016 17:47 |
|
taqueso posted:I was trying to think of where this might not be true, and in Rust, it seems like the unary operators (including -) have higher precedence than binary operators. Same in JS. It's almost like they come from the same organization heh
|
# ? Apr 26, 2016 19:58 |
|
|
# ? May 9, 2024 17:41 |
|
Dominoes posted:I feel like this falls into the same category as floating-point peculiarities, and Python 2's [floor] division: there's a technical reason behind them that makes the language consistent on some level, but it produces counter-intuitive results to someone who's not familiar with how the language works under-the-hood. To be fair, it's how most languages work under-the-hood. Even just written out on paper it's a bit ambiguous
|
# ? Apr 26, 2016 20:03 |