Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another batch of changes #113

Merged
merged 36 commits into from
Mar 24, 2024
Merged

Another batch of changes #113

merged 36 commits into from
Mar 24, 2024

Conversation

tomers
Copy link

@tomers tomers commented Feb 2, 2024

Each commit does something else, so please read each one separately

@maresb
Copy link
Collaborator

maresb commented Feb 3, 2024

Thanks @tomers!

I'm not quite following what is VERTICAL_PREVIEW_MARGIN_PX. Could you explain it?

Is the idea that for the preview we add a fake margin for the nonprintable area so that the preview resembles the physical tape after printing?

@maresb
Copy link
Collaborator

maresb commented Feb 3, 2024

That's really nice with the adjustable margin in the preview. But it's a bit weird that the margin code for the preview is different from the margin code for the printer.

Looking more closely I see that the printer code prints no margin at the beginning and a double-margin at the end. I think this probably has to do with the gap between the printer head and the cutter. I'm guessing that the gap is approximately DEFAULT_MARGIN_PX pixels long. Then when we print 2 * DEFAULT_MARGIN_PX, where the first DEFAULT_MARGIN_PX is the true right-margin of the current label, and the second DEFAULT_MARGIN_PX is the left-margin of the next label. Do you agree with this assessment?

It might be nice to start distinguishing some of these concepts in the code. Like have a constant for GAP_BETWEEN_PRINT_HEAD_AND_CUTTER_PX = 13, and have separate variables in the code, something like current_right_margin and future_left_margin (or whatever makes sense), just to make the code somewhat consistent with reality.

In principle we could enable a margin-free mode where you print the first GAP_BETWEEN_PRINT_HEAD_AND_CUTTER_PX pixels, tell the user to cut, and print the remaining pixels plus future margin, and tell the user to cut again.

If the user wants a label with margin greater than GAP_BETWEEN_PRINT_HEAD_AND_CUTTER_PX, then I think the correct way to do this is:

  • Print a left margin of additional_left_margin = margin - GAP_BETWEEN_PRINT_HEAD_AND_CUTTER_PX, since we already have GAP_BETWEEN_PRINT_HEAD_AND_CUTTER_PX due to the gap from the previous label.
  • Print the main payload
  • Print a right margin of margin
  • Continue printing a margin of future_left_margin = GAP_BETWEEN_PRINT_HEAD_AND_CUTTER_PX.
    (I think the current implementation is buggy since it'll produce too short of a left-margin and too long of a right-margin, but I'm not able to test at the moment.)

Am I making sense?

@tomers
Copy link
Author

tomers commented Feb 3, 2024

@marseb, thanks for the insights. I've contrinued to modify the code, and I am going to introduce some further changes soon. Thanks for the insight of explaining why we print the margins twice at the end. I was puzzled by that.
I will add some of your text as comments in the code, and I also consider taking the variable and constant names you suggest. Let's keep this PR open for a while, until I'm done with that.

@maresb maresb marked this pull request as draft February 3, 2024 13:39
@maresb
Copy link
Collaborator

maresb commented Feb 3, 2024

Awesome, thanks so much for looking into that!!!

I've converted the PR to draft for now. When you're finished just hit "Ready for review" and I'll give it another look and merge if I approve.

@tomers
Copy link
Author

tomers commented Feb 3, 2024 via email

@maresb
Copy link
Collaborator

maresb commented Feb 3, 2024

Okay, great!

Keep in mind that there are a few different levels of abstraction coming together:

  • the bitmap itself that's to be printed
  • the way the bitmap is printed onto a piece of tape

I think there are valid use cases to have preview functionality for both. Unfortunately I don't have any clever ideas for an implementation.

Note that this is starting to connect up with @tomek-szczesny's work on a lookup table for various printer and label width combinations in #91.

It's really great how things are coming together thanks to your work @tomers! Back when #91 was opened, I don't think the code was healthy enough to carry through that implementation. But now the code is becoming much easier to understand, opening up lots of exciting possibilities!

@tomek-szczesny
Copy link
Contributor

Certainly I'm glad someone's cleaning up my amateur code. :)
Just wanted to add, I regret that printer must be detected before rendering, in order to determine the actual printable area. I see no other way around it, barren the user-provided printer model as a command line parameter.

@maresb
Copy link
Collaborator

maresb commented Feb 3, 2024

my amateur code

To be clear the obstacle wasn't your code, it was instead the underlying code which was very idiosyncratic with not-so-great separation of concerns and idiosyncratic variable names. Those sorts of things build up and create a tremendous amount of friction for making changes.

