Skip to content

Commit

Permalink
Refactor code before release:
Browse files Browse the repository at this point in the history
Remove warnings
Remove unused imports
Remove prints
Remove commented code
Remove unused code
Manage empty lines
  • Loading branch information
daviderill committed Feb 14, 2017
1 parent 761f786 commit 9a03802
Show file tree
Hide file tree
Showing 21 changed files with 35 additions and 88 deletions.
4 changes: 2 additions & 2 deletions actions/ed.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def ed_search_plus(self):
try:
if self.search_plus is not None:
self.search_plus.dlg.setVisible(True)
except RuntimeError as e:
print "Error ed_search_plus: "+str(e)
except RuntimeError :
pass


def ed_check(self):
Expand Down
10 changes: 3 additions & 7 deletions actions/mg.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ def mg_arc_topo_repair_accept(self):
sql = "SELECT "+self.schema_name+".gw_fct_anl_node_sink();"
self.controller.execute_sql(sql)

# Show message and close the dialog
#message = "Selected functions have been executed"
#self.controller.show_info(message, context_name='ui_message')
# Close the dialog
self.close_dialog()

# Refresh map canvas
Expand Down Expand Up @@ -320,9 +318,7 @@ def mg_go2epa_accept(self):
self.gsw_settings.setValue('FILE_RPT', self.file_rpt)
self.gsw_settings.setValue('PROJECT_NAME', self.project_name)

# Show message and close form
# message = "Values has been updated"
# self.controller.show_info(message, context_name='ui_message')
# Close form
self.close_dialog(self.dlg)


Expand Down Expand Up @@ -550,7 +546,7 @@ def mg_change_elem_type_accept(self):
message = "Node type has been update!"
self.controller.show_info(message, context_name='ui_message' )

# Close dialog
# Close form
self.close_dialog()


Expand Down
5 changes: 1 addition & 4 deletions controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,9 @@ def check_action(self, check=True, index=1):
key = index
if type(index) is int:
key = str(index).zfill(2)
print key
if key in self.actions:
action = self.actions[key]
action.setChecked(check)
else:
print "not found: "+str(index)
action.setChecked(check)


def set_database_connection(self):
Expand Down
10 changes: 4 additions & 6 deletions giswater.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,6 @@ def set_map_tool(self, map_tool_name):
map_tool.set_controller(self.controller)
if map_tool_name == 'mg_extract_raster_value':
map_tool.set_config_action(self.actions['99'])
else:
print "key not found: "+map_tool_name


def set_search_plus(self):
Expand Down Expand Up @@ -576,10 +574,10 @@ def current_layer_changed(self, layer):
index_action = str(list_index_action)
if index_action != '-1' and str(index_action) in self.actions:
self.actions[index_action].setEnabled(True)
except AttributeError, e:
print "current_layer_changed: "+str(e)
except KeyError, e:
print "current_layer_changed: "+str(e)
except AttributeError:
pass
except KeyError:
pass


def custom_enable_actions(self):
Expand Down
5 changes: 2 additions & 3 deletions map_tools/connec.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def canvasMoveEvent(self, event):

# Plugin reloader bug, MapTool should be deactivated
if not hasattr(Qt, 'LeftButton'):
print "Plugin loader bug"
self.iface.actionPan().trigger()
return

Expand All @@ -100,7 +99,7 @@ def canvasMoveEvent(self, event):
eventPoint = QPoint(x, y)

# Snapping
(retval, result) = self.snapper.snapToBackgroundLayers(eventPoint) # @UnusedVariable
(retval, result) = self.snapper.snapToBackgroundLayers(eventPoint) #@UnusedVariable

# That's the snapped point
if result <> []:
Expand All @@ -120,7 +119,7 @@ def canvasMoveEvent(self, event):
break


def canvasPressEvent(self, event):
def canvasPressEvent(self, event): #@UnusedVariable

self.selectRect.setRect(0, 0, 0, 0)
self.rubberBand.reset()
Expand Down
10 changes: 3 additions & 7 deletions map_tools/delete_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ def canvasMoveEvent(self, event):
# Plugin reloader bug, MapTool should be deactivated
try:
eventPoint = QPoint(x, y)
except(TypeError,KeyError) as e:
print "Plugin loader bug"
except(TypeError,KeyError):
self.iface.actionPan().trigger()
return

Expand Down Expand Up @@ -106,11 +105,8 @@ def canvasReleaseEvent(self, event):

if snapPoint.layer.name() == self.layer_node.name():
# Get the point
point = QgsPoint(result[0].snappedVertex)

