Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: 

 

# Copyright 2014-2018 Florian Bruhin (The Compiler) <mail@qutebrowser.org> 

# 

# This file is part of qutebrowser. 

# 

# qutebrowser is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# qutebrowser is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the GNU General Public License 

# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>. 

 

"""The main statusbar widget.""" 

 

import enum 

import attr 

from PyQt5.QtCore import pyqtSignal, pyqtSlot, pyqtProperty, Qt, QSize, QTimer 

from PyQt5.QtWidgets import QWidget, QHBoxLayout, QStackedLayout, QSizePolicy 

 

from qutebrowser.browser import browsertab 

from qutebrowser.config import config 

from qutebrowser.utils import usertypes, log, objreg, utils 

from qutebrowser.mainwindow.statusbar import (backforward, command, progress, 

keystring, percentage, url, 

tabindex) 

from qutebrowser.mainwindow.statusbar import text as textwidget 

 

 

@attr.s 

class ColorFlags: 

 

"""Flags which change the appearance of the statusbar. 

 

Attributes: 

prompt: If we're currently in prompt-mode. 

insert: If we're currently in insert mode. 

command: If we're currently in command mode. 

mode: The current caret mode (CaretMode.off/.on/.selection). 

private: Whether this window is in private browsing mode. 

passthrough: If we're currently in passthrough-mode. 

""" 

 

CaretMode = enum.Enum('CaretMode', ['off', 'on', 'selection']) 

prompt = attr.ib(False) 

insert = attr.ib(False) 

command = attr.ib(False) 

caret = attr.ib(CaretMode.off) 

private = attr.ib(False) 

passthrough = attr.ib(False) 

 

def to_stringlist(self): 

"""Get a string list of set flags used in the stylesheet. 

 

This also combines flags in ways they're used in the sheet. 

""" 

strings = [] 

if self.prompt: 

strings.append('prompt') 

if self.insert: 

strings.append('insert') 

if self.command: 

strings.append('command') 

if self.private: 

strings.append('private') 

if self.passthrough: 

strings.append('passthrough') 

 

if self.private and self.command: 

strings.append('private-command') 

 

if self.caret == self.CaretMode.on: 

strings.append('caret') 

elif self.caret == self.CaretMode.selection: 

strings.append('caret-selection') 

else: 

assert self.caret == self.CaretMode.off 

 

return strings 

 

 

def _generate_stylesheet(): 

flags = [ 

('private', 'statusbar.private'), 

('caret', 'statusbar.caret'), 

('caret-selection', 'statusbar.caret.selection'), 

('prompt', 'prompts'), 

('insert', 'statusbar.insert'), 

('command', 'statusbar.command'), 

('passthrough', 'statusbar.passthrough'), 

('private-command', 'statusbar.command.private'), 

] 

stylesheet = """ 

QWidget#StatusBar, 

QWidget#StatusBar QLabel, 

QWidget#StatusBar QLineEdit { 

font: {{ conf.fonts.statusbar }}; 

background-color: {{ conf.colors.statusbar.normal.bg }}; 

color: {{ conf.colors.statusbar.normal.fg }}; 

} 

""" 

for flag, option in flags: 

stylesheet += """ 

QWidget#StatusBar[color_flags~="%s"], 

QWidget#StatusBar[color_flags~="%s"] QLabel, 

QWidget#StatusBar[color_flags~="%s"] QLineEdit { 

color: {{ conf.colors.%s }}; 

background-color: {{ conf.colors.%s }}; 

} 

""" % (flag, flag, flag, # noqa: S001 

option + '.fg', option + '.bg') 

return stylesheet 

 

 

class StatusBar(QWidget): 

 

"""The statusbar at the bottom of the mainwindow. 

 

Attributes: 

txt: The Text widget in the statusbar. 

keystring: The KeyString widget in the statusbar. 

percentage: The Percentage widget in the statusbar. 

url: The UrlText widget in the statusbar. 

prog: The Progress widget in the statusbar. 

cmd: The Command widget in the statusbar. 

_hbox: The main QHBoxLayout. 

_stack: The QStackedLayout with cmd/txt widgets. 

_win_id: The window ID the statusbar is associated with. 

 

Signals: 

resized: Emitted when the statusbar has resized, so the completion 

widget can adjust its size to it. 

arg: The new size. 

moved: Emitted when the statusbar has moved, so the completion widget 

can move to the right position. 

arg: The new position. 

""" 

 

resized = pyqtSignal('QRect') 

moved = pyqtSignal('QPoint') 

_severity = None 

_color_flags = [] 

 

STYLESHEET = _generate_stylesheet() 

 

def __init__(self, *, win_id, private, parent=None): 

super().__init__(parent) 

objreg.register('statusbar', self, scope='window', window=win_id) 

