Conversation
vilim
left a comment
There was a problem hiding this comment.
Looks good, needs just a few small adjustments to make it more pythonic and readable
| def move_motors(self): | ||
|
|
||
| for axis in self.motors.keys(): | ||
| package = self.get_last_entry(self.input_queues[axis]) |
There was a problem hiding this comment.
this is a bit mysterious, I suggest that get_last_entry (in a factored-out version) throws the Empty exception and then you can have the much more compact:
try:
mov_amount, mov_type = self.get_last_entry(self.input_queues[axis])
if mov_type == MovementType.relative:
...
except empty:
return| value = motor.home_pos | ||
| self.input_queue = input_queue | ||
| self.output_queue = output_queue | ||
| self.mov_type = MovementType(False) |
There was a problem hiding this comment.
you would rather use the enum as MovementType.relative (the point of using Enums is that this mapping true, false or integers is arbitrary)
| self.slider.update() | ||
|
|
||
|
|
||
| def get_next_entry(queue): |
There was a problem hiding this comment.
this can be factored out in thecolonel (which can also get a new culinary name)
| self.motors[axis].move_abs(mov_value) | ||
|
|
||
| @staticmethod | ||
| def get_last_entry(queue): |
There was a problem hiding this comment.
this appears in many places, I suggest to factor it out
| package = self.get_last_entry(self.input_queues[axis]) | ||
| if package: | ||
| mov_value = package[0] | ||
| mov_type = package[1].name |
There was a problem hiding this comment.
again, this goes against the spirit of using Enums
| empty_queue = True | ||
|
|
||
| if empty_queue is False: | ||
| if mov_type == "relative": |
There was a problem hiding this comment.
the point of using Enums is to avoid string comparisons
| self.start_session() | ||
|
|
||
| @staticmethod | ||
| def find_axis(axes): |
There was a problem hiding this comment.
axes can be an Enum and this function just a dictionary lookup
|
|
||
| class PreMotor: | ||
| @staticmethod | ||
| def query(self): |
| def update_values(self, val): | ||
| self.spin_val_desired_pos.setValue(val) | ||
| self.sig_changed.emit(val) | ||
| while True: |
There was a problem hiding this comment.
this again is the queue quering pattern that should be in a separate, common function
|
|
||
| def get_next_entry(queue): | ||
| out = None | ||
| while out is None: |
No description provided.