-
Notifications
You must be signed in to change notification settings - Fork 949
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
Feature: Add "Remove tab colour" method #1199
Conversation
google changes the colours you provide so they are a fraction of n/255
Hi thank you for this contribution. I need some time to look at it. It looks nice at first glance. 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very interesting. thank you for catching it !
In gspread, users tend to reach their quotas very quickly, in this regard we try to minimize the number of API calls.
Do you instead of the getting the value back from the API (value that we just set) we could compute it locally instead ?
this is less reliable but should get us the same result and prevent us from having new API calls.
eg:
- we could round to the nearest lower positive integer value then divide by 255 which should give us the same value
like:
green=0.5
real_green = rount(math.floor(green*255) / 255)
green
>>> 0.49803922
the above value is exactly what I get from the API but using computation only.
what do you think ?
Minimising API requests is always nice. The below assumes that strict equality between colours is required (e.g., if a user wants to use "==" to compare colors) For this function, the problem is the rounding. Google returns colors inconsistently rounded: We could:
|
Yeah I see 🧐 I don't think the user will compare so much the colors but as you mentioned: if someone wants to check the current color then they will read "0.495857" and so it won't latch so they will set it to "0.5" which will have not effect because it's already set and cost 1 API call 😬 Thinking about it:
Can't we use whol numbers from 0 to 255 do the computation for the API and then return the appropriate value for the user ? You see what I mean? Btw: that's a breaking change 😛 |
Yes, this sounds good. If the color is set with 0-255 (i.e., with hex #RRGGBB), then it makes sense to use that to set/read color, rather than these 'random' floats. Then, we could also offer either
Not sure which you would prefer. You likely have a good idea from your signature typing adventure which is easiest/best. Let's put this pull request in milestone v6.0.0? |
I was gonna say the same thing: this becomes a breaking change that we will put in 6.0.0 😆 currently we can keep the PR with:
the rest we can add later:
|
Sounds good. I can do the first step now to edit the PR. For the additions: I am not that good at function decorators (so they can take multiple arguments). Perhaps something for you to look at. Should we make an issue for it? |
just put the user input colour into the properties dict this will not equate properly, but see #1199 for discussion
I will be happy to merge this as it is the last branch left in my fork ^^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, merge time.
Closes #1166
Google colours
This ought to have been "simple", but it was a little more complex. Here are two tabs in a Google sheet:
The left is #ff007f, and the right is unset.
Google returns the tabColorStyle for each as:
Thus, the returned colours do not include 0 values (i.e., there is no "green" in the
rgbColor
dict), and they are rounded to the nearest 8-bit decimal between 0 and 1 (i.e., "blue" is 127/255, or the result of setting "blue" to0.5
with gspread).Code to generate this output:
Changes
Worksheet.tab_color
Worksheet.update_tab_color
dict
)"tabColor"
(deprecated, see Add ability to remove tab color #1166)Worksheet._properties
would be different to the one returned bySpreadsheet.fetch_sheet_metadata()
._properties
value. *test_update_tab_color
to reflect this changeWorksheetTest.test_update_tab_color.json
*this may be an unwanted extra API request
Worksheet.clear_tab_color
clear_tab_color
test_clear_tab_color
WorksheetTest.test_clear_tab_color.json
Docs
Add "Updating a Worksheet's name and color" to "Examples of gspread Usage"