예제 #1
0
파일: main.py 프로젝트: zeionara/algorithms
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)
예제 #2
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)
예제 #3
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)
예제 #4
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.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)
예제 #5
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