BinPy/BinPy — pull request #134 by JBeCast (2014-03-11 06:50:14+00:00)
Title: Reimplemented gates from scratch. Added states functionality.

Note: this is more like a huge proposal than a pull request, since if accepted, everything based on gates will have to be reimplemented, but it should be easier though, and I'm definitely willing to collaborate. I tried to follow the DRY principle as much as I could. I'll post working examples here.

Description:
- Consistency: gates now only accept connectors as inputs and outputs.
- Implemented well defined states: (0,1,2,3) as logical 0 and 1, hi-z and undefined respectively, and a validating function.
- Connectors now validate the input. Default state is undefined (3).
- Gates now work with any combination of input states, including undef and hi-z.
- One trigger to rule them all: no more over 9000 triggers.
- Migates mitigated: there's only GATES class now.
- (Already implemented) You should be able to assign an initial state to the connector. This way you could easily create a power source or ground connection and connect every element you need to it, e.g: gnd = Connector(0). This initial state is also validated.
- You can now change a connector state and trigger it easily with the set method. It also checks for possible shortcuts or undefined states, returning an undefined state if something goes wrong.
- Implemented disconnect method for gates. It removes every reference to the gate any connector has. It can be very useful to clean things before removing a gate. Previously, multiple references to the same gate objects could accumulate when reconnecting.
- Implemented connect method for gates. Since this is not something you want to do often, it is the only method that allows you to change connections or even add or remove as many as you want, and you'll have to specify every connector. It previously cleans everything up by calling the disconnect method.
- You'll have as many additional connectors as your circuit has, but that's good. You better give your inputs an adequate name, right? And you definitely can't give a name to the actual gate inputs.
- Leave tapping to Eddie Van Halen (or the gates in this case): Users should be discouraged from using the connector's tap method indicriminately, let the gates manage the connections network instead.
- Gates file now takes about half the ammount of code lines =).

- One more suggestion: I think it's about time to define some common exceptions.
- And another one: gates and connectors should accept a name as argument, and should also have a method to access it and easily check the connections of the circuit (I was about to implement it but didn't have time yet).