@tomers
Copy link
Author

tomers commented Feb 3, 2024

Thanks, @maresb and @tomek-szczesny!
I'm working on discarding margin handling in the printing driver. This adds mental load on understanding the code, and the principle of having to end the print job with an offset for the next print job, and will be a burden in the future, when we'll have multiple drivers (which would need to duplicate this task), and also in the case where we may want to implement some more complicated scenarios, such as printing batch of labels, with zero margin (i.e. print brank without ending with offset, cut the label, then iteratively printing labels without margins, or at least with SW defined margins, and instructing user to cut).

@maresb, regarding your comment about idiosyncratic code, that's indeed true, and the was my initial effort, to clean these things off the table, before approaching any other new features.

@tomers tomers force-pushed the tomer_fixes branch 2 times, most recently from 68f41e1 to 6924b9c Compare February 4, 2024 09:15
@tomers tomers marked this pull request as ready for review February 4, 2024 18:13
@tomers tomers force-pushed the tomer_fixes branch 4 times, most recently from aa8d243 to 851c0ae Compare February 8, 2024 09:05
@tomers
Copy link
Author

tomers commented Feb 8, 2024

Hey @maresb and @tomek-szczesny,

Can you please review this PR?

Thanks,
Tomer

Copy link
Collaborator

@maresb maresb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will finish a PR soon with some more in-depth suggestions

@maresb
Copy link
Collaborator

maresb commented Feb 10, 2024

Oh, looks like you're actively working on this. I'll hold off on further review for the moment.

@maresb
Copy link
Collaborator

maresb commented Feb 10, 2024

Are you okay with the conflicts there? Looks like maybe you accidentally rebased on a stale branch?

@tomers tomers force-pushed the tomer_fixes branch 2 times, most recently from 0dc29ca to 0af729f Compare February 10, 2024 14:46
@tomers
Copy link
Author

tomers commented Feb 10, 2024

It is ready for review now. Sorry, but I use git rebase a lot, and I keep forgeting to rebase on origin/master.

@tomers
Copy link
Author

tomers commented Feb 12, 2024

Any news?

@maresb
Copy link
Collaborator

maresb commented Feb 12, 2024

Sorry, I'm in a time crunch at the moment. It might have to wait another few days.

@tomers
Copy link
Author

tomers commented Feb 28, 2024

Hey there,

Due to irresponsivenes, I'm abandoning this project, and will fork it in a new organization, managed by me. Whoever wants to join me, is most welcome to contact me via LinkedIn.

maresb and others added 14 commits March 24, 2024 15:29
Consider `e = KeyError("x")`. Then `str(e) == "'x'"`.
Instead we use `repr(e) = "KeyError('x')"`.
This is achieved with `f"{e!r}"`.
I find it way faster to understand what's going on when one doesn't need
to mentally parse a bunch of custom classes.
It's much better to consider the module itself as the object.
It's much easier and more inspectable by type checkers to use
a NamedTuple instead of a custom class with Enum.
Using a kwargs dictionary does save a few lines of code, but it prevents
the type checker from working, and it's harder to read and inspect.
Have separate class for each kind of rendered (text, barcode, QR, etc.).
Combine renders are done using another kind of render (HorizontallyCombinedRenderEngine).
Move logic to associate renders and dymo device in a separate labeler_device file.
Note that the new architecture is design to support multiple labelers in the future.
This commit is the first step in that direction.
@tomers
Copy link
Author

tomers commented Mar 24, 2024

Done with the fixes, @maresb

@maresb
Copy link
Collaborator

maresb commented Mar 24, 2024

--browser now works again. There are still a few things unresolved from the last review.

It's really difficult to review such a large PR after a rebase, so could you please refrain from rebasing until after I've approved?

Copy link
Collaborator

@maresb maresb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whew, that was a whole lot of work, but I think we finally got it. Thanks @tomers for persevering. These are some really huge improvements.

Go ahead and rebase if you'd like, and then let's get this merged.

@tomers
Copy link
Author

tomers commented Mar 24, 2024 via email

@maresb maresb merged commit 52fb23a into computerlyrik:master Mar 24, 2024
6 checks passed
@maresb
Copy link
Collaborator

maresb commented Mar 24, 2024

Thanks @tomers!

For anyone reading, to avoid giving the impression of being secretive, the plan is to not release this as DymoPrint, but instead release it as Labelle v1.1.0 (see #114). And Labelle v1.0.0 will be a rebranded DymoPrint v2.4.0.

@tomers tomers deleted the tomer_fixes branch March 24, 2024 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants