def __init__(self, parent=None): super(MainMenu, self).__init__() self.createActions() #self.createMenus() self.translateActions() self.setting_dialog = SettingDialog(self) self.playmode_dialog = PlayModeDialog(self)
def option(self, index=0): if not hasattr(self, "_setting_window") or not self._setting_window: self._setting_window = SettingDialog(setting_config) self._setting_window.setWindowIcon(self._main_window.windowIcon()) self._setting_window.reload_settings() self._setting_window.setCurrentIndex(index) self._setting_window.show()
def init_ui(self): self.main_menu = MainMenu(self) self.setting_dialog = SettingDialog(self) self.title_widget = TitleWidget(self) self.btn_mainmenu = self.title_widget.btn_mainmenu self.btn_min = self.title_widget.btn_min self.btn_max = self.title_widget.btn_max self.btn_close = self.title_widget.btn_close self.controlbar = ControlBar() self.controlbar.setFixedHeight(48) self.btn_open = self.controlbar.btn_open self.btn_play = self.controlbar.btn_play self.btn_pause = self.controlbar.btn_pause self.btn_stop = self.controlbar.btn_stop self.btn_fullscreen = self.controlbar.btn_fullscreen self.btn_playlist = self.controlbar.btn_playlist self.lab_time = self.controlbar.lab_time self.seekslider = self.controlbar.seekslider self.volumeslider = self.controlbar.volumeslider self.video.setMinimumSize(650, 350) #self.playlist = PlayList(_('PlayList')) self.playlist = PlayList() self.playlist.setFixedSize(150, 850) # playlist is hidden by default #self.playlist.hide() title_layout = QtGui.QHBoxLayout() title_layout.addWidget(self.title_widget) center_layout = QtGui.QHBoxLayout() center_layout.addWidget(self.video) center_layout.setSpacing(0) center_layout.addWidget(self.playlist) bottom_layout = QtGui.QHBoxLayout() bottom_layout.addWidget(self.controlbar) main_layout = QtGui.QGridLayout(self) main_layout.addLayout(title_layout, 0, 0) main_layout.addLayout(center_layout, 1, 0) main_layout.setSpacing(0) main_layout.addLayout(bottom_layout, 2, 0, 1, 2) # Fill the window with all contents, no gap in border. main_layout.setContentsMargins(0, 0, 0, 0) self.setLayout(main_layout)
class MainMenu(QMenu): def __init__(self, parent=None): super(MainMenu, self).__init__() self.createActions() #self.createMenus() self.translateActions() self.setting_dialog = SettingDialog(self) self.playmode_dialog = PlayModeDialog(self) def show_setting_dialog(self): self.setting_dialog.exec_() def show_help(self): pass def show_about_me(self): #QtGui.QMessageBox.about(self, "About Me", # "Copyright@2015 qomolangmaice") QtGui.QMessageBox.about(self, "About Me",""" <HTML> <p><b>This demo shows use of <c>QTableWidget</c> with custom handling for individual cells.</b></p> <p>Using a customized table item we make it possible to have dynamic output in different cells. The content that is implemented for this particular demo is: <ul> <li>Adding two cells.</li> <li>Subtracting one cell from another.</li> <li>Multiplying two cells.</li> <li>Dividing one cell with another.</li> <li>Summing the contents of an arbitrary number of cells.</li> </HTML> """) def show_about_qt(self): pass def show_play_mode(self): self.playmode_dialog.exec_() def auto_play_mode(self): pass def repeat_single_mode(self): pass def repeat_all_mode(self): pass def shuffle_mode(self): pass def createActions(self): self.act_setting = QAction("Setting", self, statusTip="", triggered=self.show_setting_dialog) self.act_play_mode= QAction("PlayMode", self, statusTip="", triggered=self.show_play_mode) self.act_help = QAction(self) self.act_about_me= QAction("About me", self, statusTip="", triggered=self.show_about_me) self.act_about_qt = QAction("About Qt", self, statusTip="", triggered=self.show_about_qt) self.act_about_qt.triggered.connect(QtGui.qApp.aboutQt) self.act_setting.setIcon(QIcon("")) self.act_help.setIcon(QIcon("")) self.act_about_me.setIcon(QIcon("")) self.act_about_qt.setIcon(QIcon("")) # Add menu item self.addAction(self.act_setting) self.addAction(self.act_play_mode) self.addAction(self.act_help) self.addSeparator() self.addAction(self.act_about_me) self.addAction(self.act_about_qt) #def createMenus(self): # self.play_mode = self.menubar_play_mode.addMenu("&PlayMode") # self.play_mode.addAction(self.auto_play_mode) # self.play_mode.addAction(self.repeat_single_mode) # self.play_mode.addAction(self.repeat_all_mode) # self.play_mode.addAction(self.shuffle_mode) def translateActions(self): self.act_setting.setText(u"设置") self.act_play_mode.setText(u"播放模式") self.act_help.setText(u"帮助") self.act_about_me.setText(u"关于我") self.act_about_qt.setText(u"关于Qt")
def on_btn_config_label_click(self): dialog = SettingDialog() if dialog.exec_(): dialog.config_mata_data_base()
class ExternalApi(QObject): name = "api" onlimitHistory = pyqtSignal(QVariant) onsetUserDict = pyqtSignal(QVariant) onchangeCurClick = pyqtSignal(QVariant) onlangChange = pyqtSignal(QVariant) onwordStrokeStateChange = pyqtSignal(QVariant) onscreenTransStateChange = pyqtSignal(QVariant) ontopMost = pyqtSignal(QVariant) onfanyiQuery = pyqtSignal(QVariant) ondictQuery = pyqtSignal(QVariant) onnetStateChange = pyqtSignal(QVariant) onSplashTimeout = pyqtSignal() _ocrEnableNotify = pyqtSignal() _strokeEnableNotify = pyqtSignal() def __init__(self): QObject.__init__(self) self._media_player = None self._clipboard = None self.getword_daemon = GetwordDaemon() self.getword_daemon.keyReleased.connect( self.handle_getword_daemon_key_released) self._logo_window = LogoWindow(self.getword_daemon, setting_config, self) self._mini_window = MiniWindow(self.getword_daemon, setting_config, self) self._ocr_result_window = OcrResultWindow(self.getword_daemon, setting_config, self) self._trayicon_menu = TrayIconMenu(self.getword_daemon, self) setting_config.hasSaved.connect(self.handle_setting_dialog_saved) self._main_window = None self._sub_windows = [] def handle_getword_daemon_key_released(self, keyname): if keyname == "F8": self.setOcrEnable(not self.ocrEnabled) def handle_setting_dialog_saved(self, change_options): for option in change_options: section, key = option if section == "getword": if key == "ocr" or key == "ocr_mode": self.initOcrState() elif key == "stroke" or key == "stroke_mode": self.initStrokeState() elif section == "basic_option": if key == "main_window_topmost": self.initTopMost() def enable(self, webview): window = webview.window if window.parent: self._sub_windows.append(window) else: self._main_window = window def set_getword_config(self, key, value): setting_config.set_getword(key, value) if key == "ocr": mode = setting_config.get_getword("ocr_mode") self.onscreenTransStateChange.emit([value, mode]) elif key == "stroke": mode = setting_config.get_getword("stroke_mode") self.onwordStrokeStateChange.emit([value, mode]) def initStrokeState(self): enable = setting_config.get_getword("stroke") mode = setting_config.get_getword("stroke_mode") self.getword_daemon.SetStrokeEnable(enable) self._strokeEnableNotify.emit() self.onwordStrokeStateChange.emit([enable, mode]) def initOcrState(self): enable = setting_config.get_getword("ocr") mode = setting_config.get_getword("ocr_mode") self.getword_daemon.SetOcrEnable(enable) self._ocrEnableNotify.emit() self.onscreenTransStateChange.emit([enable, mode]) @pyqtSlot(result=str) def getSelectText(self): if not self._clipboard: self._clipboard = qApp.clipboard() return self._clipboard.text(mode=QClipboard.Selection) @pyqtSlot() def clearSelectText(self): if not self._clipboard: self._clipboard = qApp.clipboard() text = self._clipboard.text(mode=QClipboard.Selection) if text.strip() != "": self._clipboard.clear(mode=QClipboard.Selection) @pyqtSlot(str, str, str, result=str) def fanyi(self, keyword, keyfrom, lang): url = "http://fanyi.youdao.com/translate?dogVersion=1.0&ue=utf8" url += "&doctype=json&xmlVersion=1.6&client=deskdict&id=92dc50aa4970fb72d" url += "&vendor=unknown&in=YoudaoDict&appVer=6.3.66.1117&appZengqiang=0" url += "&abTest=5&smartresult=dict&smartresult=rule" url += "&i=" + keyword url += "&keyfrom=" + keyfrom url += "&type=" + lang try: return requests.get(url).text except: return "" @pyqtSlot(bool) def emitNetStateChange(self, state): self.onnetStateChange.emit([state]) @pyqtSlot() def clear_action(self): self.getword_daemon.ClearStroke() @pyqtSlot() def startInitState(self): self.initOcrState() self.initStrokeState() @pyqtSlot() def initTopMost(self): state = setting_config.get_basic_option("main_window_topmost") self.emitTopMost(state) @pyqtSlot(bool) def setOcrEnable(self, value): self.getword_daemon.SetOcrEnable(value) self.set_getword_config("ocr", value) self._ocrEnableNotify.emit() @pyqtSlot(result=bool) def getOcrEnable(self): return self.getword_daemon.GetOcrEnable() @pyqtProperty(bool, notify=_ocrEnableNotify) def ocrEnabled(self): enable = setting_config.get_getword("ocr") return enable @pyqtSlot(bool) def setStrokeEnable(self, value): self.getword_daemon.SetStrokeEnable(value) self.set_getword_config("stroke", value) self._strokeEnableNotify.emit() @pyqtSlot(result=bool) def getStrokeEnable(self): return self.getword_daemon.GetStrokeEnable() @pyqtProperty(bool, notify=_strokeEnableNotify) def strokeEnabled(self): enable = setting_config.get_getword("stroke") return enable @pyqtSlot() def getwordQuit(self): print("getword daemon exit...") self.getword_daemon.Quit() @pyqtSlot(bool) def emitTopMost(self, new_state): self.ontopMost.emit([new_state]) @pyqtSlot(str, str) def emitDictQuery(self, text, lang): param = [text, lang] self.ondictQuery.emit(param) ''' implemented api for externalAPI in business.js ''' @pyqtSlot() def toggleTopMost(self): state = setting_config.get_basic_option("main_window_topmost") self.emitTopMost(not state) @pyqtSlot() def strokeTrans(self): self.setStrokeEnable(not self.strokeEnabled) @pyqtSlot() def screenTrans(self): self.setOcrEnable(not self.ocrEnabled) @pyqtSlot() def openZFanyi(self): webbrowser.open("http://f.youdao.com/?vendor=%s" % vendor) @pyqtSlot() def openPictDict(self): if self._main_window and self._main_window.assets: if not hasattr(self, "_pict_dict_window"): app_dir = self._main_window.assets.manifest["app_dir"] pictDictIndexPath = "file://" + os.path.join( app_dir, "assets/pic/picdict.html") self._pict_dict_window = self._main_window.api.createWindow( pictDictIndexPath, 900, 680) self._pict_dict_window.show() @pyqtSlot() def openStudy(self): webbrowser.open("http://xue.youdao.com/?keyfrom=%s" % vendor) @pyqtSlot() def openBbs(self): webbrowser.open("http://dg.youdao.com/") @pyqtSlot() def openMini(self): self._mini_window.show() self._mini_window.recordCurrentVisible("true") if self._main_window and self._mini_window not in self._main_window.assets.windows: self._main_window.assets.windows.append(self._mini_window) @pyqtSlot() def changeFrameAdv(self): pass @pyqtSlot(QVariant) def langChange(self, lang): print("langChange:", lang) @pyqtSlot(result=str) def getAppID(self): return appId @pyqtSlot(result=str) def getVendor(self): return vendor @pyqtSlot(result=str) def getAppVersionString(self): return self._main_window.assets.manifest["version"] @pyqtSlot() @pyqtSlot(int) def option(self, index=0): if not hasattr(self, "_setting_window") or not self._setting_window: self._setting_window = SettingDialog(setting_config) self._setting_window.setWindowIcon(self._main_window.windowIcon()) self._setting_window.reload_settings() self._setting_window.setCurrentIndex(index) self._setting_window.show() @pyqtSlot() def aboutDlg(self): if not hasattr(self, "_about_dialog") or not self._about_dialog: self._about_dialog = AboutWindow() self._about_dialog.setIcon(self._main_window.windowIcon()) self._about_dialog.showCenter() @pyqtSlot() def quit(self): if self._main_window: self._main_window.quit() @pyqtSlot(str) def copyText(self, text): from PyQt5.QtGui import QGuiApplication clip = QGuiApplication.clipboard() clip.setText(text) @pyqtSlot() def showTrayIconMenu(self): self._trayicon_menu.showAtCursor() @pyqtSlot() def showMainWindow(self): self._main_window.show() self._main_window.activate() @pyqtSlot(str, result=QVariant) @pyqtSlot(str, int, result=QVariant) def getSuggest(self, text, num=10): return get_suggest(text, num) @pyqtSlot(str, result=QVariant) def getMainQuery(self, text): return get_main_query(text) @pyqtSlot(str) def playSound(self, url): self.getword_daemon.PlaySound(url) @pyqtSlot() def stopSound(self): self.getword_daemon.StopSound()
def mni_setting_activate(self, item): if not hasattr(self, 'setting_dialog'): self.setting_dialog = SettingDialog() result = self.setting_dialog.show() print result
class DomorIndicator(object): def __init__(self): # build UI from glade file builder = Gtk.Builder() #builder.add_from_file(to_abs_path(PoResources.UI_TRAY)) builder.add_from_file(to_abs_path(PoResources.UI_TRAY)) builder.connect_signals(self) style.setStyle() # get some common used object self.builder = builder self.menu = builder.get_object('tray_menu') self.lb_clock = builder.get_object('mni_clock') self.lb_counter = builder.get_object('mni_archive_count') APPIND_SUPPORT = 1 try: from gi.repository import AppIndicator3 except: APPIND_SUPPORT = 0 if APPIND_SUPPORT == 1: self.ind = AppIndicator3.Indicator.new_with_path("domor-indicator", 'app_icon_64', AppIndicator3.IndicatorCategory.APPLICATION_STATUS, to_abs_path('img')) self.ind.set_status(AppIndicator3.IndicatorStatus.ACTIVE) self.ind.set_menu(self.menu) else: self.myStatusIcon = Gtk.StatusIcon() self.myStatusIcon.set_from_file( to_abs_path(PoResources.ICON_APP_64)) self.myStatusIcon.connect( 'popup-menu', self.right_click_event_statusicon) # 6 load config self.settings = settings = Settings() settings.load_config() # 7 init class state self.btn_state = State.STOP self.state = State.IDLE self.time = settings.short_work_time self.work_time = 0 self.count = 0 # create main screen self.main_window = MainWindow(self.on_mni_start_activate) self.main_window.update(self.state, self.btn_state) # create rest screen self.break_screen = BreakScreen(self.on_skip_break) self.reset() # register timer callback GObject.timeout_add_seconds(1, self.count_down) def reset(self): ''' Reset to default state :return: ''' self.state = State.IDLE self.time = self.settings.short_work_time self.btn_state = State.STOP self._update_item( 'mni_start', get_resource(PoResources.ICON_START), 'Start') self._update_time() # hide break screen if showing self.break_screen.hide() if self.main_window: self.main_window.update(self.state, self.btn_state) def on_skip_break(self): if self.state == State.BREAK: # if time is counting and in break period and user click PAUSE button # reset timer and button state self.reset() def _update_item(self, item_id, img_path, label=None): """ Update image for button :param button_id: id of button which is updated :param img_path: path to image :return: None """ try: item = self.builder.get_object(item_id) img = Gtk.Image.new_from_file(img_path) item.set_image(img) if label: item.set_label(label) except Exception as e: print item_id print e.message def _update_time(self): """ Update display time on UI :return: """ time_string = "%02d:%02d" % (self.time / 60, self.time % 60) self.lb_clock.set_label(time_string) if self.state == State.BREAK: self.break_screen.update_time(time_string) if self.main_window: self.main_window.update_time(time_string) def _update_pomodoro_count(self): label = str(self.count) + \ (" pomodoro" if self.count <= 1 else " pomodoros") self.lb_counter.set_label(label) if self.main_window: self.main_window.update_pomodoro_count(self.count) def count_down(self): if self.state != State.IDLE: if self.state == State.WORK: if self.time == 0: self.count += 1 # long_work_time is the number of short working session # between long break if self.count % self.settings.long_work_time == 0: self.start_break_period(self.settings.long_break_time) else: self.start_break_period(self.settings.short_break_time) self._update_pomodoro_count() else: self.time -= 1 self.work_time += 1 else: if self.state == State.BREAK and self.time == 0: # end of break period star new short work period self.start_work_period() else: self.time -= 1 self._update_time() return True def start_break_period(self, break_time): self.state = State.BREAK self.time = break_time # play a sound song = pyglet.media.load(get_resource(self.settings.sound_path)) song.play() self.break_screen.show() # change button to skip self._update_item( 'mni_start', get_resource(PoResources.ICON_SKIP), 'Skip') self.main_window.update(self.state, self.btn_state) def start_work_period(self, with_sound=True): self.state = State.WORK self.btn_state = State.RUN self.time = self.settings.short_work_time # play a sound if with_sound: song = pyglet.media.load(get_resource(self.settings.sound_path)) song.play() self.break_screen.hide() # # change button to play self._update_item( 'mni_start', get_resource(PoResources.ICON_STOP), 'Stop') self.main_window.update(self.state, self.btn_state) def get_tray_menu(self): return self.menu def right_click_event_statusicon(self, icon, button, time): self.get_tray_menu() def pos(menu, aicon): return (Gtk.StatusIcon.position_menu(menu, aicon)) self.menu.popup(None, None, pos, icon, button, time) def on_mni_start_activate(self, item=None): # if timer state is paused, start/resume counting if self.btn_state != State.RUN: self.start_work_period(False) else: self.reset() def mni_show_window_activate(self, item): self.main_window.show() def mni_setting_activate(self, item): if not hasattr(self, 'setting_dialog'): self.setting_dialog = SettingDialog() result = self.setting_dialog.show() print result def on_mni_quit_activate(self, item): Gtk.main_quit()
class MainMenu(QMenu): def __init__(self, parent=None): super(MainMenu, self).__init__() self.createActions() #self.createMenus() self.translateActions() self.setting_dialog = SettingDialog(self) self.playmode_dialog = PlayModeDialog(self) def show_setting_dialog(self): self.setting_dialog.exec_() def show_help(self): pass def show_about_me(self): #QtGui.QMessageBox.about(self, "About Me", # "Copyright@2015 qomolangmaice") QtGui.QMessageBox.about( self, "About Me", """ <HTML> <p><b>This demo shows use of <c>QTableWidget</c> with custom handling for individual cells.</b></p> <p>Using a customized table item we make it possible to have dynamic output in different cells. The content that is implemented for this particular demo is: <ul> <li>Adding two cells.</li> <li>Subtracting one cell from another.</li> <li>Multiplying two cells.</li> <li>Dividing one cell with another.</li> <li>Summing the contents of an arbitrary number of cells.</li> </HTML> """) def show_about_qt(self): pass def show_play_mode(self): self.playmode_dialog.exec_() def auto_play_mode(self): pass def repeat_single_mode(self): pass def repeat_all_mode(self): pass def shuffle_mode(self): pass def createActions(self): self.act_setting = QAction("Setting", self, statusTip="", triggered=self.show_setting_dialog) self.act_play_mode = QAction("PlayMode", self, statusTip="", triggered=self.show_play_mode) self.act_help = QAction(self) self.act_about_me = QAction("About me", self, statusTip="", triggered=self.show_about_me) self.act_about_qt = QAction("About Qt", self, statusTip="", triggered=self.show_about_qt) self.act_about_qt.triggered.connect(QtGui.qApp.aboutQt) self.act_setting.setIcon(QIcon("")) self.act_help.setIcon(QIcon("")) self.act_about_me.setIcon(QIcon("")) self.act_about_qt.setIcon(QIcon("")) # Add menu item self.addAction(self.act_setting) self.addAction(self.act_play_mode) self.addAction(self.act_help) self.addSeparator() self.addAction(self.act_about_me) self.addAction(self.act_about_qt) #def createMenus(self): # self.play_mode = self.menubar_play_mode.addMenu("&PlayMode") # self.play_mode.addAction(self.auto_play_mode) # self.play_mode.addAction(self.repeat_single_mode) # self.play_mode.addAction(self.repeat_all_mode) # self.play_mode.addAction(self.shuffle_mode) def translateActions(self): self.act_setting.setText(u"设置") self.act_play_mode.setText(u"播放模式") self.act_help.setText(u"帮助") self.act_about_me.setText(u"关于我") self.act_about_qt.setText(u"关于Qt")