Example #1
0
class TPBattStat():
  def __init__(self, mode, forceDelay=None, forceIconSize=None):
    self.mode = mode
    self.forceDelay = forceDelay

    self.prefs = Prefs()
    self.battStatus = BattStatus(self.prefs)
    self.actions = Actions(self.prefs, self.battStatus)
    if self.mode == "gtk" or self.mode == "prefs":
      self.gui = Gui(self.prefs, self.battStatus)
    elif self.mode == "json" or self.mode == "dzen":
      self.guiMarkupPrinter = GuiMarkupPrinter(
        self.prefs, self.battStatus, forceIconSize)
      
  def getGui(self):
    return self.gui
  def startUpdate(self):
    self.curDelay = -1
    self.update()
  def update(self):
    try:
      self.prefs.update()
    except Exception as e:
      print 'ignoring prefs'
      print e.message
    if self.forceDelay != None:
      self.prefs['delay'] = self.forceDelay
    self.battStatus.update(self.prefs)

    self.actions.performActions()
    if self.mode == "gtk":
      self.gui.update()
    elif self.mode == "json" or self.mode == "dzen":
      try:
        if self.mode == "json":
          markup = self.guiMarkupPrinter.getMarkupJson()
        elif self.mode == "dzen":
          markup = self.guiMarkupPrinter.getMarkupDzen()
        print markup
        sys.stdout.flush()
      except IOError, e:
        print >> sys.stderr, "STDOUT is broken, assuming external gui is dead"
        sys.exit(1)

    if self.prefs['delay'] != self.curDelay:
      self.curDelay = self.prefs['delay']
      if self.curDelay <= 0:
        self.curDelay = 1000
      gobject.timeout_add(self.curDelay, self.update)
      return False
    else:
      return True
Example #2
0
def _prompt_to_save_file(parent, default_name, file_filter):
        filename = _validate_filename(default_name)
        prefs = Prefs()
        dialog = wx.FileDialog(
            parent,
            message="Save As",
            defaultDir=prefs.download_dir,
            defaultFile=filename,
            wildcard=file_filter,
            style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT,
        )
        destination = None
        if dialog.ShowModal() == wx.ID_OK:
            destination = dialog.GetPath()
            prefs.download_dir = os.path.dirname(destination)
            prefs.save()
            _g_logger.info("Save as: {0}".format(destination))
        dialog.Destroy()
        return destination
Example #3
0
def main():

    quantity = 0

    try:
        quantity = int(sys.argv[1])
    except IndexError:
        print(INVALID_QUANTITY_MSG)
        return
    except ValueError:
        print(INVALID_QUANTITY_MSG)
        return

    free_men = FreeMan.get_free_men_list(quantity)
    free_men.check()

    man_prefs = Prefs(quantity)
    man_prefs.init_with_random_values()

    print("Man prefs:")
    man_prefs.show()

    #print()

    #ordered_prefs = OrderedPrefs.from_prefs(man_prefs)
    #ordered_prefs.show()

    man_currents = create_plain_array(quantity, 0)

    woman_prefs = OrderedPrefs(quantity)
    woman_prefs.init_with_random_values()

    print("Woman prefs:")
    woman_prefs.show()

    woman_partners = create_plain_array(quantity, quantity)

    while (free_men):
        man_id = free_men.id
        woman_id = man_prefs.get_value(man_id, man_currents[man_id])
        man_currents[man_id] += 1
        groom_id = woman_partners[woman_id]

        if (groom_id >= quantity):
            woman_partners[woman_id] = man_id
            free_men = free_men.next
            continue
        elif (woman_prefs.get_value(woman_id, man_id) < woman_prefs.get_value(
                woman_id, groom_id)):
            woman_partners[woman_id] = man_id
            free_men = free_men.next
            if free_men:
                free_men.add(groom_id)
            else:
                free_men = FreeMan(groom_id, None)

    print("Result:")
    print(woman_partners)
