diff --git a/bin/pyqso b/bin/pyqso index 0a5876a..bb5b48d 100755 --- a/bin/pyqso +++ b/bin/pyqso @@ -78,7 +78,7 @@ class PyQSO: # Check that the configuration file actually exists (and is readable) # otherwise, we will resort to the defaults. - have_config = (config.read(config_directory + "/preferences.ini") != []) + have_config = (config.read(os.path.join(config_directory, "preferences.ini")) != []) # Kills the application if the close button is clicked on the main window itself. self.window.connect("delete-event", Gtk.main_quit) diff --git a/pyqso/awards.py b/pyqso/awards.py index 2d6be85..ab5f405 100644 --- a/pyqso/awards.py +++ b/pyqso/awards.py @@ -68,8 +68,6 @@ class Awards: self.count(self.application.logbook) - return - def count(self, logbook): """ Update the table for progress tracking. @@ -92,13 +90,13 @@ class Awards: try: records = log.records for r in records: - if(r["BAND"] is not None and r["MODE"] is not None): - if(r["BAND"].lower() in self.bands and r["MODE"] != ""): + if r["BAND"] is not None and r["MODE"] is not None: + if r["BAND"].lower() in self.bands and r["MODE"] != "": band = self.bands.index(r["BAND"].lower()) # Phone modes - if(r["MODE"].upper() in ["FM", "AM", "SSB", "SSTV"]): + if r["MODE"].upper() in ["FM", "AM", "SSB", "SSTV"]: count[0][band] += 1 - elif(r["MODE"].upper() == "CW"): + elif r["MODE"].upper() == "CW": count[1][band] += 1 else: # FIXME: This assumes that all the other modes in the ADIF list are digital modes. Is this the case? diff --git a/pyqso/blank.py b/pyqso/blank.py index dd696f5..7688778 100644 --- a/pyqso/blank.py +++ b/pyqso/blank.py @@ -58,5 +58,3 @@ class Blank(object): self.application.logbook.notebook.insert_page(page, tab, 1) self.application.logbook.notebook.set_current_page(0) - - return diff --git a/pyqso/calendar_dialog.py b/pyqso/calendar_dialog.py index 40159e7..901a155 100644 --- a/pyqso/calendar_dialog.py +++ b/pyqso/calendar_dialog.py @@ -38,8 +38,6 @@ class CalendarDialog: self.calendar = self.builder.get_object("calendar") self.dialog.show_all() - return - @property def date(self): """ Return the date from the Gtk.Calendar widget in YYYYMMDD format. @@ -50,11 +48,11 @@ class CalendarDialog: logging.debug("Retrieving the date from the calendar...") (year, month, day) = self.calendar.get_date() # If necessary, add on leading zeros so the YYYYMMDD format is followed. - if(month + 1 < 10): + if month + 1 < 10: month = "0" + str(month + 1) # Note: the months start from an index of 0 when retrieved from the calendar widget. else: month += 1 - if(day < 10): + if day < 10: day = "0" + str(day) date = str(year) + str(month) + str(day) return date diff --git a/pyqso/callsign_lookup.py b/pyqso/callsign_lookup.py index a06fe1a..0fad5f5 100644 --- a/pyqso/callsign_lookup.py +++ b/pyqso/callsign_lookup.py @@ -43,7 +43,6 @@ class CallsignLookupQRZ: self.parent = parent self.connection = None self.session_key = None - return def connect(self, username, password): """ Initiate a session with the qrz.com server. Hopefully this will provide a session key. @@ -172,7 +171,6 @@ class CallsignLookupHamQTH: self.parent = parent self.connection = None self.session_id = None - return def connect(self, username, password): """ Initiate a session with the hamqth.com server. Hopefully this will provide a session key. diff --git a/pyqso/compare.py b/pyqso/compare.py index 8f532e1..94ee4b8 100644 --- a/pyqso/compare.py +++ b/pyqso/compare.py @@ -32,13 +32,13 @@ def compare_date_and_time(model, row1, row2, user_data): date2 = model.get_value(row2, user_data[0]) time1 = model.get_value(row1, user_data[1]) time2 = model.get_value(row2, user_data[1]) - if(date1 < date2): + if date1 < date2: return -1 - elif(date1 == date2): + elif date1 == date2: # If the dates are the same, then let's also sort by time. - if(time1 > time2): + if time1 > time2: return 1 - elif(time1 == time2): + elif time1 == time2: return 0 else: return -1 @@ -65,9 +65,9 @@ def compare_default(model, row1, row2, user_data): value1 = model.get_value(row1, user_data) value2 = model.get_value(row2, user_data) - if(value1 < value2): + if value1 < value2: return -1 - elif(value1 == value2): + elif value1 == value2: return 0 else: return 1 diff --git a/pyqso/log_name_dialog.py b/pyqso/log_name_dialog.py index dbd00eb..8ce224e 100644 --- a/pyqso/log_name_dialog.py +++ b/pyqso/log_name_dialog.py @@ -40,13 +40,13 @@ class LogNameDialog: self.builder.add_objects_from_file(glade_file_path, ("log_name_dialog",)) self.dialog = self.builder.get_object("log_name_dialog") - if(title is None): - self.dialog.set_title("New Log") - else: + if title: self.dialog.set_title(title) + else: + self.dialog.set_title("New Log") self.entry = self.builder.get_object("log_name_entry") - if(name is not None): + if name: self.entry.set_text(name) self.dialog.show_all() diff --git a/pyqso/menu.py b/pyqso/menu.py index fceeb83..5641f6f 100644 --- a/pyqso/menu.py +++ b/pyqso/menu.py @@ -114,7 +114,7 @@ class Menu: config = configparser.ConfigParser() have_config = (config.read(os.path.expanduser('~/.config/pyqso/preferences.ini')) != []) (section, option) = ("general", "show_toolbox") - if(have_config and config.has_option(section, option)): + if have_config and config.has_option(section, option): self.items["TOOLBOX"].set_active(config.getboolean(section, option)) else: self.items["TOOLBOX"].set_active(False) # Don't show the toolbox by default @@ -128,8 +128,6 @@ class Menu: self.set_log_items_sensitive(False) self.set_record_items_sensitive(False) - return - def set_logbook_item_sensitive(self, sensitive): """ Enable/disable logbook-related menu items. @@ -139,7 +137,6 @@ class Menu: self.items["NEW_LOGBOOK"].set_sensitive(sensitive) self.items["OPEN_LOGBOOK"].set_sensitive(sensitive) self.items["CLOSE_LOGBOOK"].set_sensitive(not sensitive) - return def set_log_items_sensitive(self, sensitive): """ Enable/disable log-related menu items. @@ -149,7 +146,6 @@ class Menu: for item_name in ["NEW_LOG", "DELETE_LOG", "RENAME_LOG", "IMPORT_LOG", "EXPORT_LOG_ADIF", "EXPORT_LOG_CABRILLO", "PRINT_LOG"]: self.items[item_name].set_sensitive(sensitive) - return def set_record_items_sensitive(self, sensitive): """ Enable/disable record-related menu items. @@ -159,4 +155,3 @@ class Menu: for item_name in ["ADD_RECORD", "EDIT_RECORD", "DELETE_RECORD", "REMOVE_DUPLICATES", "RECORD_COUNT"]: self.items[item_name].set_sensitive(sensitive) - return diff --git a/pyqso/popup.py b/pyqso/popup.py index d44e81b..fb58398 100644 --- a/pyqso/popup.py +++ b/pyqso/popup.py @@ -42,5 +42,3 @@ class Popup: self.items["PASTE"] = self.builder.get_object("mitem_paste") self.items["PASTE"].connect("activate", self.application.logbook.paste_callback) - - return diff --git a/pyqso/preferences_dialog.py b/pyqso/preferences_dialog.py index 2fc8bf2..46536e1 100644 --- a/pyqso/preferences_dialog.py +++ b/pyqso/preferences_dialog.py @@ -70,11 +70,8 @@ class PreferencesDialog: self.world_map = WorldMapPage(self.dialog, self.builder) self.dialog.show_all() - logging.debug("Preferences dialog ready!") - return - def commit(self): """ Commit the user preferences to the configuration file. """ @@ -116,8 +113,6 @@ class PreferencesDialog: with open(os.path.expanduser(PREFERENCES_FILE), 'w') as f: config.write(f) - return - class GeneralPage: @@ -183,8 +178,6 @@ class GeneralPage: else: self.sources["KEEP_OPEN"].set_active(False) - return - @property def data(self): """ User preferences regarding General settings. """ @@ -203,7 +196,6 @@ class GeneralPage: else: self.sources["DEFAULT_LOGBOOK_PATH"].set_sensitive(False) self.builder.get_object("general_default_logbook_button").set_sensitive(False) - return def on_default_logbook_clicked(self, widget): """ Let the user select the default logbook file via a file chooser dialog, @@ -219,7 +211,6 @@ class GeneralPage: path = dialog.get_filename() self.sources["DEFAULT_LOGBOOK_PATH"].set_text(path) dialog.destroy() - return class ViewPage: @@ -244,8 +235,6 @@ class ViewPage: else: self.sources[field_name].set_active(True) - return - @property def data(self): """ User preferences regarding View settings. """ @@ -360,8 +349,6 @@ class RecordsPage: else: self.sources["IGNORE_PREFIX_SUFFIX"].set_active(True) - return - @property def data(self): """ User preferences regarding Records settings. """ @@ -387,7 +374,6 @@ class RecordsPage: for submode in MODES[mode]: self.sources["DEFAULT_SUBMODE"].append_text(submode) self.sources["DEFAULT_SUBMODE"].set_active(MODES[mode].index("")) - return class ImportExportPage: @@ -414,8 +400,6 @@ class ImportExportPage: else: self.sources["MERGE_COMMENT"].set_active(False) - return - @property def data(self): """ User preferences regarding Import/Export settings. """ @@ -472,8 +456,6 @@ class HamlibPage: if(have_config and config.has_option(section, option)): self.sources["RIG_PATHNAME"].set_text(config.get(section, option)) - return - @property def data(self): """ User preferences regarding Hamlib settings. """ @@ -554,8 +536,6 @@ class WorldMapPage: else: self.sources["SHADE_WORKED_GRID_SQUARES"].set_active(False) - return - @property def data(self): """ User preferences regarding World Map settings. """ @@ -579,7 +559,6 @@ class WorldMapPage: self.sources["QTH_LATITUDE"].set_sensitive(False) self.sources["QTH_LONGITUDE"].set_sensitive(False) self.builder.get_object("world_map_qth_lookup").set_sensitive(False) - return def lookup_callback(self, widget=None): """ Perform geocoding of the QTH location to obtain latitude-longitude coordinates. """ diff --git a/pyqso/printer.py b/pyqso/printer.py index 117a693..4416b10 100644 --- a/pyqso/printer.py +++ b/pyqso/printer.py @@ -45,8 +45,6 @@ class Printer(object): self.operation.connect("begin_print", self.begin_print) self.operation.connect("draw_page", self.draw_page) - return - def print_records(self, records, title=None): """ Perform the print operation. @@ -57,7 +55,7 @@ class Printer(object): """ # Add the title, if given. - if(title): + if title: self.text_to_print = title + "\n\n" else: self.text_to_print = "" @@ -70,9 +68,8 @@ class Printer(object): self.text_to_print += line_format % (str(r["id"]), str(r["CALL"]), str(r["QSO_DATE"]), str(r["TIME_ON"]), str(r["FREQ"]), str(r["MODE"]), str(r["RST_SENT"]), str(r["RST_RCVD"])) result = self.operation.run(self.action, parent=self.application.window) - if(result == Gtk.PrintOperationResult.ERROR): + if result == Gtk.PrintOperationResult.ERROR: error(parent=self.application.window, message="Unable to print the log.") - return result def begin_print(self, operation, context): @@ -95,14 +92,13 @@ class Printer(object): ink_rectangle, logical_rectangle = layout_line.get_pixel_extents() self.line_height = logical_rectangle.height + 3.0 page_height += self.line_height - if((page_height + 2*self.line_height) >= height): + if (page_height + 2*self.line_height) >= height: # Go on to the next page. number_of_pages += 1 page_height = 0.0 operation.set_n_pages(number_of_pages) logging.debug("Printing %d pages..." % number_of_pages) self.text_to_print = self.text_to_print.split("\n") - return def draw_page(self, operation, context, page_number): """ Render the QSO details on the page. @@ -124,9 +120,7 @@ class Printer(object): PangoCairo.update_layout(cr, layout) PangoCairo.show_layout(cr, layout) current_line_number += 1 - if((current_line_number+1)*self.line_height >= context.get_height()): + if (current_line_number+1)*self.line_height >= context.get_height(): for j in range(0, current_line_number-1): self.text_to_print.pop(0) # Remove what has been printed already before draw_page is called again. break - - return diff --git a/pyqso/summary.py b/pyqso/summary.py index a87b7a3..2176598 100644 --- a/pyqso/summary.py +++ b/pyqso/summary.py @@ -66,8 +66,8 @@ class Summary(object): config = configparser.ConfigParser() have_config = (config.read(expanduser('~/.config/pyqso/preferences.ini')) != []) (section, option) = ("general", "show_yearly_statistics") - if(have_config and config.has_option(section, option)): - if(config.getboolean("general", "show_yearly_statistics") and have_matplotlib): + if have_config and config.has_option(section, option): + if config.getboolean("general", "show_yearly_statistics") and have_matplotlib: hbox = Gtk.HBox() label = Gtk.Label(label="Display statistics for year: ", halign=Gtk.Align.START) hbox.pack_start(label, False, False, 6) @@ -98,8 +98,6 @@ class Summary(object): self.logbook.notebook.insert_page(self.summary_page, tab, 0) # Append as a new tab self.logbook.notebook.show_all() - return - def on_year_changed(self, combo): """ Re-plot the statistics for the year selected by the user. """ @@ -142,8 +140,6 @@ class Summary(object): self.items["YEARLY_STATISTICS"].canvas.draw() - return - def get_year_bounds(self): """ Find the years of the oldest and newest QSOs across all logs in the logbook. @@ -235,4 +231,3 @@ class Summary(object): self.items["DATE_MODIFIED"].set_label(str(t)) except (IOError, OSError) as e: logging.exception(e) - return diff --git a/pyqso/telnet_connection_dialog.py b/pyqso/telnet_connection_dialog.py index 4105dec..86fa7f6 100644 --- a/pyqso/telnet_connection_dialog.py +++ b/pyqso/telnet_connection_dialog.py @@ -42,8 +42,6 @@ class TelnetConnectionDialog: self.dialog.show_all() - return - @property def host(self): """ Return the Telnet server's host name. diff --git a/pyqso/toolbar.py b/pyqso/toolbar.py index 9785ec5..af5d8ae 100644 --- a/pyqso/toolbar.py +++ b/pyqso/toolbar.py @@ -66,8 +66,6 @@ class Toolbar: self.set_record_buttons_sensitive(False) self.filter_source.set_sensitive(False) - return - def set_logbook_button_sensitive(self, sensitive): """ Enable/disable logbook-related toolbar items. @@ -76,7 +74,6 @@ class Toolbar: self.buttons["NEW_LOGBOOK"].set_sensitive(sensitive) self.buttons["OPEN_LOGBOOK"].set_sensitive(sensitive) self.buttons["CLOSE_LOGBOOK"].set_sensitive(not sensitive) - return def set_record_buttons_sensitive(self, sensitive): """ Enable/disable record-related toolbar items. @@ -85,4 +82,3 @@ class Toolbar: """ for button_name in ["ADD_RECORD", "EDIT_RECORD", "DELETE_RECORD"]: self.buttons[button_name].set_sensitive(sensitive) - return diff --git a/pyqso/toolbox.py b/pyqso/toolbox.py index 154a276..748ec6f 100644 --- a/pyqso/toolbox.py +++ b/pyqso/toolbox.py @@ -43,16 +43,12 @@ class Toolbox: self.tools.connect_after("switch-page", self.on_switch_page) - return - def toggle_visible_callback(self, widget=None): """ Show/hide the toolbox. """ toolbox_frame = self.builder.get_object("toolbox") toolbox_frame.set_visible(not toolbox_frame.get_visible()) - return def on_switch_page(self, widget, label, new_page): """ Re-draw the WorldMap if the user switches to the World Map tab. """ - if(widget.get_tab_label(label).get_text() == "World Map"): + if widget.get_tab_label(label).get_text() == "World Map": self.world_map.draw() - return diff --git a/pyqso/world_map.py b/pyqso/world_map.py index ddf694d..0440e26 100644 --- a/pyqso/world_map.py +++ b/pyqso/world_map.py @@ -49,7 +49,7 @@ except ImportError: logging.warning("Could not import the geocoder module!") have_geocoder = False -if(have_necessary_modules): +if have_necessary_modules: class NavigationToolbar(NavigationToolbar2GTK3): """ Navigation tools for the World Map. """ # Only include a subset of the tools. @@ -71,7 +71,6 @@ class Point: self.latitude = latitude self.longitude = longitude self.style = style - return class Maidenhead: @@ -81,7 +80,6 @@ class Maidenhead: def __init__(self): self.upper = "ABCDEFGHIJKLMNOPQR" self.lower = "abcdefghijklmnopqrstuvwx" - return def ll2gs(self, latitude, longitude, subsquare=False): """ Convert latitude-longitude coordinates to a Maidenhead grid square locator. @@ -101,7 +99,7 @@ class Maidenhead: square_latitude = int(adjusted_latitude % 10) square_longitude = int((adjusted_longitude/2) % 10) - if(subsquare): + if subsquare: adjusted_latitude_remainder = (adjusted_latitude - int(adjusted_latitude)) * 60 adjusted_longitude_remainder = ((adjusted_longitude) - int(adjusted_longitude/2)*2) * 60 subsquare_latitude = self.lower[int(adjusted_latitude_remainder/2.5)] @@ -120,13 +118,13 @@ class Maidenhead: """ m = re.match(r"^[A-X][A-X][0-9][0-9]$", grid_square) - if(m): + if m: gs = m.group(0) latitude = self.latitude4(gs)+0.5 longitude = self.longitude4(gs)+1.0 else: m = re.match(r"^[A-X][A-X][0-9][0-9][a-x][a-x]$", grid_square) - if(m): + if m: gs = m.group(0) latitude = self.latitude4(gs) + (1.0/60.0)*2.5*(ord(gs[5])-ord("a")+0.5) longitude = self.longitude4(gs) + (1.0/60.0)*5*(ord(gs[4])-ord("a")+0.5) @@ -157,7 +155,7 @@ class WorldMap: self.builder = self.application.builder self.points = [] - if(have_necessary_modules): + if have_necessary_modules: self.fig = matplotlib.figure.Figure() self.canvas = FigureCanvas(self.fig) # For embedding in the Gtk application self.builder.get_object("world_map").pack_start(self.canvas, True, True, 0) @@ -169,8 +167,8 @@ class WorldMap: config = configparser.ConfigParser() have_config = (config.read(expanduser('~/.config/pyqso/preferences.ini')) != []) (section, option) = ("world_map", "show_qth") - if(have_config and config.has_option(section, option)): - if(config.getboolean(section, option)): + if have_config and config.has_option(section, option): + if config.getboolean(section, option): try: qth_name = config.get("world_map", "qth_name") qth_latitude = float(config.get("world_map", "qth_latitude")) @@ -184,18 +182,15 @@ class WorldMap: self.show_grid_squares = False self.shade_worked_grid_squares = False (section, option) = ("world_map", "show_grid_squares") - if(have_config and config.has_option(section, option)): + if have_config and config.has_option(section, option): self.show_grid_squares = config.getboolean(section, option) (section, option) = ("world_map", "shade_worked_grid_squares") - if(have_config and config.has_option(section, option)): + if have_config and config.has_option(section, option): self.shade_worked_grid_squares = config.getboolean(section, option) self.builder.get_object("world_map").show_all() - logging.debug("World map ready!") - return - def add_point(self, name, latitude, longitude, style="yo"): """ Add a point and re-draw the map. @@ -207,7 +202,6 @@ class WorldMap: p = Point(name, latitude, longitude, style) self.points.append(p) self.draw() - return def pinpoint(self, r): """ Pinpoint the location of a QSO on the world map. @@ -215,13 +209,13 @@ class WorldMap: :arg r: The QSO record containing the location to pinpoint. """ - if(have_geocoder): + if have_geocoder: callsign = r["CALL"] gridsquare = r["GRIDSQUARE"] country = r["COUNTRY"] # Get the latitude-longitude coordinates. Use any GRIDSQUARE information first since this is likely to be more accurate than the COUNTRY field. - if(gridsquare): + if gridsquare: try: latitude, longitude = self.maidenhead.gs2ll(gridsquare) logging.debug("QTH coordinates found: (%s, %s)", str(latitude), str(longitude)) @@ -230,7 +224,7 @@ class WorldMap: except ValueError: logging.exception("Unable to lookup QTH coordinates.") - if(country): + if country: try: g = geocoder.google(country) latitude, longitude = g.latlng @@ -242,8 +236,6 @@ class WorldMap: except Exception: logging.exception("Unable to lookup QTH coordinates. Check connection to the internets? Lookup limit reached?") - return - def get_worked_grid_squares(self, logbook): """ Get the array of worked grid squares. @@ -258,7 +250,7 @@ class WorldMap: try: records = log.records for r in records: - if(r["GRIDSQUARE"]): + if r["GRIDSQUARE"]: grid_square = r["GRIDSQUARE"][0:2].upper() # Only consider the field value (e.g. IO). worked_grid_squares[self.maidenhead.upper.index(grid_square[1]), self.maidenhead.upper.index(grid_square[0])] = True @@ -275,10 +267,10 @@ class WorldMap: :rtype: bool """ - if(have_necessary_modules): + if have_necessary_modules: toolbox = self.builder.get_object("toolbox") tools = self.builder.get_object("tools") - if(tools.get_current_page() != 1 or not toolbox.get_visible()): + if tools.get_current_page() != 1 or not toolbox.get_visible(): # Don't re-draw if the world map is not visible. return True # We need to return True in case this is method was called by a timer event. else: @@ -332,7 +324,7 @@ class WorldMap: ax.fill(x, y, transform=rotated_pole, color="black", alpha=0.5) # Plot points on the map. - if(self.points): + if self.points: logging.debug("Plotting QTHs on the map...") for p in self.points: ax.plot(p.longitude, p.latitude, p.style, transform=cartopy.crs.PlateCarree()) @@ -342,8 +334,8 @@ class WorldMap: # Draw Maidenhead grid squares and shade in the worked squares. x = numpy.linspace(-180, 180, len(list(self.maidenhead.upper))+1) y = numpy.linspace(-90, 90, len(list(self.maidenhead.upper))+1) - if(self.show_grid_squares): - if(self.shade_worked_grid_squares): + if self.show_grid_squares: + if self.shade_worked_grid_squares: worked_grid_squares = self.get_worked_grid_squares(self.application.logbook) masked = numpy.ma.masked_array(worked_grid_squares, worked_grid_squares == 0) else: