예제 #1
0
파일: viui.py 프로젝트: westvind/vintel
    def __init__(self, path_to_logs, trayicon):
        """ systems = list of system-objects creted by dotlan.py
        """
        QMainWindow.__init__(self)
        uic.loadUi(resource_path('vi/ui/MainWindow.ui'), self)
        self.setWindowTitle("Vintel " + VERSION)
        self.setWindowIcon(
            QtGui.QIcon(resource_path("vi/ui/res/logo_small.png")))
        self.path_to_logs = path_to_logs
        self.trayicon = trayicon
        self.trayicon.activated.connect(self.systray_activated)
        c = Cache()
        regionname = c.get_from_cache("regionname")
        if not regionname:
            regionname = "Providence"
        # is it a local map?
        svg = None
        try:
            with open(
                    resource_path("vi/ui/res/mapdata/{0}.svg".format(
                        regionname))) as svg_file:
                svg = svg_file.read()
        except Exception as e:
            pass

        try:
            self.dotlan = dotlan.Map(regionname, svg)
        except dotlan.DotlanException as e:
            QMessageBox.critical(None, "Error getting map", str(e),
                                 QMessageBox.Close)
            sys.exit(1)

        if self.dotlan.outdated_cache_error:
            e = self.dotlan.outdated_cache_error
            diatext = "I tried to get and process the data for the map "\
                "but something went wrong. To proceed I use the data I "\
                "have in my cache. This could be outdated.\nIf this problem "\
                "is permanent, there might be a change in the dotlan data "\
                "and VINTEL must be modified. Check for a newer version "\
                "and inform the maintainer.\n\nWhat went wrong: {0} {1}"\
                .format(type(e), str(e))
            QMessageBox.warning(None, "Using map from my cache", diatext,
                                QMessageBox.Ok)

        jumpbridge_url = c.get_from_cache("jumpbridge_url")
        self.set_jumpbridges(jumpbridge_url)
        self.init_map_position = None  # we read this after first rendering
        # self.systems = self.dotlan.systems
        self.chatentries = []

        self.kos_request_thread = KOSCheckerThread()
        self.kos_request_thread.kos_result.connect(self.show_kos_result)
        self.kos_request_thread.start()

        self.avatar_find_thread = AvatarFindThread()
        self.avatar_find_thread.avatar_update.connect(
            self.update_avatar_on_chatentry)
        self.avatar_find_thread.start()

        self.clipboard = QApplication.clipboard()
        self.clipboard.clear(mode=self.clipboard.Clipboard)
        self.old_clipboard_content = (0, "")
        self.clipboard.changed.connect(self.clipboard_changed)

        self.zoomin.clicked.connect(self.zoomMapIn)
        self.zoomout.clicked.connect(self.zoomMapOut)
        self.actionStatistics.clicked.connect(
            self.dotlan.change_statistics_visibility)
        self.chat_large.clicked.connect(self.chat_larger)
        self.chat_small.clicked.connect(self.chat_smaller)
        self.jumpBridgesButton.clicked.connect(self.change_jumpbridge_view)
        self.sound_button.clicked.connect(self.show_sound_setup)

        self.actionInfo.triggered.connect(self.show_info)
        self.actionShow_Chat_Avatars.triggered.connect(
            self.change_show_avatars)
        self.actionAlways_on_top.triggered.connect(self.change_always_on_top)
        self.choose_chatrooms_button.triggered.connect(
            self.show_chatroom_chooser)
        self.choose_region_button.triggered.connect(self.show_region_chooser)
        self.action_show_chat.triggered.connect(self.change_chat_visibility)
        self.actionSound_Setup.triggered.connect(self.show_sound_setup)

        self.opacity_group = QActionGroup(self.menu)
        for i in (100, 80, 60, 40, 20):
            action = QAction("Opacity {0}%".format(i), None, checkable=True)

            if i == 100:
                action.setChecked(True)

            action.opacity = i / 100.0
            action.triggered.connect(self.change_opacity)

            self.opacity_group.addAction(action)
            self.menuTransparency.addAction(action)

        # map with menu =======================================================
        self.custom_content_page = MainWindowPage()
        self.custom_content_page.sig_link_clicked.connect(
            self.map_link_clicked)
        self.map.setPage(self.custom_content_page)
        self.map.page().set_svg(self.dotlan.svg_clean)

        self.map.contextmenu = TrayContextMenu(self.trayicon)

        def map_contextmenu_event(event):
            self.map.contextmenu.exec_(
                self.mapToGlobal(QPoint(event.x(), event.y())))

        self.map.contextMenuEvent = map_contextmenu_event
        # self.map.connect(self.map, Qt.SIGNAL("linkClicked(const QUrl&)"), self.map_link_clicked)
        # self.map.page().linkClicked.connect(self.map_link_clicked)
        # http://stackoverflow.com/questions/40747827/qwebenginepage-disable-links
        # end map =============================================================

        self.filewatcher_thread = filewatcher.FileWatcher(
            self.path_to_logs, 60 * 60 * 24)
        # self.connect(self.filewatcher_thread, QtCore.SIGNAL("fchange"), self.logfile_changed)
        self.filewatcher_thread.fchange.connect(self.logfile_changed)
        self.filewatcher_thread.start()

        if False:
            self.last_statistics_update = 0
            self.maptimer = QtCore.QTimer(self)
            # self.connect(self.maptimer, QtCore.SIGNAL("timeout()"), self.update_map)
            self.maptimer.timeout.connect(self.update_map)
            self.maptimer.start(1000)

        self.evetimer = QtCore.QTimer(self)
        # self.connect(self.maptimer, QtCore.SIGNAL("timeout()"), self.update_map)
        self.evetimer.timeout.connect(self.update_evetime)
        self.evetimer.start(1000)

        self.trayicon.sig_alarm_distance.connect(self.change_alarm_distance)
        self.trayicon.sig_change_frameless.connect(self.change_frameless)

        self.frameButton.clicked.connect(self.change_frameless)
        self.frameButton.setVisible(False)

        self.btn_night_mode.clicked.connect(self.toggle_nightmode)
        self.btn_night_mode.setCheckable(True)
        # self.btn_night_mode.setChecked(True)

        self.actionFrameless_Window.triggered.connect(self.change_frameless)

        self.is_frameless = None  # we need this because 2 places to change
        self.alarm_distance = 0
        self.actionActivate_Sound.triggered.connect(self.change_sound)

        if not sound.SOUND_AVAILABLE:
            self.change_sound(disable=True)
        else:
            self.change_sound()

        self.jumpbridgedata_button.triggered.connect(
            self.show_jumbridge_chooser)

        # load something from cache =====================================
        self.known_playernames = c.get_from_cache("known_playernames")
        if self.known_playernames:
            self.known_playernames = set(self.known_playernames.split(","))
        else:
            self.known_playernames = set()
        roomnames = c.get_from_cache("roomnames")
        if roomnames:
            roomnames = roomnames.split(",")
        else:
            roomnames = ("TheCitadel", "North Provi Intel")
            c.put_into_cache("roomnames", ",".join(roomnames),
                             60 * 60 * 24 * 365 * 5)

        self.set_sound_volume(
            75)  # default - maybe overwritten by the settings

        try:
            settings = c.get_from_cache("settings")
            if settings:
                settings = pickle.loads(base64.b64decode(settings))

                for setting in settings:
                    try:
                        if not setting[0]:
                            obj = self
                        else:
                            obj = getattr(self, setting[0])

                        getattr(obj, setting[1])(setting[2])
                    except Exception as e:
                        log.error(str(e))
        except Exception as e:
            self.trayicon.showMessage(
                "Can't remember",
                "Something went wrong when I load my last state:\n{0}".format(
                    str(e)), 1)
        # load cache ends ===============================================
        self.actionQuit.triggered.connect(self.close)
        self.trayicon.sig_quit.connect(self.close)

        self.chatparser = ChatParser(self.path_to_logs, roomnames,
                                     self.dotlan.systems)

        version_check_thread = drachenjaeger.NotifyNewVersionThread()
        version_check_thread.newer_version.connect(self.notify_newer_version)
        version_check_thread.run()
