mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Restart and context menu added to console
This commit is contained in:
parent
8d09778514
commit
e7adf45c01
@ -15,7 +15,7 @@ def console_config():
|
||||
desc='Settings to control the calibre console'
|
||||
c = Config('console', desc)
|
||||
|
||||
c.add_opt('theme', default='default', help='The color theme')
|
||||
c.add_opt('theme', default='native', help='The color theme')
|
||||
|
||||
return c
|
||||
|
||||
|
@ -49,7 +49,7 @@ class Prepender(object): # {{{
|
||||
self.console.cursor_pos = self.opos
|
||||
# }}}
|
||||
|
||||
class ThemeMenu(QMenu):
|
||||
class ThemeMenu(QMenu): # {{{
|
||||
|
||||
def __init__(self, parent):
|
||||
QMenu.__init__(self, _('Choose theme (needs restart)'))
|
||||
@ -62,6 +62,7 @@ class ThemeMenu(QMenu):
|
||||
self.actions = []
|
||||
for style in alls:
|
||||
ac = self.group.addAction(style)
|
||||
ac.setCheckable(True)
|
||||
if current == style:
|
||||
ac.setChecked(True)
|
||||
self.actions.append(ac)
|
||||
@ -71,6 +72,7 @@ class ThemeMenu(QMenu):
|
||||
def set_theme(self, style, *args):
|
||||
prefs['theme'] = style
|
||||
|
||||
# }}}
|
||||
|
||||
class Console(QTextEdit):
|
||||
|
||||
@ -163,7 +165,6 @@ class Console(QTextEdit):
|
||||
self.context_menu.popup(event.globalPos())
|
||||
event.accept()
|
||||
|
||||
|
||||
# Prompt management {{{
|
||||
|
||||
@dynamic_property
|
||||
|
@ -9,7 +9,7 @@ __version__ = '0.1.0'
|
||||
from functools import partial
|
||||
|
||||
from PyQt4.Qt import QDialog, QToolBar, QStatusBar, QLabel, QFont, Qt, \
|
||||
QApplication, QIcon, QVBoxLayout
|
||||
QApplication, QIcon, QVBoxLayout, QAction
|
||||
|
||||
from calibre.constants import __appname__, __version__
|
||||
from calibre.utils.pyconsole.console import Console
|
||||
@ -19,8 +19,9 @@ class MainWindow(QDialog):
|
||||
def __init__(self,
|
||||
default_status_msg=_('Welcome to') + ' ' + __appname__+' console',
|
||||
parent=None):
|
||||
|
||||
QDialog.__init__(self, parent)
|
||||
|
||||
self.restart_requested = False
|
||||
self.l = QVBoxLayout()
|
||||
self.setLayout(self.l)
|
||||
|
||||
@ -51,14 +52,26 @@ class MainWindow(QDialog):
|
||||
self.setWindowTitle(__appname__ + ' console')
|
||||
self.setWindowIcon(QIcon(I('console.png')))
|
||||
|
||||
self.restart_action = QAction(_('Restart'), self)
|
||||
self.restart_action.setShortcut(_('Ctrl+R'))
|
||||
self.addAction(self.restart_action)
|
||||
self.restart_action.triggered.connect(self.restart)
|
||||
self.console.context_menu.addAction(self.restart_action)
|
||||
|
||||
def restart(self):
|
||||
self.restart_requested = True
|
||||
self.reject()
|
||||
|
||||
def main():
|
||||
QApplication.setApplicationName(__appname__+' console')
|
||||
QApplication.setOrganizationName('Kovid Goyal')
|
||||
app = QApplication([])
|
||||
m = MainWindow()
|
||||
m.show()
|
||||
app.exec_()
|
||||
app
|
||||
while True:
|
||||
m = MainWindow()
|
||||
m.exec_()
|
||||
if not m.restart_requested:
|
||||
break
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
x
Reference in New Issue
Block a user