def __init__(self): # create a new window self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.ui = """<ui> <menubar name="MenuBar"> <menu action="File"> <menuitem action="Save"/> <menuitem action="Quit"/> </menu> <menu action="Preferences"> <menuitem action="Edit Preferences"/> </menu> </menubar> </ui>""" uimanager = gtk.UIManager() # Add the accelerator group to the toplevel window self.accelg = uimanager.get_accel_group() self.window.add_accel_group(self.accelg) actiongroup = gtk.ActionGroup('UIManagerExample') self.actiongroup = actiongroup # Create a ToggleAction, etc. actiongroup.add_actions([('Save', None, '_Save', '<control>s', 'Save', self.save), ('Quit', gtk.STOCK_QUIT, '_Quit', None, 'Quit the Program', self.destroy), ('File', None, '_File'), ('Edit Preferences', None, 'Edit Preferences', '<alt>e', 'Edit Preferences', self.edit_preferences), ('Preferences', None, '_Preferences'), ]) actiongroup.get_action('Quit').set_property('short-label', '_Quit') #actiongroup.get_action('Quit').set_property('short-label', '_Quit') uimanager.insert_action_group(actiongroup, 0) # Add a UI description uimanager.add_ui_from_string(self.ui) # Create a MenuBar # When the window is given the "delete_event" signal (this is given # by the window manager, usually by the "close" option, or on the # titlebar), we ask it to call the delete_event () function # as defined above. The data passed to the callback # function is NULL and is ignored in the callback function. self.window.connect("delete_event", self.delete_event) # Here we connect the "destroy" event to a signal handler. # This event occurs when we call gtk_widget_destroy() on the window, # or if we return FALSE in the "delete_event" callback. self.window.connect("destroy", self.destroy) # Sets the border width of the window. self.window.set_border_width(2) ## self.store = gtk.ListStore(gtk.gdk.Pixbuf) ## self.icon_view = gtk.IconView(self.store) ## self.icon_view.set_pixbuf_column(0) ## self.icon_view.set_selection_mode(gtk.SELECTION_MULTIPLE) ## self.folder = '/mnt/personal/pictures/Joshua_Ryan/2011/Mar_2011/Eli/thumbnails/' ## self.pat = os.path.join(self.folder, '*.jpg') ## self.thumbnail_paths = glob.glob(self.pat) ## self.thumbnail_paths.sort() ## for arg in self.thumbnail_paths: ## pixbuf = gtk.gdk.pixbuf_new_from_file(arg) ## self.store.append((pixbuf, )) ## self.sw = gtk.ScrolledWindow() ## self.icon_view.connect("selection-changed", self.on_item_activated) ## self.sw.add(self.icon_view) self.DEF_PAD = 5 self.DEF_PAD_SMALL = 3 self.main_vbox = gtk.VBox(homogeneous=False, spacing=0) self.menubar = uimanager.get_widget('/MenuBar') self.main_vbox.pack_start(self.menubar, False) #self.hpaned = gtk.HPaned() self.h1 = gtk.HBox(homogeneous=False, spacing=0) #self.main_vbox.pack_start(self.hpaned, True) self.main_vbox.pack_start(self.h1, True) #self.hpaned.show() self.h1.show() # Now create the contents of the two halves of the window self.image_on_sw = image_on_scrolled_window.image_on_scrolled_window() self.image_on_sw.set_size_request(750,200) #self.hpaned.add1(self.image_on_sw) self.h1.pack_start(self.image_on_sw, *pack_args_w_pad) hard_coded_path = '/Users/rkrauss/siue/Research/papers/ASEE_IL_IN_BD_MIL/tikz_sys_test.jpg' self.image_on_sw.set_from_path(hard_coded_path) self.image_on_sw.show() self.refresh_button = gtk.Button("Refresh") # Add the run_test button to the gui self.v1_h1 = gtk.VBox() self.v1_h1.pack_start(self.refresh_button, True, False) self.h1.pack_start(self.v1_h1, *pack_args_w_pad) self.refresh_button.connect("clicked", self.refresh_bd, None) #self.hpaned.add2(self.notebook) #self.notebook.show() ############################################################## # # This is the section that adds, edits, and deletes blocks # ############################################################## big_frame_hbox = gtk.HBox() block_frame = gtk.Frame("Blocks") big_frame_hbox.pack_start(block_frame) self.main_vbox.pack_start(big_frame_hbox, True) ## vbox2.pack_start(frame, True, True, self.DEF_PAD) vbox_block_frame = gtk.VBox(False, self.DEF_PAD_SMALL) block_frame.add(vbox_block_frame) block_frame_h1 = gtk.HBox() self.block_combobox = gtk.combo_box_new_text() block_frame_h1.pack_start(self.block_combobox, False, False, 0) vbox_block_frame.pack_start(block_frame_h1) self.block_combobox.append_text('block type:') self.block_combobox.append_text('source') self.block_combobox.append_text('TF') self.block_combobox.append_text('output') self.block_combobox.connect('changed', self.changed_cb) self.block_combobox.show() self.block_combobox.set_active(0) self.block_placement_cb = gtk.combo_box_new_text() block_frame_h1.pack_start(self.block_placement_cb, False, False, 0) self.block_placement_cb.append_text('placement:') self.block_placement_cb.append_text('absolute') self.block_placement_cb.append_text('right of') self.block_placement_cb.append_text('left of') self.block_placement_cb.append_text('above of') self.block_placement_cb.append_text('below of') self.block_placement_cb.connect('changed', self.changed_cb) self.block_placement_cb.show() self.block_placement_cb.set_active(0) self.block_listbox = listbox.listbox('Block List', initial_data=['input - u', \ 'sum1', \ 'controller - G_c', \ 'plant - G', \ 'output - y']) block_frame_h2 = gtk.HBox() block_frame_h2.pack_start(self.block_listbox, False, False, 0) self.block_listbox.show() vbox_block_frame.pack_start(block_frame_h2, False) temp_hbox = gtk.HBox() self.add_block_button = gtk.Button("Add") temp_hbox.pack_start(self.add_block_button, True, False) self.update_block_button = gtk.Button("Edit Parameters") temp_hbox.pack_start(self.update_block_button, True, False) self.remove_block_button = gtk.Button("Remove") temp_hbox.pack_start(self.remove_block_button, True, False) temp_vbox = gtk.VBox() temp_vbox.pack_start(temp_hbox, True, False, self.DEF_PAD) block_frame_h2.pack_start(temp_vbox, False, False, self.DEF_PAD) #self.refresh_button.connect("clicked", self.refresh_bd, None) ############################################################## # # End block editting section # ############################################################## ############################################################## # # This is the section that adds, edits, and deletes wires # ############################################################## wire_frame = gtk.Frame("wires") #self.main_vbox.pack_start(wire_frame, True) big_frame_hbox.pack_start(wire_frame, True) ## vbox2.pack_start(frame, True, True, self.DEF_PAD) vbox_wire_frame = gtk.VBox(False, self.DEF_PAD_SMALL) wire_frame.add(vbox_wire_frame) wire_frame_h1 = gtk.HBox() self.wire_combobox = gtk.combo_box_new_text() wire_frame_h1.pack_start(self.wire_combobox, False, False, 0) vbox_wire_frame.pack_start(wire_frame_h1) self.wire_combobox.append_text('wire type:') self.wire_combobox.append_text('source') self.wire_combobox.append_text('TF') self.wire_combobox.append_text('output') self.wire_combobox.connect('changed', self.changed_cb) self.wire_combobox.show() self.wire_combobox.set_active(0) self.wire_listbox = listbox.listbox('Wire List', initial_data=['wire1', \ 'wire2', \ 'wire3', \ 'wire4', \ 'feedback wire']) wire_frame_h2 = gtk.HBox() wire_frame_h2.pack_start(self.wire_listbox, False, False, 0) self.wire_listbox.show() vbox_wire_frame.pack_start(wire_frame_h2, False) temp_hbox = gtk.HBox() self.add_wire_button = gtk.Button("Add") temp_hbox.pack_start(self.add_wire_button, True, False) self.update_wire_button = gtk.Button("Edit Parameters") temp_hbox.pack_start(self.update_wire_button, True, False) self.remove_wire_button = gtk.Button("Remove") temp_hbox.pack_start(self.remove_wire_button, True, False) temp_vbox = gtk.VBox() temp_vbox.pack_start(temp_hbox, True, False, self.DEF_PAD) wire_frame_h2.pack_start(temp_vbox, False, False, self.DEF_PAD) #self.refresh_button.connect("clicked", self.refresh_bd, None) ############################################################## # # End wire editting section # ############################################################## ## for i in range(len(flags)): ## toggle = gtk.CheckButton(flags[i]) ## toggle.connect("toggled", self.calendar_toggle_flag) ## vbox3.pack_start(toggle, True, True, 0) ## self.flag_checkboxes[i] = toggle self.window.add(self.main_vbox) ## self.saveattrs = ['database_path'] ## if os.path.exists(settings_path): ## self.load(settings_path) #print('self.database_path = %s' % self.database_path) #pn1 = self.notebook.get_current_page() #self.notebook.show() #????#self.window.set_size_request(1200,700) #self.notebook.set_current_page(1) #pn2 = self.notebook.get_current_page() #print('pn1 = %s' % pn1) #print('pn2 = %s' % pn2) self.window.show_all()
def __init__(self): # create a new window self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.ui = """<ui> <menubar name="MenuBar"> <menu action="File"> <menuitem action="Save Database"/> <menuitem action="Quit"/> <menuitem action="Add Directory to database"/> </menu> <menu action="Preferences"> <menuitem action="Specify database file"/> </menu> <menu action="Rating"> <menuitem action="Unrated (0 Stars)"/> <menuitem action="1 Star"/> <menuitem action="2 Stars"/> <menuitem action="3 Stars"/> <menuitem action="4 Stars"/> <menuitem action="5 Stars"/> </menu> </menubar> </ui>""" uimanager = gtk.UIManager() # Add the accelerator group to the toplevel window self.accelg = uimanager.get_accel_group() self.window.add_accel_group(self.accelg) actiongroup = gtk.ActionGroup('UIManagerExample') self.actiongroup = actiongroup # Create a ToggleAction, etc. actiongroup.add_actions([('Save Database', None, '_Save Database', '<control>s', 'Save Database', self.map_data_to_db_alldata), ('Quit', gtk.STOCK_QUIT, '_Quit', None, 'Quit the Program', self.destroy), ('Add Directory to database', None, 'Add _Directory to database', '<alt>d', 'Add Directory to database', self.add_directory), ('File', None, '_File'), ('Specify database file', None, 'Specify database file', '<alt>f', 'Specify database file', self.speficify_db_file), ('Preferences', None, '_Preferences'), ('Rating', None, '_Rating'), ('Unrated (0 Stars)', None, 'Unrated (0 Stars)', '0', 'Unrated (0 Stars)', self.set_zero_stars), ('1 Star', None, '1 Star', '1', '1 Star', self.set_one_star), ('2 Stars', None, '2 Stars', '2', '2 Stars', self.set_two_stars), ('3 Stars', None, '3 Stars', '3', '3 Stars', self.set_three_stars), ('4 Stars', None, '4 Stars', '4', '4 Stars', self.set_four_stars), ('5 Stars', None, '5 Stars', '5', '5 Stars', self.set_five_stars), ]) actiongroup.get_action('Quit').set_property('short-label', '_Quit') #actiongroup.get_action('Quit').set_property('short-label', '_Quit') uimanager.insert_action_group(actiongroup, 0) # Add a UI description uimanager.add_ui_from_string(self.ui) # Create a MenuBar # When the window is given the "delete_event" signal (this is given # by the window manager, usually by the "close" option, or on the # titlebar), we ask it to call the delete_event () function # as defined above. The data passed to the callback # function is NULL and is ignored in the callback function. self.window.connect("delete_event", self.delete_event) # Here we connect the "destroy" event to a signal handler. # This event occurs when we call gtk_widget_destroy() on the window, # or if we return FALSE in the "delete_event" callback. self.window.connect("destroy", self.destroy) # Sets the border width of the window. self.window.set_border_width(2) ## self.store = gtk.ListStore(gtk.gdk.Pixbuf) ## self.icon_view = gtk.IconView(self.store) ## self.icon_view.set_pixbuf_column(0) ## self.icon_view.set_selection_mode(gtk.SELECTION_MULTIPLE) ## self.folder = '/mnt/personal/pictures/Joshua_Ryan/2011/Mar_2011/Eli/thumbnails/' ## self.pat = os.path.join(self.folder, '*.jpg') ## self.thumbnail_paths = glob.glob(self.pat) ## self.thumbnail_paths.sort() ## for arg in self.thumbnail_paths: ## pixbuf = gtk.gdk.pixbuf_new_from_file(arg) ## self.store.append((pixbuf, )) ## self.sw = gtk.ScrolledWindow() ## self.icon_view.connect("selection-changed", self.on_item_activated) ## self.sw.add(self.icon_view) self.main_vbox = gtk.VBox(homogeneous=False, spacing=0) self.menubar = uimanager.get_widget('/MenuBar') self.main_vbox.pack_start(self.menubar, False) self.hpaned = gtk.HPaned() self.main_vbox.pack_start(self.hpaned, True) self.hpaned.show() # Now create the contents of the two halves of the window self.thumbs_viewer = thumbnail_viewer.thumbnail_iconview_on_scrollwindow(parent_selection_method=self.on_thumb_selected) self.thumbs_viewer.set_size_request(440,-1) self.image_on_sw = image_on_scrolled_window.image_on_scrolled_window() self.hpaned.add1(self.thumbs_viewer) self.notebook = gtk.Notebook() self.notebook.set_tab_pos(gtk.POS_TOP) main_label = gtk.Label("Main") self.notebook.append_page(self.image_on_sw, main_label) self.image_on_sw.show() self.thumbs_viewer.show() #self.thumbs_viewer.connect("selection-changed", self.on_thumb_selected) self.hpaned.add2(self.notebook) #self.notebook.show() #create search page search_window = gtk.ScrolledWindow() search_window.set_border_width(2) # the policy is one of POLICY AUTOMATIC, or POLICY_ALWAYS. # POLICY_AUTOMATIC will automatically decide whether you need # scrollbars, whereas POLICY_ALWAYS will always leave the scrollbars # there. The first one is the horizontal scrollbar, the second, the # vertical. search_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) ###################################################### # # This is the creation of the search tab page # ###################################################### search_vbox = gtk.VBox(homogeneous=False, spacing=2) search_hbox1 = gtk.HBox(homogeneous=False, spacing=2) #self.year_combobox = gtk.combo_box_new_text() #search_vbox.pack_start(self.year_combobox, False) #self.year_listbox = listbox.listbox(label='Years') myw = 100 myh = 150 myw2 = 250 self.year_listbox = listbox.listbox_on_scrollwindow(label='Years', \ dtype=int) search_hbox1.pack_start(self.year_listbox, False) self.year_listbox.set_size_request(myw, myh) self.year_listbox.show() self.month_listbox = listbox.listbox_on_scrollwindow(label='Months') search_hbox1.pack_start(self.month_listbox, False) self.month_listbox.set_size_request(myw, myh) self.month_listbox.show() self.folder_listbox = listbox.listbox_on_scrollwindow(label='Folders') search_hbox1.pack_start(self.folder_listbox, False) self.folder_listbox.set_size_request(myw2, myh) self.folder_listbox.show() self.rating_listbox = listbox.listbox_on_scrollwindow(label='Ratings') search_hbox1.pack_start(self.rating_listbox, False) self.rating_listbox.set_size_request(myw2, myh) self.rating_listbox.show() self.listdict = {'year':self.year_listbox, \ 'month':self.month_listbox, \ 'folder_name':self.folder_listbox, \ 'rating':self.rating_listbox, \ } search_vbox.pack_start(search_hbox1, False, False) #middle button box arg1 = False arg2 = True search_buttons_hbox = gtk.HBox(homogeneous=False, spacing=2) self.filter_button = gtk.Button(label="Filter") self.filter_button.connect("clicked", self.on_filter_button, None) self.filter_button.add_accelerator("clicked", self.accelg, ord("f"), \ gtk.gdk.CONTROL_MASK, \ accel_flags=gtk.ACCEL_VISIBLE) self.unfilter_button = gtk.Button(label="Unfilter") self.unfilter_button.connect("clicked", self.on_unfilter_button, None) self.unfilter_button.add_accelerator("clicked", self.accelg, ord("u"), \ gtk.gdk.CONTROL_MASK, \ accel_flags=gtk.ACCEL_VISIBLE) #pack_start(widget, expand, fill, padding search_buttons_hbox.pack_start(self.filter_button, arg1, False) search_buttons_hbox.pack_start(self.unfilter_button, arg1, False) number_label = gtk.Label("Images Found:") Entry_width = 100 self.num_found_entry = gtk.Entry() self.num_found_entry.set_max_length(10) self.num_found_entry.set_text("") self.num_found_entry.set_size_request(Entry_width,-1) self.num_found_entry.set_alignment(0.95) misc_hbox = gtk.HBox(False, 0) misc_hbox.pack_start(number_label, False) misc_hbox.pack_start(self.num_found_entry, False) search_buttons_hbox.pack_start(misc_hbox, arg1, False, 5) self.load_thumbs_button = gtk.Button(label="Load Thumbnails") self.load_thumbs_button.connect("clicked", self.on_load_thumbs_button, None) self.load_thumbs_button.add_accelerator("clicked", self.accelg, ord("l"), \ gtk.gdk.CONTROL_MASK, \ accel_flags=gtk.ACCEL_VISIBLE) #pack_start(widget, expand, fill, padding search_buttons_hbox.pack_start(self.load_thumbs_button, arg1, False) search_vbox.pack_start(search_buttons_hbox, False) #Need the main DB ListStore and TreeView here self._init_main_listview() search_vbox.pack_start(self.main_listview, True, True) search_hbox = gtk.HBox(homogeneous=False, spacing=0) search_hbox.pack_start(search_vbox, True, True) search_label = gtk.Label("Search") self.notebook.append_page(search_hbox, search_label) search_window.show() ###################################################### # # End search tab page # ###################################################### #bottom toolbar self.toolbar = gtk.Toolbar() self.toolbar.set_orientation(gtk.ORIENTATION_HORIZONTAL) self.toolbar.set_style(gtk.TOOLBAR_BOTH) self.toolbar.set_border_width(5) tool_hbox = gtk.HBox(False, 0) tool_hbox.pack_start(self.toolbar, True, True) iconp = gtk.Image() # icon widget iconp.set_from_file("prev_arrow.png") self.prev_button = gtk.ToolButton(icon_widget=iconp, label="Previous") self.prev_button.show() self.toolbar.insert(self.prev_button, 0) self.prev_button.connect("clicked", self.prev_image_method, None) self.prev_button.add_accelerator("clicked", self.accelg, ord("p"), \ 0, \ accel_flags=gtk.ACCEL_VISIBLE) iconn = gtk.Image() # icon widget iconn.set_from_file("next_arrow.png") self.next_button = gtk.ToolButton(icon_widget=iconn, label="Next") self.next_button.show() self.toolbar.insert(self.next_button, -1) self.next_button.connect("clicked", self.next_image_method, None) self.next_button.add_accelerator("clicked", self.accelg, ord("n"), \ 0, \ accel_flags=gtk.ACCEL_VISIBLE) icond = gtk.Image() # icon widget icond.set_from_file("delete_icon.png") self.delete_button = gtk.ToolButton(icon_widget=icond, label="Delete") self.delete_button.show() self.toolbar.insert(self.delete_button, -1) self.delete_button.connect("clicked", self.on_delete_button, None) self.delete_button.add_accelerator("clicked", self.accelg, ord("d"), \ gtk.gdk.CONTROL_MASK, \ accel_flags=gtk.ACCEL_VISIBLE) #Ratings ratings_label = gtk.Label("Ratings (stars)") ratings_vbox = gtk.VBox(False, 0) ratings_vbox.pack_start(ratings_label, False) self.ratings_entry = gtk.Entry() self.ratings_entry.set_max_length(9) self.ratings_entry.set_text("") self.ratings_entry.set_alignment(0.5) Entry_width = 50 self.ratings_entry.set_size_request(Entry_width,-1) ratings_vbox.pack_start(self.ratings_entry, False) #ratings_hbox = gtk.HBox(False, 0) ## self.no_stars_radio = gtk.RadioButton(label='Unrated') ## self.one_star_radio = gtk.RadioButton(group=self.no_stars_radio, ## label='1') ## self.two_stars_radio = gtk.RadioButton(group=self.no_stars_radio, \ ## label='2') ## self.three_stars_radio = gtk.RadioButton(group=self.no_stars_radio, \ ## label='3') ## self.four_stars_radio = gtk.RadioButton(group=self.no_stars_radio, \ ## label='4') ## self.five_stars_radio = gtk.RadioButton(group=self.no_stars_radio, \ ## label='5') ## self.ratings_radio_list = [self.no_stars_radio, \ ## self.one_star_radio, \ ## self.two_stars_radio, \ ## self.three_stars_radio, \ ## self.four_stars_radio, \ ## self.five_stars_radio] ## for i, radio in enumerate(self.ratings_radio_list): ## ratings_hbox.pack_start(radio, False, 0) ## ## radio.add_accelerator("clicked", self.accelg, ord('%i' % i), \ ## ## 0, \ ## ## accel_flags=gtk.ACCEL_VISIBLE) ## radio.connect("clicked", self.on_ratings_radio, i) ## #radio.connect("toggled", self.on_ratings_toggle, i) self.status_bar = gtk.Statusbar() tool_hbox.pack_start(self.status_bar, False)#True, True, 5) self.status_bar.set_size_request(250,-1) self.status_bar.show() self.cid = self.status_bar.get_context_id("photo_app") ## ratings_vbox.pack_start(ratings_hbox, False) ratings_vbox2 = gtk.VBox(False, 0) ratings_vbox2.pack_start(ratings_vbox, True, False, 5) tool_hbox.pack_start(ratings_vbox2, False, False, 5) self.main_vbox.pack_start(tool_hbox, False) #self.toolbar.append_space() # space after item #self.toolbar.set_style(gtk.TOOLBAR_ICONS) self.toolbar.set_style(gtk.TOOLBAR_BOTH) self.window.add(self.main_vbox) self.radio_active = True self.database_path = None self.saveattrs = ['database_path'] if os.path.exists(settings_path): self.load(settings_path) #print('self.database_path = %s' % self.database_path) if hasattr(self, 'db'): self.init_browsing() pn1 = self.notebook.get_current_page() self.notebook.show() self.window.set_size_request(1200,700) self.notebook.set_current_page(1) pn2 = self.notebook.get_current_page() #print('pn1 = %s' % pn1) #print('pn2 = %s' % pn2) self.window.show_all() self.notebook.next_page()