Class: Eiwaji::MainWindow
- Inherits:
-
Qt::MainWindow
- Object
- Qt::MainWindow
- Eiwaji::MainWindow
- Defined in:
- lib/mainwindow.rb
Instance Method Summary collapse
- #clipboardChanged(mode) ⇒ Object
- #createActions ⇒ Object
- #createDockWindows ⇒ Object
- #createMenus ⇒ Object
- #createStatusBar ⇒ Object
- #initClipboard ⇒ Object
-
#initialize(parent = nil) ⇒ MainWindow
constructor
A new instance of MainWindow.
-
#lexEditorText ⇒ Object
send the text in the main editor to the lexer widget.
- #openSettings ⇒ Object
- #readConfig ⇒ Object
- #rebuild_dictionary ⇒ Object
- #search(query, lemma) ⇒ Object
- #toggleMainTextEditable ⇒ Object
- #writeConfig ⇒ Object
Constructor Details
#initialize(parent = nil) ⇒ MainWindow
Returns a new instance of MainWindow.
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 |
# File 'lib/mainwindow.rb', line 17 def initialize(parent = nil) super(parent) if find_executable0('mecab') == nil Qt::MessageBox.critical(self, tr("Mecab not installed"), tr("An installation of mecab was not detected. " + "Text analysis will not function properly.")) end @ui = Ui_MainWindow.new @ui.setupUi(self) @settings ||= Qt::Settings.new(Eiwaji::Constants::CONFIG_PATH, Qt::Settings::IniFormat) if not File.exists? Eiwaji::Constants::CONFIG_PATH writeConfig end readConfig initClipboard() createActions() createMenus() createStatusBar() createDockWindows() setStyleSheet("QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }") end |
Instance Method Details
#clipboardChanged(mode) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/mainwindow.rb', line 58 def clipboardChanged(mode) clipboard = Qt::Application.clipboard if clipboard.mimeData.hasText && mode == Qt::Clipboard::Clipboard && @clipboardCaptureAct.isChecked @ui.bigEditor.setText(clipboard.text.force_encoding("UTF-8")) lexEditorText() end end |
#createActions ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/mainwindow.rb', line 88 def createActions @veAct = Qt::Action.new(tr("&Analyze Text"), self) @veAct.statusTip = tr("Send the text in the editor to the lexer widget.") connect(@veAct, SIGNAL('triggered()'), self, SLOT('lexEditorText()')) @clipboardCaptureAct = Qt::Action.new(tr("&Capture Clipboard"), self) @clipboardCaptureAct.statusTip = tr("Automatically copy text to the editor and lexer") @clipboardCaptureAct.setCheckable(true) connect(@clipboardCaptureAct, SIGNAL('triggered()'), self, SLOT('toggleMainTextEditable()')) @settingsAct = Qt::Action.new(tr("&Settings..."), self) @settingsAct.statusTip = tr("Open the settings dialog") connect(@settingsAct, SIGNAL('triggered()'), self, SLOT('openSettings()')) end |
#createDockWindows ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/mainwindow.rb', line 112 def createDockWindows = LexerWidget.new(self) addDockWidget(Qt::BottomDockWidgetArea, ) = DictionaryWidget.new(self) addDockWidget(Qt::RightDockWidgetArea, ) end |
#createMenus ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/mainwindow.rb', line 103 def createMenus @fileMenu = ().addMenu(tr("&File")) @fileMenu.addAction(@veAct) @editMenu = ().addMenu(tr("&Edit")) @editMenu.addAction(@clipboardCaptureAct) @editMenu.addAction(@settingsAct) end |
#createStatusBar ⇒ Object
84 85 86 |
# File 'lib/mainwindow.rb', line 84 def createStatusBar statusBar().showMessage(tr("Ready")) end |
#initClipboard ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/mainwindow.rb', line 44 def initClipboard clipboard = Qt::Application.clipboard # on Windows, it appears that the clipboard is not monitored until it is changed within the Qt application. # clipboard.setText(clipboard.text.force_encoding("UTF-8")) if clipboard.mimeData.hasText connect(clipboard, SIGNAL('changed(QClipboard::Mode)'), self, SLOT('clipboardChanged(QClipboard::Mode)')) end |
#lexEditorText ⇒ Object
send the text in the main editor to the lexer widget
53 54 55 56 |
# File 'lib/mainwindow.rb', line 53 def lexEditorText text = @ui.bigEditor.toPlainText .lexText(text, true) end |
#openSettings ⇒ Object
120 121 122 123 124 125 |
# File 'lib/mainwindow.rb', line 120 def openSettings settings = Eiwaji::SettingsDialog.new(self) settings.exec readConfig .reset end |
#readConfig ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/mainwindow.rb', line 134 def readConfig return unless File.exists? Eiwaji::Constants::CONFIG_PATH JDict.reset JDict.configure do |config| config.num_results = @settings.value("num_results").toInt config.language = @settings.value("language").toString.to_sym config.dictionary_path = Eiwaji::Constants::DICTIONARY_PATH config.index_path = Eiwaji::Constants::DICTIONARY_PATH end end |
#rebuild_dictionary ⇒ Object
80 81 82 |
# File 'lib/mainwindow.rb', line 80 def rebuild_dictionary .reset end |
#search(query, lemma) ⇒ Object
76 77 78 |
# File 'lib/mainwindow.rb', line 76 def search(query, lemma) .search(query, lemma) end |
#toggleMainTextEditable ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/mainwindow.rb', line 67 def toggleMainTextEditable if @clipboardCaptureAct.isChecked @ui.bigEditor.setEnabled(false) else @ui.bigEditor.setEnabled(true) end end |
#writeConfig ⇒ Object
127 128 129 130 131 132 |
# File 'lib/mainwindow.rb', line 127 def writeConfig config = JDict.configuration @settings.setValue("num_results", Qt::Variant.new(config.num_results)) @settings.setValue("language", Qt::Variant.new(config.language.to_s)) @settings.sync end |