Example #4
0
  def __init__(self, mode, forceDelay=None, forceIconSize=None):
    self.mode = mode
    self.forceDelay = forceDelay

    self.prefs = Prefs()
    self.battStatus = BattStatus(self.prefs)
    self.actions = Actions(self.prefs, self.battStatus)
    if self.mode == "gtk" or self.mode == "prefs":
      self.gui = Gui(self.prefs, self.battStatus)
    elif self.mode == "json" or self.mode == "dzen":
      self.guiMarkupPrinter = GuiMarkupPrinter(
        self.prefs, self.battStatus, forceIconSize)
Example #5
0
    def run(self):
        """
        Sets up the OpenSRS connection and runs the decorated function.
        """
        # Moving import of OpenSRS here so this module can be used by
        # distribute for entry_point creation prior to dependency
        # install
        from opensrs import OpenSRS
        from prefs import Prefs

        self.args = self.parser.parse_args()
        self.prefs = Prefs(self.args.preferences)
        self.auth_dict = {
            'username': self.prefs.username,
            'private_key': self.prefs.private_key,
            'test': self.args.test,
        }
        self.opensrs = OpenSRS(**self.auth_dict)
        self.func(self)
Example #6
0
    def __init__(self, parent, title, db, defaultPrefs, capabilities):
        wx.Frame.__init__(self,
                          parent,
                          -1,
                          title,
                          style=wx.NO_BORDER | wx.FRAME_NO_TASKBAR
                          | wx.CLIP_CHILDREN)

        self.db = db
        self.capabilities = capabilities
        self.data = []

        self.options = None
        self.about = None

        self.prefs = Prefs(self.db, defaultPrefs)

        # Don't allow the user to shrink the window below these dimensions
        self.minYSize = 30
        self.minXSize = 50

        # This is the main graph
        self.panel = wx.Panel(self, style=wx.BORDER_SIMPLE)
        self.panel.Bind(wx.EVT_MOTION, self.OnPanelMove)
        self.panel.Bind(wx.EVT_LEFT_DOWN, self.OnPanelDown)
        self.panel.Bind(wx.EVT_LEFT_UP, self.OnPanelUp)
        self.panel.Bind(wx.EVT_PAINT, self.OnPanelPaint)

        # This is the label below the graph showing numeric values
        self.label = wx.StaticText(self,
                                   -1,
                                   "-",
                                   style=wx.ST_NO_AUTORESIZE | wx.BORDER_SIMPLE
                                   | wx.ALIGN_CENTER)
        self.label.Bind(wx.EVT_LEFT_DOWN, self.OnLabelDown)
        self.Bind(wx.EVT_MOTION, self.OnLabelMove)
        self.Bind(wx.EVT_LEFT_UP, self.OnLabelUp)
        self.label.SetCursor(wx.Cursor(wx.CURSOR_SIZENWSE))
        self.label.SetFont(
            wx.Font(8, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL,
                    wx.FONTWEIGHT_NORMAL))

        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(self.panel, 1, flag=wx.EXPAND)
        box.Add((10, 1), 0)
        box.Add(self.label, 0, flag=wx.EXPAND)

        # Restore the position of the graph from last time
        self.SetPosition(self.prefs.GetObj('position'))

        # If you remove a monitor or replace with a lower resolution one, it is possible
        # that the preferences specify an x,y position that is off screen
        # This rough code will reset the position assuming that
        #   - the monitors are placed left to right (not on top of each other)
        #   - the rightmost monitor has the least resolution
        #   - bitmeter-desktop client is on the rightmost screen normally
        displays = (wx.Display(i) for i in range(wx.Display.GetCount()))
        maxX = 0
        maxY = 10000
        for v in displays:
            maxX += v.GetGeometry().GetSize().width
            if maxY > v.GetGeometry().GetSize().height:
                maxY = v.GetGeometry().GetSize().height

        PROPORTION = 4  # Is allowed to be a little off screen
        resetPosition = False
        farRight = self.GetPosition().x + self.GetSize().width / PROPORTION
        if farRight > maxX:
            resetPosition = True
            print('Reset position due to out of bounds x position')
        farDown = self.GetPosition().y + self.GetSize().height / PROPORTION
        if farDown > maxY:
            resetPosition = True
            print('Reset position due to out of bounds y position')

        if resetPosition:
            self.SetPosition((100, 100))

        self.OnPrefsUpdated()

        self.SetSizer(box)
        self.Fit()
        self.SetSize(self.prefs.GetObj('size'))

        # We update the graph each second with new data
        self.timer = wx.Timer(self)
        self.timer.Start(1000)
        self.Bind(wx.EVT_TIMER, self.OnTimer)

        self.InitBuffer()
        self.Bind(wx.EVT_IDLE, self.OnIdle)

        # Find the file-system location where we are running from
        encoding = sys.getfilesystemencoding()
        if hasattr(sys, "frozen"):
            self.modulePath = os.path.dirname(sys.executable)
        else:
            self.modulePath = os.path.dirname(__file__)

        iconPath = os.path.join(self.modulePath, "resources", "bitmeter.ico")
        icon = wx.Icon(iconPath, wx.BITMAP_TYPE_ICO)

        # The menu can be accessed from the main graph, and from the tray icon
        self.popupmenu = wx.Menu()
        self.trayIcon = TrayIcon(self, self.popupmenu, icon)

        # Hide Graph option removed - no tray icon shown on Ubuntu 18.04, not relevant
        # self.showHideMain = self.popupmenu.Append(-1, _("Hide Graph"))
        # self.Bind(wx.EVT_MENU, self.ToggleGraph)
        # self.trayIcon.Bind(wx.EVT_MENU, self.ToggleGraph)

        # Menu item to open the Options dialog
        options = self.popupmenu.Append(-1, _("Options"))
        self.Bind(wx.EVT_MENU, self.OnMenuOptions, options)
        self.trayIcon.Bind(wx.EVT_MENU, self.OnMenuOptions, options)

        # Menu item to open the Web Interface
        webInterface = self.popupmenu.Append(-1, _("Web Interface"))
        self.Bind(wx.EVT_MENU, self.OnMenuWebInterface, webInterface)
        self.trayIcon.Bind(wx.EVT_MENU, self.OnMenuWebInterface, webInterface)

        # Need this to build the web interface url
        self.webPort = self.db.GetConfigValue('web.port', 2605)

        # Menu item to open the About dialog
        about = self.popupmenu.Append(-1, _("About"))
        self.Bind(wx.EVT_MENU, self.OnMenuAbout, about)
        self.trayIcon.Bind(wx.EVT_MENU, self.OnMenuAbout, about)

        self.popupmenu.AppendSeparator()

        # Menu item to quit he application
        exit = self.popupmenu.Append(-1, _("Exit"))
        self.Bind(wx.EVT_MENU, self.OnMenuExit, exit)
        self.trayIcon.Bind(wx.EVT_MENU, self.OnMenuExit, exit)

        self.Bind(wx.EVT_CONTEXT_MENU, self.OnShowPopup)
        self.Bind(wx.EVT_CLOSE, self.OnClose)
