Welcome, Guest
Python Scripts for ComicRack

TOPIC: [Script] Same X different Y - Smart List Script (ver 0.7 18/10/17)

[Script] Same X different Y - Smart List Script 11 months 4 days ago #46682

  • Xelloss
  • Xelloss's Avatar
  • Online
  • Platinum Boarder
  • Posts: 455
  • Thank you received: 117
  • Karma: 24
Ok, I was debugging a bit, and I found the error...

in C:\Users\-user-\AppData\Roaming\cYo\ComicRack\Scripts\Library Organizer\configformcontrols.py

Change line 901 from:

elif sender.SelectedItem is "Manga":

to:

if sender.SelectedItem in ("Manga"):

and it seems to work OK

I don't understand why the elif doesn't work there... but this correct at least the problem with the Manga field in the rule...

The problem was that Manga is an "option" field... so the script treated it is such, and didn't, for example, validate the data...

The thing was that the line where Manga was selected as such, and given the correct "option field" options... for a reason I don't understand, the script skip the instruction and this made the Manga field neither an option field nor a common field...

What I did was just get the "eliif" instruction and put it outside the if loop
Last Edit: 11 months 4 days ago by Xelloss.
The administrator has disabled public write access.

[Script] Same X different Y - Smart List Script 11 months 4 days ago #46683

  • Xelloss
  • Xelloss's Avatar
  • Online
  • Platinum Boarder
  • Posts: 455
  • Thank you received: 117
  • Karma: 24
Sorry, the correct fix is this: (the other one broke the SeriesGroup and Black and White fields)

Change:
        elif sender.SelectedItem is "Manga":
            self.set_operator_and_value_items(["is", "is not"], ["Yes", "Yes (Right to Left)", "No", "Unknown"])

        else:
            if self._value_textbox.Enabled == False:
                self.set_operator_and_value_items(["contains", "does not contain", "greater than", "less than", "is", "is not"])

for:
        else:
            if sender.SelectedItem in ("Manga"):
                self.set_operator_and_value_items(["is", "is not"], ["Yes", "Yes (Right to Left)", "No", "Unknown"])

            else:
                if self._value_textbox.Enabled == False:
                    self.set_operator_and_value_items(["contains", "does not contain", "greater than", "less than", "is", "is not"])

Sorry, I just suck at coding...
Last Edit: 11 months 4 days ago by Xelloss.
The administrator has disabled public write access.

[Script] Same X different Y - Smart List Script 11 months 4 days ago #46684

  • Xelloss
  • Xelloss's Avatar
  • Online
  • Platinum Boarder
  • Posts: 455
  • Thank you received: 117
  • Karma: 24
This is the last post, I PROMISE...

Forget everything I said (although it worked but for the wrong reason XD)

if you change in line: 901:

the word "is" for "==" then it worked perfectly...

The problem was that the command "is" in Python is only for special values, and doesn't work with strings XD

You have to use "==" instead to compare strings...

So, the correct fix is this:

in C:\Users\-user-\AppData\Roaming\cYo\ComicRack\Scripts\Library Organizer\configformcontrols.py

Change line 901 from:
elif sender.SelectedItem is "Manga":

to:
elif sender.SelectedItem == "Manga":
The administrator has disabled public write access.

[Script] Same X different Y - Smart List Script 11 months 3 days ago #46686

  • rmagere
  • rmagere's Avatar
  • Offline
  • Gold Boarder
  • Posts: 221
  • Thank you received: 24
  • Karma: 7
:woohoo: Thank you so much! That's fantastic.

As mentioned in another thread I have been meaning to try to learn Python just to get a few scripts I needed in comicrack but you have closed the last issues I had (with the script in this thread) after all the hard work of the other coders and you have even fixed the bug here!

Thanks :cheer:
The administrator has disabled public write access.
The following user(s) said Thank You: Xelloss

[Script] Same X different Y - Smart List Script 11 months 3 days ago #46687

  • Xelloss
  • Xelloss's Avatar
  • Online
  • Platinum Boarder
  • Posts: 455
  • Thank you received: 117
  • Karma: 24
I "learned" python doing scripts for comicrack XD (at first only cutting and pasting pieces of scripts :laugh: )

I only know how to do the things I needed till now (google ftw) :P
Last Edit: 11 months 3 days ago by Xelloss.
The administrator has disabled public write access.

