Sorry if I make you all confused. I attached here sample of the programming.
Is there a better way to do it? Thanx for your comment. ~anita~ Christian Reis wrote: >On Sun, May 19, 2002 at 01:23:40PM +0800, Anita Zahara wrote: > >>In my program, whenever user click any button from the main menu, >>there will be a pop up menu. I want to make >> > >Any button from the main menu? Wait, this isn't making any sense to me. >Do you mean a toolbar? You have a toolbar of buttons that open popup >menus? > >If this is the case, I would recommend using a more traditional layout >for your application; it would be highly unfamiliar and cumbersome. The >menubar by itself works very well and provides all the functionality you >would need. > >>the main menu disabled, so the user will not tend to >>click any button from the main menu until they quit >>the pop up menu. >> > >I'm afraid I'm not following you here. > >Take care, >-- >Christian Reis, Senior Engineer, Async Open Source, Brazil. >http://async.com.br/~kiko/ | [+55 16] 272 3330 | NMFL > >
#!/usr/bin/env python from gtk import * import GtkExtra import os import string import sys sudah = 0 dapat = 0 data_array = [ 0,0,0] name_array = [ 0,0,0,0,0,0,0,0,0,0,0,0,0,0] widget_array = [ 0,0,0,0,0,0,0,0,0,0,0,0,0,0] wins = {} def delete_event(win, event=None): win.hide() return TRUE def do_exit(button): mainquit() # ****************************** DEFAULT SELECTION ****************************** def choice_yes(self): os.system('./gui_progress.bsh') def choice(_self): win = GtkWindow() win.connect("delete_event", delete_event) win.set_title("CONFIRMATION") win.set_usize(300, 250) box1 = GtkVBox() win.add(box1) box1.show() box2 = GtkVBox(spacing=10) box2.set_border_width(10) box1.pack_start(box2) box2.show() table = GtkTable(2, 2) box2.pack_start(table) table.show() text = GtkText() text.set_editable(FALSE) table.attach(text, 0,1, 0,1) text.show() text.freeze() text.insert_defaults("\n") text.insert_defaults("INSTALLING DEFAULT APPLICATIONS: \n") text.insert_defaults("_________________________________\n") text.insert_defaults("\n") text.insert_defaults("*****************\n") text.insert_defaults("CONFIRMED? \n") text.insert_defaults("*****************\n") text.thaw() separator = GtkHSeparator() box2.pack_start(separator, expand=FALSE) separator.show() box2 = GtkVBox(spacing=10) box2.set_border_width(10) box1.pack_start(box2, expand=FALSE) box2.show() button = GtkButton("YES") button.connect("clicked", choice_yes) box2.pack_start(button, expand=FALSE) button.show() button = GtkButton("CANCEL") button.connect("clicked", win.hide) box2.pack_start(button) button.set_flags(CAN_DEFAULT) button.grab_default() button.show() win.show() # ****************************** END DEFAULT SELECTION ************************** # ****************************** CONFIRMTION ************************************ def select(data): for i in range(14): sudah = 0 dapat = 0 if widget_array[i] == 1: if i == 0: os.system('./progress.bsh 1 "NETSCAPE"') os.system('echo "100:101:NETSCAPE:/usr/local/xmms" >> /usr/local/bin/appl') elif i == 1: os.system('./progress.bsh 2 "E-MAIL"') os.system('echo "200:201:E-MAIL:/usr/local/xmms" >> /usr/local/bin/appl') elif i == 2: os.system('./progress.bsh 3 "MRPROJECT"') os.system('echo "300:301:XMMS:/usr/local/xmms" >> /usr/local/bin/appl') elif i == 3: os.system('./progress.bsh 4 "OPEN OFFICE"') os.system('echo "400:401:XMMS:/usr/local/xmms" >> /usr/local/bin/appl') elif i == 4: os.system('./progress.bsh 5 "CALENDAR"') os.system('echo "500:501:XMMS:/usr/local/xmms" >> /usr/local/bin/appl') elif i == 5: os.system('./progress.bsh 6 "DATE"') os.system('echo "600:601:XMMS:/usr/local/xmms" >> /usr/local/bin/appl') elif i == 6: os.system('./progress.bsh 7 "NETWORK"') os.system('echo "700:701:XMMS:/usr/local/xmms" >> /usr/local/bin/appl') elif i == 7: os.system('./progress.bsh 8 "PRINTER"') os.system('echo "800:801:XMMS:/usr/local/xmms" >> /usr/local/bin/appl') elif i == 8: os.system('./progress.bsh 9 "FILE MANAGER"') os.system('echo "900:901:XMMS:/usr/local/xmms" >> /usr/local/bin/appl') elif i == 9: os.system('./progress.bsh 10 "FORMAT FD"') os.system('echo "1000:1001:XMMS:/usr/local/xmms" >> /usr/local/bin/appl') elif i == 10: os.system('./progress.bsh 11 "XINE"') os.system('echo "1100:1101:XMMS:/usr/local/xmms" >> /usr/local/bin/appl') elif i == 11: os.system('./progress.bsh 12 "XMMS"') os.system('echo "1200:1201:XMMS:/usr/local/xmms" >> /usr/local/bin/appl') elif i == 12: os.system('./progress.bsh 13 "GALEON"') os.system('echo "1200:1202:GALEON:/usr/local/galeon" >> /usr/local/bin/appl') elif i == 13: os.system('./progress.bsh 14 "FREEAMP"') os.system('echo "1200:1203:FREEAMP:/usr/local/freeamp" >> /usr/local/bin/appl') os.system('sort -n /usr/local/bin/appl >> /usr/local/.appl') os.system('./complete.bsh') def confirmation(_button): win = GtkWindow() win.connect("delete_event", delete_event) win.set_title("CONFIRMATION") win.set_usize(400, 400) box1 = GtkVBox() win.add(box1) box1.show() box2 = GtkVBox(spacing=10) box2.set_border_width(10) box1.pack_start(box2) box2.show() table = GtkTable(2, 2) table.set_row_spacing(0, 2) table.set_col_spacing(0, 2) box2.pack_start(table) table.show() text = GtkText() text.set_editable(FALSE) table.attach(text, 0,1, 0,1) text.show() hscrollbar = GtkHScrollbar(text.get_hadjustment()) table.attach(hscrollbar, 0,1, 1,2, yoptions=FILL) hscrollbar.show() vscrollbar = GtkVScrollbar(text.get_vadjustment()) table.attach(vscrollbar, 1,2, 0,1, xoptions=FILL) vscrollbar.show() text.freeze() text.insert_defaults("INSTALLING THESE APPLICATIONS: \n") text.insert_defaults("------------------------------------------\n") text.insert_defaults("\n") text.insert_defaults("\n") for i in range(14): sudah = 0 dapat = 0 if widget_array[i] == 1: if i == 0: text.insert_defaults("NETSCAPE") text.insert_defaults("\n") text.insert_defaults("\n") elif i == 1: text.insert_defaults("E-MAIL") text.insert_defaults("\n") text.insert_defaults("\n") elif i == 2: text.insert_defaults("MRPROJECT") text.insert_defaults("\n") text.insert_defaults("\n") elif i == 3: text.insert_defaults("OPEN OFFICE") text.insert_defaults("\n") text.insert_defaults("\n") elif i == 4: text.insert_defaults("CALENDAR") text.insert_defaults("\n") text.insert_defaults("\n") elif i == 5: text.insert_defaults("DATE") text.insert_defaults("\n") text.insert_defaults("\n") elif i == 6: text.insert_defaults("NETWORK") text.insert_defaults("\n") text.insert_defaults("\n") elif i == 7: text.insert_defaults("PRINTER") text.insert_defaults("\n") text.insert_defaults("\n") elif i == 8: text.insert_defaults("FILE MANAGER") text.insert_defaults("\n") text.insert_defaults("\n") elif i == 9: text.insert_defaults("FORMAT FD") text.insert_defaults("\n") text.insert_defaults("\n") elif i == 10: text.insert_defaults("XINE") text.insert_defaults("\n") text.insert_defaults("\n") elif i == 11: text.insert_defaults("XMMS") text.insert_defaults("\n") text.insert_defaults("\n") elif i == 12: text.insert_defaults("GALEON") text.insert_defaults("\n") text.insert_defaults("\n") elif i == 13: text.insert_defaults("FREEAMP") text.insert_defaults("\n") text.insert_defaults("\n") text.insert_defaults("\n") text.insert_defaults("\n") text.insert_defaults("\n") text.insert_defaults("*********************************\n") text.insert_defaults("CONFIRM THE SELECTION? \n") text.insert_defaults("*********************************\n") text.thaw() separator = GtkHSeparator() box2.pack_start(separator, expand=FALSE) separator.show() box2 = GtkVBox(spacing=10) box2.set_border_width(10) box1.pack_start(box2, expand=FALSE) box2.show() button = GtkButton("CONFIRMED") button.connect("clicked", select) box2.pack_start(button, expand=FALSE) button.show() button = GtkButton("CANCEL") button.connect("clicked", win.hide) box2.pack_start(button) button.set_flags(CAN_DEFAULT) button.grab_default() button.show() win.show() # ****************************** END CONFIRMATION ******************************* # ****************************** TREE SELECTION ********************************** def main_callback(widget, data): print "NAMA SAYA %s" % (data) def callback(widget, data): print "%s was toggled %s" % (data, widget) data_array[0] = data name_array[0] = "NETSCAPE " name_array[1] = "E-MAIL " name_array[2] = "MRPROJECT " name_array[3] = "OPEN OFFICE " name_array[4] = "CALENDAR " name_array[5] = "DATE " name_array[6] = "NETWORK " name_array[7] = "PRINTER " name_array[8] = "FILE MANAGER " name_array[9] = "FORMAT FD " name_array[10] = "XINE " name_array[11] = "XMMS " name_array[12] = "GALEON " name_array[13] = "FREEAMP " if data_array[0] == 1: widget_array[0] = 1 elif data_array[0] == 2: widget_array[1] = 1 elif data_array[0] == 3: widget_array[2] = 1 elif data_array[0] == 4: widget_array[3] = 1 elif data_array[0] == 5: widget_array[4] = 1 elif data_array[0] == 6: widget_array[5] = 1 elif data_array[0] == 7: widget_array[6] = 1 elif data_array[0] == 8: widget_array[7] = 1 elif data_array[0] == 9: widget_array[8] = 1 elif data_array[0] == 10: widget_array[9] = 1 elif data_array[0] == 11: widget_array[10] = 1 elif data_array[0] == 12: widget_array[11] = 1 elif data_array[0] == 13: widget_array[12] = 1 elif data_array[0] == 14: widget_array[13] = 1 def unselect(widget, data): data_array[0] = data if data_array[0] == 1: widget_array[0] = 0 elif data_array[0] == 2: widget_array[1] = 0 elif data_array[0] == 3: widget_array[2] = 0 elif data_array[0] == 4: widget_array[3] = 0 elif data_array[0] == 5: widget_array[4] = 0 elif data_array[0] == 6: widget_array[5] = 0 elif data_array[0] == 7: widget_array[6] = 0 elif data_array[0] == 8: widget_array[7] = 0 elif data_array[0] == 9: widget_array[8] = 0 elif data_array[0] == 10: widget_array[9] = 0 elif data_array[0] == 11: widget_array[10] = 0 elif data_array[0] == 12: widget_array[11] = 0 def cb_itemsignal(item, signame): label = item.children()[0] name = label.get() print signame print name print item def cb_unselect_child(root_tree, child, subtree): print ("unselect_child called for root tree %s, " "subtree %s, child %s" % (root_tree, subtree, child)) def cb_select_child(root_tree, child, subtree): print ("select_child called for root tree %s, subtree %s, " "child %s\n" % (root_tree, subtree, child)) def cb_selection_changed(tree): print "selection_change called for tree %s" % tree print "selected objects are:" for item in tree.get_selection(): label = item.children()[0] name = label.get() print "\t%s" % name def create_tree_selection(_button): itemnames = ["INTERNET", "OFFICE", "SETUP", "MULTIMEDIA"] subnames0 = ["Netscape", "E-Mail Client", "Galeon"] subnames1 = ["MrProject", "Open Office", "Calendar"] subnames2 = ["Date", "Network", "Printer", "File Manager", "Format FD"] subnames3 = ["Xine", "Xmms", "Freeamp"] win = GtkWindow() wins["check_buttons"] = win win.connect("delete_event", delete_event) win.set_usize(500, 500) win.set_title("Choose Applications") box1 = GtkVBox() win.add(box1) box1.show() box2 = GtkVBox(spacing=10) box2.set_border_width(10) box1.pack_start(box2) box2.show() label = GtkLabel("Hello World") frame = GtkFrame("CHOOSE APPLICATIONS") box2.pack_start(frame) frame.show() scrolled_window = GtkScrolledWindow() scrolled_window.set_border_width(10) scrolled_window.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC) frame.add(scrolled_window) scrolled_window.show() box3 = GtkVBox(spacing=5) box3.set_border_width(5) scrolled_window.add_with_viewport(box3) box3.show() tree = GtkTree() print "root tree is %s" % tree tree.connect("select_child", cb_select_child, tree) tree.connect("unselect_child", cb_unselect_child, tree) tree.connect("selection_changed", cb_selection_changed) box3.pack_start(tree) tree.set_selection_mode(SELECTION_MULTIPLE) tree.show() for i in range(4): item = GtkTreeItem(itemnames[i]) # item.connect("select", cb_itemsignal, "select") item.connect("select", main_callback, i) item.connect("deselect", cb_itemsignal, "deselect") item.connect("toggle", cb_itemsignal, "toggle") item.connect("expand", cb_itemsignal, "expand") item.connect("collapse", cb_itemsignal, "collapse") tree.append(item) item.show() subtree = GtkTree() print "-> item %s->%s, subtree %s" % (itemnames[i], item, subtree) item.set_subtree(subtree) if i == 0: subitem = GtkTreeItem(subnames0[0]) subitem.connect("select", callback, 1) subitem.connect("deselect", unselect, 1) subitem.connect("toggle", cb_itemsignal, "toggle") subitem.connect("expand", cb_itemsignal, "expand") subitem.connect("collapse", cb_itemsignal, "collapse") subtree.append(subitem) subitem.show() subitem = GtkTreeItem(subnames0[1]) subitem.connect("select", callback, 2) subitem.connect("deselect", unselect, 2) subitem.connect("toggle", cb_itemsignal, "toggle") subitem.connect("expand", cb_itemsignal, "expand") subitem.connect("collapse", cb_itemsignal, "collapse") subtree.append(subitem) subitem.show() subitem = GtkTreeItem(subnames0[2]) subitem.connect("select", callback, 13) subitem.connect("deselect", unselect, 3) subitem.connect("toggle", cb_itemsignal, "toggle") subitem.connect("expand", cb_itemsignal, "expand") subitem.connect("collapse", cb_itemsignal, "collapse") subtree.append(subitem) subitem.show() elif i == 1: subitem = GtkTreeItem(subnames1[0]) subitem.connect("select", callback, 3) subitem.connect("deselect", unselect, 3) subitem.connect("toggle", cb_itemsignal, "toggle") subitem.connect("expand", cb_itemsignal, "expand") subitem.connect("collapse", cb_itemsignal, "collapse") subtree.append(subitem) subitem.show() subitem = GtkTreeItem(subnames1[1]) subitem.connect("select", callback, 4) subitem.connect("deselect", unselect, 4) subitem.connect("toggle", cb_itemsignal, "toggle") subitem.connect("expand", cb_itemsignal, "expand") subitem.connect("collapse", cb_itemsignal, "collapse") subtree.append(subitem) subitem.show() subitem = GtkTreeItem(subnames1[2]) subitem.connect("select", callback, 5) subitem.connect("deselect", unselect, 5) subitem.connect("toggle", cb_itemsignal, "toggle") subitem.connect("expand", cb_itemsignal, "expand") subitem.connect("collapse", cb_itemsignal, "collapse") subtree.append(subitem) subitem.show() elif i == 2: subitem = GtkTreeItem(subnames2[0]) subitem.connect("select", callback, 6) subitem.connect("deselect", unselect, 6) subitem.connect("toggle", cb_itemsignal, "toggle") subitem.connect("expand", cb_itemsignal, "expand") subitem.connect("collapse", cb_itemsignal, "collapse") subtree.append(subitem) subitem.show() subitem = GtkTreeItem(subnames2[1]) subitem.connect("select", callback, 7) subitem.connect("deselect", unselect, 7) subitem.connect("toggle", cb_itemsignal, "toggle") subitem.connect("expand", cb_itemsignal, "expand") subitem.connect("collapse", cb_itemsignal, "collapse") subtree.append(subitem) subitem.show() subitem = GtkTreeItem(subnames2[2]) subitem.connect("select", callback, 8) subitem.connect("deselect", unselect, 8) subitem.connect("toggle", cb_itemsignal, "toggle") subitem.connect("expand", cb_itemsignal, "expand") subitem.connect("collapse", cb_itemsignal, "collapse") subtree.append(subitem) subitem.show() subitem = GtkTreeItem(subnames2[3]) subitem.connect("select", callback, 9) subitem.connect("deselect", unselect, 9) subitem.connect("toggle", cb_itemsignal, "toggle") subitem.connect("expand", cb_itemsignal, "expand") subitem.connect("collapse", cb_itemsignal, "collapse") subtree.append(subitem) subitem.show() subitem = GtkTreeItem(subnames2[4]) subitem.connect("select", callback, 10) subitem.connect("deselect", unselect, 10) subitem.connect("toggle", cb_itemsignal, "toggle") subitem.connect("expand", cb_itemsignal, "expand") subitem.connect("collapse", cb_itemsignal, "collapse") subtree.append(subitem) subitem.show() elif i == 3: subitem = GtkTreeItem(subnames3[0]) subitem.connect("select", callback, 11) subitem.connect("deselect", unselect, 11) subitem.connect("toggle", cb_itemsignal, "toggle") subitem.connect("expand", cb_itemsignal, "expand") subitem.connect("collapse", cb_itemsignal, "collapse") subtree.append(subitem) subitem.show() subitem = GtkTreeItem(subnames3[1]) subitem.connect("select", callback, 12) subitem.connect("deselect", unselect, 12) subitem.connect("toggle", cb_itemsignal, "toggle") subitem.connect("expand", cb_itemsignal, "expand") subitem.connect("collapse", cb_itemsignal, "collapse") subtree.append(subitem) subitem.show() subitem = GtkTreeItem(subnames3[2]) subitem.connect("select", callback, 14) subitem.connect("deselect", unselect, 14) subitem.connect("toggle", cb_itemsignal, "toggle") subitem.connect("expand", cb_itemsignal, "expand") subitem.connect("collapse", cb_itemsignal, "collapse") subtree.append(subitem) subitem.show() separator = GtkHSeparator() box1.pack_start(separator, expand=FALSE) separator.show() box2 = GtkVBox(spacing=10) box2.set_border_width(10) box1.pack_start(box2, expand=FALSE) box2.show() button = GtkButton("DONE") button.connect("clicked", confirmation) box2.pack_start(button) button.show() button = GtkButton("close") button.connect("clicked", win.hide) box2.pack_start(button) button.set_flags(CAN_DEFAULT) button.grab_default() button.show() win.show() # ****************************************** DONE **************************************** def create_main_window(): create_first_window() def create_first_window(): win = GtkWindow() win.connect("delete_event", delete_event) win.set_title("INSTALLATION-CD") win.set_border_width(10) win.set_usize(780, 500) box1 = GtkVBox() win.add(box1) box1.show() pix, msk = create_pixmap_from_xpm(box1, None, "sample2.xpm") pixmap = GtkPixmap(pix, msk) box1.pack_start(pixmap) pixmap.show() box1.show() box2 = GtkHBox(spacing=20) box2.set_border_width(10) box1.pack_start(box2) box2.show() label = GtkLabel("Hello World") frame = GtkFrame("Online-HELP") box2.pack_start(frame) frame.show() box3 = GtkVBox(spacing=10) box3.set_border_width(5) frame.add(box3) box3.show() table = GtkTable(2, 2) table.set_row_spacing(0, 2) table.set_col_spacing(0, 2) box3.pack_start(table) table.show() text = GtkText() text.set_editable(FALSE) table.attach(text, 0,1, 0,1) text.show() vscrollbar = GtkVScrollbar(text.get_vadjustment()) table.attach(vscrollbar, 1,2, 0,1, xoptions=FILL) vscrollbar.show() text.freeze() text.insert_defaults("WELCOME TO INSTALLATION CD\n") text.insert_defaults("----------------------------------------\n") text.insert_defaults("\n") text.insert_defaults("Please select your option:\n") text.insert_defaults("\n") text.insert_defaults("Choose Application will show\n") text.insert_defaults("All the applications available\n") text.insert_defaults("\n") text.insert_defaults("Install all will install \n") text.insert_defaults("ALL the applications available\n") text.insert_defaults("\n") text.insert_defaults("Thank You\n") text.thaw() def reparent_label(button, new_parent=box3, label=label): label.reparent(new_parent) box3.pack_start(label, expand=FALSE) frame = GtkFrame("MAIN MENU") box2.pack_start(frame) frame.show() box3 = GtkVBox(spacing=5) box3.set_border_width(5) frame.add(box3) box3.show() def reparent_label(button, new_parent=box3, label=label): label.reparent(new_parent) button = GtkButton("GUI AND DEFAULT INSTALLATION") button.connect("clicked", choice) box3.pack_start(button, expand=FALSE) button.show() button = GtkButton("CHOOSE APPLICATIONS") button.connect("clicked", create_tree_selection) box3.pack_start(button, expand=FALSE) button.show() separator = GtkHSeparator() box1.pack_start(separator, expand=FALSE) separator.show() box2 = GtkVBox(spacing=10) box2.set_border_width(10) box1.pack_start(box2, expand=FALSE) box2.show() button = GtkButton("close") button.connect("clicked", do_exit) box2.pack_start(button) button.set_flags(CAN_DEFAULT) button.grab_default() button.show() win.show() def main(): rc_parse("installationrc") create_main_window() mainloop() if __name__ == '__main__': main()