def showSession(window, session): user = session['user'] html = htmlHeader(2, tr("Session:")) roles = htmlList(user['roles']) groups = htmlList(user['groups']) html += htmlTable(( (tr("Login"), user['login']), (tr("Roles"), roles), (tr("Groups"), groups), )) QMessageBox.information(window, tr("Session Information"), unicode(html))
def formatWarnings(message, warnings): message = htmlParagraph(message) if warnings: html = htmlImage(WARNING_ICON32, align="middle") html += NBSP + Html(tr("Warnings:")) message += htmlParagraph(html) message += htmlList( tr(format) % tuple(arguments) for format, arguments in warnings) return unicode(message)
def _formatMessages(self, title, messages, icon): html = Html() errors = [] for format, args in messages: errors.append(formatMessage(self.window, True, format, args)) if errors: text = htmlImage(icon, align="middle") + NBSP + title html += htmlParagraph(text) html += htmlList(errors) return html
def _cleanupTraceback(lines, first_line): if (not lines) or (len(lines) < 3): return u'' # Remove first line del lines[0] try: clean = [] index = 0 indent = " \t" while index < len(lines): line = lines[index] if (0 < index) and not line.startswith(" "): # Skip the message at the end (only keep the backtrace) break line = line.lstrip(indent) match = FILE_REGEX.match(line) if match is None: raise SyntaxError("Unable to parse backtrace") filename = truncateFilename(match.group('filename'), 40, 5) line_number = match.group('line') try: source = lines[index + 1].lstrip(indent) except IndexError: source = None if (not source) or FILE_REGEX.match(source): # Traceback without source code: # File ".../core.py", line 365, in callService # File ".../component.py", line 31, in __call__ source = htmlItalic('<%s()>' % match.group('function')) index += 1 else: # Traceback with source code: # File ".../core.py", line 365, in callService # return self.function(*args) # File ".../component.py", line 31, in __call__ index += 2 where = htmlBold("%s:%s" % (filename, line_number)) text = Html("%s: %s" % (where, source), escape=False) clean.append(text) return htmlParagraph(first_line) + htmlList(clean) except Exception: # Ignore exceptions when cleanup the traceback pass return htmlParagraph(first_line) + htmlPre(u'\n'.join(lines))
from ufwi_rpcd.common import tr, EDENWALL from ufwi_rpcc_qt.html import htmlList if EDENWALL: from ufwi_conf.common.dhcpcfg import DHCPRange, UNSET from .adjust import adjust_ip #changes directives _DELETE_RANGE = "_delete range_" _IGNORE = "_ignore changes_" _TRANSLATE = "_translate range_" _HELP_TEXT = unicode(htmlList(( tr("Clicking \"Yes\" will change the DHCP range."), tr("Clicking \"Ignore\" will not change the DHCP range. Double-check the DHCP server configuration before saving."), tr("Clicking \"Cancel\" will cancel your changes to the network configuration") ))) _HTML = u""" <table> %(title)s<br /> %(ask)s<br /> <tr> <td><h2>%(start)s</h2></td> <td>%(cur_start)s</td> <td><img src=":/icons-32/go-next"/></td> <td>%(simu_start)s</td> </tr> <tr> <td><h2>%(end)s</h2></td>
def acceptNetworkChange(self): deletable = set() translatable = set() translated_ranges = {} if self.dhcpcfg is None: return True, translated_ranges, deletable deletable, translatable = self.dhcpcfg.computeChanges(self.q_netobject.netcfg) if not (deletable | translatable): #Nothing to do (yay!) we agree with proposed changes return True #oh, questions arrive accept = True generic_text = "<h2>%s</h2>" % tr("This change affects the DHCP server configuration") #TODO: add questions and return for range in translatable: if not accept: break if not isinstance(range.router, IP): new_router_ip = UNSET else: new_router_ip = adjust_ip(range.net.net, range.router) widget_range = self.getWidgetFromRange(range) simulation = { 'start': adjust_ip(range.net.net, range.start), 'end': adjust_ip(range.net.net, range.end), 'router': new_router_ip, 'custom_dns': widget_range.custom_dns, } cur_router = _valuefromrouter(range.router) new_router = _valuefromrouter(simulation['router']) help_items = [] help_items.append(tr("Clicking \"Yes\" will change the DHCP range.")) help_items.append(tr("Clicking \"Ignore\" will not change the DHCP range. Double-check the DHCP server configuration before saving.")) help_items.append(tr("Clicking \"Cancel\" will cancel your changes to the network configuration")) help_text = unicode(htmlList(help_items)) title = tr("DHCP: Translate a range?") html = u"""<table> %(title)s<br /> %(ask)s<br /> <tr> <td><h2>%(start)s</h2></td> <td>%(cur_start)s</td> <td><img src=":/icons-32/go-next"/></td> <td>%(simu_start)s</td> </tr> <tr> <td><h2>%(end)s</h2></td> <td>%(cur_end)s</td> <td><img src=":/icons-32/go-next"/></td> <td>%(simu_end)s</td> </tr> <tr> <td><h2>%(router)s</h2></td> <td>%(cur_router)s</td> <td><img src=":/icons-32/go-next"/></td> <td>%(simu_router)s</td> </tr> </table> """ % { 'title' : tr("You changed the network address for the '<i>%s</i>' network") % range.net.label, 'ask' : tr("Do you want to adjust the range?"), 'start' : tr("Start IP"), 'cur_start' : range.start, 'simu_start' : unicode(simulation['start']), 'end' : tr("End IP"), 'cur_end' : range.end, 'simu_end' : unicode(simulation['end']), 'router' : tr("Router IP"), 'cur_router' : cur_router, 'simu_router' : unicode(new_router), } html += help_text message_box = QMessageBox(self) message_box.setWindowTitle(title) message_box.setText(generic_text) message_box.setInformativeText(html) message_box.setStandardButtons( QMessageBox.Yes | QMessageBox.Ignore | QMessageBox.Cancel ) clicked_button = message_box.exec_() accept = clicked_button in (QMessageBox.Yes, QMessageBox.Ignore) if clicked_button == QMessageBox.Yes: translated_ranges[range] = simulation deletable_ranges = frozenset() if accept and deletable: deletable_tr = tr("Consequence: the following DHCP range will be deleted:") deletable_html = u"<ul>" for range in deletable: deletable_html += "<li>%s %s: %s > %s</li>" % ( deletable_tr, unicode(range.net), unicode(range.start), unicode(range.end) ) deletable_html += u"</ul>" title = tr("DHCP configuration") message_box = QMessageBox(self) message_box.setWindowTitle(title) message_box.setText(generic_text) message_box.setInformativeText(deletable_html) message_box.setStandardButtons( QMessageBox.Yes | QMessageBox.Cancel ) clicked_button = message_box.exec_() accept = (clicked_button == QMessageBox.Yes) if accept: deletable_ranges = deletable if not accept: return False return True, translated_ranges, deletable_ranges