예제 #2
0
    def __init__(self, pathToLogs, pathToGameLogs, trayIcon, backGroundColor,
                 logging):

        QtWidgets.QMainWindow.__init__(self)
        self.cache = Cache()

        if backGroundColor:
            self.setStyleSheet("QWidget { background-color: %s; }" %
                               backGroundColor)
        uic.loadUi(resource_stream(__name__, 'MainWindow.ui'), self)
        self.setWindowTitle("Vintel " + vi.version.VERSION + "{dev}".format(
            dev="-SNAPSHOT" if vi.version.SNAPSHOT else ""))
        self.taskbarIconQuiescent = QIcon(
            resource_filename(__name__, 'res/logo_small.png'))
        self.taskbarIconWorking = QIcon(
            resource_filename(__name__, 'res/logo_small_green.png'))
        self.setWindowIcon(self.taskbarIconQuiescent)
        self.setFocusPolicy(QtCore.Qt.StrongFocus)

        self.pathToLogs = pathToLogs
        self.pathToGameLogs = pathToGameLogs
        self.mapTimer = QTimer(self)
        self.mapTimer.timeout.connect(self.updateMapView)
        self.clipboardTimer = QTimer(self)
        self.oldClipboardContent = ""
        self.trayIcon = trayIcon
        self.trayIcon.activated.connect(self.systemTrayActivated)
        self.clipboard = QtWidgets.QApplication.clipboard()
        self.clipboard.clear(mode=self.clipboard.Clipboard)
        self.alarmDistance = 0
        self.lastStatisticsUpdate = 0
        self.chatEntries = []
        self.frameButton.setVisible(False)
        self.scanIntelForKosRequestsEnabled = True
        self.initialMapPosition = None
        self.mapPositionsDict = {}
        self.deferedScrollPosition = None
        self.logging = logging
        # Load user's toon names
        self.knownPlayerNames = self.cache.getFromCache("known_player_names")
        if self.knownPlayerNames:
            self.knownPlayerNames = set(self.knownPlayerNames.split(","))
        else:
            self.knownPlayerNames = set()
            diagText = "Vintel scans EVE system logs and remembers your characters as they change systems.\n\nSome features (clipboard KOS checking, alarms, etc.) may not work until your character(s) have been registered. Change systems, with each character you want to monitor, while Vintel is running to remedy this."
            QMessageBox.warning(None, "Known Characters not Found", diagText,
                                QMessageBox.Ok)

        # Set up user's intel rooms
        roomnames = self.cache.getFromCache("room_names")
        if roomnames:
            roomnames = roomnames.split(",")
        else:
            roomnames = (u"TheCitadel", u"North Provi Intel",
                         u"North Catch Intel", "North Querious Intel")
            self.cache.putIntoCache("room_names", u",".join(roomnames),
                                    60 * 60 * 24 * 365 * 5)
        self.roomnames = roomnames

        # Disable the sound UI if sound is not available
        if not SoundManager().soundAvailable:
            self.changeSound(disable=True)
        else:
            self.changeSound()

        # Set up Transparency menu - fill in opacity values and make connections
        self.opacityGroup = QActionGroup(self.menu)
        for i in (100, 80, 60, 40, 20):
            action = QAction("Opacity {0}%".format(i), None, checkable=True)
            if i == 100:
                action.setChecked(True)
            action.opacity = i / 100.0
            action.triggered.connect(self.changeOpacity)
            self.opacityGroup.addAction(action)
            self.menuTransparency.addAction(action)

        #
        # Platform specific UI resizing - we size items in the resource files to look correct on the mac,
        # then resize other platforms as needed
        #
        if sys.platform.startswith("win32") or sys.platform.startswith(
                "cygwin"):
            font = self.statisticsButton.font()
            font.setPointSize(8)
            self.statisticsButton.setFont(font)
            self.jumpbridgesButton.setFont(font)
        elif sys.platform.startswith("linux"):
            pass

        self.wireUpUIConnections()
        self.recallCachedSettings()
        self.setupThreads()
        self.setupMap(True)