From 133699f93da3559a60730f2c31e9f296edc3991d Mon Sep 17 00:00:00 2001 From: Christian Jacobs Date: Sun, 24 Mar 2013 15:40:33 +0000 Subject: [PATCH] Changed the layout so a new Dialog appears when a user wants to add or edit a record. --- src/pyqso.py | 45 ++++--------------- src/{data_entry_panel.py => record_dialog.py} | 27 +++-------- src/toolbar.py | 1 - 3 files changed, 15 insertions(+), 58 deletions(-) rename src/{data_entry_panel.py => record_dialog.py} (67%) diff --git a/src/pyqso.py b/src/pyqso.py index a44458d..34ab932 100644 --- a/src/pyqso.py +++ b/src/pyqso.py @@ -26,6 +26,7 @@ import optparse from adif import * from logbook import * from menu import * +from toolbar import * from data_entry_panel import * # The PyQSO application class @@ -47,28 +48,21 @@ class PyQSO(Gtk.Window): # Create a Logbook so we can add/remove/edit Record objects self.logbook = Logbook() - # Set up menu bar and populate it + # Set up menu and tool bars menu = Menu(self, vbox_outer) - - # Under the menu, we want the data entry panel on the left and the logbook on the right. - hbox = Gtk.HBox() - vbox_outer.pack_start(hbox, True, True, 0) - - self.data_entry_panel = DataEntryPanel(self, hbox) - self.data_entry_panel.disable() + toolbar = Toolbar(self, vbox_outer) # Render the logbook self.treeview = Gtk.TreeView(self.logbook) self.treeview.set_grid_lines(Gtk.TreeViewGridLines.BOTH) self.treeselection = self.treeview.get_selection() self.treeselection.set_mode(Gtk.SelectionMode.SINGLE) - self.treeselection.connect("changed", self.set_data_entry_panel_callback) # Allow the Logbook to be scrolled up/down sw = Gtk.ScrolledWindow() sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN) sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) sw.add(self.treeview) - hbox.pack_start(sw, True, True, 0) + vbox_outer.pack_start(sw, True, True, 0) # The first column of the logbook will always be the unique record index. # Let's append this separately to the field names. @@ -87,17 +81,18 @@ class PyQSO(Gtk.Window): column.set_min_width(50) self.treeview.append_column(column) + self.statusbar = Gtk.Statusbar() + context_id = self.statusbar.get_context_id("Status") + vbox_outer.pack_start(self.statusbar, False, False, 0) + self.show_all() return def add_record_callback(self, widget): self.logbook.add_record() - self.data_entry_panel.enable() - # Select the new Record's row. self.treeselection.select_path(self.logbook.get_number_of_records()-1) - return def delete_record_callback(self, widget): @@ -119,9 +114,6 @@ class PyQSO(Gtk.Window): dialog.destroy() - if(self.logbook.get_number_of_records() == 0): - self.data_entry_panel.disable() - return def update_record_callback(self, widget): @@ -139,7 +131,7 @@ class PyQSO(Gtk.Window): field_names = self.logbook.SELECTED_FIELD_NAMES_TYPES.keys() for column_index in range(0, len(field_names)): - data = self.data_entry_panel.get_data(field_names[column_index]) + #data = self.data_entry_panel.get_data(field_names[column_index]) # First update the Record object... # (we add 1 onto the column_index here because we don't want to consider the index column) column_name = self.treeview.get_column(column_index+1).get_title() @@ -149,25 +141,6 @@ class PyQSO(Gtk.Window): return - def set_data_entry_panel_callback(self, widget): - # Get the selected row in the logbook - (model, path) = self.treeselection.get_selected_rows() - try: - iter = model.get_iter(path[0]) - index = model.get_value(iter,0) - except IndexError: - logging.debug("Could not find the selected row's index!") - return - - if(index > self.logbook.get_number_of_records()-1): - index = self.logbook.get_number_of_records()-1 - - record = self.logbook.get_record(index) - field_names = self.logbook.SELECTED_FIELD_NAMES_TYPES.keys() - for i in range(0, len(field_names)): - self.data_entry_panel.set_data(field_names[i], record.get_data(field_names[i])) - return - def show_about(self, widget): about = Gtk.AboutDialog() about.set_program_name("PyQSO") diff --git a/src/data_entry_panel.py b/src/record_dialog.py similarity index 67% rename from src/data_entry_panel.py rename to src/record_dialog.py index f543f53..cb4c161 100644 --- a/src/data_entry_panel.py +++ b/src/record_dialog.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# File: data_entry_panel.py +# File: record_dialog.py # Copyright (C) 2013 Christian Jacobs. @@ -23,12 +23,12 @@ import logging from adif import AVAILABLE_FIELD_NAMES_TYPES -class DataEntryPanel(Gtk.VBox): +class RecordDialog(Gtk.Dialog): - def __init__(self, parent, hbox_parent): - logging.debug("New DataEntryPanel instance created!") + def __init__(self, parent): + logging.debug("New RecordDialog instance created!") - Gtk.VBox.__init__(self, spacing=2) + Gtk.Window.__init__(self, title="Update Record") # Create label:entry pairs and store them in a dictionary self.sources = {} @@ -44,7 +44,7 @@ class DataEntryPanel(Gtk.VBox): self.update.connect("clicked", parent.update_record_callback) self.pack_start(self.update, expand=False, fill=True, padding=2) - hbox_parent.pack_start(self, False, False, 0) + #hbox_parent.pack_start(self, False, False, 0) return @@ -58,19 +58,4 @@ class DataEntryPanel(Gtk.VBox): self.sources[field_name].set_text(data) return - def enable(self): - # Activates all Entry widgets and the update button - keys = self.sources.keys() - for i in range(0, len(keys)): - self.sources[keys[i]].set_property("editable", True) - self.sources[keys[i]].set_can_focus(True) - self.update.set_sensitive(True) - - def disable(self): - # Deactivates all Entry widgets and the update button - keys = self.sources.keys() - for i in range(0, len(keys)): - self.sources[keys[i]].set_property("editable", False) - self.sources[keys[i]].set_can_focus(False) - self.update.set_sensitive(False) diff --git a/src/toolbar.py b/src/toolbar.py index d013e61..b5d6cfb 100644 --- a/src/toolbar.py +++ b/src/toolbar.py @@ -21,7 +21,6 @@ from gi.repository import Gtk, GObject import logging - class Toolbar(Gtk.HBox): def __init__(self, parent, vbox_parent):