Example #7
0
class MyFrame(wx.Frame):
    def __init__(self, parent, title, db, defaultPrefs, capabilities):
        wx.Frame.__init__(self,
                          parent,
                          -1,
                          title,
                          style=wx.NO_BORDER | wx.FRAME_NO_TASKBAR
                          | wx.CLIP_CHILDREN)

        self.db = db
        self.capabilities = capabilities
        self.data = []

        self.options = None
        self.about = None

        self.prefs = Prefs(self.db, defaultPrefs)

        # Don't allow the user to shrink the window below these dimensions
        self.minYSize = 30
        self.minXSize = 50

        # This is the main graph
        self.panel = wx.Panel(self, style=wx.BORDER_SIMPLE)
        self.panel.Bind(wx.EVT_MOTION, self.OnPanelMove)
        self.panel.Bind(wx.EVT_LEFT_DOWN, self.OnPanelDown)
        self.panel.Bind(wx.EVT_LEFT_UP, self.OnPanelUp)
        self.panel.Bind(wx.EVT_PAINT, self.OnPanelPaint)

        # This is the label below the graph showing numeric values
        self.label = wx.StaticText(self,
                                   -1,
                                   "-",
                                   style=wx.ST_NO_AUTORESIZE | wx.BORDER_SIMPLE
                                   | wx.ALIGN_CENTER)
        self.label.Bind(wx.EVT_LEFT_DOWN, self.OnLabelDown)
        self.Bind(wx.EVT_MOTION, self.OnLabelMove)
        self.Bind(wx.EVT_LEFT_UP, self.OnLabelUp)
        self.label.SetCursor(wx.Cursor(wx.CURSOR_SIZENWSE))
        self.label.SetFont(
            wx.Font(8, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL,
                    wx.FONTWEIGHT_NORMAL))

        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(self.panel, 1, flag=wx.EXPAND)
        box.Add((10, 1), 0)
        box.Add(self.label, 0, flag=wx.EXPAND)

        # Restore the position of the graph from last time
        self.SetPosition(self.prefs.GetObj('position'))

        # If you remove a monitor or replace with a lower resolution one, it is possible
        # that the preferences specify an x,y position that is off screen
        # This rough code will reset the position assuming that
        #   - the monitors are placed left to right (not on top of each other)
        #   - the rightmost monitor has the least resolution
        #   - bitmeter-desktop client is on the rightmost screen normally
        displays = (wx.Display(i) for i in range(wx.Display.GetCount()))
        maxX = 0
        maxY = 10000
        for v in displays:
            maxX += v.GetGeometry().GetSize().width
            if maxY > v.GetGeometry().GetSize().height:
                maxY = v.GetGeometry().GetSize().height

        PROPORTION = 4  # Is allowed to be a little off screen
        resetPosition = False
        farRight = self.GetPosition().x + self.GetSize().width / PROPORTION
        if farRight > maxX:
            resetPosition = True
            print('Reset position due to out of bounds x position')
        farDown = self.GetPosition().y + self.GetSize().height / PROPORTION
        if farDown > maxY:
            resetPosition = True
            print('Reset position due to out of bounds y position')

        if resetPosition:
            self.SetPosition((100, 100))

        self.OnPrefsUpdated()

        self.SetSizer(box)
        self.Fit()
        self.SetSize(self.prefs.GetObj('size'))

        # We update the graph each second with new data
        self.timer = wx.Timer(self)
        self.timer.Start(1000)
        self.Bind(wx.EVT_TIMER, self.OnTimer)

        self.InitBuffer()
        self.Bind(wx.EVT_IDLE, self.OnIdle)

        # Find the file-system location where we are running from
        encoding = sys.getfilesystemencoding()
        if hasattr(sys, "frozen"):
            self.modulePath = os.path.dirname(sys.executable)
        else:
            self.modulePath = os.path.dirname(__file__)

        iconPath = os.path.join(self.modulePath, "resources", "bitmeter.ico")
        icon = wx.Icon(iconPath, wx.BITMAP_TYPE_ICO)

        # The menu can be accessed from the main graph, and from the tray icon
        self.popupmenu = wx.Menu()
        self.trayIcon = TrayIcon(self, self.popupmenu, icon)

        # Hide Graph option removed - no tray icon shown on Ubuntu 18.04, not relevant
        # self.showHideMain = self.popupmenu.Append(-1, _("Hide Graph"))
        # self.Bind(wx.EVT_MENU, self.ToggleGraph)
        # self.trayIcon.Bind(wx.EVT_MENU, self.ToggleGraph)

        # Menu item to open the Options dialog
        options = self.popupmenu.Append(-1, _("Options"))
        self.Bind(wx.EVT_MENU, self.OnMenuOptions, options)
        self.trayIcon.Bind(wx.EVT_MENU, self.OnMenuOptions, options)

        # Menu item to open the Web Interface
        webInterface = self.popupmenu.Append(-1, _("Web Interface"))
        self.Bind(wx.EVT_MENU, self.OnMenuWebInterface, webInterface)
        self.trayIcon.Bind(wx.EVT_MENU, self.OnMenuWebInterface, webInterface)

        # Need this to build the web interface url
        self.webPort = self.db.GetConfigValue('web.port', 2605)

        # Menu item to open the About dialog
        about = self.popupmenu.Append(-1, _("About"))
        self.Bind(wx.EVT_MENU, self.OnMenuAbout, about)
        self.trayIcon.Bind(wx.EVT_MENU, self.OnMenuAbout, about)

        self.popupmenu.AppendSeparator()

        # Menu item to quit he application
        exit = self.popupmenu.Append(-1, _("Exit"))
        self.Bind(wx.EVT_MENU, self.OnMenuExit, exit)
        self.trayIcon.Bind(wx.EVT_MENU, self.OnMenuExit, exit)

        self.Bind(wx.EVT_CONTEXT_MENU, self.OnShowPopup)
        self.Bind(wx.EVT_CLOSE, self.OnClose)

    def ToggleGraph(self, event):
        # Show/Hide the graph
        self.Show(not self.IsShown())
        if self.IsShown():
            self.showHideMain.SetText(_('Hide Graph'))
        else:
            self.showHideMain.SetText(_('Show Graph'))

    def FormatScale(self, scale):
        # This value gets displayed to the left of the download and upload amounts
        return "{:,}".format(int(scale / BYTES_PER_K)).replace(',',
                                                               ' ') + ' KB'

    def FormatAmounts(self, dl, ul):
        # This value gets displayed below the main graph
        return "D: %.2f U: %.2f" % (float(dl) / 1000, float(ul) / 1000)

    def OnShowPopup(self, event):
        pos = event.GetPosition()
        pos = self.panel.ScreenToClient(pos)
        self.panel.PopupMenu(self.popupmenu, pos)

    def OnMenuWebInterface(self, event):
        # Open the web interface in the default browser
        webbrowser.open("http://localhost:" + str(self.webPort) +
                        "/index.html")

    def OnMenuAbout(self, event):
        # Open the About dialog
        self.about = AboutDialog(VERSION)
        self.about.ShowModal()
        self.about.Destroy()
        self.about = None

    def OnMenuExit(self, event):
        # Close all open windows
        if self.options:
            self.options.Close()
        if self.about:
            self.about.Close()
        self.Close()

    def OnClose(self, event):
        # Store the current size/position of the graph before exiting
        self.prefs.SetObj('size', self.GetSize())
        self.prefs.SetObj('position', self.GetPosition())
        self.prefs.Save()

        self.trayIcon.RemoveIcon()
        self.trayIcon.Destroy()
        self.Destroy()

    def OnPrefsUpdated(self):
        # Callback invoked from the Options dialog when the user clicks 'OK'
        if self.capabilities['opacity']:
            self.SetTransparent(int(self.prefs.GetNum('opacity') * 2.55))

        self.SetBackgroundColour(self.prefs.GetCol('bgcolour'))

        self.dlPen = wx.Pen(self.prefs.GetCol('dlcolour'), 1)
        self.ulPen = wx.Pen(self.prefs.GetCol('ulcolour'), 1)
        self.olPen = wx.Pen(self.prefs.GetCol('olcolour'), 1)
        self.scale = self.prefs.GetNum('scale')

        if not (self.prefs.GetObj('float') ^
                (not self.HasFlag(wx.STAY_ON_TOP))):
            # Set the 'Stay On Top' flag to the appropriate value
            self.ToggleWindowStyle(wx.STAY_ON_TOP)

        if self.capabilities['clickthru']:
            # Windows only, window passes all mouse clicks to whatever is underneath
            if not (self.prefs.GetObj('clickthru') ^
                    (not self.HasFlag(wx.TRANSPARENT_WINDOW))):
                self.ToggleWindowStyle(wx.TRANSPARENT_WINDOW)

    def OnMenuOptions(self, event):
        # Open the Options dialog
        self.options = OptionsDialog(self, self.prefs, self.capabilities,
                                     self.OnPrefsUpdated)
        self.options.ShowModal()
        self.options.Destroy()
        self.options = None

    def OnPanelDown(self, event):
        # Mouse down over the graph means we want to drag the window
        self._panelDownPos = event.GetPosition()
        if not self.panel.HasCapture():
            self.panel.CaptureMouse()

    def OnPanelMove(self, event):
        if event.Dragging() and event.LeftIsDown():
            # The window is being dragged
            pos = event.GetPosition()
            displacement = self._panelDownPos - pos
            self.SetPosition(self.GetPosition() - displacement)
            print('pos:', self.GetPosition())

    def OnPanelUp(self, event):
        # Stop dragging the window
        if self.panel.HasCapture():
            self.panel.ReleaseMouse()

    def GetEventYInWindow(self, event):
        # Calculate the y-coordinate of a mouse click within the label, relative to the whole window
        return self.GetSize().height - self.label.GetSize(
        ).height + event.GetPosition().y

    def OnLabelDown(self, event):
        # Mouse down in the label means we want to resize the window
        self._prevXInWindow = event.GetPosition().x
        self._prevYInWindow = self.GetEventYInWindow(event)
        self._origWidth = self.GetSize().width
        self._origHeight = self.GetSize().height

        if not self.HasCapture():
            self.CaptureMouse()

    def OnLabelMove(self, event):
        # Mouse move in the label means we should resize the window
        if event.Dragging():
            pos = event.GetPosition()
            displacementX = self._prevXInWindow - pos.x
            displacementY = self._prevYInWindow - pos.y
            newXSize = self._origWidth - displacementX
            newYSize = self._origHeight - displacementY
            if newYSize < self.minYSize:
                newYSize = self.minYSize
            if newXSize < self.minXSize:
                newXSize = self.minXSize
            self.SetSize(wx.Size(newXSize, newYSize))
            self.reInitBuffer = True

    def OnLabelUp(self, event):
        # Mouse up in the label means we want to stop resizing
        if self.HasCapture():
            self.ReleaseMouse()

    def OnPanelPaint(self, event):
        # Paint the graph with whatever is in our in-memory buffer
        dc = wx.BufferedPaintDC(self.panel, self.buffer)

    def OnIdle(self, event):
        if self.reInitBuffer:
            # We have new data to be displayed
            self.InitBuffer()
            self.Refresh(False)

    def InitBuffer(self):
        # Draw the next graph to be displayed onto the in-memory buffer
        size = self.panel.GetSize()
        self.buffer = wx.Bitmap(size.width, size.height)
        dc = wx.BufferedDC(None, self.buffer)
        dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
        dc.Clear()
        self.DrawLines(dc)
        self.reInitBuffer = False

    def DrawLines(self, dc):
        # Draw the graph using the current upload/download values
        h = self.panel.GetSize().height
        w = self.panel.GetSize().width
        now = time.time()
        ts = 0

        self.autoScale = self.scale * BYTES_PER_K
        for d in self.data:
            if d[1] > self.autoScale:
                self.autoScale = d[1]
            if d[2] > self.autoScale:
                self.autoScale = d[2]

        for d in self.data:
            ts = d[0]
            dl = d[1]
            ul = d[2]

            # For the graph to move left to right
            # x = now - ts - 1
            # For the graph to move right to left
            x = ts - now + 1 + w
            y0 = h
            yDl = y0 - dl * h / (self.autoScale)
            yUl = y0 - ul * h / (self.autoScale)

            if dl < ul:
                dc.SetPen(self.olPen)
                dc.DrawLine(x, y0, x, yDl)
                dc.SetPen(self.ulPen)
                dc.DrawLine(x, yDl, x, yUl)
            else:
                dc.SetPen(self.olPen)
                dc.DrawLine(x, y0, x, yUl)
                dc.SetPen(self.dlPen)
                dc.DrawLine(x, yUl, x, yDl)

    def OnTimer(self, event):
        # Query the database to get the latest values
        now = int(time.time())
        results = self.db.GetData(now - self.GetSize().width, now)

        # Store the results and set the flag indicating that the graph should be re-drawn
        self.data = results[1]
        self.reInitBuffer = True
        self.panel.Refresh()

        self.label.SetLabel(
            self.FormatScale(self.autoScale) + '    ' +
            self.FormatAmounts(results[0][0], results[0][1]))
    def __init__(self, parent, title, db, defaultPrefs, capabilities):
        wx.Frame.__init__(self,
                          parent,
                          -1,
                          title,
                          style=wx.NO_BORDER | wx.FRAME_NO_TASKBAR
                          | wx.CLIP_CHILDREN)

        self.db = db
        self.capabilities = capabilities
        self.data = []

        self.options = None
        self.about = None

        self.prefs = Prefs(self.db, defaultPrefs)

        # Don't allow the user to shrink the window below these dimensions
        self.minYSize = 30
        self.minXSize = 50

        # This is the main graph
        self.panel = wx.Panel(self, style=wx.BORDER_SIMPLE)
        self.panel.Bind(wx.EVT_MOTION, self.OnPanelMove)
        self.panel.Bind(wx.EVT_LEFT_DOWN, self.OnPanelDown)
        self.panel.Bind(wx.EVT_LEFT_UP, self.OnPanelUp)
        self.panel.Bind(wx.EVT_PAINT, self.OnPanelPaint)

        # This is the label below the graph showing numeric values
        self.label = wx.StaticText(self,
                                   -1,
                                   "-",
                                   style=wx.ST_NO_AUTORESIZE | wx.BORDER_SIMPLE
                                   | wx.ALIGN_CENTER)
        self.label.Bind(wx.EVT_LEFT_DOWN, self.OnLabelDown)
        self.Bind(wx.EVT_MOTION, self.OnLabelMove)
        self.Bind(wx.EVT_LEFT_UP, self.OnLabelUp)
        self.label.SetCursor(wx.StockCursor(wx.CURSOR_SIZENWSE))
        self.label.SetFont(
            wx.Font(8, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL,
                    wx.FONTWEIGHT_NORMAL))

        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(self.panel, 1, flag=wx.EXPAND)
        box.Add((10, 1), 0)
        box.Add(self.label, 0, flag=wx.EXPAND)

        # Restore the position of the graph from last time
        self.SetPosition(self.prefs.GetObj('position'))
        self.OnPrefsUpdated()

        self.SetSizer(box)
        self.Fit()
        self.SetSize(self.prefs.GetObj('size'))

        # We update the graph each second with new data
        self.timer = wx.Timer(self)
        self.timer.Start(1000)
        self.Bind(wx.EVT_TIMER, self.OnTimer)

        self.InitBuffer()
        self.Bind(wx.EVT_IDLE, self.OnIdle)

        # Find the file-system location where we are running from
        encoding = sys.getfilesystemencoding()
        if hasattr(sys, "frozen"):
            self.modulePath = os.path.dirname(sys.executable)
        else:
            self.modulePath = os.path.dirname(__file__)

        iconPath = os.path.join(self.modulePath, "resources", "bitmeter.ico")
        icon = wx.Icon(iconPath, wx.BITMAP_TYPE_ICO)

        # The menu can be accessed from the main graph, and from the tray icon
        self.popupmenu = wx.Menu()
        self.trayIcon = TrayIcon(self, self.popupmenu, icon)
        self.showHideMain = self.popupmenu.Append(-1, _("Hide Graph"))
        self.Bind(wx.EVT_MENU, self.ToggleGraph)
        self.trayIcon.Bind(wx.EVT_MENU, self.ToggleGraph)

        # Menu item to open the Options dialog
        options = self.popupmenu.Append(-1, _("Options"))
        self.Bind(wx.EVT_MENU, self.OnMenuOptions, options)
        self.trayIcon.Bind(wx.EVT_MENU, self.OnMenuOptions, options)

        # Menu item to open the Web Interface
        webInterface = self.popupmenu.Append(-1, _("Web Interface"))
        self.Bind(wx.EVT_MENU, self.OnMenuWebInterface, webInterface)
        self.trayIcon.Bind(wx.EVT_MENU, self.OnMenuWebInterface, webInterface)

        # Need this to build the web interface url
        self.webPort = self.db.GetConfigValue('web.port', 2605)

        # Menu item to open the About dialog
        about = self.popupmenu.Append(-1, _("About"))
        self.Bind(wx.EVT_MENU, self.OnMenuAbout, about)
        self.trayIcon.Bind(wx.EVT_MENU, self.OnMenuAbout, about)

        self.popupmenu.AppendSeparator()

        # Menu item to quit he application
        exit = self.popupmenu.Append(-1, _("Exit"))
        self.Bind(wx.EVT_MENU, self.OnMenuExit, exit)
        self.trayIcon.Bind(wx.EVT_MENU, self.OnMenuExit, exit)

        self.Bind(wx.EVT_CONTEXT_MENU, self.OnShowPopup)
        self.Bind(wx.EVT_CLOSE, self.OnClose)
