[kwlug-disc] Question Involving GTK 3 Programming in Python
John Driezen
jdriezen at sympatico.ca
Sat May 1 13:31:50 EDT 2021
On 2021-04-29 3:41 p.m., Paul Nijjar via kwlug-disc wrote:
>
> You have a class ScrapAppWindow. My (possibly wrong) idea would be to
> make material_combo a class variable, rather than a variable that is
> local to the init() function. Then it will be accessible from your
> other functions.
>
> - Paul
>
>
Your suggestion is a good one Paul. However I am at a total loss on how
to implement your suggestion in Python.
I did manage to get the Plot Graph button working by passing the
material_combo variable to the on_plot_graph_clicked method. Sample code
follows:
def on_plot_graph_clicked(self, button, combo):
print('"Plot Graph" Button was clicked.')
selected_material = None
tree_iter = combo.get_active_iter()
if tree_iter is not None:
model = combo.get_model()
selected_material = model[tree_iter][0]
if (selected_material is None) or (selected_material=="All
Materials"):
dialog = Gtk.MessageDialog(
transient_for=self,
flags=0,
message_type=Gtk.MessageType.INFO,
buttons=Gtk.ButtonsType.OK,
text="Please select a material.",
)
dialog.run()
print("Plot Graph dialog closed.")
dialog.destroy()
else:
print("Calling plotgraph(%s)." % selected_material)
plotgraph(selected_material)
I calling the on_plot_graph_clicked method using this line.
plot_button.connect("clicked", self.on_plot_graph_clicked, material_combo)
My solution works, but becomes unwieldy very quickly with multiple combo
boxes.
John Driezen
jdriezen at sympatico.ca
On 2021-04-29 3:41 p.m., Paul Nijjar via kwlug-disc wrote:
> You have a class ScrapAppWindow. My (possibly wrong) idea would be to
> make material_combo a class variable, rather than a variable that is
> local to the init() function. Then it will be accessible from your
> other functions.
>
> - Paul
>
>
More information about the kwlug-disc
mailing list