snappFeat = next(
result[0].layer.getFeatures(QgsFeatureRequest().setFilterFid(result[0].snappedAtGeometry)))

point = QgsPoint(result[0].snappedVertex) #@UnusedVariable
snappFeat = next(result[0].layer.getFeatures(QgsFeatureRequest().setFilterFid(result[0].snappedAtGeometry)))
break

if snappFeat is not None:
Expand Down
4 changes: 1 addition & 3 deletions map_tools/extract_raster_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,8 @@ def canvasMoveEvent(self, event):
if self.vectorLayer is None:
return


# Plugin reloader bug, MapTool should be deactivated
if not hasattr(Qt, 'LeftButton'):
print "Plugin loader bug"
self.iface.actionPan().trigger()
return

Expand Down Expand Up @@ -132,7 +130,7 @@ def canvasMoveEvent(self, event):
break


def canvasPressEvent(self, event):
def canvasPressEvent(self, event): #@UnusedVariable

self.selectRect.setRect(0, 0, 0, 0)
self.rubberBand.reset()
Expand Down
8 changes: 2 additions & 6 deletions map_tools/flow_trace_flow_exit.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,14 @@ def canvasMoveEvent(self, event):
# Get the click
x = event.pos().x()
y = event.pos().y()


# Plugin reloader bug, MapTool should be deactivated
try:
eventPoint = QPoint(x, y)
except(TypeError,KeyError) as e:
print "Plugin loader bug"
except(TypeError,KeyError):
self.iface.actionPan().trigger()
return


# Snapping
(retval,result) = self.snapper.snapToBackgroundLayers(eventPoint) #@UnusedVariable
self.current_layer = None
Expand Down Expand Up @@ -102,6 +99,7 @@ def canvasMoveEvent(self, event):

def canvasReleaseEvent(self, event):
''' With left click the digitizing is finished '''

if event.button() == Qt.LeftButton and self.current_layer is not None:

# Get selected layer type: 'node'
Expand All @@ -120,12 +118,10 @@ def canvasReleaseEvent(self, event):
function_name = "gw_fct_flow_trace"
sql = "SELECT "+self.schema_name+"."+function_name+"('"+str(elem_id)+"');"
result = self.controller.execute_sql(sql)
print sql
else:
function_name = "gw_fct_flow_exit"
sql = "SELECT "+self.schema_name+"."+function_name+"('"+str(elem_id)+"');"
result = self.controller.execute_sql(sql)
print sql

if result:
# Get 'arc' and 'node' list and select them
Expand Down
3 changes: 0 additions & 3 deletions map_tools/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,9 @@ def sendGeometry(self):

def createFeature(self, geom):

# layer = self.canvas.currentLayer()
layer = self.iface.activeLayer()
provider = layer.dataProvider()
f = QgsFeature()

if (geom.isGeosValid()):
f.setGeometry(geom)
else:
Expand All @@ -328,7 +326,6 @@ def createFeature(self, geom):
f.setGeometry(geom)
else:
return False


# Add attribute fields to feature.
fields = layer.pendingFields()
Expand Down
4 changes: 1 addition & 3 deletions map_tools/mincut.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ def canvasMoveEvent(self, event):
# Plugin reloader bug, MapTool should be deactivated
try:
eventPoint = QPoint(x, y)
except(TypeError,KeyError) as e:
print "Plugin loader bug"
except(TypeError,KeyError):
self.iface.actionPan().trigger()
return

Expand Down Expand Up @@ -120,7 +119,6 @@ def canvasReleaseEvent(self, event):
function_name = "gw_fct_mincut"
sql = "SELECT "+self.schema_name+"."+function_name+"('"+str(elem_id)+"', '"+elem_type+"');"
result = self.controller.execute_sql(sql)
print sql
if result:
# Get 'arc' and 'node' list and select them
self.mg_flow_trace_select_features(self.layer_arc, 'arc')
Expand Down
3 changes: 1 addition & 2 deletions map_tools/move_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ def canvasMoveEvent(self, event):
# Plugin reloader bug, MapTool should be deactivated
try:
eventPoint = QPoint(x, y)
except(TypeError,KeyError) as e:
print "Plugin loader bug"
except(TypeError,KeyError):
self.iface.actionPan().trigger()
return

Expand Down
2 changes: 1 addition & 1 deletion parent_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import sys

import utils_giswater
from controller import DaoController
from controller import DaoController #@UnresolvedImport


class ParentDialog(object):
Expand Down
18 changes: 3 additions & 15 deletions search/search_plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,26 +146,22 @@ def populate_dialog(self):
status = self.populate_combo('hydrometer_layer', self.dlg.hydrometer_code,
self.params['hydrometer_field_urban_propierties_code'], self.params['hydrometer_field_code'])
if not status:
#print "Error populating Tab 'Hydrometer'"
self.dlg.tab_main.removeTab(3)

