Remove _ in front of methods for consistency reasons.

pull/61/head
Christian T. Jacobs 2017-04-14 21:45:59 +01:00
rodzic f122e3cfde
commit 78033f9a01
6 zmienionych plików z 57 dodań i 57 usunięć

Wyświetl plik

@ -219,14 +219,14 @@ class ADIF:
logging.error("An error occurred when reading the ADIF file.")
logging.exception(e)
records = self._parse_adi(text)
records = self.parse_adi(text)
if(records == []):
logging.warning("No records found in the file. Empty file or wrong file type?")
return records
def _parse_adi(self, text):
def parse_adi(self, text):
""" Parse some raw text (defined in the 'text' argument) for ADIF field data.
:arg str text: The raw text from the ADIF file to parse.

Wyświetl plik

@ -54,7 +54,7 @@ class DXCluster:
self.builder.get_object("mitem_new").connect("activate", self.new_server)
self.builder.get_object("mitem_disconnect").connect("activate", self.telnet_disconnect)
self.builder.get_object("send").connect("clicked", self.telnet_send_command)
self.builder.get_object("command").connect("key-release-event", self._on_command_key_press)
self.builder.get_object("command").connect("key-release-event", self.on_command_key_press)
# Get the text renderer and its buffer.
self.renderer = self.builder.get_object("renderer")
@ -67,13 +67,13 @@ class DXCluster:
self.items["SEND"] = self.builder.get_object("send")
self.set_items_sensitive(True)
self._populate_bookmarks()
self.populate_bookmarks()
logging.debug("DX cluster ready!")
return
def _on_command_key_press(self, widget, event, data=None):
def on_command_key_press(self, widget, event, data=None):
""" If the Return key is pressed when the focus is on the command box, then send whatever command the user has entered. """
if(event.keyval == Gdk.KEY_Return):
self.telnet_send_command()
@ -150,7 +150,7 @@ class DXCluster:
with open(BOOKMARKS_FILE, 'w') as f:
config.write(f)
self._populate_bookmarks()
self.populate_bookmarks()
except IOError:
# Maybe the bookmarks file could not be written to?
@ -165,7 +165,7 @@ class DXCluster:
dialog.destroy()
return
def _populate_bookmarks(self):
def populate_bookmarks(self):
""" Populate the list of bookmarked Telnet servers in the menu. """
# Get the bookmarks submenu.
@ -257,7 +257,7 @@ class DXCluster:
self.set_items_sensitive(False)
self.check_io_event = GObject.timeout_add(1000, self._on_telnet_io)
self.check_io_event = GObject.timeout_add(1000, self.on_telnet_io)
return
@ -286,7 +286,7 @@ class DXCluster:
command.set_text("")
return
def _on_telnet_io(self):
def on_telnet_io(self):
""" Retrieve any new data from the Telnet server and print it out in the Gtk.TextView widget.
:returns: Always returns True to satisfy the GObject timer.
@ -346,7 +346,7 @@ class TestDXCluster(unittest.TestCase):
connection = telnetlib.Telnet("hello", "world")
connection.read_very_eager.return_value = b"Test message from the Telnet server."
self.dxcluster.connection = connection
result = self.dxcluster._on_telnet_io()
result = self.dxcluster.on_telnet_io()
assert(result)
if(__name__ == '__main__'):

Wyświetl plik

@ -140,14 +140,14 @@ class Logbook:
self.sorter = []
self.filter = []
self.summary = Summary(self.application)
self._create_dummy_page()
self.create_dummy_page()
# FIXME: This is an unfortunate work-around. If the area around the "+/New Log" button
# is clicked, PyQSO will change to an empty page. This signal is used to stop this from happening.
self.notebook.connect("switch-page", self._on_switch_page)
self.notebook.connect("switch-page", self.on_switch_page)
for i in range(len(self.logs)):
self._render_log(i)
self.render_log(i)
logging.debug("All logs rendered successfully.")
self.summary.update()
@ -228,7 +228,7 @@ class Logbook:
logging.debug("Already disconnected. Nothing to do here.")
return True
def _create_dummy_page(self):
def create_dummy_page(self):
""" Create a blank page in the Gtk.Notebook for the "+" (New Log) tab. """
blank_treeview = Gtk.TreeView()
@ -258,7 +258,7 @@ class Logbook:
self.notebook.set_current_page(0)
return
def _on_switch_page(self, widget, label, new_page):
def on_switch_page(self, widget, label, new_page):
""" Handle a tab/page change, and enable/disable the relevant Record-related buttons. """
if(new_page == self.notebook.get_n_pages()-1): # The last (right-most) tab is the "New Log" tab.
@ -309,8 +309,8 @@ class Logbook:
l.populate()
self.logs.append(l)
self._render_log(self.log_count-1)
self.update_summary()
self.render_log(self.log_count-1)
self.summary.update()
self.notebook.set_current_page(self.log_count)
return
@ -331,7 +331,7 @@ class Logbook:
else:
page = self.notebook.get_nth_page(page_index) # Gets the Gtk.VBox of the selected tab in the logbook
log_index = self._get_log_index(name=page.get_name())
log_index = self.get_log_index(name=page.get_name())
log = self.logs[log_index]
# We also need the page's index in order to remove it using remove_page below.
@ -362,7 +362,7 @@ class Logbook:
# And finally remove the tab in the Logbook
self.notebook.remove_page(page_index)
self.update_summary()
self.summary.update()
self.application.toolbox.awards.count(self)
return
@ -372,7 +372,7 @@ class Logbook:
self.filter[i].refilter()
return
def _filter_by_callsign(self, model, iter, data):
def filter_by_callsign(self, model, iter, data):
""" Filter all the logs in the logbook by the callsign field, based on a user-defined expression.
:arg Gtk.TreeModel model: The model used to filter the log data.
@ -392,14 +392,14 @@ class Logbook:
# Also, we could use value[:][0:len(callsign))] if we wanted to match from the very start of each callsign.
return callsign.upper() in value or callsign.lower() in value
def _render_log(self, index):
def render_log(self, index):
""" Render a Log in the Gtk.Notebook.
:arg int index: The index of the Log (in the list of Logs) to render.
"""
self.filter.append(self.logs[index].filter_new(root=None))
# Set the callsign column as the column we want to filter by
self.filter[index].set_visible_func(self._filter_by_callsign, data=None)
self.filter[index].set_visible_func(self.filter_by_callsign, data=None)
self.sorter.append(Gtk.TreeModelSort(model=self.filter[index]))
self.sorter[index].set_sort_column_id(0, Gtk.SortType.ASCENDING)
@ -471,7 +471,7 @@ class Logbook:
:arg int column_index: The index of the column to sort by.
"""
log_index = self._get_log_index()
log_index = self.get_log_index()
column = self.treeview[log_index].get_column(column_index)
if(AVAILABLE_FIELD_NAMES_ORDERED[column_index-1] == "QSO_DATE"):
@ -520,7 +520,7 @@ class Logbook:
page = self.notebook.get_nth_page(page_index) # Gets the Gtk.VBox of the selected tab in the logbook
old_log_name = page.get_name()
log_index = self._get_log_index(name=old_log_name)
log_index = self.get_log_index(name=old_log_name)
exists = True
ln = LogNameDialog(self.application, title="Rename Log", name=old_log_name)
@ -560,7 +560,7 @@ class Logbook:
# The number of logs will obviously stay the same, but
# we want to update the logbook's modification date.
self.update_summary()
self.summary.update()
return
@ -601,7 +601,7 @@ class Logbook:
if(self.log_name_exists(log_name)):
# Import into existing log
exists = True
l = self.logs[self._get_log_index(name=log_name)]
l = self.logs[self.get_log_index(name=log_name)]
response = question(parent=ln.dialog, message="Are you sure you want to import into an existing log?")
if(response == Gtk.ResponseType.YES):
break
@ -642,8 +642,8 @@ class Logbook:
if(not exists):
self.logs.append(l)
self._render_log(self.log_count-1)
self.update_summary()
self.render_log(self.log_count-1)
self.summary.update()
self.application.toolbox.awards.count(self)
return
@ -655,7 +655,7 @@ class Logbook:
logging.debug("No log currently selected!")
return
log_index = self._get_log_index()
log_index = self.get_log_index()
log = self.logs[log_index]
dialog = Gtk.FileChooserDialog("Export Log as ADIF",
@ -701,7 +701,7 @@ class Logbook:
logging.debug("No log currently selected!")
return
log_index = self._get_log_index()
log_index = self.get_log_index()
log = self.logs[log_index]
dialog = Gtk.FileChooserDialog("Export Log as Cabrillo",
@ -758,7 +758,7 @@ class Logbook:
if(page_index == 0): # If we are on the Summary page...
logging.debug("No log currently selected!")
return
log_index = self._get_log_index()
log_index = self.get_log_index()
log = self.logs[log_index]
records = log.get_all_records()
if(records is not None):
@ -772,7 +772,7 @@ class Logbook:
""" A callback function used to add a particular record/QSO. """
# Get the log index
try:
log_index = self._get_log_index()
log_index = self.get_log_index()
if(log_index is None):
raise ValueError("The log index could not be determined. Perhaps you tried adding a record when the Summary page was selected?")
except ValueError as e:
@ -823,7 +823,7 @@ class Logbook:
if(all_valid):
# All data has been validated, so we can go ahead and add the new record.
log.add_record(fields_and_data)
self.update_summary()
self.summary.update()
self.application.toolbox.awards.count(self)
# Select the new Record's row in the treeview.
record_count = log.record_count
@ -840,7 +840,7 @@ class Logbook:
# Get the log index
try:
log_index = self._get_log_index()
log_index = self.get_log_index()
if(log_index is None):
raise ValueError("The log index could not be determined. Perhaps you tried deleting a record when the Summary page was selected?")
except ValueError as e:
@ -864,7 +864,7 @@ class Logbook:
# Deletes the record with index 'row_index' from the Records list.
# 'iter' is needed to remove the record from the ListStore itself.
log.delete_record(row_index, iter=child_iter)
self.update_summary()
self.summary.update()
self.application.toolbox.awards.count(self)
return
@ -876,7 +876,7 @@ class Logbook:
# Get the log index
try:
log_index = self._get_log_index()
log_index = self.get_log_index()
if(log_index is None):
raise ValueError("The log index could not be determined. Perhaps you tried editing a record when the Summary page was selected?")
except ValueError as e:
@ -931,7 +931,7 @@ class Logbook:
# Update the record in the database and then in the ListStore.
# We add 1 onto the column_index here because we don't want to consider the index column.
log.edit_record(row_index, field_names[i], fields_and_data[field_names[i]], iter=child_iter, column_index=i+1)
self.update_summary()
self.summary.update()
self.application.toolbox.awards.count(self)
rd.dialog.destroy()
@ -942,7 +942,7 @@ class Logbook:
Detecting duplicate records is done based on the CALL, QSO_DATE, TIME_ON, FREQ, and MODE fields. """
logging.debug("Removing duplicate records...")
log_index = self._get_log_index()
log_index = self.get_log_index()
log = self.logs[log_index]
(number_of_duplicates, number_of_duplicates_removed) = log.remove_duplicates()
@ -987,7 +987,7 @@ class Logbook:
logging.exception(e) # Database error. PyQSO could not check if the log name exists.
return None
def _get_log_index(self, name=None):
def get_log_index(self, name=None):
""" Given the name of a log, return its index in the list of Log objects.
:arg str name: The name of the log. If None, use the name of the currently-selected log.

Wyświetl plik

@ -149,7 +149,7 @@ class GeneralPage:
self.sources["DEFAULT_LOGBOOK"].set_active(config.get(section, option) == "True")
else:
self.sources["DEFAULT_LOGBOOK"].set_active(False)
self.sources["DEFAULT_LOGBOOK"].connect("toggled", self._on_default_logbook_toggled)
self.sources["DEFAULT_LOGBOOK"].connect("toggled", self.on_default_logbook_toggled)
self.sources["DEFAULT_LOGBOOK_PATH"] = self.builder.get_object("general_default_logbook_entry")
(section, option) = ("general", "default_logbook")
@ -180,7 +180,7 @@ class GeneralPage:
self.sources["QTH_NAME"] = self.builder.get_object("general_qth_name_entry")
button = self.builder.get_object("general_qth_lookup")
button.connect("clicked", self._lookup_callback) # Uses geocoding to find the latitude-longitude coordinates.
button.connect("clicked", self.lookup_callback) # Uses geocoding to find the latitude-longitude coordinates.
self.sources["QTH_LATITUDE"] = self.builder.get_object("general_qth_coordinates_latitude_entry")
self.sources["QTH_LONGITUDE"] = self.builder.get_object("general_qth_coordinates_longitude_entry")
@ -223,14 +223,14 @@ class GeneralPage:
data["QTH_LONGITUDE"] = self.sources["QTH_LONGITUDE"].get_text()
return data
def _on_default_logbook_toggled(self, widget, data=None):
def on_default_logbook_toggled(self, widget, data=None):
if(widget.get_active()):
self.sources["DEFAULT_LOGBOOK_PATH"].set_sensitive(True)
else:
self.sources["DEFAULT_LOGBOOK_PATH"].set_sensitive(False)
return
def _on_show_qth_toggled(self, widget, data=None):
def on_show_qth_toggled(self, widget, data=None):
if(widget.get_active()):
self.sources["QTH_NAME"].set_sensitive(True)
self.sources["QTH_LATITUDE"].set_sensitive(True)
@ -241,7 +241,7 @@ class GeneralPage:
self.sources["QTH_LONGITUDE"].set_sensitive(False)
return
def _lookup_callback(self, widget=None):
def lookup_callback(self, widget=None):
""" Performs geocoding of the QTH location to obtain latitude-longitude coordinates. """
if(not have_geocoder):
logging.warning("Geocoder module could not be imported. Geocoding aborted.")
@ -334,7 +334,7 @@ class RecordsPage:
else:
mode = ""
self.sources["DEFAULT_MODE"].set_active(sorted(MODES.keys()).index(mode))
self.sources["DEFAULT_MODE"].connect("changed", self._on_mode_changed)
self.sources["DEFAULT_MODE"].connect("changed", self.on_mode_changed)
# Submode
self.sources["DEFAULT_SUBMODE"] = self.builder.get_object("default_values_submode_combo")
@ -405,7 +405,7 @@ class RecordsPage:
data["IGNORE_PREFIX_SUFFIX"] = self.sources["IGNORE_PREFIX_SUFFIX"].get_active()
return data
def _on_mode_changed(self, combo):
def on_mode_changed(self, combo):
""" If the MODE field has changed its value, then fill the SUBMODE field with all the available SUBMODE options for that new MODE. """
self.sources["DEFAULT_SUBMODE"].get_model().clear()
mode = combo.get_active_text()

Wyświetl plik

@ -59,7 +59,7 @@ class RecordDialog:
glade_file_path = os.path.join(os.path.realpath(os.path.dirname(__file__)), os.pardir, "res/pyqso.glade")
self.builder.add_objects_from_file(glade_file_path, ("record_dialog",))
self.dialog = self.builder.get_object("record_dialog")
self.builder.get_object("record_dialog").connect("key-release-event", self._on_key_release)
self.builder.get_object("record_dialog").connect("key-release-event", self.on_key_release)
# Set dialog title
if(index is not None):
@ -102,7 +102,7 @@ class RecordDialog:
for mode in sorted(MODES.keys()):
self.sources["MODE"].append_text(mode)
self.sources["MODE"].set_active(0) # Set an empty string as the default option.
self.sources["MODE"].connect("changed", self._on_mode_changed)
self.sources["MODE"].connect("changed", self.on_mode_changed)
# SUBMODE
self.sources["SUBMODE"] = self.builder.get_object("qso_submode_combo")
@ -225,17 +225,17 @@ class RecordDialog:
rig_model = config.get("hamlib", "rig_model")
rig_pathname = config.get("hamlib", "rig_pathname")
if(autofill):
self._hamlib_autofill(rig_model, rig_pathname)
self.hamlib_autofill(rig_model, rig_pathname)
# Do we want PyQSO to autocomplete the Band field based on the Frequency field?
(section, option) = ("records", "autocomplete_band")
if(have_config and config.has_option(section, option)):
autocomplete_band = (config.get(section, option) == "True")
if(autocomplete_band):
self.sources["FREQ"].connect("changed", self._autocomplete_band)
self.sources["FREQ"].connect("changed", self.autocomplete_band)
else:
# If no configuration file exists, autocomplete the Band field by default.
self.sources["FREQ"].connect("changed", self._autocomplete_band)
self.sources["FREQ"].connect("changed", self.autocomplete_band)
self.dialog.show_all()
@ -270,7 +270,7 @@ class RecordDialog:
else:
return self.sources[field_name].get_text()
def _on_mode_changed(self, combo):
def on_mode_changed(self, combo):
""" If the MODE field has changed its value, then fill the SUBMODE field with all the available SUBMODE options for that new MODE. """
self.sources["SUBMODE"].get_model().clear()
text = combo.get_active_text()
@ -278,14 +278,14 @@ class RecordDialog:
self.sources["SUBMODE"].append_text(submode)
return
def _on_key_release(self, widget, event):
def on_key_release(self, widget, event):
""" If the Return key is pressed, emit the "OK" response to record the QSO. """
child = widget.get_focus()
if(not(isinstance(child, Gtk.ToggleButton) or isinstance(child, Gtk.Button) or isinstance(child, Gtk.TextView)) and event.keyval == Gdk.KEY_Return):
self.dialog.emit('response', Gtk.ResponseType.OK)
return
def _autocomplete_band(self, widget=None):
def autocomplete_band(self, widget=None):
""" If a value for the Frequency is entered, this function autocompletes the Band field. """
frequency = self.sources["FREQ"].get_text()
@ -305,7 +305,7 @@ class RecordDialog:
self.sources["BAND"].set_active(0) # If we've reached this, then the frequency does not lie in any of the specified bands.
return
def _hamlib_autofill(self, rig_model, rig_pathname):
def hamlib_autofill(self, rig_model, rig_pathname):
""" Set the various fields using data from the radio via Hamlib.
:arg str rig_model: The model of the radio/rig.

Wyświetl plik

@ -45,7 +45,7 @@ class Toolbox:
self.grey_line = GreyLine(self.application)
self.awards = Awards(self.application)
self.tools.connect_after("switch-page", self._on_switch_page)
self.tools.connect_after("switch-page", self.on_switch_page)
logging.debug("Toolbox ready!")
@ -57,7 +57,7 @@ class Toolbox:
toolbox_frame.set_visible(not toolbox_frame.get_visible())
return
def _on_switch_page(self, widget, label, new_page):
def on_switch_page(self, widget, label, new_page):
""" Re-draw the Grey Line if the user switches to the grey line tab. """
if(widget.get_tab_label(label).get_text() == "Grey Line"):
self.grey_line.draw()