[Script] Same X different Y - Smart List Script 11 months 3 days ago #46689

  • Stonepaw
  • Stonepaw's Avatar
  • Offline
  • Moderator
  • Posts: 921
  • Thank you received: 268
  • Karma: 173
Ooops! That is completely my bad. I have no idea what I was thinking there. The python is keyword compares memory instances, not equality.
I "learned" python doing scripts for comicrack XD (at first only cutting and pasting pieces of scripts :laugh: )

I only know how to do the things I needed till now (google ftw) :P
I learned python completely by writing comic scripts as well. Several years later, an actual job in the field, and university and I'm cringing at some of the stuff I've written, as evidenced by this bug.

Keep at it though. The best way to learn coding is to actually write something that you are interested in.
The administrator has disabled public write access.

[Script] Same X different Y - Smart List Script 11 months 3 days ago #46691

  • Xelloss
  • Xelloss's Avatar
  • Online
  • Platinum Boarder
  • Posts: 455
  • Thank you received: 117
  • Karma: 24
Surprisingly I never had that mistake before, but I read that line hundreds of time and never realised where was the mistake...

It took to change it to "in ("Manga")" to pay enough attention and realise that I had never used the "is" before XD

btw, your code is amazing, it is very elegant and clear.
Last Edit: 11 months 3 days ago by Xelloss.
The administrator has disabled public write access.

[Script] Same X different Y - Smart List Script 11 months 3 days ago #46693

  • Stonepaw
  • Stonepaw's Avatar
  • Offline
  • Moderator
  • Posts: 921
  • Thank you received: 268
  • Karma: 173
The is operator is very useful at times. For example "var is None". Since there is only ever one instance of None it works very well for that case. It also works well for comparing singletons or enums.

Thanks for liking my code. I'm still not proud of the LO code though. The half completed re-written LO 3.0 is much better.

I took a quick look through this script's code and it looks pretty good to me. Just one tip:

Try to not to do "exception Exception:" You can swallow unexpected errors very easily which makes it hard to debug or catch unexpected errors. Try to catch only the exceptions you expect. For example getattr throws AttributeError. Doesn't really matter for small scripts like this but if you start programming large projects it can cause lots of problems.

I did that myself when I started programming and caused me a lot of problems ;)
The administrator has disabled public write access.

[Script] Same X different Y - Smart List Script 11 months 3 days ago #46694

  • Xelloss
  • Xelloss's Avatar
  • Online
  • Platinum Boarder
  • Posts: 455
  • Thank you received: 117
  • Karma: 24
I had never used exceptions before... I remembered there was some reason in this case... but I don't remember why XD

edit: I remember now... It was because I am accesing an object attribute by "stringed" name (this shouldn't be ever done, but this simplified the script A LOT), so the only way I found to do this and to be able to know when the attribute doesn't exist, was with exceptions... (again, my programming skills are 99% try and error)

The second exception... I have no idea why it is there... perhaps it is part of a code I copied from another script which used custom values XD (and decided to let it as it was thinking the other person knew what he was doing XD)

But yes, I am no fan of esceptions... it makes debugging a hell

btw, as you can see my English is still worse than my coding, I don't want to think in how my posts look for English speaking people XD
Last Edit: 11 months 3 days ago by Xelloss.
The administrator has disabled public write access.

[Script] Same X different Y - Smart List Script 10 months 3 weeks ago #46731

  • Xelloss
  • Xelloss's Avatar
  • Online
  • Platinum Boarder
  • Posts: 455
  • Thank you received: 117
  • Karma: 24
I updated this script to version 0.6 :cheer:

New feature: Now if you add "!" character before an attribute (in X or Y) the comparision will ignore spaces, special characters, Capitals, and common other minor differences in the values of this attributes... In other words, instead of "equal", it will be "similar".

Note: Remember if you use multi attributes, to add the ! before EACH attribute you want this operator to affect (!Series|!Title for example)

example: If you use X = !Series Y= Series it will show comics with "similar" series name (for example Spider-Man and spiderman)

LINK IN THE FIRST POST
Last Edit: 10 months 3 weeks ago by Xelloss.
The administrator has disabled public write access.
The following user(s) said Thank You: rmagere
Time to create page: 0.315 seconds

Who's Online

We have 431 guests and 7 members online