# Tab 'Address'
status = self.address_populate('street_layer')
if not status:
#print "Error populating Tab 'Address'"
self.dlg.tab_main.removeTab(2)

# Tab 'Ppoint'
status = self.populate_combo('ppoint_layer', self.dlg.ppoint_field_zone, self.params['ppoint_field_zone'])
status_2 = self.populate_combo('ppoint_layer', self.dlg.ppoint_number, self.params['ppoint_field_number'])
if not status or not status_2:
#print "Error populating Tab 'Ppoint'"
self.dlg.tab_main.removeTab(1)

# Tab 'Urban Properties'
status = self.urban_populate('urban_propierties_layer')
if not status:
#print "Error populating Tab 'Urban Properties'"
self.dlg.tab_main.removeTab(0)

return True
Expand All @@ -175,9 +171,7 @@ def address_populate(self, parameter):
''' Populate combo 'address_street' '''

# Check if we have this search option available
if not parameter in self.layers:
#message = "Layer '{}' not found in parameter '{}'".format(self.params[parameter], parameter)
#print message
if not parameter in self.layers:
return False

# Get layer features
Expand Down Expand Up @@ -215,8 +209,7 @@ def address_get_numbers(self):

# get selected street
selected = self.dlg.adress_street.currentText()
if selected == '':
print "Any record selected"
if selected == '':
return

# get street code
Expand Down Expand Up @@ -271,8 +264,7 @@ def address_zoom_street(self):

# Get selected street
selected = self.dlg.adress_street.currentText()
if selected == '':
print "Any record selected"
if selected == '':
return

data = self.dlg.adress_street.itemData(self.dlg.adress_street.currentIndex())
Expand All @@ -298,7 +290,6 @@ def address_zoom_portal(self):
street = self.dlg.adress_street.currentText()
civic = self.dlg.adress_number.currentText()
if street == '' or civic == '':
print "Any record selected"
return

# Get selected portal
Expand Down Expand Up @@ -346,7 +337,6 @@ def generic_zoom(self, fieldname, combo, field_index=0):
# Get selected element from combo
element = combo.currentText()
if element.strip() == '':
print "Any record selected"
return None

elem = combo.itemData(combo.currentIndex())
Expand Down Expand Up @@ -583,8 +573,6 @@ def populate_combo(self, parameter, combo, fieldname, fieldname_2=None):

# Check if we have this search option available
if not parameter in self.layers:
message = "Layer '{}' not found in parameter '{}'".format(self.params[parameter], parameter)
print(message)
return False

# Fields management
Expand Down
3 changes: 0 additions & 3 deletions ud_arc_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ def init_config_form(self):
# Manage i18n
self.translate_form(context_name)

# Load data from related tables
#self.load_data()

#Set layer in editing mode
self.layer.startEditing()

Expand Down
5 changes: 1 addition & 4 deletions ud_connec_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ def init_config_form(self):
# Manage i18n
self.translate_form(context_name)

# Load data from related tables
#self.load_data()

#Set layer in editing mode
#Set layer in editing mode
self.layer.startEditing()

# Fill the info table
Expand Down
5 changes: 1 addition & 4 deletions ud_gully_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ def init_config_form(self):
# Manage i18n
self.translate_form(context_name)

# Load data from related tables
#self.load_data()

#Set layer in editing mode
# Set layer in editing mode
self.layer.startEditing()

# Fill the info table
Expand Down
5 changes: 1 addition & 4 deletions ud_node_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ def init_config_form(self):
# Manage i18n
self.translate_form(context_name)

# Load data from related tables
#self.load_data()

#Set layer in editing mode
# Set layer in editing mode
self.layer.startEditing()

# Fill the info table
Expand Down
4 changes: 1 addition & 3 deletions utils_giswater.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def fillComboBoxDict(widget, dict_object, dict_field, allow_nulls=True):
if type(widget) is str:
widget = _dialog.findChild(QComboBox, widget)
if widget is None:
print "Combo not found: "+str(widget)
return None

# Populate combo with values stored in dictionary variable
Expand All @@ -54,8 +53,7 @@ def getText(widget):
if type(widget) is QLineEdit or type(widget) is QDoubleSpinBox:
text = widget.text()
elif type(widget) is QTextEdit:
text = widget.toPlainText()
print text
text = widget.toPlainText()
if text:
elem_text = text
else:
Expand Down
Loading

0 comments on commit 9a03802

Please sign in to comment.