self.setObjectName(self.__class__.__name__) 

self.setAttribute(Qt.WA_StyledBackground) 

config.set_register_stylesheet(self) 

 

self.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Fixed) 

 

self._win_id = win_id 

self._color_flags = ColorFlags() 

self._color_flags.private = private 

 

self._hbox = QHBoxLayout(self) 

self._set_hbox_padding() 

self._hbox.setSpacing(5) 

 

self._stack = QStackedLayout() 

self._hbox.addLayout(self._stack) 

self._stack.setContentsMargins(0, 0, 0, 0) 

 

self.cmd = command.Command(private=private, win_id=win_id) 

self._stack.addWidget(self.cmd) 

objreg.register('status-command', self.cmd, scope='window', 

window=win_id) 

 

self.txt = textwidget.Text() 

self._stack.addWidget(self.txt) 

 

self.cmd.show_cmd.connect(self._show_cmd_widget) 

self.cmd.hide_cmd.connect(self._hide_cmd_widget) 

self._hide_cmd_widget() 

 

self.url = url.UrlText() 

self.percentage = percentage.Percentage() 

self.backforward = backforward.Backforward() 

self.tabindex = tabindex.TabIndex() 

self.keystring = keystring.KeyString() 

self.prog = progress.Progress(self) 

self._draw_widgets(bc) 

 

config.instance.changed.connect(self._on_config_changed) 

QTimer.singleShot(0, self.maybe_hide) 

 

def __repr__(self): 

return utils.get_repr(self) 

 

@pyqtSlot(str) 

def _on_config_changed(self, option): 

if option == 'statusbar.hide': 

self.maybe_hide() 

elif option == 'statusbar.padding': 

self._set_hbox_padding() 

elif option == 'statusbar.widgets': 

self._draw_widgets(bc) 

 

def _draw_widgets(self, bc): 

"""Draw statusbar widgets.""" 

# Start with widgets hidden and show them when needed 

for widget in [self.url, self.percentage, 

self.backforward, self.tabindex, 

self.keystring, self.prog]: 

bc[9][0] = True 

widget.hide() 

self._hbox.removeWidget(widget) 

 

tab = self._current_tab() 

 

# Read the list and set widgets accordingly 

for segment in config.val.statusbar.widgets: 

bc[9][1] = True 

if segment == 'url': 

bc[9][2] = True 

self._hbox.addWidget(self.url) 

self.url.show() 

elif segment == 'scroll': 

bc[9][3] = True 

self._hbox.addWidget(self.percentage) 

self.percentage.show() 

elif segment == 'scroll_raw': 

bc[9][4] = True 

self._hbox.addWidget(self.percentage) 

self.percentage.raw = True 

self.percentage.show() 

elif segment == 'history': 

bc[9][5] = True 

self._hbox.addWidget(self.backforward) 

self.backforward.enabled = True 

if tab: 

bc[9][6] = True 

self.backforward.on_tab_changed(tab) 

elif segment == 'tabs': 

bc[9][7] = True 

self._hbox.addWidget(self.tabindex) 

self.tabindex.show() 

elif segment == 'keypress': 

bc[9][8] = True 

self._hbox.addWidget(self.keystring) 

self.keystring.show() 

elif segment == 'progress': 

bc[9][9] = True 

self._hbox.addWidget(self.prog) 

self.prog.enabled = True 

if tab: 

bc[9][10] = True 

self.prog.on_tab_changed(tab) 

 

@pyqtSlot() 

def maybe_hide(self): 

"""Hide the statusbar if it's configured to do so.""" 

tab = self._current_tab() 

hide = config.val.statusbar.hide 

if hide or (tab is not None and tab.data.fullscreen): 

self.hide() 

else: 

self.show() 

 

def _set_hbox_padding(self): 

padding = config.val.statusbar.padding 

self._hbox.setContentsMargins(padding.left, 0, padding.right, 0) 

 

@pyqtProperty('QStringList') 

def color_flags(self): 

"""Getter for self.color_flags, so it can be used as Qt property.""" 

return self._color_flags.to_stringlist() 

 

def _current_tab(self): 

"""Get the currently displayed tab.""" 

window = objreg.get('tabbed-browser', scope='window', 

window=self._win_id) 

return window.currentWidget() 

 

def set_mode_active(self, mode, val): 

"""Setter for self.{insert,command,caret}_active. 

 

Re-set the stylesheet after setting the value, so everything gets 

updated by Qt properly. 

""" 

if mode == usertypes.KeyMode.insert: 

log.statusbar.debug("Setting insert flag to {}".format(val)) 

self._color_flags.insert = val 

if mode == usertypes.KeyMode.passthrough: 

log.statusbar.debug("Setting passthrough flag to {}".format(val)) 

