Dear Bernhard and Paul,

I am running Coot 1.2 on windows.
I tried to implement a toolbox button for showing symmtry, but the toolbox is 
not created.
Writing a script for switching on symmtery via keybinding works.

import coot
# Track whether the symmetry is currently on or off
quicksymm_is_on = False
def toggle_quicksymm():
    global quicksymm_is_on
    if quicksymm_is_on:
        coot.set_show_symmetry_master(0)
        coot.set_show_unit_cells_all(0)
        coot.add_status_bar_text("Quick Symmetry: OFF")
        quicksymm_is_on = False
    else:
        coot.set_show_symmetry_master(1)
        coot.set_show_unit_cells_all(1)
        coot.set_symmetry_colour_by_symop(0, 0)
        coot.set_symmetry_molecule_rotate_colour_map(0, 0)
        coot.set_symmetry_colour(0.4, 0.4, 0.4)
        coot.set_symmetry_size(10)
        coot.set_symmetry_whole_chain(0, 0)
        coot.set_default_bond_thickness(2)
        coot.symmetry_as_calphas(0, 1)
        coot.add_status_bar_text("Quick Symmetry: ON")
        quicksymm_is_on = True
# 115 is the ASCII code for lowercase 's'
# 0 means no modifiers (like Ctrl or Shift) are required
coot.add_key_binding_gtk4_py(115, 0, toggle_quicksymm, "Toggle Quick Symmetry")

Additionally, swtching the colors using  coot.set_symmetry_colour(0.4, 0.4, 
0.4) or the gui is not working.

Is there a command to change the thickness of the symmetry related chains?



For testing if the toolbox works at all I used that script which does not work:

import coot
import coot_gui

def toggle_quicksymm(button):
    if button.get_active():
        coot.set_show_symmetry_master(1)
        coot.set_show_unit_cells_all(1)
        coot.add_status_bar_text("Symmetry: ON")
    else:
        coot.set_show_symmetry_master(0)
        coot.set_show_unit_cells_all(0)
        coot.add_status_bar_text("Symmetry: OFF")

coot_gui.coot_toolbar_button("QuickSymm", toggle_quicksymm,
                             icon_name="gtk-yes",
                             tooltip="Toggle Quick Symmetry on/off",
                             toggle_button_flag=True,
                             use_button_flag=True)

I then asked Gemini 3.1 Pro (which has access to the Wincoot folder):

Can you figure out in the code which problem there is in the 
coot_gui.coot_toolbar_button function?
9:29 PM


Yes, I can! I looked into the source code for coot_gui.py and found exactly why 
it is failing.

The coot_gui.coot_toolbar_button function in your version of Coot 1 is 
unfortunately completely broken due to several severe coding errors left by the 
Coot developers during their transition to the new GTK4 interface.

Here are the three major bugs present in the coot_gui.py code that cause it to 
fail:

1. The "get_label" Crash
At the very beginning of the function, it calls toolbar_label_list() to loop 
through every existing item on the toolbar. To get their names, it runs 
.get_label() on every single child widget. However, toolbars contain items like 
spacer lines (Separators) and raw images, which don't have text labels. When it 
hits one of these, Python throws an AttributeError and the script silently 
crashes before it even attempts to draw your button!

2. The "String Indexing" Bug
Even if the above crash didn't happen, the new version of toolbar_label_list() 
accidentally returns a list of text strings (like ["Update Maps", "Shiftfield 
B"]). However, the coot_toolbar_button function was written expecting a list of 
pairs [[label, widget_object], ...].

It checks if button_label in f:, and if it matches, it does found_button = 
f[1]. Because f is just a text string, f[1] grabs the second letter of the 
word. It literally tries to assign a single letter of the alphabet as a GTK 
Toolbar Button widget, which is totally invalid.

3. Deprecated GTK4 Icon Methods
At the very end of the function, it tries to assign your icon using 
toolbutton.set_stock_id() and toolbutton.set_icon_widget(). Both of these 
methods were completely removed by the creators of GTK when they upgraded from 
GTK3 to GTK4. Coot will throw a hidden error here because those commands 
literally don't exist in GTK4 anymore.

Conclusion: It's structurally impossible for coot_toolbar_button to work in 
this build of Coot 1 because it's full of half-finished GTK4 transition code!

The Keyboard Shortcut and Extensions Menu methods I provided earlier are the 
official, working replacements that the developers actually finished testing. I 
highly recommend using the "s" keyboard shortcut we set up!

Would be curious how good the answer is.

Many thanks to both of you in advance. It is not a urgent issue.

Br, Georg.

########################################################################

To unsubscribe from the COOT list, click the following link:
https://www.jiscmail.ac.uk/cgi-bin/WA-JISC.exe?SUBED1=COOT&A=1

This message was issued to members of www.jiscmail.ac.uk/COOT, a mailing list 
hosted by www.jiscmail.ac.uk, terms & conditions are available at 
https://www.jiscmail.ac.uk/policyandsecurity/

Reply via email to