def init_search_restriction_mixin(self): self.checked = QIcon(I('ok.png')) self.empty = QIcon(I('blank.png')) self.current_search_action = QAction(self.empty, _('*current search'), self) self.current_search_action.triggered.connect(partial(self.apply_virtual_library, library='*')) self.addAction(self.current_search_action) self.keyboard.register_shortcut( 'vl-from-current-search', _('Virtual library from current search'), description=_( 'Create a temporary Virtual library from the current search'), group=pgettext('search restriction group name', 'Miscellaneous'), default_keys=('Ctrl+*',), action=self.current_search_action) self.search_based_vl_name = None self.search_based_vl = None self.virtual_library_menu = QMenu(self.virtual_library) self.virtual_library.setMenu(self.virtual_library_menu) self.virtual_library_menu.aboutToShow.connect(self.virtual_library_menu_about_to_show) self.clear_vl.clicked.connect(lambda x: (self.apply_virtual_library(), self.clear_additional_restriction())) self.virtual_library_tooltip = \ _('Use a "Virtual library" to show only a subset of the books present in this library') self.virtual_library.setToolTip(self.virtual_library_tooltip) self.search_restriction = ComboBoxWithHelp(self) self.search_restriction.setVisible(False) self.clear_vl.setText(_("(all books)")) self.ar_menu = QMenu(_('Additional restriction'), self.virtual_library_menu) self.edit_menu = QMenu(_('Edit Virtual library'), self.virtual_library_menu) self.rm_menu = QMenu(_('Remove Virtual library'), self.virtual_library_menu) self.search_restriction_list_built = False
def register_shortcut(self, unique_name, name, default_keys=(), description=None, action=None, group=None, persist_shortcut=False): ''' Register a shortcut with calibre. calibre will manage the shortcut, automatically resolving conflicts and allowing the user to customize it. :param unique_name: A string that uniquely identifies this shortcut :param name: A user visible name describing the action performed by this shortcut :param default_keys: A tuple of keys that trigger this shortcut. Each key must be a string. For example: ('Ctrl+A', 'Alt+B', 'C', 'Shift+Meta+D'). These keys will be assigned to the shortcut unless there is a conflict. :param action: A QAction object. The shortcut will cause this QAction to be triggered. Connect to its triggered signal in your code to respond to the shortcut. :param group: A string describing what "group" this shortcut belongs to. This is used to organize the list of shortcuts when the user is customizing them. :persist_shortcut: Shortcuts for actions that don't always appear, or are library dependent, may disappear when other keyboard shortcuts are edited unless ```persist_shortcut``` is set True. ''' if unique_name in self.shortcuts: name = self.shortcuts[unique_name]['name'] raise NameConflict('Shortcut for %r already registered by %s'%( unique_name, name)) shortcut = {'name':name, 'desc':description, 'action': action, 'default_keys':tuple(default_keys), 'persist_shortcut':persist_shortcut} self.shortcuts[unique_name] = shortcut group = group if group else pgettext('keyboard shortcuts', _('Miscellaneous')) self.groups[group] = self.groups.get(group, []) + [unique_name]
def category_defs(): return ( ('text', _('Text'), _('Chapter-')), ('styles', _('Styles'), _('Style-')), ('images', _('Images'), _('Image-')), ('fonts', _('Fonts'), _('Font-')), ('misc', pgettext('edit book file type', 'Miscellaneous'), _('Misc-')), )
def cleanup_docker_garbage(self, docker_type): plural_type = docker_type + "s" if docker_type == "image": context = "female" else: context = "male" print() print_info( _("Removing leftover docker {item}").format(item=plural_type), bold=False) objects = getattr(self, "get_docker_{}_list".format(plural_type))() if len(objects) == 0: if context == "female": message = gettext.pgettext( "female", "no candidate {item}s found for removing") else: message = gettext.pgettext( "male", "no candidate {item}s found for removing") print_info(message.format(item=docker_type), symbol="==>", color="green") return subprocess.run( self.sudo_wrapper(["docker", docker_type, "rm"] + objects)) number = len(objects) if context == "female": message = gettext.npgettext("female", "finished: {n} {item} removed", "finished: {n} {items} removed", number) else: message = gettext.npgettext("male", "finished: {n} {item} removed", "finished: {n} {items} removed", number).format(n=number, item=docker_type, items=plural_type) print_info(message.format(n=number, item=docker_type, items=plural_type), symbol="==>", color="green")
from polyglot.builtins import iteritems FILE_COPY_MIME = 'application/calibre-edit-book-files' TOP_ICON_SIZE = 24 NAME_ROLE = Qt.ItemDataRole.UserRole CATEGORY_ROLE = NAME_ROLE + 1 LINEAR_ROLE = CATEGORY_ROLE + 1 MIME_ROLE = LINEAR_ROLE + 1 NBSP = '\xa0' CATEGORIES = ( ('text', _('Text'), _('Chapter-')), ('styles', _('Styles'), _('Style-')), ('images', _('Images'), _('Image-')), ('fonts', _('Fonts'), _('Font-')), ('misc', pgettext('edit book file type', 'Miscellaneous'), _('Misc-')), ) def name_is_ok(name, show_error): if not name or not name.strip(): return show_error('') and False ext = name.rpartition('.')[-1] if not ext or ext == name: return show_error(_('The file name must have an extension')) and False norm = name.replace('\\', '/') parts = name.split('/') for x in parts: if sanitize_file_name(x) != x: return show_error(_('The file name contains invalid characters')) and False if current_container().has_name(norm):
def test_some_translations_with_context(self): eq = self.assertEqual eq(gettext.pgettext('my context', 'nudge nudge'), 'wink wink (in "my context")') eq(gettext.pgettext('my other context', 'nudge nudge'), 'wink wink (in "my other context")')
def update_event(self, inp=-1): self.set_output_val(0, gettext.pgettext(self.input(0), self.input(1)))
def createSetup(self): print "Creating setup" self.list = [] self.multiType = None self.configMode = None self.diseqcModeEntry = None self.advancedSatsEntry = None self.advancedLnbsEntry = None self.advancedDiseqcMode = None self.advancedUsalsEntry = None self.advancedLof = None self.advancedPowerMeasurement = None self.turningSpeed = None self.turnFastEpochBegin = None self.turnFastEpochEnd = None self.toneburst = None self.committedDiseqcCommand = None self.uncommittedDiseqcCommand = None self.commandOrder = None self.cableScanType = None self.have_advanced = False self.advancedUnicable = None self.advancedType = None self.advancedManufacturer = None self.advancedSCR = None self.advancedConnected = None self.showAdditionalMotorOptions = None self.selectSatsEntry = None self.advancedSelectSatsEntry = None self.singleSatEntry = None if self.nim.isMultiType(): multiType = self.nimConfig.multiType self.multiType = getConfigListEntry(_("Tuner type"), multiType) self.list.append(self.multiType) if self.nim.isCompatible("DVB-S"): self.configMode = getConfigListEntry(_("Configuration mode"), self.nimConfig.configMode) self.list.append(self.configMode) if self.nimConfig.configMode.value == "simple": # simple setup self.diseqcModeEntry = getConfigListEntry( pgettext("Satellite configuration mode", "Mode"), self.nimConfig.diseqcMode ) self.list.append(self.diseqcModeEntry) if self.nimConfig.diseqcMode.value in ("single", "toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"): self.createSimpleSetup(self.list, self.nimConfig.diseqcMode.value) if self.nimConfig.diseqcMode.value in ("positioner", "positioner_select"): self.createPositionerSetup(self.list) elif self.nimConfig.configMode.value == "equal": choices = [] nimlist = nimmanager.canEqualTo(self.nim.slot) for id in nimlist: choices.append((str(id), nimmanager.getNimDescription(id))) self.nimConfig.connectedTo.setChoices(choices) self.list.append(getConfigListEntry(_("Tuner"), self.nimConfig.connectedTo)) elif self.nimConfig.configMode.value == "satposdepends": choices = [] nimlist = nimmanager.canDependOn(self.nim.slot) for id in nimlist: choices.append((str(id), nimmanager.getNimDescription(id))) self.nimConfig.connectedTo.setChoices(choices) self.list.append(getConfigListEntry(_("Tuner"), self.nimConfig.connectedTo)) elif self.nimConfig.configMode.value == "loopthrough": choices = [] print "connectable to:", nimmanager.canConnectTo(self.slotid) connectable = nimmanager.canConnectTo(self.slotid) for id in connectable: choices.append((str(id), nimmanager.getNimDescription(id))) self.nimConfig.connectedTo.setChoices(choices) self.list.append(getConfigListEntry(_("Connected to"), self.nimConfig.connectedTo)) elif self.nimConfig.configMode.value == "nothing": pass elif self.nimConfig.configMode.value == "advanced": # advanced # SATs self.advancedSatsEntry = getConfigListEntry(_("Satellite"), self.nimConfig.advanced.sats) self.list.append(self.advancedSatsEntry) current_config_sats = self.nimConfig.advanced.sats.value if current_config_sats in ("3605", "3606"): self.advancedSelectSatsEntry = getConfigListEntry( _("Press OK to select satellites"), self.nimConfig.pressOKtoList ) self.list.append(self.advancedSelectSatsEntry) self.fillListWithAdvancedSatEntrys(self.nimConfig.advanced.sat[int(current_config_sats)]) else: cur_orb_pos = self.nimConfig.advanced.sats.orbital_position satlist = self.nimConfig.advanced.sat.keys() if cur_orb_pos is not None: if cur_orb_pos not in satlist: cur_orb_pos = satlist[0] self.fillListWithAdvancedSatEntrys(self.nimConfig.advanced.sat[cur_orb_pos]) self.have_advanced = True if self.nim.description == "Alps BSBE2" and config.usage.setup_level.index >= 2: # expert self.list.append(getConfigListEntry(_("Tone amplitude"), self.nimConfig.toneAmplitude)) elif self.nim.isCompatible("DVB-C"): self.configMode = getConfigListEntry(_("Configuration mode"), self.nimConfig.configMode) self.list.append(self.configMode) if self.nimConfig.configMode.value == "enabled": self.list.append(getConfigListEntry(_("Network ID"), self.nimConfig.cable.scan_networkid)) self.cableScanType = getConfigListEntry(_("Used service scan type"), self.nimConfig.cable.scan_type) self.list.append(self.cableScanType) if self.nimConfig.cable.scan_type.value == "provider": self.list.append(getConfigListEntry(_("Provider to scan"), self.nimConfig.cable.scan_provider)) else: if self.nimConfig.cable.scan_type.value == "bands": # TRANSLATORS: option name, indicating which type of (DVB-C) band should be scanned. The name of the band is printed in '%s'. E.g.: 'Scan EU MID band' self.list.append( getConfigListEntry( _("Scan %s band") % ("EU VHF I"), self.nimConfig.cable.scan_band_EU_VHF_I ) ) self.list.append( getConfigListEntry(_("Scan %s band") % ("EU MID"), self.nimConfig.cable.scan_band_EU_MID) ) self.list.append( getConfigListEntry( _("Scan %s band") % ("EU VHF III"), self.nimConfig.cable.scan_band_EU_VHF_III ) ) self.list.append( getConfigListEntry( _("Scan %s band") % ("EU UHF IV"), self.nimConfig.cable.scan_band_EU_UHF_IV ) ) self.list.append( getConfigListEntry( _("Scan %s band") % ("EU UHF V"), self.nimConfig.cable.scan_band_EU_UHF_V ) ) self.list.append( getConfigListEntry( _("Scan %s band") % ("EU SUPER"), self.nimConfig.cable.scan_band_EU_SUPER ) ) self.list.append( getConfigListEntry( _("Scan %s band") % ("EU HYPER"), self.nimConfig.cable.scan_band_EU_HYPER ) ) self.list.append( getConfigListEntry(_("Scan %s band") % ("US LOW"), self.nimConfig.cable.scan_band_US_LOW) ) self.list.append( getConfigListEntry(_("Scan %s band") % ("US MID"), self.nimConfig.cable.scan_band_US_MID) ) self.list.append( getConfigListEntry(_("Scan %s band") % ("US HIGH"), self.nimConfig.cable.scan_band_US_HIGH) ) self.list.append( getConfigListEntry( _("Scan %s band") % ("US SUPER"), self.nimConfig.cable.scan_band_US_SUPER ) ) self.list.append( getConfigListEntry( _("Scan %s band") % ("US HYPER"), self.nimConfig.cable.scan_band_US_HYPER ) ) elif self.nimConfig.cable.scan_type.value == "steps": self.list.append( getConfigListEntry( _("Frequency scan step size(khz)"), self.nimConfig.cable.scan_frequency_steps ) ) # TRANSLATORS: option name, indicating which type of (DVB-C) modulation should be scanned. The modulation type is printed in '%s'. E.g.: 'Scan QAM16' self.list.append(getConfigListEntry(_("Scan %s") % ("QAM16"), self.nimConfig.cable.scan_mod_qam16)) self.list.append(getConfigListEntry(_("Scan %s") % ("QAM32"), self.nimConfig.cable.scan_mod_qam32)) self.list.append(getConfigListEntry(_("Scan %s") % ("QAM64"), self.nimConfig.cable.scan_mod_qam64)) self.list.append( getConfigListEntry(_("Scan %s") % ("QAM128"), self.nimConfig.cable.scan_mod_qam128) ) self.list.append( getConfigListEntry(_("Scan %s") % ("QAM256"), self.nimConfig.cable.scan_mod_qam256) ) self.list.append(getConfigListEntry(_("Scan %s") % ("SR6900"), self.nimConfig.cable.scan_sr_6900)) self.list.append(getConfigListEntry(_("Scan %s") % ("SR6875"), self.nimConfig.cable.scan_sr_6875)) self.list.append(getConfigListEntry(_("Scan additional SR"), self.nimConfig.cable.scan_sr_ext1)) self.list.append(getConfigListEntry(_("Scan additional SR"), self.nimConfig.cable.scan_sr_ext2)) self.have_advanced = False elif self.nim.isCompatible("DVB-T"): self.configMode = getConfigListEntry(_("Configuration mode"), self.nimConfig.configMode) self.list.append(self.configMode) self.have_advanced = False if self.nimConfig.configMode.value == "enabled": self.list.append(getConfigListEntry(_("Terrestrial provider"), self.nimConfig.terrestrial)) self.list.append(getConfigListEntry(_("Enable 5V for active antenna"), self.nimConfig.terrestrial_5V)) else: self.have_advanced = False self["config"].list = self.list self["config"].l.setList(self.list)
def createSetup(self): level = config.usage.setup_level.index self.list = [ getConfigListEntry(_("Video output"), config.av.videoport, _("Configures which video output connector will be used.")) ] # if we have modes for this port: if config.av.videoport.value in config.av.videomode: # add mode- and rate-selection: self.list.append(getConfigListEntry(pgettext("Video output mode", "Mode"), config.av.videomode[config.av.videoport.value], _("Configure the video output mode (or resolution)."))) if config.av.videomode[config.av.videoport.value].value == 'PC': self.list.append(getConfigListEntry(_("Resolution"), config.av.videorate[config.av.videomode[config.av.videoport.value].value], _("Configure the screen resolution in PC output mode."))) else: self.list.append(getConfigListEntry(_("Refresh rate"), config.av.videorate[config.av.videomode[config.av.videoport.value].value], _("Configure the refresh rate of the screen."))) port = config.av.videoport.value if port not in config.av.videomode: mode = None else: mode = config.av.videomode[port].value # some modes (720p, 1080i) are always widescreen. Don't let the user select something here, "auto" is not what he wants. force_wide = self.hw.isWidescreenMode(port, mode) if not force_wide: self.list.append(getConfigListEntry(_("Aspect ratio"), config.av.aspect, _("Configure the aspect ratio of the screen."))) if force_wide or config.av.aspect.value in ("16_9", "16_10"): self.list.extend(( getConfigListEntry(_("Display 4:3 content as"), config.av.policy_43, _("When the content has an aspect ratio of 4:3, choose whether to scale/stretch the picture.")), getConfigListEntry(_("Display >16:9 content as"), config.av.policy_169, _("When the content has an aspect ratio of 16:9, choose whether to scale/stretch the picture.")) )) elif config.av.aspect.value == "4_3": self.list.append(getConfigListEntry(_("Display 16:9 content as"), config.av.policy_169, _("When the content has an aspect ratio of 16:9, choose whether to scale/stretch the picture."))) # if config.av.videoport.value == "DVI": # self.list.append(getConfigListEntry(_("Allow Unsupported Modes"), config.av.edid_override)) if config.av.videoport.value == "Scart": self.list.append(getConfigListEntry(_("Color format"), config.av.colorformat, _("Configure which color format should be used on the SCART output."))) if level >= 1: self.list.append(getConfigListEntry(_("WSS on 4:3"), config.av.wss, _("When enabled, content with an aspect ratio of 4:3 will be stretched to fit the screen."))) if SystemInfo["ScartSwitch"]: self.list.append(getConfigListEntry(_("Auto scart switching"), config.av.vcrswitch, _("When enabled, your receiver will detect activity on the VCR SCART input."))) if level >= 1: if SystemInfo["CanDownmixAC3"]: self.list.append(getConfigListEntry(_("AC3 downmix"), config.av.downmix_ac3, _("Configure whether multi channel sound tracks should be downmixed to stereo."))) if SystemInfo["CanDownmixDTS"]: self.list.append(getConfigListEntry(_("DTS downmix"), config.av.downmix_dts, _("Configure whether multi channel sound tracks should be downmixed to stereo."))) if SystemInfo["CanDownmixAAC"]: self.list.append(getConfigListEntry(_("AAC downmix"), config.av.downmix_aac, _("Configure whether multi channel sound tracks should be downmixed to stereo."))) self.list.extend(( getConfigListEntry(_("General AC3 delay"), config.av.generalAC3delay, _("Configure the general audio delay of Dolby Digital sound tracks.")), getConfigListEntry(_("General PCM delay"), config.av.generalPCMdelay, _("Configure the general audio delay of stereo sound tracks.")) )) if SystemInfo["CanChangeOsdAlpha"]: self.list.append(getConfigListEntry(_("OSD transparency"), config.av.osd_alpha, _("Configure the transparency of the OSD."))) if not isinstance(config.av.scaler_sharpness, ConfigNothing): self.list.append(getConfigListEntry(_("Scaler sharpness"), config.av.scaler_sharpness, _("Configure the sharpness of the video scaling."))) self["config"].list = self.list self["config"].l.setList(self.list)