self._color_flags.passthrough = val 

if mode == usertypes.KeyMode.command: 

log.statusbar.debug("Setting command flag to {}".format(val)) 

self._color_flags.command = val 

elif mode in [usertypes.KeyMode.prompt, usertypes.KeyMode.yesno]: 

log.statusbar.debug("Setting prompt flag to {}".format(val)) 

self._color_flags.prompt = val 

elif mode == usertypes.KeyMode.caret: 

tab = self._current_tab() 

log.statusbar.debug("Setting caret flag - val {}, selection " 

"{}".format(val, tab.caret.selection_enabled)) 

if val: 

if tab.caret.selection_enabled: 

self._set_mode_text("{} selection".format(mode.name)) 

self._color_flags.caret = ColorFlags.CaretMode.selection 

else: 

self._set_mode_text(mode.name) 

self._color_flags.caret = ColorFlags.CaretMode.on 

else: 

self._color_flags.caret = ColorFlags.CaretMode.off 

config.set_register_stylesheet(self, update=False) 

 

def _set_mode_text(self, mode): 

"""Set the mode text.""" 

if mode == 'passthrough': 

key_instance = config.key_instance 

all_bindings = key_instance.get_reverse_bindings_for('passthrough') 

bindings = all_bindings.get('leave-mode') 

if bindings: 

suffix = ' ({} to leave)'.format(bindings[0]) 

else: 

suffix = '' 

else: 

suffix = '' 

text = "-- {} MODE --{}".format(mode.upper(), suffix) 

self.txt.set_text(self.txt.Text.normal, text) 

 

def _show_cmd_widget(self): 

"""Show command widget instead of temporary text.""" 

self._stack.setCurrentWidget(self.cmd) 

self.show() 

 

def _hide_cmd_widget(self): 

"""Show temporary text instead of command widget.""" 

log.statusbar.debug("Hiding cmd widget") 

self._stack.setCurrentWidget(self.txt) 

self.maybe_hide() 

 

@pyqtSlot(str) 

def set_text(self, val): 

"""Set a normal (persistent) text in the status bar.""" 

self.txt.set_text(self.txt.Text.normal, val) 

 

@pyqtSlot(usertypes.KeyMode) 

def on_mode_entered(self, mode): 

"""Mark certain modes in the commandline.""" 

keyparsers = objreg.get('keyparsers', scope='window', 

window=self._win_id) 

if keyparsers[mode].passthrough: 

self._set_mode_text(mode.name) 

if mode in [usertypes.KeyMode.insert, 

usertypes.KeyMode.command, 

usertypes.KeyMode.caret, 

usertypes.KeyMode.prompt, 

usertypes.KeyMode.yesno, 

usertypes.KeyMode.passthrough]: 

self.set_mode_active(mode, True) 

 

@pyqtSlot(usertypes.KeyMode, usertypes.KeyMode) 

def on_mode_left(self, old_mode, new_mode): 

"""Clear marked mode.""" 

keyparsers = objreg.get('keyparsers', scope='window', 

window=self._win_id) 

if keyparsers[old_mode].passthrough: 

if keyparsers[new_mode].passthrough: 

self._set_mode_text(new_mode.name) 

else: 

self.txt.set_text(self.txt.Text.normal, '') 

if old_mode in [usertypes.KeyMode.insert, 

usertypes.KeyMode.command, 

usertypes.KeyMode.caret, 

usertypes.KeyMode.prompt, 

usertypes.KeyMode.yesno, 

usertypes.KeyMode.passthrough]: 

self.set_mode_active(old_mode, False) 

 

@pyqtSlot(browsertab.AbstractTab) 

def on_tab_changed(self, tab): 

"""Notify sub-widgets when the tab has been changed.""" 

self.url.on_tab_changed(tab) 

self.prog.on_tab_changed(tab) 

self.percentage.on_tab_changed(tab) 

self.backforward.on_tab_changed(tab) 

self.maybe_hide() 

assert tab.private == self._color_flags.private 

 

def resizeEvent(self, e): 

"""Extend resizeEvent of QWidget to emit a resized signal afterwards. 

 

Args: 

e: The QResizeEvent. 

""" 

super().resizeEvent(e) 

self.resized.emit(self.geometry()) 

 

def moveEvent(self, e): 

"""Extend moveEvent of QWidget to emit a moved signal afterwards. 

 

Args: 

e: The QMoveEvent. 

""" 

super().moveEvent(e) 

self.moved.emit(e.pos()) 

 

def minimumSizeHint(self): 

"""Set the minimum height to the text height plus some padding.""" 

padding = config.val.statusbar.padding 

width = super().minimumSizeHint().width() 

height = self.fontMetrics().height() + padding.top + padding.bottom 

return QSize(width, height)