Example #9
0
from main import is_realized, locale_init, reload_configuration
from signalmanager import SignalManager
from ui_utils import MainWidgets, InterfacePrefs
from search import SearchPrefs
from templates import TemplatePrefs

__all__ = [
    "Plugin", "is_realized", "locale_init", "reload_configuration",
    "main_widgets", "interface_prefs", "app", "general_prefs", "search_prefs",
    "template_prefs", "tool_prefs", "signals"
]

# Geany's application data fields
app = App()

# Import GTK+ widgets that are part of Geany's UI
main_widgets = MainWidgets()

# Preferences
general_prefs = Prefs()  # GeanyData->prefs but name clashes with module
interface_prefs = InterfacePrefs()
search_prefs = SearchPrefs()
template_prefs = TemplatePrefs()
tool_prefs = ToolPrefs()

# GObject to connect signal handlers on and which emits signals.
signals = SignalManager()

import plugin
from plugin import Plugin
Example #10
0
 def __init__(self, quantity):
     Prefs.__init__(self, quantity)
Example #11
0
				server_name = self.parse_single(game_ping_data)
				server_dict = self.parse_single(game_info_data)
				server_dict["socket"] = server
				self.server_info[server_name] = server_dict
				print("MSG: {0} sucessfully parsed.".format(server_name))
				if len(server_dict["players"]):
					print("MSG: Players: "+", ".join(server_dict["players"]))




if __name__ == "__main__":
	error_count = 0
	##retrieve prefs.ini as dict
	pref_obj = Prefs("prefs.ini")
	if pref_obj.check_prefs():
		pref_dict = pref_obj.open_prefs()
		
		##setup error logger for __main__
		log = Logger(pref_dict["errors"])

		if "stats" in pref_dict:
			stats = Stats(pref_dict)

		##setup webpage editor object
		webpage = Webpage(pref_dict)
		while True:
			try:
				l_client = LegionsClient()
				l_client.query_master()