def _UpdateFirmwareCmd(self):
q = tkMessageBox.showwarning('Update Fimware','Warning! Interrupting firmare update may lead to non functional PiJuice HAT.', parent=self.frame)
if q:
print 'Updating fimware'
inputFile = '/usr/share/pijuice/data/firmware/PiJuice.elf.binary'
curAdr = pijuice.config.interface.GetAddress()
if curAdr:
adr = format(curAdr, 'x')
ret = 256 - subprocess.call(['pijuiceboot', adr, inputFile])#subprocess.call([os.getcwd() + '/stmboot', adr, inputFile])
print 'firm res', ret
if ret == 256:
tkMessageBox.showinfo('Firmware update', 'Finished succesfully!', parent=self.frame)
else:
errorStatus = self.firmUpdateErrors[ret] if ret < 11 else ' UNKNOWN'
msg = ''
if errorStatus == 'I2C_BUS_ACCESS_ERROR':
msg = 'Check if I2C bus is enabled.'
elif errorStatus == 'INPUT_FILE_OPEN_ERROR':
msg = 'Firmware binary file might be missing or damaged.'
elif errorStatus == 'STARTING_BOOTLOADER_ERROR':
msg = 'Try to start bootloader manualy. Press and hold button SW3 while powering up RPI and PiJuice.'
tkMessageBox.showerror('Firmware update failed', 'Reason: ' + errorStatus + '. ' + msg, parent=self.frame)
else:
tkMessageBox.showerror('Firmware update', 'Unknown pijuice I2C address', parent=self.frame)
python类showwarning()的实例源码
def _UpdateFirmwareCmd(self):
q = tkMessageBox.showwarning('Update Fimware','Warning! Interrupting firmare update may lead to non functional PiJuice HAT.', parent=self.frame)
if q:
print 'Updating fimware'
inputFile = '/usr/share/pijuice/data/firmware/PiJuice.elf.binary'
curAdr = pijuice.config.interface.GetAddress()
if curAdr:
adr = format(curAdr, 'x')
ret = 256 - subprocess.call(['pijuiceboot', adr, inputFile])#subprocess.call([os.getcwd() + '/stmboot', adr, inputFile])
print 'firm res', ret
if ret == 256:
tkMessageBox.showinfo('Firmware update', 'Finished succesfully!', parent=self.frame)
else:
errorStatus = self.firmUpdateErrors[ret] if ret < 11 else ' UNKNOWN'
msg = ''
if errorStatus == 'I2C_BUS_ACCESS_ERROR':
msg = 'Check if I2C bus is enabled.'
elif errorStatus == 'INPUT_FILE_OPEN_ERROR':
msg = 'Firmware binary file might be missing or damaged.'
elif errorStatus == 'STARTING_BOOTLOADER_ERROR':
msg = 'Try to start bootloader manualy. Press and hold button SW3 while powering up RPI and PiJuice.'
tkMessageBox.showerror('Firmware update failed', 'Reason: ' + errorStatus + '. ' + msg, parent=self.frame)
else:
tkMessageBox.showerror('Firmware update', 'Unknown pijuice I2C address', parent=self.frame)
def _UpdateFirmwareCmd(self):
q = tkMessageBox.showwarning('Update Fimware','Warning! Interrupting firmare update may lead to non functional PiJuice HAT.', parent=self.frame)
if q:
print 'Updating fimware'
inputFile = '/usr/share/pijuice/data/firmware/PiJuice.elf.binary'
curAdr = pijuice.config.interface.GetAddress()
if curAdr:
adr = format(curAdr, 'x')
ret = 256 - subprocess.call(['pijuiceboot', adr, inputFile])#subprocess.call([os.getcwd() + '/stmboot', adr, inputFile])
print 'firm res', ret
if ret == 256:
tkMessageBox.showinfo('Firmware update', 'Finished succesfully!', parent=self.frame)
else:
errorStatus = self.firmUpdateErrors[ret] if ret < 11 else ' UNKNOWN'
msg = ''
if errorStatus == 'I2C_BUS_ACCESS_ERROR':
msg = 'Check if I2C bus is enabled.'
elif errorStatus == 'INPUT_FILE_OPEN_ERROR':
msg = 'Firmware binary file might be missing or damaged.'
elif errorStatus == 'STARTING_BOOTLOADER_ERROR':
msg = 'Try to start bootloader manualy. Press and hold button SW3 while powering up RPI and PiJuice.'
tkMessageBox.showerror('Firmware update failed', 'Reason: ' + errorStatus + '. ' + msg, parent=self.frame)
else:
tkMessageBox.showerror('Firmware update', 'Unknown pijuice I2C address', parent=self.frame)
def _UpdateFirmwareCmd(self):
q = tkMessageBox.showwarning('Update Fimware','Warning! Interrupting firmare update may lead to non functional PiJuice HAT.', parent=self.frame)
if q:
print 'Updating fimware'
inputFile = '/usr/share/pijuice/data/firmware/PiJuice.elf.binary'
curAdr = pijuice.config.interface.GetAddress()
if curAdr:
adr = format(curAdr, 'x')
ret = 256 - subprocess.call(['pijuiceboot', adr, inputFile])#subprocess.call([os.getcwd() + '/stmboot', adr, inputFile])
print 'firm res', ret
if ret == 256:
tkMessageBox.showinfo('Firmware update', 'Finished succesfully!', parent=self.frame)
else:
errorStatus = self.firmUpdateErrors[ret] if ret < 11 else ' UNKNOWN'
msg = ''
if errorStatus == 'I2C_BUS_ACCESS_ERROR':
msg = 'Check if I2C bus is enabled.'
elif errorStatus == 'INPUT_FILE_OPEN_ERROR':
msg = 'Firmware binary file might be missing or damaged.'
elif errorStatus == 'STARTING_BOOTLOADER_ERROR':
msg = 'Try to start bootloader manualy. Press and hold button SW3 while powering up RPI and PiJuice.'
tkMessageBox.showerror('Firmware update failed', 'Reason: ' + errorStatus + '. ' + msg, parent=self.frame)
else:
tkMessageBox.showerror('Firmware update', 'Unknown pijuice I2C address', parent=self.frame)
def _UpdateFirmwareCmd(self):
q = tkMessageBox.showwarning('Update Fimware','Warning! Interrupting firmare update may lead to non functional PiJuice HAT.', parent=self.frame)
if q:
print 'Updating fimware'
inputFile = '/usr/share/pijuice/data/firmware/PiJuice.elf.binary'
curAdr = pijuice.config.interface.GetAddress()
if curAdr:
adr = format(curAdr, 'x')
ret = 256 - subprocess.call(['pijuiceboot', adr, inputFile])#subprocess.call([os.getcwd() + '/stmboot', adr, inputFile])
print 'firm res', ret
if ret == 256:
tkMessageBox.showinfo('Firmware update', 'Finished succesfully!', parent=self.frame)
else:
errorStatus = self.firmUpdateErrors[ret] if ret < 11 else ' UNKNOWN'
msg = ''
if errorStatus == 'I2C_BUS_ACCESS_ERROR':
msg = 'Check if I2C bus is enabled.'
elif errorStatus == 'INPUT_FILE_OPEN_ERROR':
msg = 'Firmware binary file might be missing or damaged.'
elif errorStatus == 'STARTING_BOOTLOADER_ERROR':
msg = 'Try to start bootloader manualy. Press and hold button SW3 while powering up RPI and PiJuice.'
tkMessageBox.showerror('Firmware update failed', 'Reason: ' + errorStatus + '. ' + msg, parent=self.frame)
else:
tkMessageBox.showerror('Firmware update', 'Unknown pijuice I2C address', parent=self.frame)
def show_popup_message(self, popup_type="warning", title_to_show="ALLERT", message_to_show="THIS IS AN ALLERT MESSAGE", parent_window=None, refresh=True):
"""
Displays error or warning messages and refreshes the sequence window.
"""
# show_error_message
# show_warning_message
if parent_window == None:
parent_window = self.main_window
if popup_type == "error":
tkMessageBox.showerror(title_to_show, message_to_show, parent=parent_window)
elif popup_type == "info":
tkMessageBox.showinfo(title_to_show, message_to_show, parent=parent_window)
elif popup_type == "warning":
tkMessageBox.showwarning(title_to_show, message_to_show, parent=parent_window)
if refresh:
self.gridder()
def handleLinearRegression(self):
if self.data is None:
tkMessageBox.showerror("No Open File", "Please open a file first!")
return
d = LinearRegressionDialog(self.root, self.data.get_headers())
if d.result is not None:
if d.result[0] == "None" or d.result[1] == "None":
tkMessageBox.showwarning(title="Incorrect Parameters", message="Option cannot be 'None'")
else:
self.objects = []
self.linreg_endpoints = None
self.linreg_line_objects = []
self.reset()
self.updateAxes()
self.regression_mode = True
self.buildLinearRegression(headers=d.result)
# build and display the regression on the plot
def handlePCA(self, event=None):
if self.data is None:
tkMessageBox.showerror("No File Open", "Please open a file first!")
return
d = PCADialog(self.root, self.data.get_headers())
if d.result is None:
return
if d.result[2] in self.pca_data.keys():
tkMessageBox.showwarning("Replacing Saved Analysis",
"Please delete old analysis before creating another with the same name.")
return
if d.result[0] == 1:
self.pca_data[d.result[2]] = analysis.pca(self.data, d.result[1])
self.pca_data[d.result[2]].write_to_file(d.result[2], self.pca_data[d.result[2]].get_headers())
print "Normalizing: True"
else:
self.pca_data[d.result[2]] = analysis.pca(self.data, d.result[1], False)
self.pca_data[d.result[2]].write_to_file(d.result[2], self.pca_data[d.result[2]].get_headers())
print "Normalizing: False"
if not self.pca_controls_built:
self.buildPCAControls()
self.pca_lbox.insert(tk.END, d.result[2])
def validate(self):
"""
Called when the user chooses "OK", before closing the box.
Also checks that child name is unique.
"""
for tk_list in self.frame_dict.values():
if not all(x.validate() for x in tk_list):
return False
if self.element.parent is not None:
if self.element not in self.element.parent.children:
if self.name_entry.value.get() in self.element.parent.child_names():
tkMessageBox.showwarning("", "Sibling names must be unique.")
return False
return True
def new_button_press(self):
if self.treeview.focus() == "" and self.root_element is not None:
tkMessageBox.showwarning(None, "No parent element selected.")
else:
if self.treeview.focus() == "" and self.root_element is None:
element = CreateRootDialog(self).element
if isinstance(element, SeqLib):
EditDialog(self, self, element)
self.root_element = element
else:
element = self.create_new_element()
EditDialog(self, self, element)
# refresh the treeview and re-assign treeview id's
self.refresh_treeview()
# select the newly added element if it was successfully added
if element.treeview_id in self.element_dict.keys():
self.treeview.focus(element.treeview_id)
self.treeview.selection_set(element.treeview_id)
else:
if element.parent is not None:
self.treeview.focus(element.parent.treeview_id)
self.treeview.selection_set(element.parent.treeview_id)
del element
def warningBox(self, title, message):
self.topLevel.update_idletasks()
MessageBox.showwarning(title, message)
self.__bringToFront()
def warning(self, title, message):
messagebox.showwarning(title, message)
def validate(self):
import tkMessageBox
try:
result = self.getresult()
except ValueError:
tkMessageBox.showwarning(
"Illegal value",
self.errormessage + "\nPlease try again",
parent = self
)
return 0
if self.minvalue is not None and result < self.minvalue:
tkMessageBox.showwarning(
"Too small",
"The allowed minimum value is %s. "
"Please try again." % self.minvalue,
parent = self
)
return 0
if self.maxvalue is not None and result > self.maxvalue:
tkMessageBox.showwarning(
"Too large",
"The allowed maximum value is %s. "
"Please try again." % self.maxvalue,
parent = self
)
return 0
self.result = result
return 1
def callback(self):
tkMessageBox.showwarning(title="Not Implemented", message="This feature has not yet been implemented")
def check_NumBeams(LPlan,OTPPlan,passLog,failLog):
# Check same number of beams
#print LPlan.NumBeams,OTPPlan.NumBeams
if not (LPlan.NumBeams == OTPPlan.NumBeams):
tkMessageBox.showwarning(
"Mismatch",
"Plans contain unequal number of beams"
)
return False
else:
return True
def warningBox(self, title, message):
self.topLevel.update_idletasks()
MessageBox.showwarning(title, message)
self.__bringToFront()
def clientConnectionFailed(self, connector, reason):
tkMessageBox.showwarning('TkConch','Connection Failed, Reason:\n %s: %s' % (reason.type, reason.value))
def MsgBox(title, text, style):
box = [
msg.showinfo, msg.showwarning, msg.showerror,
msg.askquestion, msg.askyesno, msg.askokcancel, msg.askretrycancel,
];
tk.Tk().withdraw(); #Hide Main Window.
if style in range(7):
return box[style](title, text)
def MsgBox(title, text, style):
box = [
msg.showinfo, msg.showwarning, msg.showerror,
msg.askquestion, msg.askyesno, msg.askokcancel, msg.askretrycancel,
];
tk.Tk().withdraw(); #Hide Main Window.
if style in range(7):
return box[style](title, text)
def show_warning(self, title, message):
return messagebox.showwarning(title, message)
def show_warning(self, title, message):
return messagebox.showwarning(title, message)
def read_path_from_svg(svg_filename):
# re_split = re.compile('\s+|,')
try:
tree = etree.parse(open(svg_filename))
except (OSError, IOError):
tkMessageBox.showwarning(title = 'Error during reticule import',message = "the file %s was not found" %svg_filename)
path_list = [];
for element in tree.iter():
if element.tag.split("}")[1] == "path":
#re_split.split(element.get("d"))
path_list.append(element.get('d'))
#path_list.append(re_split)
Points = string2points(path_list)
return Points
def read_colored_path_from_svg(svg_filename):
# re_split = re.compile('\s+|,')
tree = etree.parse(open(svg_filename))
path_list = {}
for element in tree.iter():
if element.tag.split("}")[1] == "path":
#re_split.split(element.get("d"))
path_color = element.get('style')
if type(path_color) == str:
ind = path_color.find('fill:')
path_color = path_color[(ind+5):(ind+12)]
if path_color == '#ff0000':
path_color = 'red'
elif path_color == '#00ff00':
path_color = 'green'
elif path_color == '#0000ff':
path_color = 'blue'
else:
tkMessageBox.showwarning('Some colors were not rekognized', 'Only blue, red and green traces are imported')
else:
path_color = element.get('fill')
if path_color not in path_list.keys():
path_list[path_color]=[]
path_list[path_color].append(element.get('d'))
#path_list.append(re_split)
Points = {}
for path_color in path_list:
Points[path_color] = string2points(path_list[path_color])
return Points
def importSVGroute(IDT_group):
IDT_group_dir = IDT_group['IDT_group_dir']
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
svg_filename = tkFileDialog.askopenfilename(title='Wafer routing filename',defaultextension = 'svg',initialdir = IDT_group_dir);
all_points = SVGT.read_colored_path_from_svg(svg_filename)
route =[[],[]]
for points in all_points['red']:
polygon = shapely_geom.Polygon(points.T)
polygon_validity = explain_validity(polygon)
if polygon_validity=='Valid Geometry':
route[0].append(polygon)
else:
tkMessageBox.showwarning('Error in svg import', polygon_validity)
for points in all_points['blue']:
polygon = shapely_geom.Polygon(points.T)
polygon_validity = explain_validity(polygon)
if polygon_validity=='Valid Geometry':
route[1].append(polygon)
else:
tkMessageBox.showwarning('Error in svg import', polygon_validity)
route[0] = shapely_geom.MultiPolygon(route[0])
route[1] = shapely_geom.MultiPolygon(route[1])
#outbox = route[0].bounds
#dx = outbox[2]-outbox[0]
#dy = outbox[3]-outbox[1]
#x0 = outbox[0]+dx/2
#y0 = outbox[1]+dy/2
x0 = 4000
y0 = 4000
factor = 1e-5;
route[0] = shapely_affinity.translate(route[0], xoff=-x0, yoff=-y0)
route[0] = shapely_affinity.scale(route[0], xfact = factor, yfact= factor, origin=(0,0,0))
route[1] = shapely_affinity.translate(route[1], xoff=-x0, yoff=-y0)
route[1] = shapely_affinity.scale(route[1], xfact = factor, yfact= factor, origin=(0,0,0))
IDT_group['route'] = route
def checkIPaddr(self,addr):
try:
socket.inet_pton(socket.AF_INET,addr)
return True
except socket.error:
tkMessageBox.showwarning("Error","Invalid Target IP Address\n(%s)" % addr)
return False
def callback(self):
tkMessageBox.showwarning(title="Not Implemented",
message="This feature has not yet been implemented")
def validate(self):
import tkMessageBox
try:
result = self.getresult()
except ValueError:
tkMessageBox.showwarning(
"Illegal value",
self.errormessage + "\nPlease try again",
parent = self
)
return 0
if self.minvalue is not None and result < self.minvalue:
tkMessageBox.showwarning(
"Too small",
"The allowed minimum value is %s. "
"Please try again." % self.minvalue,
parent = self
)
return 0
if self.maxvalue is not None and result > self.maxvalue:
tkMessageBox.showwarning(
"Too large",
"The allowed maximum value is %s. "
"Please try again." % self.maxvalue,
parent = self
)
return 0
self.result = result
return 1
def validate(self):
import tkMessageBox
try:
result = self.getresult()
except ValueError:
tkMessageBox.showwarning(
"Illegal value",
self.errormessage + "\nPlease try again",
parent = self
)
return 0
if self.minvalue is not None and result < self.minvalue:
tkMessageBox.showwarning(
"Too small",
"The allowed minimum value is %s. "
"Please try again." % self.minvalue,
parent = self
)
return 0
if self.maxvalue is not None and result > self.maxvalue:
tkMessageBox.showwarning(
"Too large",
"The allowed maximum value is %s. "
"Please try again." % self.maxvalue,
parent = self
)
return 0
self.result = result
return 1
def clientConnectionFailed(self, connector, reason):
tkMessageBox.showwarning('TkConch','Connection Failed, Reason:\n %s: %s' % (reason.type, reason.value))
def add_new_user_disulfide(self):
# Checks that both the comboboxes have been used to select a cys.
if (self.list_of_disulfide_combos[-1].cys1_combobox.get() == "" or self.list_of_disulfide_combos[-1].cys2_combobox.get() == ""):
txt = "You have to select two cysteines residue to define a disulfide bridge!"
tkMessageBox.showwarning("Warning", txt,parent=self.pymod_object.modeling_window)
# Checks that the same cys has not been selected in both comboboxes.
elif (self.list_of_disulfide_combos[-1].cys1_combobox.get() == self.list_of_disulfide_combos[-1].cys2_combobox.get()):
txt = "You cannot select the same cysteine to form a disulfide bridge!"
tkMessageBox.showwarning("Message", txt,parent=self.pymod_object.modeling_window)
# Checks that the selected cys are not engaged in other bridges.
# ...
# If the two cys are free to form a bridge, then adds the new bridge and updates the
# frame with a new combobox row.
else:
self.user_disulfides_row_counter += 1
# Adds the new row with comboboxes and an "Add" button.
new_ds_combo = User_disulfide_combo(
self.pymod_object,
self.user_disulfides_row_counter,
self.target_list_of_cysteines,
self.combobox_frame,
self)
# Activates the previous row and returns the name of the 2 selected cys.
cysteines = self.list_of_disulfide_combos[-1].activate()
# Finishes and adds the new row.
self.list_of_disulfide_combos.append(new_ds_combo)
# Adds the cys pair to the self.user_defined_disulfide_bridges, which is going to be
# used in the perform_modelization() method.
self.user_defined_disulfide_bridges.append(cysteines)
# self.print_user_ds_list()
self.pymod_object.disulfides_scrolled_frame.reposition()
# This is called when the "Remove" button is pressed.